diff --git a/ChangeLog b/ChangeLog index 7e9d10654840..fbaf247d3848 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4185 +1,4209 @@ +2023-05-10 Simon J Gerraty + + * VERSION (_MAKE_VERSION): 20230510 + Merge with NetBSD make, pick up + o parse.c: don't print null filename in stack traces + o var.c: :mtime operate on each word in variable value + +2023-05-09 Simon J Gerraty + + * VERSION (_MAKE_VERSION): 20230509 + Merge with NetBSD make, pick up + o for.c: skip syntactically wrong .for loops + o var.c: allow for :gmtime=${mtime} + add :mtime[=timestamp] where timestamp is used if stat(2) + fails, if :mtime=error stat(2) failure causes error. + +2023-05-05 Simon J Gerraty + + * VERSION (_MAKE_VERSION): 20230504 + Merge with NetBSD make, pick up + o compat.c: fix compile on NetBSD 7.2 + o make.1: fix documentation of .PREFIX to match reality and POSIX + o unit-tests: improved var-scope-local + 2023-04-14 Simon J Gerraty * VERSION (_MAKE_VERSION): 20230414 Merge with NetBSD make, pick up o minor cleanup 2023-03-25 Simon J Gerraty * main.c: on some systems (eg OS/X) setting RLIMIT_NOFILE to unlimited results in an insane number (0x7fffffffffffffff). If BMAKE_NOFILE_MAX is defined, use that instead. 2023-03-22 Simon J Gerraty * VERSION (_MAKE_VERSION): 20230321 Merge with NetBSD make, pick up * make.1: document seemingly unexplained Error code 6. 2023-03-18 Simon J Gerraty * VERSION (_MAKE_VERSION): 20230317 Merge with NetBSD make, pick up o compat.c: CompatDeleteTarget skip .PHONY targets to be consistent with JobDeleteTarget. o job.c: fix memory leak in handling sysv :from=to modifiers 2023-03-04 Simon J Gerraty * VERSION (_MAKE_VERSION): 20230303 Merge with NetBSD make, pick up o several updated unit-tests 2023-02-22 Simon J Gerraty * VERSION (_MAKE_VERSION): 20230222 Merge with NetBSD make, pick up o unit tests for .MAKE.META.IGNORE_{FILTER,PATHS,PATTERNS} 2023-02-20 Simon J Gerraty * VERSION (_MAKE_VERSION): 20230218 Merge with NetBSD make, pick up o var.c: fix parsing of unevaluated subexpressions with unbalanced '{}' 2023-02-17 Simon J Gerraty * VERSION (_MAKE_VERSION): 20230215 Merge with NetBSD make, pick up o inline macros for some variable names o cond.c: reduce complexity of evaluating expressions 2023-02-08 Simon J Gerraty * VERSION (_MAKE_VERSION): 20230208 Merge with NetBSD make, pick up o var.c: always use SCOPE_GLOBAL for :_ to avoid problems when it has been used within conditional expressions 2023-01-27 Simon J Gerraty * VERSION (_MAKE_VERSION): 20230127 * install-sh: if making directories ensure umask is set to match mode. * Makefile: use DIRMODE for directories and NONBINMODE for man pages and mk files 2023-01-26 Simon J Gerraty * VERSION (_MAKE_VERSION): 20230126 Merge with NetBSD make, pick up o variables like .newline and .MAKE.{GID,PID,PPID,UID} should be read-only. 2023-01-23 Simon J Gerraty * VERSION (_MAKE_VERSION): 20230123 Merge with NetBSD make, pick up o .[NO]READONLY: for control of read-only variables o .SYSPATH: for controlling the path searched for makefiles 2023-01-20 Simon J Gerraty * VERSION (_MAKE_VERSION): 20230120 Merge with NetBSD make, pick up o allow for white-space between command specifiers @+- o add more details to warning 'Extra targets ignored' 2023-01-12 Simon J Gerraty * machine.sh: leverage os.sh rather than duplicate also dispence with the $OS.$MACHINE values - we have $HOST_TARGET for that purpose for the past decade or so. We invariably get MACHINE and MACHINE_ARCH at runtime anyway. 2023-01-02 Simon J Gerraty * VERSION (_MAKE_VERSION): 20230101 Merge with NetBSD make, pick up o cleanup comments, inline some LazyBuf_ methods o unit-tests/ add/improve comments in tests o make.1: sync list of built-in variables with reality sort list of built-in variables reduce indentation of the long list of variable names use consistent markup for boolean flags move description of .MAKE.MODE below the .MAKE.META block clarify in which case an expression may omit braces 2022-11-08 Simon J Gerraty * VERSION (_MAKE_VERSION): 20221024 Merge with NetBSD make, pick up o change return type of unlink_file back to int 2022-10-07 Simon J Gerraty * Makefile: Darwin and Linux can handle MANTARGET=man 2022-09-28 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220928 Merge with NetBSD make, pick up o fix more ignored returns from snprintf o compile with higher warnings 2022-09-26 Simon J Gerraty * main.c meta.c: do not ignore return from snprintf * meta.c strlcpy.c: we need prototype for strlcpy * sigcompat.c: fix unused function warnings 2022-09-24 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220924 Merge with NetBSD make, pick up o fix bug in .break reset of conditional depth o overhaul and simplify tracking of conditional depth 2022-09-17 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220912 Merge with NetBSD make, pick up o man page updates 2022-09-09 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220909 Merge with NetBSD make, pick up o update unit-tests to handle deprecation of egrep o cond.c: add more details to error message for numeric comparison * configure.in: allow for deprecation of egrep * Makefile: Linux can handle MANTARGET=man 2022-09-03 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220903 Merge with NetBSD make, pick up o job.c: fix handling of null bytes in output 2022-09-02 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220902 Merge with NetBSD make, pick up o Allow .break to terminate a .for loop early 2022-09-01 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220901 Merge with NetBSD make, pick up o var.c: fix out-of-bounds errors when parsing 2022-08-24 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220824 Merge with NetBSD make, pick up o var.c: revert change to modifier parsing that breaks shell variable references within ':@var@body@' o adjust unit-tests 2022-08-18 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220818 Merge with NetBSD make, pick up o fix exit status for '-q' (since 1994) 2022-08-08 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220808 Merge with NetBSD make, pick up o var.c: fix parsing of modifiers containing unbalanced subexpressions extract parsing of ':D' and ':U' modifiers into separate function 2022-07-26 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220726 * Auto-create objdir for bmake/unit-tests if appropriate 2022-07-24 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220724 Merge with NetBSD make, pick up o make.1: describe variable assignment and evaluation more precisely o parse.c: fix out-of-bounds read when parsing an invalid line o var.c: simplify return type of IsShortVarnameValid 2022-06-12 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220612 Merge with NetBSD make, pick up o allow to randomize build order of targets .MAKE.MODE += randomize-targets can help uncover dependency bugs within a makefile. o compat.c: rename Compat_Run to Compat_MakeAll o make.c: inline MakeBuildParent inline make_abort, improve error details o parse.c: reorganize Parse_Error fix memory leak in wildcard targets and sources separate cases in HandleDependencyTargetMundane extract HandleSingleDependencyTargetMundane rename loadfile to LoadFile split IncludeFile into separate functions condense code for searching a file in the paths fix off-by-one error in buffer for .WAIT nodes o str.c: condense Str_Match make code for string matching syntactically more consistent 2022-04-18 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220418 Merge with NetBSD make, pick up o ignore '.POSIX:' if not in first non-comment line of Makefile as specified by POSIX. add unit-tests for above. o meta.c: make it easier to find usage of identifiers o targ.c: add .USEBEFORE to Targ_PrintType 2022-04-14 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220414 * unit-tests/Makefile: simplify checks for shells with BROKEN_TESTS, this helps with other Linux distros that use dash. 2022-03-30 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220330 Merge with NetBSD make, pick up o var.c: fix spacing, and a typo in a test 2022-03-26 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220326 Merge with NetBSD make, pick up o parse.c: try to include 'posix.mk' the first time .POSIX: is encountered, to allow for beter POSIX compliance. o var.c: make debug logs more readable prefer 'long long' over 'long' on 32-bit C99 platforms fix crash on .undef of an environment variable 2022-03-03 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220303 Merge with NetBSD make, pick up o tell meta mode unit tests not to expect filemon o cond.c: make debug logging for comparisons less technical o lst.c: fix mem leak in Lst_Remove o str.c: make code for string matching syntactically more consistent o var.c: simplify ParseModifier_Match 2022-02-14 Simon J Gerraty * unit-tests/Makefile: control MAKESYSPATH for deptgt-phony * VERSION (_MAKE_VERSION): 20220214 Merge with NetBSD make, pick up o cond.c: simplify control flow in CondParser_Comparison o job.c: fix echoing of command with '-' in silent target in jobs mode o main.c: prefix the warning about read-only .OBJDIR with a colon o parse.c: remove redundant conditions o var.c: simplify control flow in ModifyWord_SysVSubst 2022-02-08 Simon J Gerraty * unit-tests/Makefile: disable opt-debug-x-trace on Linux if there is any chance we have dash as .SHELL * VERSION (_MAKE_VERSION): 20220208 Merge with NetBSD make, pick up o more unit tests o meta.c: use a variable to hold command line to be filtered to avoid any side effects from content of command line. 2022-02-04 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220204 Merge with NetBSD make, pick up o use unsigned consistently for line numbers, avoid the need for %z o parse.c: do not step off end of input in Parse_IsVar when checking for target local variable assignments 2022-02-02 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220202 Merge with NetBSD make, pick up o remove redundant declaration of HashIter_Init o make DEBUG0 simpler 2022-01-30 Simon J Gerraty * cast gn->lineno to avoid %z * VERSION (_MAKE_VERSION): 20220130 Merge with NetBSD make, pick up o more unit tests o make GNode lineno unsigned to please lint o print location of recursive variable references in commands o print "stack trace" (makefile includes) on fatal errors o make.1: refine documentation for target local assignments 2022-01-28 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220128 Merge with NetBSD make, pick up o inline functions called only once o for.c: clean up AddEscape for building the body of a .for loop o hash.c: merge duplicate code for finding an entry in a hash table replace HashEntry_KeyEquals with strncmp o make.1: document quirks of target local variable assignments. o parse.c: cleanup white-space 2022-01-26 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220126 Merge with NetBSD make, pick up o allow setting target local variables o more unit tests o add missing newline after "cannot continue" message o meta.c: clean up eat_dots o parse.c: fix filename in warning about duplicate script o var.c: when expanding nested variables, check simple things first 2022-01-16 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220116 Merge with NetBSD make, pick up o fix for unit-tests/varname-makeflags on non-BSD systems o use Var_Exists rather than Var_Value where appropriate o remove unnecessary functions for expanding variable names o cond.c: inline EvalBare o main.c: lint cleanup o parse.c: condense code in Parse_IsVar use islower for parsing directives (none have upper case) 2022-01-12 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220112 Merge with NetBSD make, pick up o meta.c: add .MAKE.META.CMP_FILTER for filtering commands before comparion, rarely needed but useful when it is. 2022-01-10 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220110 Merge with NetBSD make, pick up o inline Buf_Clear o remove redundant braces o rename and inline Targ_Precious o cond.c: remove redundant initializer in CondParser_ComparisonOrLeaf o for.c: clean up handling of .for loops fix reported line numbers of continuation lines add details about .for loop variables to stack traces o job.c: reduce code for initializing error handling in shell o main.c: in Cmd_Exec, return error message instead of format string have as few statements as possible between va_start and va_end add debug logging for capturing the output of external commands o make.c: use consistent variable names for varargs o make_malloc.c: remove duplicate code from bmake_strdup o parse.c: add missing printflike annotations remove redundant lines from stack traces fix stack traces in -dp mode reduce confusing code in ParseForLoop fix line number in debug log after returning from a file rename IFile and its fields to match their actual content clean up ParseDependencySources o var.c: shorten ApplyModifier_Assign rename is_shell_metachar, fix character conversion warning merge calls to ApplyModifier_Time merge duplicate code for modifiers 'gmtime' and 'localtime' 2022-01-04 Simon J Gerraty * parse.c: loadfile restore extra byte in buffer. 2022-01-01 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220101 Merge with NetBSD make, pick up o more unit-tests o remove unnecessary words from command line options in CmdOpts o rename eunlink to unlink_file o cond.c: make ParseWord in condition parser simpler internally return false for irrelevant leaves in conditions replace table for function lookup in conditions with simple code merge duplicate types CondEvalResult and CondResult o for.c: clean up handling of .for loops and .include directives o main.c: constify cached_realpath clean up Cmd_Exec o parse.c: sync API documentation fix error message when reading more than 1 GB from stdin clean up parsing of makefiles fix line number in error message about open conditionals unexport types VarAssignOp and VarAssign clean up function names remove redundant parameters in dependency parsing functions reduce scope of the list of wildcard target names extract OP_NOTARGET into separate function clean up variable names for parsing dependency lines make debug logging a bit more human-friendly o var.c: condense code in ApplyModifier_Assign 2021-12-21 Simon J Gerraty * VERSION (_MAKE_VERSION): 20211221 Merge with NetBSD make, pick up o more unit-tests o style cleanup o in CLEANUP mode, free interned strings at the very end o fix memory leak for filenames in .for loops o buf.c: avoid memory leak o cond.c: condense CondParser_ComparisonOp o hash.c: change return type of HashTable_Set to void o job.c: change return type of Compat_RunCommand from int to bool o main.c: remove bmake_free o parse.c: condense repetetive code in ParseDirective remove dead code for handling traditional include directives clean up parsing of variable assignments remove unreachable code for parsing the dependency operator clean up loading of files fix memory leak in IncludeFile o var.c: fix memory leak when parsing a variable name fix memory leak from ${.SUFFIXES} reduce memory allocation in modifier ':?' and ':C' condense RegexReplace for the modifier ':C' and avoid strlen merge duplicate code for memory handling in Var_Parse distinguish between short-lived and environment variables rename VarFreeEnv to VarFreeShortLived 2021-12-15 Simon J Gerraty * cond.c: fix mem leak in CondParser_Leaf 2021-12-12 Simon J Gerraty * VERSION (_MAKE_VERSION): 20211212 Merge with NetBSD make, pick up o rename Parse_SetInput to Parse_PushInput o remove remove period from end of error messages and warnings to be more consistent o arch.c: use simpler memory management for parsing archive members o cond.c: rework and reduce recursion o for.c: rename some functions to better reflect purpose o suff.c: add Suff_NamesStr to provide .SUFFIXES as a string. o var.c: in parse errors, mark whitespace more clearly inline ParseEmptyArg into CondParser_FuncCallEmpty minimize calls to LazyBuf_Get in ParseVarnameLong treat .SUFFIXES as a read-only variable 2021-12-07 Simon J Gerraty * VERSION (_MAKE_VERSION): 20211207 Merge with NetBSD make, pick up o inline HashIter_Init o parse.c: inline common subexpression in ParseRawLine o var.c: merge branches for modifiers ':D' and ':U' extract common code into Expr_Words extract common code into Expr_Str move low-level implementation details out of Var_Parse 2021-12-06 Simon J Gerraty * VERSION (_MAKE_VERSION): 20211206 Merge with NetBSD make, pick up o add unit-tests/varmod-loop-delete o for.c: inline Str_Words - reduce memory allocation o parse.c: do not try to expand fixed variable names only allocate the name of an included file if necessary clean up ParseInclude o var.c: fix use-after-free in modifier ':@' save a memory allocation in each modifier ':O' and ':u' save a memory allocation in the modifier ':[...]' in UnexportVars, replace Str_Words with Substring_Words to reduce allocations and copying. 2021-12-04 Simon J Gerraty * VERSION (_MAKE_VERSION): 20211204 Merge with NetBSD make, pick up o flesh out a number of tests o replace enums with bitfields, this simplifies a lot of code. o var.c: refactor ParseModifierPartSubst 2021-10-24 Simon J Gerraty * VERSION (_MAKE_VERSION): 20211024 Merge with NetBSD make, pick up o Punt on write errors - ENOSPC etc. 2021-10-22 Simon J Gerraty * configure.in: use_defshell, set both DEFSHELL_INDEX and defshell_path if appropriate. This makes it easier to use say the KSH specification with and alternate path for the shell. * configure.in compat.c: for SCO we need to force UseShell * configure.in: SCO /bin/sh is not usable, provide a list of alternatives for use as .SHELL. We still have to mark some tests as broken, plus more if we end up with ksh as .SHELL. Issue a warning about skipped tests. * boot-strap: leave TOOL_DIFF to configure * configure.in: on SCO native cc is not usable, gcc is to be found in /usr/gnu/bin and while ancient is at least able to compile bmake. Thus we add /usr/gnu/bin to PATH if it exists, and later check if $CC would have been found via $PATH. If not we set CC to the full path of $CC. Also gnu diff is known to support -u, so if it exists use it. * configure.in: move getopt to AC_REPLACE_FUNCS also add AC_C_INLINE - in an attempt to compile using native cc on SCO. * configure.in: check for stresep as well as strsep, since we define the later to the former if necessary, and if we have to provide stresep we also need to provide a prototype. * configure.in: we no longer need to worry about sys/cdefs.h providing __RCSID which simplifies things quite a bit. * make.h: make sure we have __RCSID * unit-tests/Makefile.config.in: add TOOL_DIFF so configure can control it. 2021-10-20 Simon J Gerraty * VERSION: 20211020 Merge with NetBSD make, pick up o confirm sync of unit-tests 2021-10-18 Simon J Gerraty * configure.in: check if timezone Europe/Berlin is supported if not try UTC-1 * configure.in: if .OBJDIR is $srcdir/obj we need to create a symlink unit-tests -> ../unit-tests/obj so that unit-tests/Makefile.config is put in the right place. * refine filtering of .OBJDIR in unit-tests 2021-10-16 Simon J Gerraty * Fix unit-tests on Minix 3.2.0 o job.c: do not punt if read of token pipe fails for EAGAIN. On Minix at least, we are not ready to read the childExitJob pipe when poll says we are. There should actually be no reason for this pipe to be non-blocking, but while that works fine on {Net,Free}BSD it breaks another test case on Minix. o unit-tests/Makefile: deal with variants of error messages and use of obj as .OBJDIR 2021-10-14 Simon J Gerraty * configure.in: add sigaction to AC_REPLACE_FUNCS we also need to check for sigaddset etc just for the benefit of sigact.c * Add sigact.c as sigaction.c so this "just works". This should have been done back when bmake_signal started using sigaction (I only just noticed that sigact.c wasn't here ;-) Note: I no longer have access to any system where this would matter. 2021-10-13 Simon J Gerraty * VERSION (_MAKE_VERSION): 20211011 * Makefile: cleanup a little * configure.in: check for sigsetmask 2021-10-01 Simon J Gerraty * VERSION (_MAKE_VERSION): 20211001 Merge with NetBSD make, pick up o reduce locations reducing text size o remove unnecessary const o cond.c: fix lint warning on i386 do not allow unquoted 'left == right' after modifier ':?' o hash.c: fix build for DEBUG_HASH_LOOKUP o var.c: fix memory leak in error case of the ':?' modifier 2021-09-11 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210911 Merge with NetBSD make, pick up o var.c: replace remaining ModChain_ShouldEval with Expr_ShouldEval 2021-09-08 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210906 Merge with NetBSD make, pick up o more unit tests o lint cleanup o rename some functions to better fit purpose o for.c: cleanup - remove unnecessary optimization fix embedded newlines o parse.c: correct case for CVS/RCS 2021-08-11 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210808 Merge with NetBSD make, pick up o var.c: remove redundant initialization in ApplyModifier_Order * mk/options.mk: issue warning for incorrect usage 2021-08-03 Simon J Gerraty * var.c: use long for :On if we don't have a 64bit int type * VERSION (_MAKE_VERSION): 20210803 Merge with NetBSD make, pick up o rework varmod-order tests to avoid qsort instability o make.1: clarify :On entry 2021-07-31 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210731 Merge with NetBSD make, pick up o fix some lint issues o more unit tests o var.c: rework of ApplyModifier_Order 2021-07-30 Simon J Gerraty * util.c: add strto*l if HAVE_STRTO*L not defined * VERSION (_MAKE_VERSION): 20210730 Merge with NetBSD make, pick up o var.c: add :On and :Orn for numeric sort disabled if no 64bit type available. o _strtol.h: to implement strto*l functions 2021-07-04 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210704 Merge with NetBSD make, pick up o unit-tests: fix some tests to be more portable - job-output-null not all shells do the same number of write calls - objdir-writable if TMPDIR is set; /tmp may not be usable 2021-07-01 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210701 Merge with NetBSD make, pick up o unit-tests: allow for BROKEN_TESTS to list TESTS to be skipped; some tests just cannot work in some environments. o buf.c: simpler upper bound for length in Buf_AddInt o cond.c: fix grammar in error message for malformed conditional o for.c: prevent newline injection (from ${.newline}) in .for loops o var.c: use more practical data type in RegexReplace (avoid need for %zu) extract RegexReplace from ModifyWord_SubstRegex 2021-06-21 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210621 Merge with NetBSD make, pick up o var.c: only report error for unmatched regex subexpression when linting (-dL) since we cannot tell when an unmatched subexpression is an expected result. o move unmatched regex subexpression tests to varmod-subst-regex.mk and enable strict (lint) mode 2021-06-16 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210616 Merge with NetBSD make, pick up o more unit tests o cond.c: rename If_Eval to EvalBare improve function names for parsing conditions o job.c: fix error handling of targets that cannot be made o var.c: uncompress code in ApplyModifier_Unique 2021-05-18 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210518 Merge with NetBSD make, pick up o fix unit-tests/opt-chdir to cope with /nonexistent existing. o job.c: Print -de error information when running multiple jobs 2021-04-20 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210420 Merge with NetBSD make, pick up o use C99 bool type o convert VarEvalFlags back into an enum o cond.c: do not complain when skipping the condition 'no >= 10' o hash.c: avoid allocating memory for simple variable names o job.c: use distinct wording for writing to the shell commands file remove type name for the abort status in job handling rename PrintOutput to PrintFilteredOutput to avoid confusion o main.c: avoid double slash in name of temporary directory o var.c: use straight quotes for error 'Bad conditional expression' reduce memory allocations in the modifiers ':D' and ':U' rename members of ModifyWord_LoopArgs clean up pattern flags for the modifiers ':S' and ':C' reduce memory allocation and strlen calls in modifier ':from=to' in the ':Q' modifier, only allocate memory if necessary improve performance for LazyBuf remove redundant parameter from ParseVarnameLong migrate ParseModifierPart to use Substring avoid unnecessary calls to strlen when evaluating modifiers migrate ModifyWord functions to use Substring migrate handling of the modifier ':S,from,to,' to Substring reduce debug logging and memory allocation for ${:U...} reduce verbosity of the -dv debug logging for standard cases clean up debug logging for ':M' and ':N' disallow '$' in the variable name of the modifier ':@' simplify access to the name of an expression during evaluation 2021-03-30 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210330 Merge with NetBSD make, pick up o replace enum bit-field with struct bit-field for VarEvalFlags o rename VARE_NONE to VARE_PARSE_ONLY o var.c: rename ApplyModifiersState to ModChain fix double varname expansion in the variable modifier '::=' change debug log for variable evaluation flags to lowercase 2021-03-14 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210314 Merge with NetBSD make, pick up o var.c: avoid evaluating many modifiers in parse only mode in strict mode (-dL) many variable references are parsed twice, the first time just to report parse errors early, so we want to avoid side effects and wasted effort to the extent possible. 2021-02-26 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210226 Merge with NetBSD make, pick up o remove freestanding freeIt variables link via FStr o var.c: restructure code in ParseVarname to target human readers improve error message for; bad modifier in variable expression unclosed modifier unknown modifier remove redundant parameter of ApplySingleModifier explain non-obvious code around indirect variable modifiers quote ':S' in error message about missing delimiter extract ParseModifier_Match into separate function add context information to error message about ':range' modifier add quotes around variable name in an error message reorder code in ModifyWords use more common parameter order for VarSelectWords make ModifyWord_Subst a little easier to understand do not expand variable name from the command line twice extract ExistsInCmdline from Var_SetWithFlags save a hash map lookup when defining a cmdline variable clean up VarAdd, Var_Delete, Var_ReexportVars use bit-shift expressions for VarFlags constants rename constants for VarFlags rename ExprDefined constants for debug logging rename ExprStatus to ExprDefined split parameters for evaluating variable expressions reduce redundant code around ModifyWords print error about failed shell command before overwriting variable clean up ValidShortVarname, ParseVarnameShort rename VarExprStatus to ExprStatus add functions for assigning the value of an expression rename ApplyModifiersState_Define to Expr_Define condense the code for parsing :S and :C modifiers 2021-02-06 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210206 Merge with NetBSD make, pick up o unit-tests: use private TMPDIR to avoid errors from other users 2021-02-05 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210205 Merge with NetBSD make, pick up o avoid strdup in mkTempFile o always use vfork o rename context and ctxt to scope o rename some VAR constants to SCOPE o Var_ functions, move the scope to the front o use shortcut functions Global_Set and Global_Append o add shortcut Global_Delete for deleting a global variable o rename Var_Delete to Var_DeleteExpand, Var_DeleteVar to Var_Delete o compat.c: when exiting due to an error, print graph information o enum.c: remove overengineered Enum_ValueToString o make.c: remove unused INTERNAL flag remove unused return type of MakeBuildParent o parse.c: replace parse error "Need an operator" with better message o var.c: improve documentation about variable scopes rename Var_ValueDirect to GNode_ValueDirect rename old Var_SetWithFlags to Var_SetExpandWithFlags merge SetVar into Var_SetWithFlags split Var_Exists into plain Var_Exists and Var_ExistsExpand split Var_Append into Var_Append and Var_AppendExpand replace enum bit-set with bit-field o unit-tests/var-op-shell: use kill rather than kill -14 which broke on darwin with recent update. 2021-02-01 Simon J Gerraty * configure.in: check for sig_atomic_t and define it as 'int' if missing. * VERSION (_MAKE_VERSION): 20210201 Merge with NetBSD make, pick up o use sig_atomic_t for caught_sigchld 2021-01-30 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210130 Merge with NetBSD make, pick up o more unit tests o convert SearchPath to struct o split Buf_Destroy into Buf_Done and Buf_DoneData o for.c: split For_Eval into separate functions rename struct For to struct ForLoop o job.c: do not create empty shell files in jobs mode rename JobOpenTmpFile to JobWriteShellCommands reduce unnecessary calls to waitpid o parse.c: in -dp mode, print stack trace with each diagnostic 2021-01-23 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210123 Merge with NetBSD make, pick up o rename Dir_Expand to SearchPath_Expand o rename Dir_AddDir, reorder parameters of SearchPath_ToFlags o cond.c: fix debug output for comparison operators in conditionals o dir.c: split Dir_FindFile into separate functions 2021-01-20 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210120 Merge with NetBSD make, pick up o fix some more lint nits o refine some unit tests for portability o cond.c: rework parsing 2021-01-10 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210110 Merge with NetBSD make, pick up o fix lint warnings o consistently use boolean expressions in conditions 2021-01-08 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210108 Merge with NetBSD make, pick up o job.c: back to polling token pipe if we want a token o main.c: always print 'stopped in' on first call The execption is if we bail because of an abort token in which case just exit 6. 2021-01-01 Simon J Gerraty * VERSION (_MAKE_VERSION): 20210101 Merge with NetBSD make, pick up o Happy New Year! o rename CmdOpts.lint to strict o exit 2 on technical errors o replace pointers in controlling conditions with booleans o replace global preserveUndefined with VARE_KEEP_UNDEF o compat.c: re-export variables from the actual make process if using vfork this is the effect anyway o cond.c: clean up VarParseResult constants o for.c: fix undefined behavior in SubstVarLong make control flow in SubstVarLong of .for loops more obvious clean up SubstVarShort in .for loops extract ForSubstBody from ForReadMore clean up ForReadMore simplify termination condition for .for loop add error handling for .for loop items job.c: re-export variables from the actual make process parse.c: remove mmap for loading files, only allow files < 1 GiB fix edge case in := with undefined in variable name skip variable expansion in ParseDependencyTargetWord var.c: split ExportVar into separate functions clean up code in extracted ExportVar functions remove dead code from ApplyModifiersIndirect split Var_Subst into easily understandable functions clean up VarParseResult constants 2020-12-25 Simon J Gerraty * main.c: use .MAKE.DEPENDFILE as set by makefiles 2020-12-22 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201222 Merge with NetBSD make, pick up o make DEBUG macro return boolean o parse.c: fix assertion failure for files without trailing newline o var.c: allow .undef to undefine multiple variables at once remove excess newline from parse errors 2020-12-21 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201221 Merge with NetBSD make, pick up o some unit-test updates 2020-12-20 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201220 Merge with NetBSD make, pick up o more unit tests o return FStr from Var_Parse and Var_Value o spell nonexistent consistently o add str_basename to reduce duplicate code o compat.c: fix .ERROR_TARGET in compat -k mode extract InitSignals from Compat_Run extract UseShell from Compat_RunCommand o cond.c: error out if an '.endif' or '.else' contain extraneous text o for.c: rename ForIterate to ForReadMore o hash.c: clean up hash function for HashTable o lst.c: rename Vector.priv_cap to cap o main.c: remove constant parameter from MakeMode o make.c: use symbolic time for 0 in Make_Recheck extract MakeChildren from MakeStartJobs o parse.c: clean up memory handling in VarAssign_EvalShell, Parse_DoVar fix error message for .info/.warning/.error without argument extract Var_Undef from ParseDirective extract ParseSkippedBranches, ParseForLoop from ParseReadLine rename mode constants for ParseGetLine to be more expressive reduce debugging details in Parse_SetInput fix line numbers in .for loops split ParseGetLine into separate functions fix garbled output for failed shell command var.c: remove redundant assignment in ApplyModifier_SysV error out on unknown variable modifiers at parse time remove wrong error message for indirect modifier in lint mode extract ApplySingleModifier from ApplyModifiers use FStr for memory management in Var_SetWithFlags extract SetVar from Var_SetWithFlags use FStr in VarNew extract string functions from ApplyModifier_To error out if .undef has not exactly 1 argument extract Var_DeleteVar from Var_Delete extract Var_Undef from ParseDirective clean up memory management for expanding variable expressions 2020-12-12 Simon J Gerraty * avoid %zu * lst.c: avoid anonymous union * VERSION (_MAKE_VERSION): 20201212 Merge with NetBSD make, pick up o more unit tests o inline Targ_Ignore and Targ_Silent o split JobFlags into separate fields o remove const from function parameters (left overs from refactoring) o eliminate boolean argument of Var_Export o make API of Buf_Init simpler o rename ParseRunOptions to ParseCommandFlags o replace *line with line[0] o compat.c: fix wrong exit status for multiple failed main targets refactor Compat_Run to show the error condition more clearly don't make .END if the main targets already failed (-k mode) fix exit status in -k mode if a dependency fails o for.c: clean up Buf_AddEscaped in .for loops o job.c: extract ShellWriter_ErrOn from JobPrintCommand make Job_Touch simpler refactor JobFinish rename Shell.exitFlag to errFlag move Job.xtraced to ShellWriter make printing of shell commands independent from the job rename shell flags in struct Shell extract JobOpenTmpFile from JobStart rename RunFlags to CommandFlags split various Job.* into separate fields rename commandShell to shell extract InitShellNameAndPath from Shell_Init replace signal handling macros with local functions replace macro MESSAGE with local function parse.c: error out on null bytes in makefiles error out on misspelled directives rename IFile.nextbuf to readMore fix undefined behavior in ParseEOF str.c: remove redundant call to strlen in Str_Words var.c: error out on misspelled .unexport-env error out on misspelled .export directives extract ExportVars from Var_Export extract ExportVarsExpand from Var_Export eliminate boolean argument of Var_Export fix undefined behavior when exporting ${:U } rename Var_ExportVars to Var_ReexportVars rename Var_Export1 to ExportVar 2020-12-06 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201206 Merge with NetBSD make, pick up o more unit tests o inline macros for debug logging o use consistent variable names for list nodes o define constants for enum zero-values o dir.c: use fixed format for debug output of the directory cache remove Dir_InitDir o lst.c: inline Lst_Enqueue, Vector_Done o meta.c: remove unused parameter from meta_needed o parse.c: rename parse functions o suff.c: extract ExpandChildrenRegular from ExpandChildren o targ.c: don't concatenate identifiers in Targ_PrintType o var.c: remove comment decoration extract UnexportVars from Var_UnExport extract GetVarnamesToUnexport from Var_UnExport extract UnexportEnv from Var_UnExport extract UnexportVar from Var_UnExport move CleanEnv to UnexportVars replace pointer comparisons with enum add FStr to var.c to make memory handling simpler use FStr in Var_UnExport move type definitions in var.c to the top extract FreeEnvVar from Var_Parse extract ShuffleStrings from ApplyModifier_Order 2020-11-30 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201130 Merge with NetBSD make, pick up o add unit tests for META MODE o reduce memory allocation for dirSearchPath, GNode.parents, GNode.children, OpenDirs o reduce pointer indirection for GNode.cohorts and GNode.implicitParents o remove pointer indirection from GNode.commands o inline Lst_ForEachUntil in meta mode o dir.c: fix memory leak for lstat cache in -DCLEANUP mode clean up memory management for CachedDirs fix the reference count of dotLast going negative add debug logging for OpenDirs_Done extract CacheNewDir from Dir_AddDir add debug logging for reference counting of CachedDir rename some Dir functions to SearchPath o job.c: rename some global variables o main.c: reduce memory allocation in ReadBuiltinRules reduce memory allocation in CmdOpts.create, CmdOpts.variables, CmdOpts.makefiles Add .MAKE.UID and .MAKE.GID o make.c: reduce memory allocation for/in toBeMade, Make_ProcessWait, Make_ExpandUse o meta.c: reduce memory allocation in meta_oodate o parse.c: reduce memory allocations for parsing dependencies and targets o suff.c: reduce memory allocation in suffix handling 2020-11-24 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201124 Merge with NetBSD make, pick up o .MAKE.{UID,GID} represent uid and gid running make. o fix error handling for .BEGIN and .END dependency in -k mode o fix missing "Stop." after failed .END node in -k mode o use properly typed comparisons in boolean contexts o replace a few HashTable_CreateEntry with HashTable_Set o add HashSet type o compat.c: split Compat_Make into smaller functions extract DebugFailedTarget from Compat_RunCommand o dir.c: refactor Dir_UpdateMTime migrate CachedDir.files from HashTable to HashSet o make.c: add high-level API for GNode.made 2020-11-22 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201122 Merge with NetBSD make, pick up o rename GNode.context to vars o suff.c: cleanup and refactor rename some functions and vars to better reflect usage add high-level API for CandidateSearcher o targ.c: add more debug logging for suffix handling o more unit tests o add debug logging for setting and resetting the main target 2020-11-17 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201117 Merge with NetBSD make, pick up o fix some unit-tests when .SHELL is dash o rename Targ_NewGN to GNode_New o make some GNode functions const o main.c: call Targ_Init before Var_Init cleanup PrintOnError, getTmpdir and ParseBoolean o var.c: fix error message of failed :!cmd! modifier 2020-11-14 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201114 Merge with NetBSD make, pick up o replace a few HashTable_CreateEntry with HashTable_Set o clean up cached_stats o rename DEFAULT to defaultNode o remove redundant struct make_stat o cond.c: in lint mode, check for ".else " use bitset for IfState replace large switch with if-else in Cond_EvalLine o job.c: clean up JobExec, JobStart, JobDoOutput use stderr for error message about failed touch clean up Job_Touch replace macro DBPRINTF with JobPrintln rename JobState to JobStatus main.c: switch cache for realpath from GNode to HashTable clean up Fatal clean up InitDefSysIncPath use progname instead of hard-coded 'make' in warning rename Main_SetVarObjdir to SetVarObjdir make.1: document the -S option make.c: fix debug output for GNode details use symbolic names in debug output of GNodes 2020-11-12 Simon J Gerraty * configure.in: fix --with-force-machine-arch * VERSION (_MAKE_VERSION): 20201112 Merge with NetBSD make, pick up o allow env var MAKE_OBJDIR_CHECK_WRITABLE=no to skip writable checks in InitObjdir. Explicit .OBJDIR target always allows read-only directory. o cond.c: clean up Cond_EvalLine 2020-11-11 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201111 Merge with NetBSD make, pick up o more unit-tests o style cleanup remove redundant parentheses from sizeof operator replace character literal 0 with '\0'. replace pointer literal 0 with NULL. remove redundant parentheses. replace (expr & mask) == 0 with !(expr & mask). use strict typing in conditions of the form !var o rename Make_OODate to GNode_IsOODate o rename Make_TimeStamp to GNode_UpdateYoungestChild o rename Var_Set_with_flags to Var_SetWithFlags o rename dieQuietly to shouldDieQuietly o buf.c: make API of Buf_Init simpler o compat.c: clean up Compat_Make, Compat_RunCommand, CompatDeleteTarget and CompatInterrupt o cond.c: in lint mode, only allow '&&' and '||', not '&' and '|' clean up CondParser_Comparison o main.c: rename getBoolean and s2Boolean rename MAKEFILE_PREFERENCE for consistency o parse.c: replace strstr in ParseMaybeSubMake with optimized code o var.c: rename VARE_ASSIGN to VARE_KEEP_DOLLAR replace emptyString with allocated empty string error out on unclosed expressions after the colon 2020-11-01 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201101 Merge with NetBSD make, pick up o negate NoExecute to GNode_ShouldExecute o job.c: rename JobMatchShell to FindShellByName extract EscapeShellDblQuot from JobPrintCommand extract ParseRunOptions from JobPrintCommand o var.c: extract ApplyModifiersIndirect from ApplyModifiers treat malformed :range, :ts and :[...] as errors add tests for the variable modifiers :[words] and :range 2020-10-31 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201031 Merge with NetBSD make, pick up o format #include directives consistently o do not look up local variables like .TARGET anywhere else o main.c: Main_SetObjdir is first called for curdir which may be readonly reduce the scope where recursive expressions are detected remove redundant :tl from getBoolean clean up mkTempFile o meta.c: simplify memory allocation in meta_create and meta_oodate o parse.c: extract loadedfile_mmap from loadfile o trace.c: document possible undefined behavior with .CURDIR o var.c: make parsing of the :gmtime and :localtime modifiers stricter rename ismeta to is_shell_metachar remove debug logging for the :Q variable modifier rename VarIsDynamic to VarnameIsDynamic use consistent parameter order in varname parsing functions extract ParseVarnameLong from Var_Parse extract ParseVarnameShort from Var_Parse fix type of ParseModifierPart parameter delim extract IsEscapedModifierPart from ParseModifierPart clean up ModifyWords add test for combining the :@ and :? variable modifiers 2020-10-30 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201030 Merge with NetBSD make, pick up o change char * to void * in Var_Value o make iterating over HashTable simpler o rename VAR_CMD to VAR_CMDLINE o cond.c: clean up is_separator fix parse error in string literal in conditional o main.c: do not use objdir that is not writable in lint mode, exit with error status on errors o parse.c: clean up StrContainsWord fix out-of-bounds pointer in ParseTrackInput o var.c: rename Str_SYSVMatch and its parameters remove unsatisfiable conditions in Var_Set_with_flags document where the variable name is expanded fix documentation for VARP_SUB_ONE rename VAR_EXPORTED_YES to VAR_EXPORTED_SOME document VAR_READONLY prevent appending to read-only variables extract MayExport from Var_Export1 remove redundant evaluations in VarFind replace VarFindFlags with a simple Boolean rename FIND_CMD to FIND_CMDLINE, to match VAR_CMDLINE 2020-10-28 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201028 Merge with NetBSD make, pick up o rename defIncPath to defSysIncPath o initialize all CmdOpts fields o lst.c: inline Vector_Get o main.c: refactor main extract InitMaxJobs,InitObjdir,InitVarMake,InitRandom, ReadMakefiles,CleanUp,InitVpath,ReadBuiltinRules, InitDefIncPath,CmdOpts_Init,UnlimitFiles o parse.c: merge curFile into includes rename predecessor to order_pred sort ParseSpecial alphabetically remove unused, undocumented .NOEXPORT rename ParseSpecial enum values consistently rename some fields of struct IFile 2020-10-26 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201026 Merge with NetBSD make, pick up o group the command line options and arguments into a struct o rename GNode.cmgn to youngestChild o rename hash functions to identify the type name o negate OP_NOP and rename it to GNode_IsTarget o add GNode_Path to access the path of a GNode o remove macros MIN and MAX o remove unused Lst_Find and Lst_FindFrom o arch.c: and make Arch_FindLib simpler clean up code layout make Arch_ParseArchive simpler o cond.c: inline CondFindStrMatch into FuncMake o dir.c: replace Dir_CopyDir with Dir_CopyDirSearchPath omit trailing space in debug output for expanding file patterns refactor DirMatchFiles document that the SearchPath of Dir_FindFile may be NULL remove UNCONST from Dir_Expand inline DirFindName o for.c: clean up code for handling .for loops o hash.c: print hash in debug log with fixed width clean up hash table functions reduce amount of string hashing o job.c: refactor JobDeleteTarget use proper enum constants for aborting convert result of JobStart from macros to enum convert abort reason macros to enum rework Job_CheckCommands to reduce indentation rename Shell fields add field names in declaration of DEFSHELL_CUSTOM convert JobState and JobFlags to enum types move handling of the "..." command to JobPrintCommands o lst.c: clean up refactor LstNodeNew remove Lst_Open, Lst_Next, Lst_Close remove code for circular lists from Lst_Next o main.c: do not attempt to read .MAKE.DEPENFILE if set to /dev/null or anything starting with "no" convert macros for debug flags into enum o make.c: inline Lst_Copy in Make_ExpandUse o meta.c: inline Lst_Find in meta_oodate make Lst_RemoveIf simpler in meta_oodate o parse.c: convert error level for Parse_Error to an enum o suff.c: properly terminate debug output with newline add more details to DEBUG_SRC log replace Dir_CopyDir with Dir_CopyDirSearchPath don't modify GNode name while rebuilding the suffix graph o var.c: reduce duplicate code in VarFind 2020-10-22 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201022 Merge with NetBSD make, pick up o more refactoring and simplification to reduce code size o var.c: extract CanonicalVarname from VarFind o make.c: extract UpdateImplicitParentsVars from Make_Update o main.c: extract PrintVar from doPrintVars extract HandlePWD from main o lst.c: inline simple Lst getters remove unused Lst_ForEach o job.c: move struct Shell from job.h to job.c o more unit tests 2020-10-19 Simon J Gerraty * configure.in: remove inappropriate use of AC_INCLUDES_DEFAULT 2020-10-18 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201018 Merge with NetBSD make, pick up o remove USE_IOVEC o rename some Hash_* apis to Hash* o replace execError with execDie o rename Lst_Init to Lst_New o add tags to enum types o rename Stack to Vector o parse.c: more refactoring o unit-tests: make some tests use line buffered stdout o unit-tests/Makefile: in meta mode do not make all tests depend on Makefile, it isn't necessary. 2020-10-10 Simon J Gerraty * main.c: check for CTL_HW being defined. * unit-tests/Makefile: ensure export tests output are POSIX compliant disable opt-debug-jobs test until it works on ubuntu * VERSION (_MAKE_VERSION): 20201010 Merge with NetBSD make, pick up o dir.c: remove pathname limit for Dir_FindHereOrAbove o hash.c: replace strcpy with memcpy in Hash_CreateEntry o main.c: extract init_machine and init_machine_arch from main allow to disable debug logging options o parse.c: enable format string truncation warnings extract parsing of sources from ParseDoDependency split ParseDoSrc into smaller functions hide implementation details from Parse_DoVar clean up parsing of variable assignments split Parse_DoVar into manageable pieces don't modify the given line during Parse_DoVar fix out-of-bounds memory access in Parse_DoVar fix parsing of the :sh assignment modifier o var.c: rework memory allocation for the name of variables extract ApplyModifier_Literal into separate function in lint mode, reject modifiers without delimiter do not export variable names starting with '-' o fix double-free bug in -DCLEANUP mode o more cleanup to enable higher warnings level o more unit tests 2020-10-02 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201002 Merge with NetBSD make, pick up o dir.c: use hash table for looking up open directories by name o main.c: clean up option handling o parse.c: add missing const for Parse_AddIncludeDir o var.c: ApplyModifier_To, update pp in each branch o remove redundant function prototypes o more unit tests 2020-10-01 Simon J Gerraty * VERSION (_MAKE_VERSION): 20201001 Merge with NetBSD make, pick up o compat.c: comment about "..." 2020-09-30 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200930 Merge with NetBSD make, pick up o job.c: split Job.jobPipe into 2 separate fields replace Lst_Open with direct iteration o lst.c: remove redundant assertions o targ.c: replace Lst_Open with direct iteration o var.c: fix bug in evaluation of indirect variable modifiers extract ApplyModifier_Quote into separate function o make debug logging simpler 2020-09-27 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200927 Merge with NetBSD make, pick up o parse.c: ensure parse errors result in 'stopped in' message. o compat.c: make parameter of Compat_RunCommand const o main.c: extract InitVarTarget from main o parse.c: rename ParseFinishLine to FinishDependencyGroup refactor ParseDoDependency o var.c: Var_Subst no longer returns string result rename Var_ParsePP back to Var_Parse in lint mode, improve error handling for undefined variables extract ParseVarname from Var_Parse o rename Lst_ForEach to Lst_ForEachUntil o inline Lst_ForEachUntil in several cases o clean up API for finding and creating GNodes o fix assertion failure in -j mode with .END node o inline and remove LstNode_Prev and LstNode_Next o use fine-grained type names for lists and their nodes o more unit tests 2020-09-11 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200911 Merge with NetBSD make, pick up o cond.c: split EvalComparison into smaller functions reorder parameters of condition parsing functions reduce code size in CondParser_Eval rename CondGetString to CondParser_String add CondLexer_SkipWhitespace group the condition parsing state into a struct in CondGetString, replace repeated Buf_Add with Buf_AddStr o migrate Var_Parse to Var_ParsePP o add wrappers around ctype.h functions o lst.c: use a stack instead of a list for the nested include path o more unit tests 2020-09-04 Simon J Gerraty * make-bootstrap.sh.in: adjust object list 2020-09-02 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200902 Merge with NetBSD make, pick up o use make_stat to ensure no confusion over valid fields returned by cached_stat o var.c: make VarQuote const-correct o add unit tests for .for 2020-09-01 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200901 Merge with NetBSD make, pick up o rename Hash_Table fields o make data types in Dir_HasWildcards more precise 2020-08-31 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200831 Merge with NetBSD make, pick up o suff.c: fix unbalanced Lst_Open/Lst_Close in SuffFindCmds o lst.c: Lst_Open renable assert that list isn't open o unit test for .TARGET dependent flags o var.c: fix aliasing bug in VarUniq o more unit tests for :u 2020-08-30 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200830 Merge with NetBSD make, pick up o allow for strict type checking for Boolean o Var_Parse never returns NULL o Var_Subst never returns NULL o Lst_Find now takes boolean match function o rename Lst_Memeber to Lst_FindDatum o rename LstNode functions to match their type o rename GNode.iParents to implicitParents o fix assertion failure for .SUFFIXES in archives o compat.c: clean up documentation for CompatInterrupt and Compat_Run remove unreachable code from CompatRunCommand o main.c: simplify getBoolean o stc.c: replace brk_string with simpler Str_Words o suff.c: add debug macros 2020-08-28 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200828 Merge with NetBSD make, pick up o lst.c: inline LstIsValid and LstNodeIsValid o remove trailing S from Lst function names after migration complete o more comment cleanup/clarification o suff.c: clean up suffix handling o more unit tests 2020-08-26 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200826 Merge with NetBSD make, pick up o enum.c: distinguish between bitsets containing flags and ordinary enums o var.c: fix error message for ::!= modifier with shell error o fix bugs in -DCLEANUP mode 2020-08-24 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200824 Merge with NetBSD make, pick up o in debug mode, print GNode details in symbols 2020-08-23 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200823 Merge with NetBSD make, pick up o lst.c: more asserts, make args to Lst_Find match others. o var.c: pass flags to VarAdd o arch.c: use Buffer o str.c: brk_string return size_t for nwords o more unit tests 2020-08-22 Simon J Gerraty * VERSION (_MAKE_VERSION): Merge with NetBSD make, pick up o var.c: support for read-only variables eg .SHELL being the shell used to run scripts. o lst.c: more simplification o more documentation and style cleanup o more unit tests o ensure unit-test/Makefile is run by TEST_MAKE o reduce duplication of header inclusion 2020-08-21 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200821 Merge with NetBSD make, pick up o lst.c: revert invalid assertion - but document it o dir.c: split Dir_Init into two functions 2020-08-20 Simon J Gerraty * lst.c: needs inttypes.h on Linux * VERSION (_MAKE_VERSION): 20200820 Merge with NetBSD make, pick up o make.1: clarify some passages o var.c: more cleanup, clarify comments o make_malloc.c: remove unreachable code o cond.c: make CondGetString easier to debug o simplify list usage o unit-tests: more 2020-08-16 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200816 Merge with NetBSD make, pick up o refactor unit-tests to be more fine grained not all tests moved yet 2020-08-14 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200814 Merge with NetBSD make, pick up o more str_concat variants o more enums for flags o var.c: cleanup for higher warnings level 2020-08-10 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200810 Merge with NetBSD make, pick up o more unit tests o general comment and style cleanup 2020-08-08 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200808 Merge with NetBSD make, pick up o enum.[ch]: streamline, enums for use in flags and debug output o cond.c: cleanup o var.c: reduce duplicate code for modifiers debug logging for Var_Parse more detailed debug output o more unit tests 2020-08-06 Simon J Gerraty * unit-tests/Makefile: -r for recursive and include Makefile.inc so I can run tests in meta mode supress extra noise if in meta mode * VERSION (_MAKE_VERSION): 20200806 Merge with NetBSD make, pick up o parse.c: remove VARE_WANTRES for LINT we just want to check parsing (for now). 2020-08-05 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200805 Merge with NetBSD make, pick up o make.1: Rework the description of dependence operators 2020-08-03 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200803 Merge with NetBSD make, pick up o revert some C99 usage, for max portability o unit-tests/lint 2020-08-02 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200802 Merge with NetBSD make, pick up o more unit tests 2020-08-01 Simon J Gerraty * Remove NetBSD specific plumbing from unit-tests/Makefile * VERSION (_MAKE_VERSION): 20200801 Merge with NetBSD make, pick up o make Var_Value return const o size_t for buf sizes o optimize some buffer operations - avoid strlen 2020-07-31 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200731 Merge with NetBSD make, pick up o var.c: fix undefinded behavior for incomplete :t modifier fixes unit-test/moderrs on Ubuntu o parse.c: When parsing variable assignments other than := if DEBUG(LINT) test substition of value, so we get a file and line number in the resulting error. o dir.c: fix parsing of nested braces in dependency lines add unit-tests 2020-07-30 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200730 Merge with NetBSD make, pick up o var.c: minor cleanup o unit-tests: more tests to improve code coverage 2020-07-28 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200728 Merge with NetBSD make, pick up o var.c: more optimizations 2020-07-26 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200726 Merge with NetBSD make, pick up o collapse lsd.lib into lst.c - reduce code size and allow inlining o lots of function comment updates o var.c: more optimizations o make return of Var_Parse const 2020-07-20 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200720 Merge with NetBSD make, pick up o DEBUG_HASH report stats at end and tone down the noise o var.c: each flag type gets its own prefix. move SysV string matching to var.c make ampersand in ${VAR:from=to&} an ordinary character cleanup and simplify implementation of modifiers o make.1: move documentation for assignment modifiers 2020-07-18 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200718 Merge with NetBSD make, pick up o DEBUG_HASH to see how well the hash tables are working 2020-07-11 Simon J Gerraty * bsd.after-import.mk: make sure we update unit-tests/Makefile 2020-07-10 Simon J Gerraty * configure.in: use AC_INCLUDES_DEFAULT rather than AC_HEADER_STDC * VERSION (_MAKE_VERSION): 20200710 Merge with NetBSD make, pick up o filemon/filemon_dev.c: use O_CLOEXEC rather than extra syscall o meta.c: target flagged .META is out-of-date if meta file missing 2020-07-09 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200709 Merge with NetBSD make, pick up o cond.c: fix for compare_expression when doEval=0 o unit-tests/Makefile: rework o filemon/filemon_dev.c: ensure filemon fd is closed on exec. 2020-07-04 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200704 Merge with NetBSD make, pick up (most of this by rillig@) o lots of style and white-space cleanup o lots more unit tests for variable modifiers o simplified description of some functions o str.c: refactor Str_Match o var.c: debugging output for :@ constify VarModify parameter fix :hash modifier on 16-bit platforms remove unnecessary forward declarations refactor ApplyModifier_SysV to have less indentation simplify code for :E and :R clean up code for :H and :T refactor ApplyModifiers * var.c: we need stdint.h on some platforms to get uint32_t * unit-test/Makefile: we need to supress the specific error for RE substitution error in modmisc, since it varies accross different OS. 2020-07-02 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200702 Merge with NetBSD make, pick up o var.c: more improvements to avoiding unnecessary evaluation use enums for flags o remove flags arg to Var_Set which outside of var.c is always 0 2020-07-01 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200701 Merge with NetBSD make, pick up o var.c: with change to cond.c; ensure that nested variables within a variable name are expanded. o unit-tests/varmisc.mk: test for nested varname 2020-06-29 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200629 Merge with NetBSD make, pick up o cond.c: do not eval unnecessary terms of conditionals. 2020-06-25 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200625 Merge with NetBSD make, pick up o meta.c: report error if lseek in filemon_read fails 2020-06-22 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200622 Merge with NetBSD make, pick up o dieQuietly: ignore OP_SUBMAKE as too aggressive 2020-06-19 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200619 Merge with NetBSD make, pick up o str.c: performance improvement for Str_Match for multiple '*' o dieQuietly: supress the failure output from make when failing node is a sub-make or a sibling failed. This cuts down greatly on unhelpful noise at the end of build log. Disabled by -dj or .MAKE.DIE_QUIETLY=no 2020-06-10 Simon J Gerraty * FILES: add LICENSE to appease some packagers. This is an attempt to fairly represent the license on almost 200 files, which are almost all BSD-3-Clause The few exceptions being more liberal. * VERSION (_MAKE_VERSION): 20200610 Merge with NetBSD make, pick up o unit test for :Or 2020-06-06 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200606 Merge with NetBSD make, pick up o make.1: cleanup * Makefile: fix depends for main.o which broke MAKE_VERSION 2020-06-05 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200605 Merge with NetBSD make, pick up o dir.c: cached_stats - don't confuse stat and lstat results. o var.c: add :Or for reverse sort. 2020-05-24 Simon J Gerraty * configure.in: add AC_PROG_CC_C99 for mipspro compiler also if --with-filemon= specifies path to filemon.h set use_filemon=dev * dirname.c: remove include of namespace.h 2020-05-17 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200517 Merge with NetBSD make, pick up o modified dollar tests to avoid shell dependencies o new tests for .INCLUDEFROM 2020-05-16 Simon J Gerraty * unit-tests/dollar.mk: tweak '1 dollar literal' test to not depend so much on shell behavior 2020-05-10 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200510 Merge with NetBSD make, pick up o unit test for dollar handling 2020-05-06 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200506 Merge with NetBSD make, pick up o str.c: empty string does not match % pattern plus unit-test changes 2020-05-04 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200504 May the 4th be with you Merge with NetBSD make, pick up o var.c: import handling of old sysV style modifier using '%' o str.c: refactor brk_string o unit-tests: add test case for lazy conditions 2020-04-18 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200418 * configure.in: use_makefile=no for cygwin et al. case insensitive filesystems just don't work if both makefile and Makefile exist. NOTE: bmake does not support cygwin and likely never will, but if brave souls want to try it - help them out. 2020-04-02 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200402 Merge with NetBSD make, pick up o meta.c: meta_oodate, CHECK_VALID_META is too aggressive for CMD a blank command is perfectly valid. 2020-03-30 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200330 Merge with NetBSD make, pick up o make.h: extern debug_file 2020-03-18 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200318 Merge with NetBSD make, pick up o meta.c: meta_oodate, check for corrupted meta file earlier and more often. 2020-02-20 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200220 2020-02-19 Simon J Gerraty * boot-strap: unset MAKEFLAGS 2020-02-12 Simon J Gerraty * VERSION (_MAKE_VERSION): 20200212 * meta.c: meta_compat_parent check for USE_FILEMON patch from Soeren Tempel 2020-02-05 Simon J Gerraty * VERSION: 20200205 Merge with NetBSD make, pick up o meta.c: fix compat mode, need to call meta_job_output() o job.c: extra fds for meta mode not needed if using filemon_dev 2020-01-22 Simon J Gerraty * VERSION: 20200122 Merge with NetBSD make, pick up o meta.c: avoid passing NULL to filemon_*() when meta_needed() returns FALSE. 2020-01-21 Simon J Gerraty * VERSION: 20200121 Merge with NetBSD make, pick up o filemon/filemon_{dev,ktrace}.c: allow selection of filemon implementation. filemon_dev.c uses the kernel module while filemon_ktrace.c leverages the fktrace api available in NetBSD. filemon_ktrace.c can hopefully form the basis for adding support for other tracing mechanisms such as strace on Linux. o meta.c: when target is out-of-date per normal make rules record value of .OODATE in meta file. 2019-09-26 Simon J Gerraty * VERSION: 20190926 Merge with NetBSD make, pick up o parse.c: don't pass NULL to realpath(3) some versions cannot handle it. 2019-04-09 Simon J Gerraty * VERSION: 20190409 Merge with NetBSD make, pick up o parse.c: ParseDoDependency: free paths rather than assert 2018-12-22 Simon J Gerraty * VERSION: 20181222 * configure.in: add --without-makefile to avoid generating makefile and make-bootstrap.sh * include Makefile.inc if it exists * Use Makefile and Makefile.config.in in unit-tests so we can use just: make obj && make && make test when bmake is already available. We add --without-makefile to CONFIGURE_ARGS in this case. * tweak bsd.after-import.mk (captures Makefile.config etc after import to FreeBSD for example) to cope with all the above. 2018-12-21 Simon J Gerraty * VERSION: 20181221 Merge with NetBSD make, pick up o parse.c: ParseVErrorInternal use .PARSEDIR and apply if relative, and then use .PARSEFILE for consistent result. 2018-12-20 Simon J Gerraty * VERSION: 20181220 Merge with NetBSD make, pick up o parse.c: ParseVErrorInternal use .CURDIR if .PARSEDIR is relative o var.c: avoid SEGFAULT in .unexport-env when MAKELEVEL is not set 2018-12-16 Simon J Gerraty * VERSION: 20181216 Merge with NetBSD make, pick up o fix for unit-tests/varquote.mk on Debian 2018-09-21 Simon J. Gerraty * VERSION: 20180919 Merge with NetBSD make, pick up o var.c: add :q o dir.c: cleanup caching of stats 2018-09-21 Simon J Gerraty * Makefile.config.in: use += where it makes sense. 2018-05-12 Simon J. Gerraty * VERSION: 20180512 Merge with NetBSD make, pick up o job.c: skip polling job token pipe 2018-04-05 Simon J. Gerraty * VERSION: 20180405 Merge with NetBSD make, pick up o parse.c: be more cautious about detecting depenency line rather than sysV style include. 2018-02-22 Simon J. Gerraty * VERSION: 20180222 Merge with NetBSD make, pick up o parse.c: avoid calling sysconf for every call to loadfile 2018-02-18 Simon J. Gerraty * VERSION: 20180218 Merge with NetBSD make, pick up o var.c: Var_Set handle NULL value anytime. 2018-02-12 Simon J. Gerraty * VERSION: 20180212 Merge with NetBSD make, pick up o parse.c: do not treat .info as warning with -W 2017-12-07 Simon J. Gerraty * VERSION: 20171207 Merge with NetBSD make, pick up o var.c: Var_Append use Var_Set if var not previously set so that VAR_CMD is handled correctly. Add a suitable unit-test. 2017-11-26 Simon J. Gerraty * VERSION (_MAKE_VERSION): 20171126 * aclocal.m4: use AC_LINK_IFELSE for AC_C___ATTRIBUTE__ since AC_TRY_COMPILE puts input inside main() which upsets modern compilers. 2017-11-18 Simon J. Gerraty * VERSION: 20171118 Merge with NetBSD make, pick up o var.c: do not append to variable set on command line add unit-test to catch this. 2017-10-28 Simon J. Gerraty * VERSION: 20171028 Merge with NetBSD make, pick up o main.c: ignore empty MAKEOBJDIR * Makefile.config.in: make @prefix@ @machine*@ and @default_sys_path@ defaults. 2017-10-05 Simon J. Gerraty * VERSION: 20171005 * unit-tests/dotwait.mk: redirect stderr through pipe for more consistent result on some platforms. 2017-08-13 Simon J. Gerraty * machine.sh: entry for AIX 2017-08-12 Simon J. Gerraty * VERSION (_MAKE_VERSION): Move the setting of _MAKE_VERSION to a file that can be included by configure as well as make. This allows configure to set set _MAKE_VERSION in make-bootstrap.sh 2017-08-10 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170810 Merge with NetBSD make, pick up o meta.c: if target is in subdir we only need subdir name in meta_name. 2017-07-20 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170720 Merge with NetBSD make, pick up o compat.c: pass SIGINT etc onto child and wait for it to exit before we self-terminate. 2017-07-11 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170711 forgot to update after merge on 20170708 ;-) o main.c: refactor to reduce size of main function. add -v option to always fully expand values. o meta.c: ensure command output in meta file has ending newline even when filemon not being used. When matching ${.MAKE.META.IGNORE_PATTERNS} do not use pathname via ':L' since any ':' in pathname breaks that. Instead set a '${.p.}' to pathname in the target context and use that. 2017-05-10 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170510 Merge with NetBSD make, pick up o main.c: Main_SetObjdir: ensure buf2 is in scope 2017-05-08 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170505 see mk/ChangeLog 2017-05-05 Simon J. Gerraty * parse.c: not everyone has stdint.h 2017-05-01 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170501 see mk/ChangeLog 2017-04-21 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170421 Merge with NetBSD make, pick up o str.c: Str_Match: fix closure tests for [^] and add unit-test. 2017-04-20 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170420 Merge with NetBSD make, pick up o main.c: only use -C arg "as is" if it contains no relative component. 2017-04-18 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170418 Merge with NetBSD make, pick up o main.c: fix Main_SetObjdir() for relative paths (eg obj). 2017-04-17 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170417 Merge with NetBSD make, pick up o fixes a number of coverity complaints - check return value of fseek, fcntl - plug memory leak in Dir_FindFile, Var_LoopExpand, JobPrintCommand, ParseTraditionalInclude - use bmake_malloc() where NULL is not tollerated - use MAKE_ATTR_UNUSED rather that kludges like return(unused ? 0 : 0) - use purge_cached_realpaths() rather than abuse cached_realpath() 2017-04-13 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170413 Merge with NetBSD make, pick up o main.c: when setting .OBJDIR ignore '$' in paths. * job.c: use MALLOC_OPTIONS to set malloc_options. 2017-04-11 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170411 Merge with NetBSD make, pick up o str.c: Str_Match: allow [^a-z] to behave as expected. 2017-03-26 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170326 Merge with NetBSD make, pick up o main.c: purge relative paths from realpath cache when .OBJDIR is changed. 2017-03-11 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170311 Merge with NetBSD make, pick up o main.c: only use -C arg "as is" if it starts with '/'. 2017-03-01 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170301 Merge with NetBSD make, pick up o main.c: use -C arg "as is" rather than getcwd() if they identify the same directory. o parse.c: ensure loadfile buffer is \n terminated in non-mmap case 2017-02-01 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170201 Merge with NetBSD make, pick up o var.c: allow :_=var and avoid use of special context. 2017-01-30 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170130 Merge with NetBSD make, pick up o var.c: add :range and :_ o main.c: partially initialize Dir_* before MainParseArgs() can be called. If -V, skip Main_ExportMAKEFLAGS() 2017-01-14 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20170114 Merge with NetBSD make, pick up o var.c: allow specifying the utc value used by :{gm,local}time 2016-12-12 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20161212 Merge with NetBSD make, pick up o main.c: look for obj.${MACHINE}-${MACHINE_ARCH} too. 2016-12-09 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20161209 Merge with NetBSD make, pick up o main.c: cleanup setting of .OBJDIR o parse.c: avoid coredump from (var)=val 2016-11-26 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20161126 Merge with NetBSD make, pick up o make.c: Make_OODate: report src node name if path not set 2016-09-26 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20160926 Merge with NetBSD make, pick up o support for .DELETE_ON_ERROR: (remove targets that fail) 2016-09-26 Simon J. Gerraty * Makefile MAN: tweak .Dt to match ${PROG} 2016-08-18 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20160818 its a neater number; pick up whitespace fixes to man page. 2016-08-17 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20160817 Merge with NetBSD make, pick up o meta.c: move handling of .MAKE.META.IGNORE_* to meta_ignore() so we can call it before adding entries to missingFiles. Thus we do not track files we have been told to ignore. 2016-08-15 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20160815 Merge with NetBSD make, pick up o meta_oodate: apply .MAKE.META.IGNORE_FILTER (if defined) to pathnames, and skip if the expansion is empty. Useful for dirdeps.mk when checking DIRDEPS_CACHE. 2016-08-12 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20160812 Merge with NetBSD make, pick up o meta.c: remove all missingFiles entries that match a deleted dir. o main.c: set .ERROR_CMD if possible. 2016-06-06 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20160606 Merge with NetBSD make, pick up o dir.c: extend mtimes cache to others via cached_stat() 2016-06-04 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20160604 Merge with NetBSD make, pick up o meta.c: missing filemon data is only relevant if we read a meta file. Also do not return oodate for a missing metafile if gn->path points to .CURDIR 2016-06-02 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20160602 Merge with NetBSD make, pick up o cached_realpath(): avoid hitting filesystem more than necessary. o meta.c: refactor need_meta decision, add knobs for missing meta file and filemon data wrt out-of-datedness. 2016-05-28 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20160528 * boot-strap, make-bootstrap.sh.in: Makefile now uses _MAKE_VERSION 2016-05-12 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20160512 Merge with NetBSD make, pick up o meta.c: ignore paths that match .MAKE.META.IGNORE_PATTERNS this is useful for gcov builds. o propagate errors from filemon(4). 2016-05-09 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20160509 Merge with NetBSD make, pick up o remove use of non-standard types u_int etc. o meta.c: apply realpath() before matching against metaIgnorePaths 2016-04-04 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20160404 Merge with NetBSD make, pick up o allow makefile to set .MAKE.JOBS * Makefile (PROG_NAME): use ${_MAKE_VERSION} 2016-03-15 Simon J. Gerraty * Makefile (_MAKE_VERSION): 20160315 Merge with NetBSD make, pick up o fix handling of archive members 2016-03-13 Simon J. Gerraty * Makefile (_MAKE_VERSION): rename variable to avoid interference with checks for ${MAKE_VERSION} 2016-03-10 Simon J. Gerraty * Makefile (MAKE_VERSION): 20160310 Merge with NetBSD make, pick up o meta.c: treat missing Read file same as Write, incase we Delete it. 2016-03-07 Simon J. Gerraty * Makefile (MAKE_VERSION): 20160307 Merge with NetBSD make, pick up o var.c: fix :ts\nnn to be octal by default. o meta.c: meta_finish() to cleanup memory. 2016-02-26 Simon J. Gerraty * Makefile (MAKE_VERSION): 20160226 Merge with NetBSD make, pick up o meta.c: allow meta file for makeDepend if makefiles want it. 2016-02-19 Simon J. Gerraty * var.c: default .MAKE.SAVE_DOLLARS to FALSE for backwards compatability. * Makefile (MAKE_VERSION): 20160220 Merge with NetBSD make, pick up o var.c: add knob to control handling of '$$' in := 2016-02-18 Simon J. Gerraty * Makefile (MAKE_VERSION): 20160218 Merge with NetBSD make, pick up o var.c: add .export-literal allows us to fix sys.clean-env.mk post the changes to Var_Subst. Var_Subst now takes flags, and does not consume '$$' in := 2016-02-17 Simon J. Gerraty * Makefile (MAKE_VERSION): 20160217 Merge with NetBSD make, pick up o var.c: preserve '$$' in := o parse.c: add .dinclude for handling included makefile like .depend 2015-12-20 Simon J. Gerraty * Makefile (MAKE_VERSION): 20151220 Merge with NetBSD make, pick up o suff.c: re-initialize suffNull when clearing suffixes. 2015-12-01 Simon J. Gerraty * Makefile (MAKE_VERSION): 20151201 Merge with NetBSD make, pick up o cond.c: CondCvtArg: avoid access beyond end of empty buffer. o meta.c: meta_oodate: use lstat(2) for checking link target in case it is a symlink. o var.c: avoid calling brk_string and Var_Export1 with empty strings. 2015-11-26 Simon J. Gerraty * Makefile (MAKE_VERSION): 20151126 Merge with NetBSD make, pick up o parse.c: ParseTrackInput don't access beyond end of old value. 2015-10-22 Simon J. Gerraty * Makefile (MAKE_VERSION): 20151022 * Add support for BSD/OS which lacks inttypes.h and really needs sys/param.h for sys/sysctl.h also 'type' is not a shell builtin. * var.c: eliminate uint32_t and need for inttypes.h * main.c: PrintOnError flush stdout before run .ERROR * parse.c: cope with _SC_PAGESIZE not being defined. 2015-10-20 Simon J. Gerraty * Makefile (MAKE_VERSION): 20151020 Merge with NetBSD make, pick up o var.c: fix uninitialized var 2015-10-12 Simon J. Gerraty * var.c: the conditional expressions used with ':?' can be expensive, if already discarding do not evaluate or expand anything. 2015-10-10 Simon J. Gerraty * Makefile (MAKE_VERSION): 20151010 Merge with NetBSD make, pick up o Add Boolean wantit flag to Var_Subst and Var_Parse when FALSE we know we are discarding the result and can skip operations like Cmd_Exec. 2015-10-09 Simon J. Gerraty * Makefile (MAKE_VERSION): 20151009 Merge with NetBSD make, pick up o var.c: don't check for NULL before free() o meta.c: meta_oodate, do not hard code ignore of makeDependfile 2015-09-10 Simon J. Gerraty * Makefile (MAKE_VERSION): 20150910 Merge with NetBSD make, pick up o main.c: with -w print Enter/Leaving messages for objdir too if necessary. o centralize shell metachar handling * FILES: add metachar.[ch] 2015-06-06 Simon J. Gerraty * Makefile (MAKE_VERSION): 20150606 Merge with NetBSD make, pick up o make.1: document .OBJDIR target 2015-05-05 Simon J. Gerraty * Makefile (MAKE_VERSION): 20150505 Merge with NetBSD make, pick up o cond.c: be strict about lhs of comparison when evaluating .if but less so when called from variable expansion. o unit-tests/cond2.mk: test various error conditions 2015-05-04 Simon J. Gerraty * machine.sh (MACHINE): Add Bitrig patch from joerg@netbsd.org 2015-04-18 Simon J. Gerraty * Makefile (MAKE_VERSION): 20150418 Merge with NetBSD make, pick up o job.c: use memmove() rather than memcpy() * unit-tests/varshell.mk: SunOS cannot handle the TERMINATED_BY_SIGNAL case, so skip it. 2015-04-11 Simon J. Gerraty * Makefile (MAKE_VERSION): 20150411 bump version - only mk/ changes. 2015-04-10 Simon J. Gerraty * Makefile (MAKE_VERSION): 20150410 Merge with NetBSD make, pick up o document different handling of '-' in jobs mode vs compat o fix jobs mode so that '-' only applies to whole job when shell lacks hasErrCtl o meta.c: use separate vars to track lcwd and latestdir (read) per process 2015-04-01 Simon J. Gerraty * Makefile (MAKE_VERSION): 20150401 Merge with NetBSD make, pick up o meta.c: close meta file in child * Makefile: use BINDIR.bmake if set. Same for MANDIR and SHAREDIR Handy for testing release candidates in various environments. 2015-03-26 Simon J. Gerraty * move initialization of savederr to block where it is used to avoid spurious warning from gcc5 2014-11-11 Simon J. Gerraty * Makefile (MAKE_VERSION): 20141111 just a cooler number 2014-11-05 Simon J. Gerraty * Makefile (MAKE_VERSION): 20141105 Merge with NetBSD make, pick up o revert major overhaul of suffix handling and POSIX compliance - too much breakage and impossible to make backwards compatible. o we still have the new unit test structure which is ok. o meta.c ensure "-- filemon" is at start of line. 2014-09-17 Simon J. Gerraty * configure.in: test that result of getconf PATH_MAX is numeric and discard if not. Apparently needed for Hurd. 2014-08-30 Simon J. Gerraty * Makefile (MAKE_VERSION): 20140830 Merge with NetBSD make, pick up o major overhaul of suffix handling o improved POSIX compliance o overhauled unit-tests 2014-06-20 Simon J. Gerraty * Makefile (MAKE_VERSION): 20140620 Merge with NetBSD make, pick up o var.c return varNoError rather than var_Error for ::= modifiers. 2014-05-22 Simon J. Gerraty * Makefile (MAKE_VERSION): 20140522 Merge with NetBSD make, pick up o var.c detect some parse errors. 2014-04-05 Simon J. Gerraty * Fix spelling errors - patch from Pedro Giffuni 2014-02-14 Simon J. Gerraty * Makefile (MAKE_VERSION): 20140214 Merge with NetBSD make, pick up o .INCLUDEFROM* o use Var_Value to get MAKEOBJDIR[PREFIX] o reduced realloc'ign in brk_string. * configure.in: add a check for compiler supporting __func__ 2014-01-03 Simon J. Gerraty * boot-strap: ignore mksrc=none 2014-01-02 Simon J. Gerraty * Makefile (DEFAULT_SYS_PATH?): use just ${prefix}/share/mk 2014-01-01 Simon J. Gerraty * Makefile (MAKE_VERSION): 20140101 * configure.in: set bmake_path_max to min(_SC_PATH_MAX,1024) * Makefile.config: defined BMAKE_PATH_MAX to bmake_path_max * make.h: use BMAKE_PATH_MAX if MAXPATHLEN not defined (needed for Hurd) * configure.in: Add AC_PREREQ and check for sysctl; patch from Andrew Shadura andrewsh at debian.org 2013-10-16 Simon J. Gerraty * Makefile (MAKE_VERSION): 20131010 * lose the const from arg to systcl to avoid problems on older BSDs. 2013-10-01 Simon J. Gerraty * Makefile (MAKE_VERSION): 20131001 Merge with NetBSD make, pick up o main.c: for NATIVE build sysctl to get MACHINE_ARCH from hw.machine_arch if necessary. o meta.c: meta_oodate - need to look at src of Link and target of Move as well. * main.c: check that CTL_HW and HW_MACHINE_ARCH exist. provide __arraycount() if needed. 2013-09-04 Simon J. Gerraty * Makefile (MAKE_VERSION): 20130904 Merge with NetBSD make, pick up o Add VAR_INTERNAL context, so that internal setting of MAKEFILE does not override value set by makefiles. 2013-09-02 Simon J. Gerraty * Makefile (MAKE_VERSION): 20130902 Merge with NetBSD make, pick up o CompatRunCommand: only apply shellErrFlag when errCheck is true 2013-08-28 Simon J. Gerraty * Makefile (MAKE_VERSION): 20130828 Merge with NetBSD make, pick up o Fix VAR :sh = syntax from Will Andrews at freebsd.org o Call Job_SetPrefix() from Job_Init() so makefiles have opportunity to set .MAKE.JOB.PREFIX 2013-07-30 Simon J. Gerraty * Makefile (MAKE_VERSION): 20130730 Merge with NetBSD make, pick up o Allow suppression of --- job -- tokens by setting .MAKE.JOB.PREFIX empty. 2013-07-16 Simon J. Gerraty * Makefile (MAKE_VERSION): 20130716 Merge with NetBSD make, pick up o number of gmake compatibility tweaks -w for gmake style entering/leaving messages if .MAKE.LEVEL > 0 indicate it in progname "make[1]" etc. handle MAKEFLAGS containing only letters. o when overriding a GLOBAL variable on the command line, delete it from GLOBAL context so -V doesn't show the wrong value. 2013-07-06 Simon J. Gerraty * configure.in: We don't need MAKE_LEVEL_SAFE anymore. * Makefile (MAKE_VERSION): 20130706 Merge with NetBSD make, pick up o Shell_Init(): export shellErrFlag if commandShell hasErrCtl is true so that CompatRunCommand() can use it, to ensure consistent behavior with jobs mode. o use MAKE_LEVEL_ENV to define the variable to propagate .MAKE.LEVEL - currently set to MAKELEVEL (same as gmake). o meta.c: use .MAKE.META.IGNORE_PATHS to allow customization of paths to ignore. 2013-06-04 Simon J. Gerraty * Makefile (MAKE_VERSION): 20130604 Merge with NetBSD make, pick up o job.c: JobCreatePipe: do fcntl() after any tweaking of fd's to avoid leaking descriptors. 2013-05-28 Simon J. Gerraty * Makefile (MAKE_VERSION): 20130528 Merge with NetBSD make, pick up o var.c: cleanup some left-overs in VarHash() 2013-05-20 Simon J. Gerraty * Makefile (MAKE_VERSION): 20130520 generate manifest from component FILES rather than have to update FILES when mk/FILES changes. 2013-05-18 Simon J. Gerraty * Makefile (MAKE_VERSION): 20130518 Merge with NetBSD make, pick up o suff.c: don't skip all processsing for .PHONY targets else wildcard srcs do not get expanded. o var.c: expand name of variable to delete if necessary. 2013-03-30 Simon J. Gerraty * Makefile (MAKE_VERSION): 20130330 Merge with NetBSD make, pick up o meta.c: refine the handling of .OODATE in commands. Rather than suppress command comparison for the entire script as though .NOMETA_CMP had been used, only suppress it for the one command line. This allows something like ${.OODATE:M.NOMETA_CMP} to be used to suppress comparison of a command without otherwise affecting it. o make.1: document that 2013-03-22 Simon J. Gerraty * Makefile (MAKE_VERSION): 20130321 yes, not quite right but its a cooler number. Merge with NetBSD make, pick up o parse.c: fix ParseGmakeExport to be portable and add a unit-test. * meta.c: call meta_init() before makefiles are read and if built with filemon support set .MAKE.PATH_FILEMON to _PATH_FILEMON this let's makefiles test for support. Call meta_mode_init() to process .MAKE.MODE. 2013-03-13 Simon J. Gerraty * Makefile (MAKE_VERSION): 20130305 Merge with NetBSD make, pick up o run .STALE: target when a dependency from .depend is missing. o job.c: add Job_RunTarget() for the above and .BEGIN 2013-03-03 Simon J. Gerraty * Makefile (MAKE_VERSION): 20130303 Merge with NetBSD make, pick up o main.c: set .MAKE.OS to utsname.sysname o job.c: more checks for read and poll errors o var.c: lose VarChangeCase() saves 4% time 2013-03-02 Simon J. Gerraty * boot-strap: remove MAKEOBJDIRPREFIX from environment since we want to use MAKEOBJDIR 2013-01-27 Simon J. Gerraty * Merge with NetBSD make, pick up o make.1: more info on how shell commands are handled. o job.c,main.c: detect write errors to job pipes. 2013-01-25 Simon J. Gerraty * Makefile (MAKE_VERSION): 20130123 Merge with NetBSD make, pick up o meta.c: if script uses .OODATE and meta_oodate() decides rebuild is needed, .OODATE will be empty - set it to .ALLSRC. o var.c: in debug output indicate which variabale modifiers apply to. o remove Check_Cwd logic the makefiles have been fixed. 2012-12-12 Simon J. Gerraty * makefile.in: add a simple makefile for folk who insist on ./configure; make; make install it just runs boot-strap * include mk/* to accommodate the above * boot-strap: re-work to accommodate the above mksrc defaults to $Mydir/mk allow op={configure,build,install,clean,all} add options to facilitate install * Makefile.config.in: just the bits set by configure * Makefile: bump version to 20121212 abandon Makefile.in (NetBSD Makefile) leverage mk/* instead * configure.in: ensure srcdir is absolute 2012-11-11 Simon J. Gerraty * Makefile.in (MAKE_VERSION): 20121111 fix generation of bmake.cat1 2012-11-09 Simon J. Gerraty * Makefile.in (MAKE_VERSION): 20121109 Merge with NetBSD make, pick up o make.c: MakeBuildChild: return 0 so search continues if a .ORDER dependency is detected. o unit-tests/order: test the above 2012-11-02 Simon J. Gerraty * Makefile.in (MAKE_VERSION): 20121102 Merge with NetBSD make, pick up o cond.c: allow cond_state[] to grow. In meta mode with a very large tree, we can hit the limit while processing dirdeps. 2012-10-25 Simon J. Gerraty * Makefile.in: we need to use ${srcdir} not ${.CURDIR} 2012-10-10 Simon J. Gerraty * Makefile.in (MAKE_VERSION): 20121010 o protect syntax that only bmake parses correctly. o remove auto setting of FORCE_MACHINE, use configure's --with-force-machine=whatever if that is desired. 2012-10-08 Simon J. Gerraty * Makefile.in: do not lose history from make.1 when generating bmake.1 2012-10-07 Simon J. Gerraty * Makefile.in (MAKE_VERSION): 20121007 Merge with NetBSD make, pick up o compat.c: ignore empty commands - same as jobs mode. o make.1: document meta chars that cause use of shell 2012-09-11 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20120911 * bsd.after-import.mk: include Makefile.inc early and allow it to override PROG 2012-08-31 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20120831 Merge with NetBSD make, pick up o cast sizeof() to int for comparison o minor make.1 tweak 2012-08-30 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20120830 Merge with NetBSD make, pick up o .MAKE.EXPAND_VARIABLES knob can control default behavior of -V o debug flag -dV causes -V to show raw value regardless. 2012-07-05 Simon J. Gerraty * bsd.after-import.mk (after-import): ensure unit-tests/Makefile gets SRCTOP set. 2012-07-04 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20120704 Merge with NetBSD make, pick up o Job_ParseShell should call Shell_Init if it has been previously called. * Makefile.in: set USE_META based on configure result. also .PARSEDIR is safer indicator of bmake. 2012-06-26 Simon J. Gerraty * Makefile.in: bump version to 20120626 ensure CPPFLAGS is in CFLAGS * meta.c: avoid nested externs * bsd.after-import.mk: avoid ${.CURDIR}/Makefile as target 2012-06-20 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20120620 Merge with NetBSD make, pick up o make_malloc.c: avoid including make_malloc.h again * Makefile.in: avoid bmake only syntax or protect with .if defined(.MAKE.LEVEL) * bsd.after-import.mk: replace .-include with .sinclude ensure? SRCTOP gets a value * configure.in: look for filemon.h in /usr/include/dev/filemon first. 2012-06-19 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20120612 Merge with NetBSD make, pick up o use MAKE_ATTR_* rather than those defined by cdefs.h or compiler for greater portability. o unit-tests/forloop: check that .for works as expected wrt number of times and with "quoted strings". 2012-06-06 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20120606 Merge with NetBSD make, pick up o compat.c: use kill(2) rather than raise(3). * configure.in: look for sys/dev/filemon * bsd.after-import.mk: add a .-include "Makefile.inc" to Makefile and pass BOOTSTRAP_XTRAS to boot-strap. 2012-06-04 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20120604 Merge with NetBSD make, pick up o util.c and var.c share same var for tracking if environ has been reallocated. o util.c provide getenv with setenv. * Add MAKE_LEVEL_SAFE as an alternate means of passing MAKE_LEVEL when the shell actively strips .MAKE.* from the environment. We still refer to the variable always as .MAKE.LEVEL * util.c fix bug in findenv() was finding prefix of name. * compat.c: re-raising SIGINT etc after running .INTERRUPT results in more reliable termination of all activity on many platforms. 2012-06-02 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20120602 Merge with NetBSD make, pick up o for.c: handle quoted items in .for list 2012-05-30 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20120530 Merge with NetBSD make, pick up o compat.c: ignore empty command. 2012-05-24 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20120524 * FILES: add bsd.after-import.mk: A simple means of integrating bmake into a BSD build system. 2012-05-20 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20120520 Merge with NetBSD make, pick up o increased limit for nested conditionals. 2012-05-18 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20120518 Merge with NetBSD make, pick up o use _exit(2) in signal hanlder o Don't use the [dir] cache when building nodes that might have changed since the last exec. o Avoid nested extern declaration warnings. 2012-04-27 Simon J. Gerraty * meta.c (fgetLine): avoid %z - not portable. * parse.c: Since we moved include of sys/mman.h and def's of MAP_COPY etc. we got dups from a merge. 2012-04-24 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20120420 Merge with NetBSD make, pick up o restore duplicate supression in .MAKE.MAKEFILES runtime saving can be significant. o Var_Subst() uses Buf_DestroyCompact() to reduce memory consumption up to 20%. 2012-04-20 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20120420 Merge with NetBSD make, pick up o remove duplicate supression in .MAKE.MAKEFILES o improved dir cache behavior o gmake'ish export command 2012-03-25 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20120325 Merge with NetBSD make, pick up o fix parsing of :[#] in conditionals. 2012-02-10 Simon J. Gerraty * Makefile.in: replace use of .Nx in bmake.1 with NetBSD since some systems cannot cope with .Nx 2011-11-14 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20111111 Merge with NetBSD make, pick up o debug output for .PARSEDIR and .PARSEFILE 2011-10-10 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20111010 2011-10-09 Simon J. Gerraty * boot-strap: check for an expected file in the dirs we look for. * make-bootstrap.sh: pass on LDSTATIC 2011-10-01 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20111001 Merge with NetBSD make, pick up o ensure .PREFIX is set for .PHONY and .TARGET set for .PHONY run via .END o __dead used consistently 2011-09-10 Simon J. Gerraty * Makefile.in (MAKE_VERSION): 20110909 is a better number ;-) 2011-09-05 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110905 Merge with NetBSD make, pick up o meta_oodate: ignore makeDependfile 2011-08-28 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110828 Merge with NetBSD make, pick up o silent=yes in .MAKE.MODE causes meta mode to mark targets as SILENT if a .meta file is created 2011-08-18 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110818 Merge with NetBSD make, pick up o in meta mode, if target flagged .META a missing .meta file means target is out-of-date o fixes for gcc 4.5 warnings o simplify job printing code 2011-08-09 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110808 Merge with NetBSD make, pick up o do not touch OP_SPECIAL targets when doing make -t 2011-06-22 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110622 Merge with NetBSD make, pick up o meta_oodate detect corrupted .meta file and declare oodate. * configure.in: add check for setsid 2011-06-07 Simon J. Gerraty * Merge with NetBSD make, pick up o unit-tests/modts now works on MirBSD 2011-06-04 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110606 Merge with NetBSD make, pick up o ApplyModifiers: when we parse a variable which is not the entire modifier string, or not followed by ':', do not consider it as containing modifiers. o loadfile: ensure newline at end of mapped file. 2011-05-05 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110505 Merge with NetBSD make, pick up o .MAKE.META.BAILIWICK - list of prefixes which define the scope of make's control. In meta mode, any generated file within said bailiwick, which is found to be missing, causes current target to be out-of-date. 2011-04-11 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110411 Merge with NetBSD make, pick up o when long modifiers fail to match, check sysV style. - add a test case 2011-04-10 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110410 Merge with NetBSD make, pick up o :hash - cheap 32bit hash of value o :localtime, :gmtime - use value as format string for strftime. 2011-03-30 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110330 mostly because its a cooler version. Merge with NetBSD make, pick up o NetBSD tags for meta.[ch] o job.c call meta_job_finish() after meta_job_error(). o meta_job_error() should call meta_job_finish() to ensure .meta file is closed, and safe to copy - if .ERROR target wants. meta_job_finish() is safe to call repeatedly. 2011-03-29 Simon J. Gerraty * unit-tests/modts: use printf if it is a builtin, to save us from MirBSD * Makefile.in (MAKE_VERSION): bump version to 20110329 Merge with NetBSD make, pick up o fix for use after free() in CondDoExists(). o meta_oodate() report extra commands and return earlier. 2011-03-27 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110327 Merge with NetBSD make, pick up o meta.c, if .MAKE.MODE contains curdirOk=yes allow creating .meta files in .CURDIR * boot-strap (TOOL_DIFF): aparently at least on linux distro formats the output of 'type' differently - so eat any "()" 2011-03-06 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110306 Merge with NetBSD make, pick up o meta.c, only do getcwd() once 2011-03-05 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110305 Merge with NetBSD make, pick up o correct sysV substitution handling of empty lhs and variable o correct exists() check for dir with trailing / o correct handling of modifiers for non-existant variables during evaluation of conditionals. o ensure MAP_FILE is defined. o meta.c use curdir[] now exported by main.c 2011-02-25 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110225 Merge with NetBSD make, pick up o fix for incorrect .PARSEDIR when .OBJDIR is re-computed after makefiles have been read. o fix example of :? modifier in man page. 2011-02-13 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110214 Merge with NetBSD make, pick up o meta.c handle realpath() failing when generating meta file name. * sigcompat.c: convert to ansi so we can use higher warning levels. 2011-02-07 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110207 Merge with NetBSD make, pick up o fix for bug in meta mode. 2011-01-03 Simon J. Gerraty * parse.c: SunOS 5.8 at least does not have MAP_FILE 2011-01-01 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20110101 Merge with NetBSD make, pick up o use mmap(2) if available, for reading makefiles 2010-12-15 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20101215 Merge with NetBSD make, pick up o ensure meta_job_error() does not report a previous .meta file as being culprit. 2010-12-10 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20101210 Merge with NetBSD make, pick up o meta_oodate: track cwd per process, and only consider target out-of-date if missing file is outside make's CWD. Ignore files in /tmp/ etc. o to ensure unit-tests results match, need to control LC_ALL as well as LANG. o fix for parsing bug in var.c 2010-11-26 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20101126 Merge with NetBSD make, pick up o if stale dependency is an IMPSRC, search via .PATH o meta_oodate: if a referenced file is missing, target is out-of-date. o meta_oodate: if a target uses .OODATE in its commands, it (.OODATE) needs to be recomputed. o keep a pointer to youngest child node, rather than just its mtime. 2010-11-02 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20101101 2010-10-16 Simon J. Gerraty * machine.sh: like os.sh, allow for uname -p producing useless drivel 2010-09-13 Simon J. Gerraty * boot-strap: document configure knobs for meta and filemon. * Makefile.in (MAKE_VERSION): bump version to 20100911 Merge with NetBSD make, pick up o meta.c - meta mode * make-bootstrap.sh.in: handle meta.c * configure.in: add knobs for use_meta and filemon_h also, look for dirname, str[e]sep and strlcpy * util.c: add simple err[x] and warn[x] 2010-08-08 Simon J. Gerraty * boot-strap (TOOL_DIFF): set this to ensure tests use the same version of diff that configure tested * Makefile.in (MAKE_VERSION): bump version to 20100808 Merge with NetBSD make, pick up o in jobs mode, when we discover we cannot make something, call PrintOnError before exit. 2010-08-06 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100806 Merge with NetBSD make, pick up o formatting fixes for ignored errors o ensure jobs are cleaned up regardless of where wait() was called. 2010-06-28 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100618 * os.sh (MACHINE_ARCH): watch out for drivel from uname -p 2010-06-16 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100616 Merge with NetBSD make, pick up o man page update o call PrintOnError from JobFinish when we detect an error we are not ignoring. 2010-06-06 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100606 Merge with NetBSD make, pick up o man page update 2010-06-05 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100605 Merge with NetBSD make, pick up o use bmake_signal() which is a wrapper around sigaction() in place of signal() o add .export-env to allow exporting variables to environment without tracking (so no re-export when the internal value is changed). 2010-05-24 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100524 Merge with NetBSD make, pick up o fix for .info et al being greedy. 2010-05-23 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100520 Merge with NetBSD make, pick up o back to using realpath on argv[0] but only if contains '/' and does not start with '/'. 2010-05-10 Simon J. Gerraty * boot-strap: use absolute path for bmake when running tests. * Makefile.in (MAKE_VERSION): bump version to 20100510 Merge with NetBSD make, pick up o revert use of realpath on argv[0] too many corner cases. o print MAKE_PRINT_VAR_ON_ERROR before running .ERROR target. 2010-05-05 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100505 Merge with NetBSD make, pick up o fix for missed SIGCHLD when compiled with SunPRO actually for bmake, defining FORCE_POSIX_SIGNALS would have done the job. 2010-04-30 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100430 Merge with NetBSD make, pick up o fflush stdout before writing to stdout 2010-04-23 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100423 Merge with NetBSD make, pick up o updated unit tests for Haiku (this time for sure). * boot-strap: based on patch from joerg honor --with-default-sys-path better. * boot-strap: remove mention of --with-prefix-sys-path 2010-04-22 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100422 * Merge with NetBSD make, pick up o fix for vfork() on Darwin. o fix for bogus $TMPDIR. o set .MAKE.MODE=compat for -B o set .MAKE.JOBS=max_jobs for -j max_jobs o allow unit-tests to run without any *.mk o unit-tests/modmisc be more conservative in dirs presumed to exist. * boot-strap: ignore /usr/share/mk except on NetBSD. * unit-tests/Makefile.in: set LANG=C when running unit-tests to ensure sort(1) behaves as expected. 2010-04-21 Simon J. Gerraty * boot-strap: add FindHereOrAbove so we can use -m .../mk 2010-04-20 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100420 * Merge with NetBSD make, pick up o fix for variable realpath() behavior. we have to stat(2) the result to be sure. o fix for .export (all) when nested vars use :sh 2010-04-14 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100414 * Merge with NetBSD make, pick up o use realpath to resolve argv[0] (for .MAKE) if needed. o add realpath from libc. o add :tA to resolve variable via realpath(3) if possible. 2010-04-08 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100408 * Merge with NetBSD make, pick up o unit tests for .ERROR, .error o fix for .ERROR to ensure it cannot be default target. 2010-04-06 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100406 * Merge with NetBSD make, pick up o fix for compat mode "Error code" going to debug_file. o fix for .ALLSRC being populated twice. o support for .info, .warning and .error directives o .MAKE.MODE to control make's operational mode o .MAKE.MAKEFILE_PREFERENCE to control the preferred makefile name(s). o .MAKE.DEPENDFILE to control the name of the depend file o .ERROR target - run on failure. 2010-03-18 Simon J. Gerraty * make-bootstrap.sh.in: extract MAKE_VERSION from Makefile * os.sh,arch.c: patch for Haiku from joerg at netbsd 2010-03-17 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100222 * Merge with NetBSD make, pick up o better error msg for .for with mutiple inter vars * boot-strap: o use make-bootstrap.sh from joerg at netbsd to avoid the need for a native make when bootstrapping. o add "" everywhere ;-) o if /usr/share/tmac/andoc.tmac exists install nroff bmake.1 otherwise the pre-formated version. 2010-01-04 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20100102 * Merge with NetBSD make, pick up: o fix for -m .../ 2009-11-18 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20091118 * Merge with NetBSD make, pick up: o .unexport o report lines that start with '.' and should have ':' (catch typo's of .el*if). 2009-10-30 Simon J. Gerraty * configure.in: Ensure that srcdir and mksrc are absolute paths. 2009-10-09 Simon J. Gerraty * Makefile.in (MAKE_VERSION): fix version to 20091007 2009-10-07 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 200910007 * Merge with NetBSD make, pick up: o fix for parsing of :S;...;...; applied to .for loop iterator appearing in a dependency line. 2009-09-09 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20090909 * Merge with NetBSD make, pick up: o fix for -C, .CURDIR and .OBJDIR * boot-strap: o allow share_dir to be set independent of prefix. o select default share_dir better when prefix ends in $HOST_TARGET o if FORCE_BSD_MK etc were set, include them in the suggested install-mk command. 2009-09-08 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20090908 * Merge with NetBSD make, pick up: o .MAKE.LEVEL for recursion tracking o fix for :M scanning \: 2009-09-03 Simon J. Gerraty * configure.in: Don't -D__EXTENSIONS__ if AC_USE_SYSTEM_EXTENSIONS says "no". 2009-08-26 Simon J. Gerraty * Makefile.in (MAKE_VERSION): bump version to 20090826 Simplify MAKE_VERSION to just the bare date. * Merge with NetBSD make, pick up: o -C directory support. o support for SIGINFO o use $TMPDIR for temp files. o child of vfork should be careful about modifying parent's state. 2009-03-26 Simon J. Gerraty * Appy some patches for MiNT from David Brownlee 2009-02-26 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump version to 20090222 * Merge with NetBSD make, pick up: o Possible null pointer de-ref in Var_Set. 2009-02-08 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump version to 20090204 * Merge with NetBSD make, pick up: o bmake_malloc et al moved to their own .c o Count both () and {} when looking for the end of a :M pattern o Change 'Buffer' so that it is the actual struct, not a pointer to it. o strlist.c - functions for processing extendable arrays of pointers to strings. o ClientData replaced with void *, so const void * can be used. o New debug flag C for DEBUG_CWD 2008-11-11 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump version to 20081111 Apply patch from Joerg Sonnenberge to configure.in: o remove some redundant checks o check for emlloc etc only in libutil and require the whole family. util.c: o remove [v]asprintf which is no longer used. 2008-11-04 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump version to 20081101 * Merge with NetBSD make, pick up: o util.c: avoid use of putenv() - christos 2008-10-30 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump version to 20081030 pick up man page tweaks. 2008-10-29 Simon J. Gerraty * Makefile.in: move processing of LIBOBJS to after is definition! thus we'll have getenv.c in SRCS only if needed. * make.1: add examples of how to use :? * Makefile.in (BMAKE_VERSION): bump version to 20081029 * Merge with NetBSD make, pick up: o fix for .END processing with -j o segfault from Parse_Error when no makefile is open o handle numeric expressions in any variable expansion o debug output now defaults to stderr, -dF to change it - apb o make now uses bmake_malloc etc so that it can build natively on A/UX - wasn't an issue for bmake, but we want to keep in sync. 2008-09-27 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump version to 20080808 * Merge with NetBSD make, pick up: o fix for PR/38840: Pierre Pronchery: make crashes while parsing long lines in Makefiles o optimizations for VarQuote by joerg o fix for PR/38756: dominik: make dumps core on invalid makefile 2008-05-15 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump version to 20080515 * Merge with NetBSD make, pick up: o fix skip setting vars in VAR_GLOBAL context, to handle cases where VAR_CMD is used for other than command line vars. 2008-05-14 Simon J. Gerraty * boot-strap (make_version): we may need to look in $prefix/share/mk for sys.mk * Makefile.in (BMAKE_VERSION): bump version to 20080514 * Merge with NetBSD make, pick up: o skip setting vars in VAR_GLOBAL context, when already set in VAR_CMD which takes precedence. 2008-03-30 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump version to 20080330 * Merge with NetBSD make, pick up: o fix for ?= when LHS contains variable reference. 2008-02-15 Simon J. Gerraty * merge some patches from NetBSD pkgsrc. * makefile.boot.in (BOOTSTRAP_SYS_PATH): Allow better control of the MAKSYSPATH used during bootstrap. * Makefile.in (BMAKE_VERSION): bump version to 20080215 * Merge with NetBSD make, pick up: o warn if non-space chars follow 'empty' in a conditional. 2008-01-18 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump version to 20080118 * Merge with NetBSD make, pick up: o consider dependencies read from .depend as optional - dsl o remember when buffer for reading makefile grows - dsl o add -dl (aka LOUD) - David O'Brien 2007-10-22 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump version to 20071022 * Merge with NetBSD make, pick up: o Allow .PATH to be used for .include "" * boot-strap: source default settings from .bmake-boot-strap.rc 2007-10-16 Simon J. Gerraty * Makefile.in: fix maninstall on various systems provided that our man.mk is used. For non-BSD systems we install the preformatted page into $MANDIR/cat1 2007-10-15 Simon J. Gerraty * boot-strap: make bmake.1 too, so maninstall works. 2007-10-14 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump version to 20071014 * Merge with NetBSD make, pick up: o revamped handling of defshell - configure no longer needs to know the content of the shells array - apb o stop Var_Subst modifying its input - apb o avoid calling ParseTrackInput too often - dsl 2007-10-11 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump version to 20071011 * Merge with NetBSD make, pick up: o fix Shell_Init for case that _BASENAME_DEFSHELL is absolute path. * sigcompat.c: some tweaks for HP-UX 11.x based on patch from Tobias Nygren * configure.in: update handling of --with-defshell to match new make behavior. --with-defshell=/usr/xpg4/bin/sh will now do what one might hope - provided the chosen shell behaves enough like sh. 2007-10-08 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20071008 * Merge with NetBSD make, pick up: o .MAKE.JOB.PREFIX - control the token output before jobs - sjg o .export/.MAKE.EXPORTED - export of variables - sjg o .MAKE.MAKEFILES - track all makefiles read - sjg o performance improvements - dsl o revamp parallel job scheduling - dsl 2006-07-28 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20060728 * Merge with NetBSD make, pick up: o extra debug info during variable and cond processing - sjg o shell definition now covers newline - rillig o minor mem leak in PrintOnError - sjg 2006-05-11 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20060511 * Merge with NetBSD make, pick up: o more memory leaks - coverity o possible overflow in ArchFindMember - coverity o extract variable modifier code out of Var_Parse() so it can be called recursively - sjg o unit-tests/moderrs - sjg 2006-04-12 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20060412 * Merge with NetBSD make, pick up: o fixes for some memory leaks - coverity o only read first sys.mk etc when searching sysIncPath - sjg * main.c (ReadMakefile): remove hack for __INTERIX that prevented setting ${MAKEFILE} - OBATA Akio 2006-03-18 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20060318 * Merge with NetBSD make, pick up: o cleanup of job.c to remove remote handling, distcc is more useful and this code was likely bit-rotting - dsl o fix for :P modifier - sjg * boot-strap: set default prefix to something reasonable (for me anyway). 2006-03-01 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20060301 * Merge with NetBSD make, pick up: o make .WAIT apply recursively, document and test case - apb o allow variable modifiers in a variable appear anywhere in modifier list, document and test case - sjg 2006-02-22 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20060222 * Merge with NetBSD make, pick up: o improved job token handling - dsl o SIG_DFL the correct signal before exec - dsl o more debug info during parsing - dsl o allow variable modifiers to be specified via variable - sjg * boot-strap: explain why we died if no mksrc 2005-11-05 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20051105 * configure.in: always set default_sys_path default is ${prefix}/share/mk - remove prefix_sys_path, anyone wanting more than above needs to set it manually. 2005-11-04 Simon J. Gerraty * boot-strap: make this a bit easier for pkgsrc folk. bootstrap still fails on IRIX64 since MACHINE_ARCH gets set to 'mips' while pkgsrc wants 'mipseb' or 'mipsel' 2005-11-02 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20051102 * job.c (JobFinish): fix likely ancient merge lossage fix from Todd Vierling. * boot-strap (srcdir): allow setting mksrc=none 2005-10-31 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20051031 * ranlib.h: skip on OSF too. (NetBSD PR 31864) 2005-10-10 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20051002 fix a silly typo 2005-10-09 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20051001 support for UnixWare and some other systems, based on patches from pkgsrc/bootstrap 2005-09-03 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20050901 * Merge with NetBSD make, pick up: o possible parse error causing us to wander off. 2005-06-06 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20050606 * Merge with NetBSD make, pick up: o :0x modifier for randomizing a list o fixes for a number of -Wuninitialized issues. 2005-05-30 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20050530 * Merge with NetBSD make, pick up: o Handle dependencies for .BEGIN, .END and .INTERRUPT * README: was seriously out of date. 2005-03-22 Simon J. Gerraty * Important to use .MAKE rather than MAKE. 2005-03-15 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20050315 * Merge with NetBSD make, pick up: o don't mistake .elsefoo for .else o use suffix-specific search path correctly o bunch of style nits 2004-05-11 Simon J. Gerraty * boot-strap: o ensure that args to --src and --with-mksrc are resolved before giving them to configure. o add -o "objdir" so that builder can control it, default is $OS as determined by os.sh o add -q to suppress all the install instructions. 2004-05-08 Simon J. Gerraty * Remove __IDSTRING() * Makefile.in (BMAKE_VERSION): bump to 20040508 * Merge with NetBSD make, pick up: o posix fixes - remove '-e' from compat mode - add support for '+' command-line prefix. o fix for handling '--' on command-line. o fix include in lst.lib/lstInt.h to simplify '-I's o we also picked up replacement of MAKE_BOOTSTRAP with !MAKE_NATIVE which is a noop, but possibly confusing. 2004-04-14 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20040414 * Merge with NetBSD make, pick up: o allow quoted strings on lhs of conditionals o issue warning when extra .else is seen o print line numer when errors encountered during parsing from string. 2004-02-20 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20040220 * Merge with NetBSD make, pick up: o fix for old :M parsing bug. o re-jigged unit-tests 2004-02-15 Simon J. Gerraty * Makefile.in (accept test): use ${.MAKE:S,^./,${.CURDIR}/,} so that './bmake -f Makefile test' works. 2004-02-14 Simon J. Gerraty * Makefile.in: (BMAKE_VERSION): bump to 20040214 * Merge with NetBSD make, pick up: o search upwards for *.mk o fix for double free of var substitution buffers o use of getopt replaced with custom code, since the usage (re-scanning) isn't posix compatible. 2004-02-12 Simon J. Gerraty * arch.c: don't include ranlib.h on ELF systems (thanks to Chuck Cranor ). 2004-01-18 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump to 20040118 * boot-strap (while): export vars we assign to on cmdline * unit-test/Makefile.in: ternary is .PHONY 2004-01-08 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump version to 20040108 * Merge with NetBSD make, pick up: o fix for ternary modifier 2004-01-06 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump version to 20040105 * Merge with NetBSD make, pick up: o fix for cond.c to handle compound expressions better o variable expansion within sysV style replacements 2003-12-22 Simon J. Gerraty * Make portable snprintf safer - output to /dev/null first to check space needed. * Makefile.in (BMAKE_VERSION): bump version to 20031222 * Merge with NetBSD make, pick up: o -dg3 to show input graph when things go wrong. o explicitly look for makefiles in objdir if not found in curdir so that errors in .depend etc will be reported accurarely. o avoid use of -e in shell scripts in jobs mode, use '|| exit $?' instead as it more accurately reflects the expected behavior and is more consistently implemented. o avoid use of asprintf. 2003-09-28 Simon J. Gerraty * util.c: Add asprintf and vasprintf. * Makefile.in (BMAKE_VERSION): bump version to 20030928 * Merge with NetBSD make, pick up: :[] modifier - allows picking words from a variable. :tW modifier - allows treating value as one big word. W flag for :C and :S - allows treating value as one big word. 2003-09-12 Simon J. Gerraty * Merge with NetBSD make pick up -de flag to enable printing failed command. don't skip 1st two dir entries (normally . and ..) since coda does not have them. 2003-09-09 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump version to 20030909 * Merge with NetBSD make, pick up: - changes for -V '${VAR}' to print fully expanded value cf. -V VAR - CompatRunCommand now prints the command that failed. - several files got updated 3 clause Berkeley license. 2003-08-02 Simon J. Gerraty * boot-strap: Allow setting configure args on command line. 2003-07-31 Simon J. Gerraty * configure.in: add --with-defshell to allow sh or ksh to be selected as default shell. * Makefile.in: bump version to 20030731 * Merge with NetBSD make Pick up .SHELL spec for ksh and associate man page changes. Also compat mode now uses the same shell specs. 2003-07-29 Simon J. Gerraty * var.c (Var_Parse): ensure delim is initialized. * unit-tests/Makefile.in: use single quotes to avoid problems from some shells. * makefile.boot.in: Run the unit-tests as part of the bootstrap procedure. 2003-07-28 Simon J. Gerraty * unit-tests/Makefile.in: always force complaints from ${TEST_MAKE} to be from 'make'. * configure.in: add check for 'diff -u' also fix some old autoconf'isms * Makefile.in (BMAKE_VERSION): bump version to 20030728. if using GCC add -Wno-cast-qual to CFLAGS for var.o * Merge with NetBSD make Pick up fix for :ts parsing error in some cases. Pick unit-tests. 2003-07-23 Simon J. Gerraty * Makefile.in (BMAKE_VERSION): bump version to 20030723. * var.c (Var_Parse): fix bug in :ts modifier, after const correctness fixes, must pass nstr to VarModify. 2003-07-14 Simon J. Gerraty * Makefile.in: BMAKE_VERSION switch to a date based version. We'll generally use the date of last import from NetBSD. * Merge with NetBSD make Pick up fixes for const-correctness, now passes WARNS=3 on NetBSD. Pick up :ts modifier, allows controlling the separator used between words in variable expansion. 2003-07-11 Simon J. Gerraty * FILES: include boot-strap and os.sh * Makefile.in: only set WARNS if we are NetBSD, the effect on FreeBSD is known to be bad. * makefile.boot.in (bootstrap): make this the default target. * Makefile.in: bump version to 3.1.19 * machine.sh: avoid A-Z with tr as it is bound to lose. 2003-07-10 Simon J. Gerraty * Merge with NetBSD make Pick up fix for PR/19781 - unhelpful error msg on unclosed ${var:foo Plus some doc fixes. 2003-04-27 Simon J. Gerraty * Merge with NetBSD make Pick up fix for PR/1523 - don't count a library as built, if there is no way to build it * Bump version to 3.1.18 2003-03-23 Simon J. Gerraty * Merge with NetBSD make Pick up fix for ParseDoSpecialSrc - we only use it if .WAIT appears in src list. 2003-03-21 Simon J. Gerraty * Merge with NetBSD make (mmm 10th anniversary!) pick up fix for .WAIT in srcs that refer to $@ or $* (PR#20828) pick up -X which tells us to not export VAR=val via setenv if we are already doing so via MAKEFLAGS. This saves valuable env space on systems like Darwin. set MAKE_VERSION to 3.1.17 * parse.c: pix up fix for suffix rules 2003-03-06 Simon J. Gerraty * Merge with NetBSD make. pick up fix for propagating -B via MAKEFLAGS. set MAKE_VERSION to 3.1.16 * Apply some patches from pkgsrc-bootstrap/bmake Originally by Grant Beattie I may have missed some - since they are based on bmake-3.1.12 2002-12-03 Simon J. Gerraty * makefile.boot.in (bmake): update install targets for those that use them, also clear MAKEFLAGS when invoking bmake.boot to avoid havoc from gmake -w. Thanks to Harlan Stenn . * bmake.cat1: update the pre-formatted man page! 2002-11-30 Simon J. Gerraty * Merge with NetBSD make. pick up fix for premature free of pointer used in call to Dir_InitCur(). set MAKE_VERSION to 3.1.15 2002-11-26 Simon J. Gerraty * configure.in: determine suitable value for MKSRC. override using --with-mksrc=PATH. * machine.sh: use `uname -p` for MACHINE_ARCH on modern SunOS systems. configs(8) will use 'sun4' as an alias for 'sparc'. 2002-11-25 Simon J. Gerraty * Merge with NetBSD make. pick up ${.PATH} pick up fix for finding ../cat.c via .PATH when .CURDIR=.. set MAKE_VERSION to 3.1.14 add configure checks for killpg and sys/socket.h 2002-09-16 Simon J. Gerraty * tag bmake-3-1-13 * makefile.boot.in (bmake): use install-mk Also setup ./mk before trying to invoke bmake.boot incase we needed install-mk to create a sys.mk for us. * configure.in: If we need to add -I${srcdir}/missing, make it an absolute path so that it works for lst.lib too. * make.h: always include sys/cdefs.h since we provide one if the host does not. * Makefile.in (install-mk): use MKSRC/install-mk which will do the right thing. use uname -p for ARCH if possible. since install-mk will setup links bsd.prog.mk -> prog.mk if needed, just .include bsd.prog.mk * Merge with NetBSD make (NetBSD-1.6) Code is ansi-C only now. Bug in handling of dotLast is fixed. Can now assign .OBJDIR and make will reset its notions of life. New modifiers :tu :tl for toUpper and toLower. Tue Oct 16 12:18:42 2001 Simon J. Gerraty * Merge with NetBSD make pick up fix for .END failure in compat mode. pick up fix for extra va_end() in ParseVErrorInternal. Thu Oct 11 13:20:06 2001 Simon J. Gerraty * configure.in: for systems that have sys/cdefs.h check if it is compatible. If not, include the one under missing, but tell it to include the native one too - necessary on Linux. * missing/sys/cdefs.h: if NEED_HOST_CDEFS_H is defined, use include_next (for gcc) to get the native sys/cdefs.h Tue Aug 21 02:29:34 2001 Simon J. Gerraty * job.c (JobFinish): Fix an earlier merge bug that resulted in leaking descriptors when using -jN. * job.c (JobPrintCommand): See if "curdir" exists before attempting to chdir(). Doing the chdir directly in make (when in compat mode) fails silently, so let the -jN version do the same. This can happen when building kernels in an object tree and playing clever games to reset .CURDIR. * Merged with NetBSD make pick up .USEBEFORE Tue Jun 26 23:45:11 2001 Simon J. Gerraty * makefile.boot.in: Give bmake.boot a MAKESYSPATH that might work. Tue Jun 12 16:48:57 2001 Simon J. Gerraty * var.c (Var_Set): Add 4th (flags) arg so VarLoopExpand can tell us not to export the iterator variable when using VAR_CMD context. Sun Jun 10 21:55:21 2001 Simon J. Gerraty * job.c (Job_CatchChildren): don't call Job_CatchOutput() here, its the wrong "fix". Sat Jun 9 00:11:24 2001 Simon J. Gerraty * Redesigned export of VAR_CMD's via MAKEFLAGS. We now simply append the variable names to .MAKEOVERRIDES, and handle duplicate suppression and quoting in ExportMAKEFLAGS using: ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@} Apart from fixing quoting bugs in previous version, this allows us to export vars to the environment by simply doing: .MAKEOVERRIDES+= PATH Merged again with NetBSD make, but the above is the only change. * configure.in: added --disable-pwd-override disable $PWD overriding getcwd() --disable-check-make-chdir disable make trying to guess when it should automatically cd ${.CURDIR} * Merge with NetBSD make, changes include: parse.c (ParseDoDependency): Spot that the syntax error is caused by an unresolved cvs/rcs conflict and say so. var.c: most of Var* functions now take a ctxt as 1st arg. now does variable substituion on rhs of sysv style modifiers. * var.c (Var_Set): exporting of command line variables (VAR_CMD) is now done here. We append the name='value' to .MAKEOVERRIDES rather than directly into MAKEFLAGS as this allows a Makefile to use .MAKEOVERRIDES= to disable this behaviour. GNU make uses a very similar mechanism. Note that in adding name='value' to .MAKEOVERRIDES we do the moral equivalent of: .MAKEOVERRIDES:= ${.MAKEOVERRIDES:Nname=*} name='val' Fri Jun 1 14:08:02 2001 Simon J. Gerraty * make-conf.h (USE_IOVEC): make it conditional on HAVE_SYS_UIO_H * Merged with NetBSD make make -dx can now be used to run commands via sh -x better error messages on exec failures. Thu May 31 01:44:54 2001 Simon J. Gerraty * Makefile.in (main.o): depends on ${SRCS} ${MAKEFILE} so that MAKE_VERSION gets updated. Also don't use ?= for MAKE_VERSION, MACHINE etc otherwise they propagate from the previous bmake. * configure.in (machine): allow --with-machine=generic to make configure use machine.sh to set MACHINE. * job.c (JobInterrupt): convert to using WAIT_T and friends. * Makefile.in: mention in bmake.1 that we use autoconf. * make.1: mention MAKE_PRINT_VAR_ON_ERROR. Wed May 30 23:17:18 2001 Simon J. Gerraty * main.c (ReadMakefile): don't set MAKEFILE if reading ".depend" as that rather defeats the usefulness of ${MAKEFILE}. * main.c (MainParseArgs): append command line variable assignments to MAKEFLAGS so that they get propagated to child make's. Apparently this is required POSIX behaviour? Its useful anyway. Tue May 29 02:20:07 2001 Simon J. Gerraty * compat.c (CompatRunCommand): don't use perror() since stdio may cause problems in child of vfork(). * compat.c, main.c: Call PrintOnError() when we are going to bail. This routine prints out the .curdir where we stopped and will also display any vars listed in ${MAKE_PRINT_VAR_ON_ERROR}. * main.c: add ${.newline} to hold a "\n" - sometimes handy in :@ expansion. * var.c: VarLoopExpand: ignore addSpace if a \n is present. * Added RCSid's for the files we've touched. Thu May 24 15:41:37 2001 Simon J. Gerraty * configure.in: Thanks to some clues from mdb@juniper.net, added autoconf magic to control setting of MACHINE, MACHINE_ARCH as well as what ends up in _PATH_DEFSYSPATH. We now have: --with-machine=MACHINE explicitly set MACHINE --with-force-machine=MACHINE set FORCE_MACHINE --with-machine_arch=MACHINE_ARCH explicitly set MACHINE_ARCH --with-default-sys-path=PATH:DIR:LIST use an explicit _PATH_DEFSYSPATH --with-prefix-sys-path=PATH:DIR:LIST prefix _PATH_PREFIX_SYSPATH --with-path-objdirprefix=PATH override _PATH_OBJDIRPREFIX If _PATH_OBJDIRPREFIX is set to "no" we won't define it. * makefile: added a pathetically simple makefile to drive bootstrapping. Running configure by hand is more useful. * Makefile.in: added MAKE_VERSION, and reworked things to be less dependent on NetBSD bsd.*.mk * pathnames.h: allow NO_PATH_OBJDIRPREFIX to stop us defining _PATH_OBJDIRPREFIX for those that don't want a default. construct _PATH_DEFSYSPATH from the info we get from configure. * main.c: allow for no _PATH_OBJDIRPREFIX, set ${MAKE_VERSION} if MAKE_VERSION is defined. * compat.c: when we bail, print out the .CURDIR we were in. Sat May 12 00:34:12 2001 Simon J. Gerraty * Merged with NetBSD make * var.c: fixed a bug in the handling of the modifier :P if the node as found but the path was null, we segfault trying to duplicate it. Mon Mar 5 16:20:33 2001 Simon J. Gerraty * Merged with NetBSD make * make.c: Make_OODate's test for a library out of date was using cmtime where it should have used mtime (my bug). * compat.c: Use perror() to tell us what really went wrong when we cannot exec a command. Fri Dec 15 10:11:08 2000 Simon J. Gerraty * Merged with NetBSD make Sat Jun 10 10:11:08 2000 Simon J. Gerraty * Merged with NetBSD make Thu Jun 1 10:11:08 2000 Simon J. Gerraty * Merged with NetBSD make Tue May 30 10:11:08 2000 Simon J. Gerraty * Merged with NetBSD make Thu Apr 27 00:07:47 2000 Simon J. Gerraty * util.c: don't provide signal() since we use sigcompat.c * Makefile.in: added a build target. * var.c (Var_Parse): added ODE modifiers :U, :D, :L, :P, :@ and :! These allow some quite clever magic. * main.c (main): added support for getenv(MAKESYSPATH). Mon Apr 2 16:25:13 2000 Simon J. Gerraty * Disable $PWD overriding getcwd() if MAKEOBJDIRPREFIX is set. This avoids objdir having a different value depending on how a directory was reached (via command line, or subdir.mk). * If FORCE_MACHINE is defined, ignore getenv("MACHINE"). Mon Apr 2 23:15:31 2000 Simon J. Gerraty * Do a chdir(${.CURDIR}) before invoking ${.MAKE} or ${.MAKE:T} if MAKEOBJDIRPREFIX is set and NOCHECKMAKECHDIR is not. I've been testing this in NetBSD's make for some weeks. * Turn Makefile into Makefile.in and make it useful. Tue Feb 29 22:08:00 2000 Simon J. Gerraty * Imported NetBSD's -current make(1) and resolve conflicts. * Applied autoconf patches from bmake v2 * Imported clean code base from NetBSD-1.0 diff --git a/FILES b/FILES index 642b1bae7a6b..5ec98a096339 100644 --- a/FILES +++ b/FILES @@ -1,874 +1,874 @@ ChangeLog FILES LICENSE Makefile Makefile.config.in PSD.doc/Makefile PSD.doc/tutorial.ms README VERSION _strtol.h aclocal.m4 arch.c bmake.1 bmake.cat1 boot-strap bsd.after-import.mk buf.c buf.h compat.c cond.c config.h.in configure configure.in dir.c dir.h dirname.c filemon/filemon.h filemon/filemon_dev.c filemon/filemon_ktrace.c find_lib.sh for.c getopt.c hash.c hash.h install-sh job.c job.h lst.c lst.h machine.sh main.c make-bootstrap.sh.in make-conf.h make.1 make.c make.h make_malloc.c make_malloc.h makefile.in meta.c meta.h metachar.c metachar.h missing/sys/cdefs.h mkdeps.sh os.sh parse.c pathnames.h ranlib.h realpath.c setenv.c sigact.h sigaction.c sigcompat.c str.c str.h stresep.c strlcpy.c suff.c targ.c trace.c trace.h unit-tests/Makefile unit-tests/Makefile.config.in unit-tests/archive-suffix.exp unit-tests/archive-suffix.mk unit-tests/archive.exp unit-tests/archive.mk unit-tests/cmd-errors-jobs.exp unit-tests/cmd-errors-jobs.mk unit-tests/cmd-errors-lint.exp unit-tests/cmd-errors-lint.mk unit-tests/cmd-errors.exp unit-tests/cmd-errors.mk unit-tests/cmd-interrupt.exp unit-tests/cmd-interrupt.mk unit-tests/cmdline-redirect-stdin.exp unit-tests/cmdline-redirect-stdin.mk unit-tests/cmdline-undefined.exp unit-tests/cmdline-undefined.mk unit-tests/cmdline.exp unit-tests/cmdline.mk unit-tests/comment.exp unit-tests/comment.mk unit-tests/compat-error.exp unit-tests/compat-error.mk unit-tests/cond-cmp-numeric-eq.exp unit-tests/cond-cmp-numeric-eq.mk unit-tests/cond-cmp-numeric-ge.exp unit-tests/cond-cmp-numeric-ge.mk unit-tests/cond-cmp-numeric-gt.exp unit-tests/cond-cmp-numeric-gt.mk unit-tests/cond-cmp-numeric-le.exp unit-tests/cond-cmp-numeric-le.mk unit-tests/cond-cmp-numeric-lt.exp unit-tests/cond-cmp-numeric-lt.mk unit-tests/cond-cmp-numeric-ne.exp unit-tests/cond-cmp-numeric-ne.mk unit-tests/cond-cmp-numeric.exp unit-tests/cond-cmp-numeric.mk unit-tests/cond-cmp-string.exp unit-tests/cond-cmp-string.mk unit-tests/cond-cmp-unary.exp unit-tests/cond-cmp-unary.mk unit-tests/cond-eof.exp unit-tests/cond-eof.mk unit-tests/cond-func-commands.exp unit-tests/cond-func-commands.mk unit-tests/cond-func-defined.exp unit-tests/cond-func-defined.mk unit-tests/cond-func-empty.exp unit-tests/cond-func-empty.mk unit-tests/cond-func-exists.exp unit-tests/cond-func-exists.mk unit-tests/cond-func-make-main.exp unit-tests/cond-func-make-main.mk unit-tests/cond-func-make.exp unit-tests/cond-func-make.mk unit-tests/cond-func-target.exp unit-tests/cond-func-target.mk unit-tests/cond-func.exp unit-tests/cond-func.mk unit-tests/cond-late.exp unit-tests/cond-late.mk unit-tests/cond-op-and-lint.exp unit-tests/cond-op-and-lint.mk unit-tests/cond-op-and.exp unit-tests/cond-op-and.mk unit-tests/cond-op-not.exp unit-tests/cond-op-not.mk unit-tests/cond-op-or-lint.exp unit-tests/cond-op-or-lint.mk unit-tests/cond-op-or.exp unit-tests/cond-op-or.mk unit-tests/cond-op-parentheses.exp unit-tests/cond-op-parentheses.mk unit-tests/cond-op.exp unit-tests/cond-op.mk unit-tests/cond-short.exp unit-tests/cond-short.mk unit-tests/cond-token-number.exp unit-tests/cond-token-number.mk unit-tests/cond-token-plain.exp unit-tests/cond-token-plain.mk unit-tests/cond-token-string.exp unit-tests/cond-token-string.mk unit-tests/cond-token-var.exp unit-tests/cond-token-var.mk unit-tests/cond-undef-lint.exp unit-tests/cond-undef-lint.mk unit-tests/counter-append.exp unit-tests/counter-append.mk unit-tests/counter.exp unit-tests/counter.mk unit-tests/dep-colon-bug-cross-file.exp unit-tests/dep-colon-bug-cross-file.mk unit-tests/dep-colon.exp unit-tests/dep-colon.mk unit-tests/dep-double-colon-indep.exp unit-tests/dep-double-colon-indep.mk unit-tests/dep-double-colon.exp unit-tests/dep-double-colon.mk unit-tests/dep-duplicate.exp unit-tests/dep-duplicate.mk unit-tests/dep-exclam.exp unit-tests/dep-exclam.mk unit-tests/dep-none.exp unit-tests/dep-none.mk unit-tests/dep-op-missing.exp unit-tests/dep-op-missing.mk unit-tests/dep-percent.exp unit-tests/dep-percent.mk unit-tests/dep-var.exp unit-tests/dep-var.mk unit-tests/dep-wildcards.exp unit-tests/dep-wildcards.mk unit-tests/dep.exp unit-tests/dep.mk unit-tests/depsrc-end.exp unit-tests/depsrc-end.mk unit-tests/depsrc-exec.exp unit-tests/depsrc-exec.mk unit-tests/depsrc-ignore.exp unit-tests/depsrc-ignore.mk unit-tests/depsrc-made.exp unit-tests/depsrc-made.mk unit-tests/depsrc-make.exp unit-tests/depsrc-make.mk unit-tests/depsrc-meta.exp unit-tests/depsrc-meta.mk unit-tests/depsrc-nometa.exp unit-tests/depsrc-nometa.mk unit-tests/depsrc-nometa_cmp.exp unit-tests/depsrc-nometa_cmp.mk unit-tests/depsrc-nopath.exp unit-tests/depsrc-nopath.mk unit-tests/depsrc-notmain.exp unit-tests/depsrc-notmain.mk unit-tests/depsrc-optional.exp unit-tests/depsrc-optional.mk unit-tests/depsrc-phony.exp unit-tests/depsrc-phony.mk unit-tests/depsrc-precious.exp unit-tests/depsrc-precious.mk unit-tests/depsrc-recursive.exp unit-tests/depsrc-recursive.mk unit-tests/depsrc-silent.exp unit-tests/depsrc-silent.mk unit-tests/depsrc-use.exp unit-tests/depsrc-use.mk unit-tests/depsrc-usebefore-double-colon.exp unit-tests/depsrc-usebefore-double-colon.mk unit-tests/depsrc-usebefore.exp unit-tests/depsrc-usebefore.mk unit-tests/depsrc-wait.exp unit-tests/depsrc-wait.mk unit-tests/depsrc.exp unit-tests/depsrc.mk unit-tests/deptgt-begin-fail-indirect.exp unit-tests/deptgt-begin-fail-indirect.mk unit-tests/deptgt-begin-fail.exp unit-tests/deptgt-begin-fail.mk unit-tests/deptgt-begin.exp unit-tests/deptgt-begin.mk unit-tests/deptgt-default.exp unit-tests/deptgt-default.mk unit-tests/deptgt-delete_on_error.exp unit-tests/deptgt-delete_on_error.mk unit-tests/deptgt-end-fail-all.exp unit-tests/deptgt-end-fail-all.mk unit-tests/deptgt-end-fail-indirect.exp unit-tests/deptgt-end-fail-indirect.mk unit-tests/deptgt-end-fail.exp unit-tests/deptgt-end-fail.mk unit-tests/deptgt-end-jobs.exp unit-tests/deptgt-end-jobs.mk unit-tests/deptgt-end.exp unit-tests/deptgt-end.mk unit-tests/deptgt-error.exp unit-tests/deptgt-error.mk unit-tests/deptgt-ignore.exp unit-tests/deptgt-ignore.mk unit-tests/deptgt-interrupt.exp unit-tests/deptgt-interrupt.mk unit-tests/deptgt-main.exp unit-tests/deptgt-main.mk unit-tests/deptgt-makeflags.exp unit-tests/deptgt-makeflags.mk unit-tests/deptgt-no_parallel.exp unit-tests/deptgt-no_parallel.mk unit-tests/deptgt-nopath.exp unit-tests/deptgt-nopath.mk unit-tests/deptgt-notparallel.exp unit-tests/deptgt-notparallel.mk unit-tests/deptgt-objdir.exp unit-tests/deptgt-objdir.mk unit-tests/deptgt-order.exp unit-tests/deptgt-order.mk unit-tests/deptgt-path-suffix.exp unit-tests/deptgt-path-suffix.mk unit-tests/deptgt-path.exp unit-tests/deptgt-path.mk unit-tests/deptgt-phony.exp unit-tests/deptgt-phony.mk unit-tests/deptgt-posix.exp unit-tests/deptgt-posix.mk unit-tests/deptgt-precious.exp unit-tests/deptgt-precious.mk unit-tests/deptgt-shell.exp unit-tests/deptgt-shell.mk unit-tests/deptgt-silent-jobs.exp unit-tests/deptgt-silent-jobs.mk unit-tests/deptgt-silent.exp unit-tests/deptgt-silent.mk unit-tests/deptgt-stale.exp unit-tests/deptgt-stale.mk unit-tests/deptgt-suffixes.exp unit-tests/deptgt-suffixes.mk unit-tests/deptgt.exp unit-tests/deptgt.mk unit-tests/dir-expand-path.exp unit-tests/dir-expand-path.mk unit-tests/dir.exp unit-tests/dir.mk unit-tests/directive-dinclude.exp unit-tests/directive-dinclude.mk unit-tests/directive-elif.exp unit-tests/directive-elif.mk unit-tests/directive-elifdef.exp unit-tests/directive-elifdef.mk unit-tests/directive-elifmake.exp unit-tests/directive-elifmake.mk unit-tests/directive-elifndef.exp unit-tests/directive-elifndef.mk unit-tests/directive-elifnmake.exp unit-tests/directive-elifnmake.mk unit-tests/directive-else.exp unit-tests/directive-else.mk unit-tests/directive-endfor.exp unit-tests/directive-endfor.mk unit-tests/directive-endif.exp unit-tests/directive-endif.mk unit-tests/directive-error.exp unit-tests/directive-error.mk unit-tests/directive-export-env.exp unit-tests/directive-export-env.mk unit-tests/directive-export-gmake.exp unit-tests/directive-export-gmake.mk unit-tests/directive-export-impl.exp unit-tests/directive-export-impl.mk unit-tests/directive-export-literal.exp unit-tests/directive-export-literal.mk unit-tests/directive-export.exp unit-tests/directive-export.mk unit-tests/directive-for-break.exp unit-tests/directive-for-break.mk unit-tests/directive-for-empty.exp unit-tests/directive-for-empty.mk unit-tests/directive-for-errors.exp unit-tests/directive-for-errors.mk unit-tests/directive-for-escape.exp unit-tests/directive-for-escape.mk unit-tests/directive-for-generating-endif.exp unit-tests/directive-for-generating-endif.mk unit-tests/directive-for-if.exp unit-tests/directive-for-if.mk unit-tests/directive-for-lines.exp unit-tests/directive-for-lines.mk unit-tests/directive-for-null.exp unit-tests/directive-for-null.mk unit-tests/directive-for.exp unit-tests/directive-for.mk unit-tests/directive-hyphen-include.exp unit-tests/directive-hyphen-include.mk unit-tests/directive-if-nested.exp unit-tests/directive-if-nested.mk unit-tests/directive-if.exp unit-tests/directive-if.mk unit-tests/directive-ifdef.exp unit-tests/directive-ifdef.mk unit-tests/directive-ifmake.exp unit-tests/directive-ifmake.mk unit-tests/directive-ifndef.exp unit-tests/directive-ifndef.mk unit-tests/directive-ifnmake.exp unit-tests/directive-ifnmake.mk unit-tests/directive-include-fatal.exp unit-tests/directive-include-fatal.mk unit-tests/directive-include.exp unit-tests/directive-include.mk unit-tests/directive-info.exp unit-tests/directive-info.mk unit-tests/directive-misspellings.exp unit-tests/directive-misspellings.mk unit-tests/directive-sinclude.exp unit-tests/directive-sinclude.mk unit-tests/directive-undef.exp unit-tests/directive-undef.mk unit-tests/directive-unexport-env.exp unit-tests/directive-unexport-env.mk unit-tests/directive-unexport.exp unit-tests/directive-unexport.mk unit-tests/directive-warning.exp unit-tests/directive-warning.mk unit-tests/directive.exp unit-tests/directive.mk unit-tests/dollar.exp unit-tests/dollar.mk unit-tests/doterror.exp unit-tests/doterror.mk unit-tests/dotwait.exp unit-tests/dotwait.mk unit-tests/error.exp unit-tests/error.mk unit-tests/escape.exp unit-tests/escape.mk unit-tests/export-all.exp unit-tests/export-all.mk unit-tests/export-env.exp unit-tests/export-env.mk unit-tests/export-variants.exp unit-tests/export-variants.mk unit-tests/export.exp unit-tests/export.mk -unit-tests/forloop.exp -unit-tests/forloop.mk unit-tests/forsubst.exp unit-tests/forsubst.mk unit-tests/gnode-submake.exp unit-tests/gnode-submake.mk unit-tests/hanoi-include.exp unit-tests/hanoi-include.mk unit-tests/impsrc.exp unit-tests/impsrc.mk unit-tests/include-main.exp unit-tests/include-main.mk unit-tests/include-sub.inc unit-tests/include-subsub.inc unit-tests/job-flags.exp unit-tests/job-flags.mk unit-tests/job-output-long-lines.exp unit-tests/job-output-long-lines.mk unit-tests/job-output-null.exp unit-tests/job-output-null.mk unit-tests/jobs-empty-commands-error.exp unit-tests/jobs-empty-commands-error.mk unit-tests/jobs-empty-commands.exp unit-tests/jobs-empty-commands.mk unit-tests/jobs-error-indirect.exp unit-tests/jobs-error-indirect.mk unit-tests/jobs-error-nested-make.exp unit-tests/jobs-error-nested-make.mk unit-tests/jobs-error-nested.exp unit-tests/jobs-error-nested.mk unit-tests/lint.exp unit-tests/lint.mk unit-tests/make-exported.exp unit-tests/make-exported.mk unit-tests/meta-cmd-cmp.exp unit-tests/meta-cmd-cmp.mk unit-tests/meta-ignore.inc unit-tests/moderrs.exp unit-tests/moderrs.mk unit-tests/modmatch.exp unit-tests/modmatch.mk unit-tests/modmisc.exp unit-tests/modmisc.mk unit-tests/objdir-writable.exp unit-tests/objdir-writable.mk unit-tests/opt-backwards.exp unit-tests/opt-backwards.mk unit-tests/opt-chdir.exp unit-tests/opt-chdir.mk unit-tests/opt-debug-all.exp unit-tests/opt-debug-all.mk unit-tests/opt-debug-archive.exp unit-tests/opt-debug-archive.mk unit-tests/opt-debug-cond.exp unit-tests/opt-debug-cond.mk unit-tests/opt-debug-curdir.exp unit-tests/opt-debug-curdir.mk unit-tests/opt-debug-dir.exp unit-tests/opt-debug-dir.mk unit-tests/opt-debug-errors-jobs.exp unit-tests/opt-debug-errors-jobs.mk unit-tests/opt-debug-errors.exp unit-tests/opt-debug-errors.mk unit-tests/opt-debug-file.exp unit-tests/opt-debug-file.mk unit-tests/opt-debug-for.exp unit-tests/opt-debug-for.mk unit-tests/opt-debug-graph1.exp unit-tests/opt-debug-graph1.mk unit-tests/opt-debug-graph2.exp unit-tests/opt-debug-graph2.mk unit-tests/opt-debug-graph3.exp unit-tests/opt-debug-graph3.mk unit-tests/opt-debug-hash.exp unit-tests/opt-debug-hash.mk unit-tests/opt-debug-jobs.exp unit-tests/opt-debug-jobs.mk unit-tests/opt-debug-lint.exp unit-tests/opt-debug-lint.mk unit-tests/opt-debug-loud.exp unit-tests/opt-debug-loud.mk unit-tests/opt-debug-making.exp unit-tests/opt-debug-making.mk unit-tests/opt-debug-meta.exp unit-tests/opt-debug-meta.mk unit-tests/opt-debug-no-rm.exp unit-tests/opt-debug-no-rm.mk unit-tests/opt-debug-parse.exp unit-tests/opt-debug-parse.mk unit-tests/opt-debug-suff.exp unit-tests/opt-debug-suff.mk unit-tests/opt-debug-targets.exp unit-tests/opt-debug-targets.mk unit-tests/opt-debug-var.exp unit-tests/opt-debug-var.mk unit-tests/opt-debug-varraw.exp unit-tests/opt-debug-varraw.mk unit-tests/opt-debug-x-trace.exp unit-tests/opt-debug-x-trace.mk unit-tests/opt-debug.exp unit-tests/opt-debug.mk unit-tests/opt-define.exp unit-tests/opt-define.mk unit-tests/opt-env.exp unit-tests/opt-env.mk unit-tests/opt-file.exp unit-tests/opt-file.mk unit-tests/opt-ignore.exp unit-tests/opt-ignore.mk unit-tests/opt-include-dir.exp unit-tests/opt-include-dir.mk unit-tests/opt-jobs-internal.exp unit-tests/opt-jobs-internal.mk unit-tests/opt-jobs-no-action.exp unit-tests/opt-jobs-no-action.mk unit-tests/opt-jobs.exp unit-tests/opt-jobs.mk unit-tests/opt-keep-going-indirect.exp unit-tests/opt-keep-going-indirect.mk unit-tests/opt-keep-going-multiple.exp unit-tests/opt-keep-going-multiple.mk unit-tests/opt-keep-going.exp unit-tests/opt-keep-going.mk unit-tests/opt-m-include-dir.exp unit-tests/opt-m-include-dir.mk unit-tests/opt-no-action-at-all.exp unit-tests/opt-no-action-at-all.mk unit-tests/opt-no-action-runflags.exp unit-tests/opt-no-action-runflags.mk unit-tests/opt-no-action-touch.exp unit-tests/opt-no-action-touch.mk unit-tests/opt-no-action.exp unit-tests/opt-no-action.mk unit-tests/opt-query.exp unit-tests/opt-query.mk unit-tests/opt-raw.exp unit-tests/opt-raw.mk unit-tests/opt-silent.exp unit-tests/opt-silent.mk unit-tests/opt-touch-jobs.exp unit-tests/opt-touch-jobs.mk unit-tests/opt-touch.exp unit-tests/opt-touch.mk unit-tests/opt-tracefile.exp unit-tests/opt-tracefile.mk unit-tests/opt-var-expanded.exp unit-tests/opt-var-expanded.mk unit-tests/opt-var-literal.exp unit-tests/opt-var-literal.mk unit-tests/opt-version.exp unit-tests/opt-version.mk unit-tests/opt-warnings-as-errors.exp unit-tests/opt-warnings-as-errors.mk unit-tests/opt-where-am-i.exp unit-tests/opt-where-am-i.mk unit-tests/opt-x-reduce-exported.exp unit-tests/opt-x-reduce-exported.mk unit-tests/opt.exp unit-tests/opt.mk unit-tests/order.exp unit-tests/order.mk unit-tests/parse-var.exp unit-tests/parse-var.mk unit-tests/parse.exp unit-tests/parse.mk unit-tests/phony-end.exp unit-tests/phony-end.mk unit-tests/posix.exp unit-tests/posix.mk unit-tests/posix1.exp unit-tests/posix1.mk unit-tests/recursive.exp unit-tests/recursive.mk unit-tests/sh-dots.exp unit-tests/sh-dots.mk unit-tests/sh-errctl.exp unit-tests/sh-errctl.mk unit-tests/sh-flags.exp unit-tests/sh-flags.mk unit-tests/sh-jobs-error.exp unit-tests/sh-jobs-error.mk unit-tests/sh-jobs.exp unit-tests/sh-jobs.mk unit-tests/sh-leading-at.exp unit-tests/sh-leading-at.mk unit-tests/sh-leading-hyphen.exp unit-tests/sh-leading-hyphen.mk unit-tests/sh-leading-plus.exp unit-tests/sh-leading-plus.mk unit-tests/sh-meta-chars.exp unit-tests/sh-meta-chars.mk unit-tests/sh-multi-line.exp unit-tests/sh-multi-line.mk unit-tests/sh-single-line.exp unit-tests/sh-single-line.mk unit-tests/sh.exp unit-tests/sh.mk unit-tests/shell-csh.exp unit-tests/shell-csh.mk unit-tests/shell-custom.exp unit-tests/shell-custom.mk unit-tests/shell-ksh.exp unit-tests/shell-ksh.mk unit-tests/shell-sh.exp unit-tests/shell-sh.mk unit-tests/suff-add-later.exp unit-tests/suff-add-later.mk unit-tests/suff-clear-regular.exp unit-tests/suff-clear-regular.mk unit-tests/suff-clear-single.exp unit-tests/suff-clear-single.mk unit-tests/suff-incomplete.exp unit-tests/suff-incomplete.mk unit-tests/suff-lookup.exp unit-tests/suff-lookup.mk unit-tests/suff-main-several.exp unit-tests/suff-main-several.mk unit-tests/suff-main.exp unit-tests/suff-main.mk unit-tests/suff-phony.exp unit-tests/suff-phony.mk unit-tests/suff-rebuild.exp unit-tests/suff-rebuild.mk unit-tests/suff-self.exp unit-tests/suff-self.mk unit-tests/suff-transform-debug.exp unit-tests/suff-transform-debug.mk unit-tests/suff-transform-endless.exp unit-tests/suff-transform-endless.mk unit-tests/suff-transform-expand.exp unit-tests/suff-transform-expand.mk unit-tests/suff-transform-select.exp unit-tests/suff-transform-select.mk unit-tests/suff-use.exp unit-tests/suff-use.mk unit-tests/sunshcmd.exp unit-tests/sunshcmd.mk unit-tests/ternary.exp unit-tests/ternary.mk unit-tests/unexport-env.exp unit-tests/unexport-env.mk unit-tests/unexport.exp unit-tests/unexport.mk unit-tests/use-inference.exp unit-tests/use-inference.mk unit-tests/var-eval-short.exp unit-tests/var-eval-short.mk unit-tests/var-op-append.exp unit-tests/var-op-append.mk unit-tests/var-op-assign.exp unit-tests/var-op-assign.mk unit-tests/var-op-default.exp unit-tests/var-op-default.mk unit-tests/var-op-expand.exp unit-tests/var-op-expand.mk unit-tests/var-op-shell.exp unit-tests/var-op-shell.mk unit-tests/var-op-sunsh.exp unit-tests/var-op-sunsh.mk unit-tests/var-op.exp unit-tests/var-op.mk unit-tests/var-readonly.exp unit-tests/var-readonly.mk unit-tests/var-recursive.exp unit-tests/var-recursive.mk unit-tests/var-scope-cmdline.exp unit-tests/var-scope-cmdline.mk unit-tests/var-scope-env.exp unit-tests/var-scope-env.mk unit-tests/var-scope-global.exp unit-tests/var-scope-global.mk unit-tests/var-scope-local-legacy.exp unit-tests/var-scope-local-legacy.mk unit-tests/var-scope-local.exp unit-tests/var-scope-local.mk unit-tests/var-scope.exp unit-tests/var-scope.mk unit-tests/varcmd.exp unit-tests/varcmd.mk unit-tests/vardebug.exp unit-tests/vardebug.mk unit-tests/varfind.exp unit-tests/varfind.mk unit-tests/varmisc.exp unit-tests/varmisc.mk unit-tests/varmod-assign-shell.exp unit-tests/varmod-assign-shell.mk unit-tests/varmod-assign.exp unit-tests/varmod-assign.mk unit-tests/varmod-defined.exp unit-tests/varmod-defined.mk unit-tests/varmod-edge.exp unit-tests/varmod-edge.mk unit-tests/varmod-exclam-shell.exp unit-tests/varmod-exclam-shell.mk unit-tests/varmod-extension.exp unit-tests/varmod-extension.mk unit-tests/varmod-gmtime.exp unit-tests/varmod-gmtime.mk unit-tests/varmod-hash.exp unit-tests/varmod-hash.mk unit-tests/varmod-head.exp unit-tests/varmod-head.mk unit-tests/varmod-ifelse.exp unit-tests/varmod-ifelse.mk unit-tests/varmod-indirect.exp unit-tests/varmod-indirect.mk unit-tests/varmod-l-name-to-value.exp unit-tests/varmod-l-name-to-value.mk unit-tests/varmod-localtime.exp unit-tests/varmod-localtime.mk unit-tests/varmod-loop-delete.exp unit-tests/varmod-loop-delete.mk unit-tests/varmod-loop-varname.exp unit-tests/varmod-loop-varname.mk unit-tests/varmod-loop.exp unit-tests/varmod-loop.mk unit-tests/varmod-match-escape.exp unit-tests/varmod-match-escape.mk unit-tests/varmod-match.exp unit-tests/varmod-match.mk +unit-tests/varmod-mtime.exp +unit-tests/varmod-mtime.mk unit-tests/varmod-no-match.exp unit-tests/varmod-no-match.mk unit-tests/varmod-order-numeric.exp unit-tests/varmod-order-numeric.mk unit-tests/varmod-order-reverse.exp unit-tests/varmod-order-reverse.mk unit-tests/varmod-order-shuffle.exp unit-tests/varmod-order-shuffle.mk unit-tests/varmod-order-string.exp unit-tests/varmod-order-string.mk unit-tests/varmod-order.exp unit-tests/varmod-order.mk unit-tests/varmod-path.exp unit-tests/varmod-path.mk unit-tests/varmod-quote-dollar.exp unit-tests/varmod-quote-dollar.mk unit-tests/varmod-quote.exp unit-tests/varmod-quote.mk unit-tests/varmod-range.exp unit-tests/varmod-range.mk unit-tests/varmod-remember.exp unit-tests/varmod-remember.mk unit-tests/varmod-root.exp unit-tests/varmod-root.mk unit-tests/varmod-select-words.exp unit-tests/varmod-select-words.mk unit-tests/varmod-shell.exp unit-tests/varmod-shell.mk unit-tests/varmod-subst-regex.exp unit-tests/varmod-subst-regex.mk unit-tests/varmod-subst.exp unit-tests/varmod-subst.mk unit-tests/varmod-sun-shell.exp unit-tests/varmod-sun-shell.mk unit-tests/varmod-sysv.exp unit-tests/varmod-sysv.mk unit-tests/varmod-tail.exp unit-tests/varmod-tail.mk unit-tests/varmod-to-abs.exp unit-tests/varmod-to-abs.mk unit-tests/varmod-to-lower.exp unit-tests/varmod-to-lower.mk unit-tests/varmod-to-many-words.exp unit-tests/varmod-to-many-words.mk unit-tests/varmod-to-one-word.exp unit-tests/varmod-to-one-word.mk unit-tests/varmod-to-separator.exp unit-tests/varmod-to-separator.mk unit-tests/varmod-to-upper.exp unit-tests/varmod-to-upper.mk unit-tests/varmod-undefined.exp unit-tests/varmod-undefined.mk unit-tests/varmod-unique.exp unit-tests/varmod-unique.mk unit-tests/varmod.exp unit-tests/varmod.mk unit-tests/varname-dollar.exp unit-tests/varname-dollar.mk unit-tests/varname-dot-alltargets.exp unit-tests/varname-dot-alltargets.mk unit-tests/varname-dot-curdir.exp unit-tests/varname-dot-curdir.mk unit-tests/varname-dot-includedfromdir.exp unit-tests/varname-dot-includedfromdir.mk unit-tests/varname-dot-includedfromfile.exp unit-tests/varname-dot-includedfromfile.mk unit-tests/varname-dot-includes.exp unit-tests/varname-dot-includes.mk unit-tests/varname-dot-libs.exp unit-tests/varname-dot-libs.mk unit-tests/varname-dot-make-dependfile.exp unit-tests/varname-dot-make-dependfile.mk unit-tests/varname-dot-make-expand_variables.exp unit-tests/varname-dot-make-expand_variables.mk unit-tests/varname-dot-make-exported.exp unit-tests/varname-dot-make-exported.mk unit-tests/varname-dot-make-jobs-prefix.exp unit-tests/varname-dot-make-jobs-prefix.mk unit-tests/varname-dot-make-jobs.exp unit-tests/varname-dot-make-jobs.mk unit-tests/varname-dot-make-level.exp unit-tests/varname-dot-make-level.mk unit-tests/varname-dot-make-makefile_preference.exp unit-tests/varname-dot-make-makefile_preference.mk unit-tests/varname-dot-make-makefiles.exp unit-tests/varname-dot-make-makefiles.mk unit-tests/varname-dot-make-meta-bailiwick.exp unit-tests/varname-dot-make-meta-bailiwick.mk unit-tests/varname-dot-make-meta-created.exp unit-tests/varname-dot-make-meta-created.mk unit-tests/varname-dot-make-meta-files.exp unit-tests/varname-dot-make-meta-files.mk unit-tests/varname-dot-make-meta-ignore_filter.exp unit-tests/varname-dot-make-meta-ignore_filter.mk unit-tests/varname-dot-make-meta-ignore_paths.exp unit-tests/varname-dot-make-meta-ignore_paths.mk unit-tests/varname-dot-make-meta-ignore_patterns.exp unit-tests/varname-dot-make-meta-ignore_patterns.mk unit-tests/varname-dot-make-meta-prefix.exp unit-tests/varname-dot-make-meta-prefix.mk unit-tests/varname-dot-make-mode.exp unit-tests/varname-dot-make-mode.mk unit-tests/varname-dot-make-path_filemon.exp unit-tests/varname-dot-make-path_filemon.mk unit-tests/varname-dot-make-pid.exp unit-tests/varname-dot-make-pid.mk unit-tests/varname-dot-make-ppid.exp unit-tests/varname-dot-make-ppid.mk unit-tests/varname-dot-make-save_dollars.exp unit-tests/varname-dot-make-save_dollars.mk unit-tests/varname-dot-makeflags.exp unit-tests/varname-dot-makeflags.mk unit-tests/varname-dot-makeoverrides.exp unit-tests/varname-dot-makeoverrides.mk unit-tests/varname-dot-newline.exp unit-tests/varname-dot-newline.mk unit-tests/varname-dot-objdir.exp unit-tests/varname-dot-objdir.mk unit-tests/varname-dot-parsedir.exp unit-tests/varname-dot-parsedir.mk unit-tests/varname-dot-parsefile.exp unit-tests/varname-dot-parsefile.mk unit-tests/varname-dot-path.exp unit-tests/varname-dot-path.mk unit-tests/varname-dot-shell.exp unit-tests/varname-dot-shell.mk unit-tests/varname-dot-suffixes.exp unit-tests/varname-dot-suffixes.mk unit-tests/varname-dot-targets.exp unit-tests/varname-dot-targets.mk unit-tests/varname-empty.exp unit-tests/varname-empty.mk unit-tests/varname-make.exp unit-tests/varname-make.mk unit-tests/varname-make_print_var_on_error-jobs.exp unit-tests/varname-make_print_var_on_error-jobs.mk unit-tests/varname-make_print_var_on_error.exp unit-tests/varname-make_print_var_on_error.mk unit-tests/varname-makefile.exp unit-tests/varname-makefile.mk unit-tests/varname-makeflags.exp unit-tests/varname-makeflags.mk unit-tests/varname-pwd.exp unit-tests/varname-pwd.mk unit-tests/varname-vpath.exp unit-tests/varname-vpath.mk unit-tests/varname.exp unit-tests/varname.mk unit-tests/varparse-dynamic.exp unit-tests/varparse-dynamic.mk unit-tests/varparse-errors.exp unit-tests/varparse-errors.mk unit-tests/varparse-mod.exp unit-tests/varparse-mod.mk unit-tests/varparse-undef-partial.exp unit-tests/varparse-undef-partial.mk util.c var.c wait.h diff --git a/VERSION b/VERSION index 2631e0deeb1e..b49eb8cc7f26 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ # keep this compatible with sh and make -_MAKE_VERSION=20230414 +_MAKE_VERSION=20230510 diff --git a/bmake.1 b/bmake.1 index 1d5ee8f1f3aa..bfa0f2d74d0a 100644 --- a/bmake.1 +++ b/bmake.1 @@ -1,2739 +1,2754 @@ -.\" $NetBSD: make.1,v 1.361 2023/03/23 03:29:28 sjg Exp $ +.\" $NetBSD: make.1,v 1.366 2023/05/10 18:22:33 sjg Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" -.Dd March 22, 2023 +.Dd May 10, 2023 .Dt BMAKE 1 .Os .Sh NAME .Nm bmake .Nd maintain program dependencies .Sh SYNOPSIS .Nm .Op Fl BeikNnqrSstWwX .Op Fl C Ar directory .Op Fl D Ar variable .Op Fl d Ar flags .Op Fl f Ar makefile .Op Fl I Ar directory .Op Fl J Ar private .Op Fl j Ar max_jobs .Op Fl m Ar directory .Op Fl T Ar file .Op Fl V Ar variable .Op Fl v Ar variable .Op Ar variable\| Ns Cm \&= Ns Ar value .Op Ar target No ... .Sh DESCRIPTION .Nm is a program designed to simplify the maintenance of other programs. Its input is a list of specifications as to the files upon which programs and other files depend. If no .Fl f Ar makefile option is given, .Nm tries to open .Sq Pa makefile then .Sq Pa Makefile in order to find the specifications. If the file .Sq Pa .depend exists, it is read, see .Xr mkdep 1 . .Pp This manual page is intended as a reference document only. For a more thorough description of .Nm and makefiles, please refer to .%T "PMake \- A Tutorial" (from 1993). .Pp .Nm prepends the contents of the .Ev MAKEFLAGS environment variable to the command line arguments before parsing them. .Pp The options are as follows: .Bl -tag -width Ds .It Fl B Try to be backwards compatible by executing a single shell per command and by making the sources of a dependency line in sequence. .It Fl C Ar directory Change to .Ar directory before reading the makefiles or doing anything else. If multiple .Fl C options are specified, each is interpreted relative to the previous one: .Fl C Pa / Fl C Pa etc is equivalent to .Fl C Pa /etc . .It Fl D Ar variable Define .Ar variable to be 1, in the global scope. .It Fl d Oo Cm \- Oc Ns Ar flags Turn on debugging, and specify which portions of .Nm are to print debugging information. Unless the flags are preceded by .Ql \- , they are added to the .Ev MAKEFLAGS environment variable and are passed on to any child make processes. By default, debugging information is printed to standard error, but this can be changed using the .Cm F debugging flag. The debugging output is always unbuffered; in addition, if debugging is enabled but debugging output is not directed to standard output, the standard output is line buffered. The available .Ar flags are: .Bl -tag -width Ds .It Cm A Print all possible debugging information; equivalent to specifying all of the debugging flags. .It Cm a Print debugging information about archive searching and caching. .It Cm C Print debugging information about the current working directory. .It Cm c Print debugging information about conditional evaluation. .It Cm d Print debugging information about directory searching and caching. .It Cm e Print debugging information about failed commands and targets. .It Cm F Ns Oo Cm \&+ Oc Ns Ar filename Specify where debugging output is written. This must be the last flag, because it consumes the remainder of the argument. If the character immediately after the .Cm F flag is .Ql \&+ , the file is opened in append mode; otherwise the file is overwritten. If the file name is .Ql stdout or .Ql stderr , debugging output is written to the standard output or standard error output respectively (and the .Ql \&+ option has no effect). Otherwise, the output is written to the named file. If the file name ends with .Ql .%d , the .Ql %d is replaced by the pid. .It Cm f Print debugging information about loop evaluation. .It Cm g1 Print the input graph before making anything. .It Cm g2 Print the input graph after making everything, or before exiting on error. .It Cm g3 Print the input graph before exiting on error. .It Cm h Print debugging information about hash table operations. .It Cm j Print debugging information about running multiple shells. .It Cm L Turn on lint checks. This throws errors for variable assignments that do not parse correctly, at the time of assignment, so the file and line number are available. .It Cm l Print commands in Makefiles regardless of whether or not they are prefixed by .Ql @ or other .Dq quiet flags. Also known as .Dq loud behavior. .It Cm M Print debugging information about .Dq meta mode decisions about targets. .It Cm m Print debugging information about making targets, including modification dates. .It Cm n Don't delete the temporary command scripts created when running commands. These temporary scripts are created in the directory referred to by the .Ev TMPDIR environment variable, or in .Pa /tmp if .Ev TMPDIR is unset or set to the empty string. The temporary scripts are created by .Xr mkstemp 3 , and have names of the form .Pa makeXXXXXX . .Em NOTE : This can create many files in .Ev TMPDIR or .Pa /tmp , so use with care. .It Cm p Print debugging information about makefile parsing. .It Cm s Print debugging information about suffix-transformation rules. .It Cm t Print debugging information about target list maintenance. .It Cm V Force the .Fl V option to print raw values of variables, overriding the default behavior set via .Va .MAKE.EXPAND_VARIABLES . .It Cm v Print debugging information about variable assignment and expansion. .It Cm x Run shell commands with .Fl x so the actual commands are printed as they are executed. .El .It Fl e Let environment variables override global variables within makefiles. .It Fl f Ar makefile Specify a makefile to read instead of the default .Pa makefile or .Pa Makefile . If .Ar makefile is .Ql \&- , standard input is read. Multiple makefiles may be specified, and are read in the order specified. .It Fl I Ar directory Specify a directory in which to search for makefiles and included makefiles. The system makefile directory (or directories, see the .Fl m option) is automatically included as part of this list. .It Fl i Ignore non-zero exit of shell commands in the makefile. Equivalent to specifying .Ql \&- before each command line in the makefile. .It Fl J Ar private This option should .Em not be specified by the user. .Pp When the .Fl j option is in use in a recursive build, this option is passed by a make to child makes to allow all the make processes in the build to cooperate to avoid overloading the system. .It Fl j Ar max_jobs Specify the maximum number of jobs that .Nm may have running at any one time. The value of .Ar max_jobs is saved in .Va .MAKE.JOBS . Turns compatibility mode off, unless the .Fl B option is also specified. When compatibility mode is off, all commands associated with a target are executed in a single shell invocation as opposed to the traditional one shell invocation per line. This can break traditional scripts which change directories on each command invocation and then expect to start with a fresh environment on the next line. It is more efficient to correct the scripts rather than turn backwards compatibility on. .Pp A job token pool with .Ar max_jobs tokens is used to control the total number of jobs running. Each instance of .Nm will wait for a token from the pool before running a new job. .It Fl k Continue processing after errors are encountered, but only on those targets that do not depend on the target whose creation caused the error. .It Fl m Ar directory Specify a directory in which to search for .Pa sys.mk and makefiles included via the .Li \&< Ns Ar file Ns Li \&> Ns -style include statement. The .Fl m option can be used multiple times to form a search path. This path overrides the default system include path .Pa /usr/share/mk . Furthermore, the system include path is appended to the search path used for .Li \*q Ns Ar file Ns Li \*q Ns -style include statements (see the .Fl I option). The system include path can be referenced via the read-only variable .Va .SYSPATH . .Pp If a directory name in the .Fl m argument (or the .Ev MAKESYSPATH environment variable) starts with the string .Ql \&.../ , .Nm searches for the specified file or directory named in the remaining part of the argument string. The search starts with the current directory and then works upward towards the root of the file system. If the search is successful, the resulting directory replaces the .Ql \&.../ specification in the .Fl m argument. This feature allows .Nm to easily search in the current source tree for customized .Pa sys.mk files (e.g., by using .Ql \&.../mk/sys.mk as an argument). .It Fl n Display the commands that would have been executed, but do not actually execute them unless the target depends on the .Va .MAKE special source (see below) or the command is prefixed with .Sq Cm + . .It Fl N Display the commands that would have been executed, but do not actually execute any of them; useful for debugging top-level makefiles without descending into subdirectories. .It Fl q Do not execute any commands, instead exit 0 if the specified targets are up to date, and 1 otherwise. .It Fl r Do not use the built-in rules specified in the system makefile. .It Fl S Stop processing if an error is encountered. This is the default behavior and the opposite of .Fl k . .It Fl s Do not echo any commands as they are executed. Equivalent to specifying .Sq Ic @ before each command line in the makefile. .It Fl T Ar tracefile When used with the .Fl j flag, append a trace record to .Ar tracefile for each job started and completed. .It Fl t Rather than re-building a target as specified in the makefile, create it or update its modification time to make it appear up-to-date. .It Fl V Ar variable Print the value of .Ar variable . Do not build any targets. Multiple instances of this option may be specified; the variables are printed one per line, with a blank line for each null or undefined variable. The value printed is extracted from the global scope after all makefiles have been read. .Pp By default, the raw variable contents (which may include additional unexpanded variable references) are shown. If .Ar variable contains a .Ql \&$ , it is not interpreted as a variable name but rather as an expression. Its value is expanded before printing. The value is also expanded before printing if .Va .MAKE.EXPAND_VARIABLES is set to true and the .Fl dV option has not been used to override it. .Pp Note that loop-local and target-local variables, as well as values taken temporarily by global variables during makefile processing, are not accessible via this option. The .Fl dv debug mode can be used to see these at the cost of generating substantial extraneous output. .It Fl v Ar variable Like .Fl V , but all printed variables are always expanded to their complete value. The last occurrence of .Fl V or .Fl v decides whether all variables are expanded or not. .It Fl W Treat any warnings during makefile parsing as errors. .It Fl w Print entering and leaving directory messages, pre and post processing. .It Fl X Don't export variables passed on the command line to the environment individually. Variables passed on the command line are still exported via the .Ev MAKEFLAGS environment variable. This option may be useful on systems which have a small limit on the size of command arguments. .It Ar variable\| Ns Cm \&= Ns Ar value Set the value of the variable .Ar variable to .Ar value . Normally, all values passed on the command line are also exported to sub-makes in the environment. The .Fl X flag disables this behavior. Variable assignments should follow options for POSIX compatibility but no ordering is enforced. .El .Pp There are several different types of lines in a makefile: dependency specifications, shell commands, variable assignments, include statements, conditional directives, for loops, other directives, and comments. .Pp Lines may be continued from one line to the next by ending them with a backslash .Pq Ql \e . The trailing newline character and initial whitespace on the following line are compressed into a single space. .Sh FILE DEPENDENCY SPECIFICATIONS Dependency lines consist of one or more targets, an operator, and zero or more sources. This creates a relationship where the targets .Dq depend on the sources and are customarily created from them. A target is considered out of date if it does not exist, or if its modification time is less than that of any of its sources. An out-of-date target is re-created, but not until all sources have been examined and themselves re-created as needed. Three operators may be used: .Bl -tag -width flag .It Ic \&: Many dependency lines may name this target but only one may have attached shell commands. All sources named in all dependency lines are considered together, and if needed the attached shell commands are run to create or re-create the target. If .Nm is interrupted, the target is removed. .It Ic \&! The same, but the target is always re-created whether or not it is out of date. .It Ic \&:: Any dependency line may have attached shell commands, but each one is handled independently: its sources are considered and the attached shell commands are run if the target is out of date with respect to (only) those sources. Thus, different groups of the attached shell commands may be run depending on the circumstances. Furthermore, unlike .Ic \&: , for dependency lines with no sources, the attached shell commands are always run. Also unlike .Ic \&: , the target is not removed if .Nm is interrupted. .El .Pp All dependency lines mentioning a particular target must use the same operator. .Pp Targets and sources may contain the shell wildcard values .Ql \&? , .Ql * , .Ql [] , and .Ql {} . The values .Ql \&? , .Ql * , and .Ql [] may only be used as part of the final component of the target or source, and only match existing files. The value .Ql {} need not necessarily be used to describe existing files. Expansion is in directory order, not alphabetically as done in the shell. .Sh SHELL COMMANDS Each target may have associated with it one or more lines of shell commands, normally used to create the target. Each of the lines in this script .Em must be preceded by a tab. (For historical reasons, spaces are not accepted.) While targets can occur in many dependency lines if desired, by default only one of these rules may be followed by a creation script. If the .Sq Ic \&:: operator is used, however, all rules may include scripts, and the respective scripts are executed in the order found. .Pp Each line is treated as a separate shell command, unless the end of line is escaped with a backslash .Ql \e , in which case that line and the next are combined. If the first characters of the command are any combination of .Sq Ic @ , .Sq Ic + , or .Sq Ic \- , the command is treated specially. .Bl -tag -offset indent -width indent .It Ic @ causes the command not to be echoed before it is executed. .It Ic + causes the command to be executed even when .Fl n is given. This is similar to the effect of the .Va .MAKE special source, except that the effect can be limited to a single line of a script. .It Ic \- in compatibility mode causes any non-zero exit status of the command line to be ignored. .El .Pp When .Nm is run in jobs mode with .Fl j Ar max_jobs , the entire script for the target is fed to a single instance of the shell. In compatibility (non-jobs) mode, each command is run in a separate process. If the command contains any shell meta characters .Pq Ql #=|^(){};&<>*?[]:$`\e\en , it is passed to the shell; otherwise .Nm attempts direct execution. If a line starts with .Sq Ic \- and the shell has ErrCtl enabled, failure of the command line is ignored as in compatibility mode. Otherwise .Sq Ic \- affects the entire job; the script stops at the first command line that fails, but the target is not deemed to have failed. .Pp Makefiles should be written so that the mode of .Nm operation does not change their behavior. For example, any command which uses .Dq cd or .Dq chdir without the intention of changing the directory for subsequent commands should be put in parentheses so it executes in a subshell. To force the use of a single shell, escape the line breaks so as to make the whole script one command. For example: .Bd -literal -offset indent avoid-chdir-side-effects: @echo "Building $@ in $$(pwd)" @(cd ${.CURDIR} && ${MAKE} $@) @echo "Back in $$(pwd)" ensure-one-shell-regardless-of-mode: @echo "Building $@ in $$(pwd)"; \e (cd ${.CURDIR} && ${MAKE} $@); \e echo "Back in $$(pwd)" .Ed .Pp Since .Nm changes the current working directory to .Sq Va .OBJDIR before executing any targets, each child process starts with that as its current working directory. .Sh VARIABLE ASSIGNMENTS Variables in make behave much like macros in the C preprocessor. .Pp Variable assignments have the form .Sq Ar NAME Ar op Ar value , where: .Bl -tag -offset Ds -width Ds .It Ar NAME is a single-word variable name, consisting, by tradition, of all upper-case letters, .It Ar op is one of the variable assignment operators described below, and .It Ar value is interpreted according to the variable assignment operator. .El .Pp Whitespace around .Ar NAME , .Ar op and .Ar value is discarded. .Ss Variable assignment operators The five operators that assign values to variables are: .Bl -tag -width Ds .It Ic \&= Assign the value to the variable. Any previous value is overwritten. .It Ic \&+= Append the value to the current value of the variable, separating them by a single space. .It Ic \&?= Assign the value to the variable if it is not already defined. .It Ic \&:= Expand the value, then assign it to the variable. .Pp .Em NOTE : References to undefined variables are .Em not expanded. This can cause problems when variable modifiers are used. .\" See var-op-expand.mk, the section with LATER and INDIRECT. .It Ic \&!= Expand the value and pass it to the shell for execution, then assign the output from the child's standard output to the variable. Any newlines in the result are replaced with spaces. .El .Ss Expansion of variables In most contexts where variables are expanded, .Ql \&$$ expands to a single dollar sign. In other contexts (most variable modifiers, string literals in conditions), .Ql \&\e$ expands to a single dollar sign. .Pp References to variables have the form .Cm \&${ Ns Ar name Ns Oo Ns Cm \&: Ns Ar modifiers Oc Ns Cm \&} or .Cm \&$( Ns Ar name Ns Oo Ns Cm \&: Ns Ar modifiers Oc Ns Cm \&) . If the variable name consists of only a single character and the expression contains no modifiers, the surrounding curly braces or parentheses are not required. This shorter form is not recommended. .Pp If the variable name contains a dollar, the name itself is expanded first. This allows almost arbitrary variable names, however names containing dollar, braces, parentheses or whitespace are really best avoided. .Pp If the result of expanding a nested variable expression contains a dollar sign .Pq Ql \&$ , the result is subject to further expansion. .Pp Variable substitution occurs at four distinct times, depending on where the variable is being used. .Bl -enum .It Variables in dependency lines are expanded as the line is read. .It Variables in conditionals are expanded individually, but only as far as necessary to determine the result of the conditional. .It Variables in shell commands are expanded when the shell command is executed. .It .Ic .for loop index variables are expanded on each loop iteration. Note that other variables are not expanded when composing the body of a loop, so the following example code: .Bd -literal -offset indent \&.for i in 1 2 3 a+= ${i} j= ${i} b+= ${j} \&.endfor all: @echo ${a} @echo ${b} .Ed .Pp prints: .Bd -literal -offset indent 1 2 3 3 3 3 .Ed .Pp After the loop is executed: .Bl -tag -offset indent -width indent .It Va a contains .Ql ${:U1} ${:U2} ${:U3} , which expands to .Ql 1 2 3 . .It Va j contains .Ql ${:U3} , which expands to .Ql 3 . .It Va b contains .Ql ${j} ${j} ${j} , which expands to .Ql ${:U3} ${:U3} ${:U3} and further to .Ql 3 3 3 . .El .El .Ss Variable classes The four different classes of variables (in order of increasing precedence) are: .Bl -tag -width Ds .It Environment variables Variables defined as part of .Nm Ns 's environment. .It Global variables Variables defined in the makefile or in included makefiles. .It Command line variables Variables defined as part of the command line. .It Local variables Variables that are defined specific to a certain target. .El .Pp Local variables can be set on a dependency line, unless .Va .MAKE.TARGET_LOCAL_VARIABLES is set to .Ql false . The rest of the line (which already has had global variables expanded) is the variable value. For example: .Bd -literal -offset indent COMPILER_WRAPPERS= ccache distcc icecc ${OBJS}: .MAKE.META.CMP_FILTER=${COMPILER_WRAPPERS:S,^,N,} .Ed .Pp Only the targets .Ql ${OBJS} are impacted by that filter (in .Dq meta mode) and simply enabling/disabling any of the compiler wrappers does not render all of those targets out-of-date. .Pp .Em NOTE : target-local variable assignments behave differently in that; .Bl -tag -width Ds -offset indent .It Ic \&+= Only appends to a previous local assignment for the same target and variable. .It Ic \&:= Is redundant with respect to global variables, which have already been expanded. .El .Pp The seven built-in local variables are: .Bl -tag -width ".Va .ARCHIVE" -offset indent .It Va .ALLSRC The list of all sources for this target; also known as .Sq Va \&> . .It Va .ARCHIVE The name of the archive file; also known as .Sq Va \&! . .It Va .IMPSRC In suffix-transformation rules, the name/path of the source from which the target is to be transformed (the .Dq implied source); also known as .Sq Va \&< . It is not defined in explicit rules. .It Va .MEMBER The name of the archive member; also known as .Sq Va % . .It Va .OODATE The list of sources for this target that were deemed out-of-date; also known as .Sq Va \&? . .It Va .PREFIX -The file prefix of the target, containing only the file portion, no suffix -or preceding directory components; also known as +The name of the target with suffix (if declared in +.Ic .SUFFIXES ) +removed; also known as .Sq Va * . -The suffix must be one of the known suffixes declared with -.Ic .SUFFIXES , -or it is not recognized. .It Va .TARGET The name of the target; also known as .Sq Va @ . For compatibility with other makes this is an alias for .Va .ARCHIVE in archive member rules. .El .Pp The shorter forms .Po .Sq Va \&> , .Sq Va \&! , .Sq Va \&< , .Sq Va \&% , .Sq Va \&? , .Sq Va \&* , and .Sq Va \&@ .Pc are permitted for backward compatibility with historical makefiles and legacy POSIX make and are not recommended. .Pp Variants of these variables with the punctuation followed immediately by .Ql D or .Ql F , e.g.\& .Ql $(@D) , are legacy forms equivalent to using the .Ql :H and .Ql :T modifiers. These forms are accepted for compatibility with .At V makefiles and POSIX but are not recommended. .Pp Four of the local variables may be used in sources on dependency lines because they expand to the proper value for each target on the line. These variables are .Sq Va .TARGET , .Sq Va .PREFIX , .Sq Va .ARCHIVE , and .Sq Va .MEMBER . .Ss Additional built-in variables In addition, .Nm sets or knows about the following variables: .Bl -tag .\" NB: This list is sorted case-insensitive, ignoring punctuation. .\" NB: To find all built-in variables in make's source code, .\" NB: search for Var_*, Global_*, SetVarObjdir, GetBooleanExpr, .\" NB: and the implementation of Var_SetWithFlags. .\" NB: Last synced on 2023-01-01. .It Va .ALLTARGETS The list of all targets encountered in the makefiles. If evaluated during makefile parsing, lists only those targets encountered thus far. .It Va .CURDIR A path to the directory where .Nm was executed. Refer to the description of .Sq Va PWD for more details. .It Va .ERROR_CMD Is used in error handling, see .Va MAKE_PRINT_VAR_ON_ERROR . .It Va .ERROR_CWD Is used in error handling, see .Va MAKE_PRINT_VAR_ON_ERROR . .It Va .ERROR_META_FILE Is used in error handling in .Dq meta mode, see .Va MAKE_PRINT_VAR_ON_ERROR . .It Va .ERROR_TARGET Is used in error handling, see .Va MAKE_PRINT_VAR_ON_ERROR . .It Va .INCLUDEDFROMDIR The directory of the file this makefile was included from. .It Va .INCLUDEDFROMFILE The filename of the file this makefile was included from. .\" .INCLUDES is intentionally undocumented, as it is obsolete. .\" .LIBS is intentionally undocumented, as it is obsolete. .It Va MACHINE The machine hardware name, see .Xr uname 1 . .It Va MACHINE_ARCH The machine processor architecture name, see .Xr uname 1 . .It Va MAKE The name that .Nm was executed with .Pq Va argv[0] . .It Va .MAKE The same as .Va MAKE , for compatibility. The preferred variable to use is the environment variable .Ev MAKE because it is more compatible with other make variants and cannot be confused with the special target with the same name. .\" '.MAKE.cmd_filtered' is intentionally undocumented, .\" as it is an internal implementation detail. .It Va .MAKE.DEPENDFILE Names the makefile (default .Sq Pa .depend ) from which generated dependencies are read. .It Va .MAKE.DIE_QUIETLY If set to .Ql true , do not print error information at the end. .It Va .MAKE.EXPAND_VARIABLES A boolean that controls the default behavior of the .Fl V option. If true, variable values printed with .Fl V are fully expanded; if false, the raw variable contents (which may include additional unexpanded variable references) are shown. .It Va .MAKE.EXPORTED The list of variables exported by .Nm . .It Va MAKEFILE The top-level makefile that is currently read, as given in the command line. .It Va .MAKEFLAGS The environment variable .Sq Ev MAKEFLAGS may contain anything that may be specified on .Nm Ns 's command line. Anything specified on .Nm Ns 's command line is appended to the .Va .MAKEFLAGS variable, which is then added to the environment for all programs that .Nm executes. .It Va .MAKE.GID The numeric group ID of the user running .Nm . It is read-only. .It Va .MAKE.JOB.PREFIX If .Nm is run with .Fl j , the output for each target is prefixed with a token .Dl --- Ar target Li --- the first part of which can be controlled via .Va .MAKE.JOB.PREFIX . If .Va .MAKE.JOB.PREFIX is empty, no token is printed. For example, setting .Va .MAKE.JOB.PREFIX to .Ql ${.newline}---${.MAKE:T}[${.MAKE.PID}] would produce tokens like .Dl ---make[1234] Ar target Li --- making it easier to track the degree of parallelism being achieved. .It Va .MAKE.JOBS The argument to the .Fl j option. .It Va .MAKE.LEVEL The recursion depth of .Nm . The top-level instance of .Nm has level 0, and each child make has its parent level plus 1. This allows tests like: .Li .if ${.MAKE.LEVEL} == 0 to protect things which should only be evaluated in the top-level instance of .Nm . .It Va .MAKE.LEVEL.ENV The name of the environment variable that stores the level of nested calls to .Nm . .It Va .MAKE.MAKEFILE_PREFERENCE The ordered list of makefile names (default .Sq Pa makefile , .Sq Pa Makefile ) that .Nm looks for. .It Va .MAKE.MAKEFILES The list of makefiles read by .Nm , which is useful for tracking dependencies. Each makefile is recorded only once, regardless of the number of times read. .It Va .MAKE.META.BAILIWICK In .Dq meta mode, provides a list of prefixes which match the directories controlled by .Nm . If a file that was generated outside of .Va .OBJDIR but within said bailiwick is missing, the current target is considered out-of-date. .It Va .MAKE.META.CMP_FILTER In .Dq meta mode, it can (very rarely!) be useful to filter command lines before comparison. This variable can be set to a set of modifiers that are applied to each line of the old and new command that differ, if the filtered commands still differ, the target is considered out-of-date. .It Va .MAKE.META.CREATED In .Dq meta mode, this variable contains a list of all the meta files updated. If not empty, it can be used to trigger processing of .Va .MAKE.META.FILES . .It Va .MAKE.META.FILES In .Dq meta mode, this variable contains a list of all the meta files used (updated or not). This list can be used to process the meta files to extract dependency information. .It Va .MAKE.META.IGNORE_FILTER Provides a list of variable modifiers to apply to each pathname. Ignore if the expansion is an empty string. .It Va .MAKE.META.IGNORE_PATHS Provides a list of path prefixes that should be ignored; because the contents are expected to change over time. The default list includes: .Sq Pa /dev /etc /proc /tmp /var/run /var/tmp .It Va .MAKE.META.IGNORE_PATTERNS Provides a list of patterns to match against pathnames. Ignore any that match. .It Va .MAKE.META.PREFIX Defines the message printed for each meta file updated in .Dq meta verbose mode. The default value is: .Dl Building ${.TARGET:H:tA}/${.TARGET:T} .It Va .MAKE.MODE Processed after reading all makefiles. Affects the mode that .Nm runs in. It can contain these keywords: .Bl -tag -width indent .It Cm compat Like .Fl B , puts .Nm into .Dq compat mode. .It Cm meta Puts .Nm into .Dq meta mode, where meta files are created for each target to capture the command run, the output generated, and if .Xr filemon 4 is available, the system calls which are of interest to .Nm . The captured output can be useful when diagnosing errors. .It Cm curdirOk= Ns Ar bf By default, .Nm does not create .Pa .meta files in .Sq Va .CURDIR . This can be overridden by setting .Ar bf to a value which represents true. .It Cm missing-meta= Ns Ar bf If .Ar bf is true, a missing .Pa .meta file makes the target out-of-date. .It Cm missing-filemon= Ns Ar bf If .Ar bf is true, missing filemon data makes the target out-of-date. .It Cm nofilemon Do not use .Xr filemon 4 . .It Cm env For debugging, it can be useful to include the environment in the .Pa .meta file. .It Cm verbose If in .Dq meta mode, print a clue about the target being built. This is useful if the build is otherwise running silently. The message printed is the expanded value of .Va .MAKE.META.PREFIX . .It Cm ignore-cmd Some makefiles have commands which are simply not stable. This keyword causes them to be ignored for determining whether a target is out of date in .Dq meta mode. See also .Ic .NOMETA_CMP . .It Cm silent= Ns Ar bf If .Ar bf is true, when a .meta file is created, mark the target .Ic .SILENT . .It Cm randomize-targets In both compat and parallel mode, do not make the targets in the usual order, but instead randomize their order. This mode can be used to detect undeclared dependencies between files. .El .It Va MAKEOBJDIR Used to create files in a separate directory, see .Va .OBJDIR . .It Va MAKE_OBJDIR_CHECK_WRITABLE Used to force a separate directory for the created files, even if that directory is not writable, see .Va .OBJDIR . .It Va MAKEOBJDIRPREFIX Used to create files in a separate directory, see .Va .OBJDIR . .It Va .MAKE.OS The name of the operating system, see .Xr uname 1 . It is read-only. .It Va .MAKEOVERRIDES This variable is used to record the names of variables assigned to on the command line, so that they may be exported as part of .Sq Ev MAKEFLAGS . This behavior can be disabled by assigning an empty value to .Sq Va .MAKEOVERRIDES within a makefile. Extra variables can be exported from a makefile by appending their names to .Sq Va .MAKEOVERRIDES . .Sq Ev MAKEFLAGS is re-exported whenever .Sq Va .MAKEOVERRIDES is modified. .It Va .MAKE.PATH_FILEMON If .Nm was built with .Xr filemon 4 support, this is set to the path of the device node. This allows makefiles to test for this support. .It Va .MAKE.PID The process ID of .Nm . It is read-only. .It Va .MAKE.PPID The parent process ID of .Nm . It is read-only. .It Va MAKE_PRINT_VAR_ON_ERROR When .Nm stops due to an error, it sets .Sq Va .ERROR_TARGET to the name of the target that failed, .Sq Va .ERROR_CMD to the commands of the failed target, and in .Dq meta mode, it also sets .Sq Va .ERROR_CWD to the .Xr getcwd 3 , and .Sq Va .ERROR_META_FILE to the path of the meta file (if any) describing the failed target. It then prints its name and the value of .Sq Va .CURDIR as well as the value of any variables named in .Sq Va MAKE_PRINT_VAR_ON_ERROR . .It Va .MAKE.SAVE_DOLLARS If true, .Ql $$ are preserved when doing .Ql := assignments. The default is false, for backwards compatibility. Set to true for compatability with other makes. If set to false, .Ql $$ becomes .Ql $ per normal evaluation rules. .It Va .MAKE.TARGET_LOCAL_VARIABLES If set to .Ql false , apparent variable assignments in dependency lines are treated as normal sources. .It Va .MAKE.UID The numeric ID of the user running .Nm . It is read-only. .\" 'MAKE_VERSION' is intentionally undocumented .\" since it is only defined in the bmake distribution, .\" but not in NetBSD's native make. .\" '.meta.%d.lcwd' is intentionally undocumented .\" since it is an internal implementation detail. .\" '.meta.%d.ldir' is intentionally undocumented .\" since it is an internal implementation detail. .\" 'MFLAGS' is intentionally undocumented .\" since it is obsolete. .It Va .newline This variable is simply assigned a newline character as its value. It is read-only. This allows expansions using the .Cm \&:@ modifier to put a newline between iterations of the loop rather than a space. For example, in case of an error, .Nm prints the variable names and their values using: .Dl ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@} .It Va .OBJDIR A path to the directory where the targets are built. Its value is determined by trying to .Xr chdir 2 to the following directories in order and using the first match: .Bl -enum .It .Cm ${MAKEOBJDIRPREFIX} Ns Cm ${.CURDIR} .Pp (Only if .Sq Ev MAKEOBJDIRPREFIX is set in the environment or on the command line.) .It .Cm ${MAKEOBJDIR} .Pp (Only if .Sq Ev MAKEOBJDIR is set in the environment or on the command line.) .It .Cm ${.CURDIR} Ns Pa /obj. Ns Cm ${MACHINE} .It .Cm ${.CURDIR} Ns Pa /obj .It .Pa /usr/obj/ Ns Cm ${.CURDIR} .It .Cm ${.CURDIR} .El .Pp Variable expansion is performed on the value before it is used, so expressions such as .Cm ${.CURDIR:S,^/usr/src,/var/obj,} may be used. This is especially useful with .Sq Ev MAKEOBJDIR . .Pp .Sq Va .OBJDIR may be modified in the makefile via the special target .Sq Ic .OBJDIR . In all cases, .Nm changes to the specified directory if it exists, and sets .Sq Va .OBJDIR and .Sq Va PWD to that directory before executing any targets. .Pp Except in the case of an explicit .Sq Ic .OBJDIR target, .Nm checks that the specified directory is writable and ignores it if not. This check can be skipped by setting the environment variable .Sq Ev MAKE_OBJDIR_CHECK_WRITABLE to .Dq no . .It Va .PARSEDIR The directory name of the current makefile being parsed. .It Va .PARSEFILE The basename of the current makefile being parsed. This variable and .Sq Va .PARSEDIR are both set only while the makefiles are being parsed. To retain their current values, assign them to a variable using assignment with expansion .Sq Cm \&:= . .It Va .PATH The space-separated list of directories that .Nm searches for files. To update this search list, use the special target .Sq Ic .PATH rather than modifying the variable directly. .It Va %POSIX Is set in POSIX mode, see the special .Ql Va .POSIX target. .\" XXX: There is no make variable named 'PWD', .\" XXX: make only reads and writes the environment variable 'PWD'. .It Va PWD Alternate path to the current directory. .Nm normally sets .Sq Va .CURDIR to the canonical path given by .Xr getcwd 3 . However, if the environment variable .Sq Ev PWD is set and gives a path to the current directory, .Nm sets .Sq Va .CURDIR to the value of .Sq Ev PWD instead. This behavior is disabled if .Sq Ev MAKEOBJDIRPREFIX is set or .Sq Ev MAKEOBJDIR contains a variable transform. .Sq Va PWD is set to the value of .Sq Va .OBJDIR for all programs which .Nm executes. .It Va .SHELL The pathname of the shell used to run target scripts. It is read-only. .It Va .SUFFIXES The list of known suffixes. It is read-only. .It Va .SYSPATH The space-separated list of directories that .Nm searches for makefiles, referred to as the system include path. To update this search list, use the special target .Sq Ic .SYSPATH rather than modifying the variable which is read-only. .It Va .TARGETS The list of targets explicitly specified on the command line, if any. .It Va VPATH The colon-separated .Pq Dq \&: list of directories that .Nm searches for files. This variable is supported for compatibility with old make programs only, use .Sq Va .PATH instead. .El .Ss Variable modifiers The general format of a variable expansion is: .Pp .Sm off .D1 Ic \&${ Ar variable\| Oo Ic \&: Ar modifier\| Oo Ic \&: No ... Oc Oc Ic \&} .Sm on .Pp Each modifier begins with a colon. To escape a colon, precede it with a backslash .Ql \e . .Pp A list of indirect modifiers can be specified via a variable, as follows: .Pp .Bd -literal -offset indent .Ar modifier_variable\^ Li \&= Ar modifier Ns Oo Ic \&: Ns No ... Oc .Sm off .Ic \&${ Ar variable Ic \&:${ Ar modifier_variable Ic \&} Oo Ic \&: No ... Oc Ic \&} .Sm on .Ed .Pp In this case, the first modifier in the .Ar modifier_variable does not start with a colon, since that colon already occurs in the referencing variable. If any of the modifiers in the .Ar modifier_variable contains a dollar sign .Pq Ql $ , these must be doubled to avoid early expansion. .Pp Some modifiers interpret the expression value as a single string, others treat the expression value as a whitespace-separated list of words. When splitting a string into words, whitespace can be escaped using double quotes, single quotes and backslashes, like in the shell. The quotes and backslashes are retained in the words. .Pp The supported modifiers are: .Bl -tag -width EEE .It Cm \&:E Replaces each word with its suffix. .It Cm \&:H Replaces each word with its dirname. .It Cm \&:M\| Ns Ar pattern Selects only those words that match .Ar pattern . The standard shell wildcard characters .Pf ( Ql * , .Ql \&? , and .Ql \&[] ) may be used. The wildcard characters may be escaped with a backslash .Pq Ql \e . As a consequence of the way values are split into words, matched, and then joined, the construct .Ql ${VAR:M*} removes all leading and trailing whitespace and normalizes the inter-word spacing to a single space. .It Cm \&:N\| Ns Ar pattern This is the opposite of .Sq Cm \&:M , selecting all words which do .Em not match .Ar pattern . .It Cm \&:O Orders the words lexicographically. .It Cm \&:On Orders the words numerically. A number followed by one of .Ql k , .Ql M or .Ql G is multiplied by the appropriate factor, which is 1024 for .Ql k , 1048576 for .Ql M , or 1073741824 for .Ql G . Both upper- and lower-case letters are accepted. .It Cm \&:Or Orders the words in reverse lexicographical order. .It Cm \&:Orn Orders the words in reverse numerical order. .It Cm \&:Ox Shuffles the words. The results are different each time you are referring to the modified variable; use the assignment with expansion .Sq Cm \&:= to prevent such behavior. For example, .Bd -literal -offset indent LIST= uno due tre quattro RANDOM_LIST= ${LIST:Ox} STATIC_RANDOM_LIST:= ${LIST:Ox} all: @echo "${RANDOM_LIST}" @echo "${RANDOM_LIST}" @echo "${STATIC_RANDOM_LIST}" @echo "${STATIC_RANDOM_LIST}" .Ed may produce output similar to: .Bd -literal -offset indent quattro due tre uno tre due quattro uno due uno quattro tre due uno quattro tre .Ed .It Cm \&:Q Quotes every shell meta-character in the value, so that it can be passed safely to the shell. .It Cm \&:q Quotes every shell meta-character in the value, and also doubles .Sq $ characters so that it can be passed safely through recursive invocations of .Nm . This is equivalent to .Sq Cm \&:S/\e\&$/&&/g:Q . .It Cm \&:R Replaces each word with everything but its suffix. .It Cm \&:range Ns Oo Cm = Ns Ar count Oc The value is an integer sequence representing the words of the original value, or the supplied .Ar count . .It Cm \&:gmtime Ns Oo Cm = Ns Ar timestamp Oc The value is interpreted as a format string for .Xr strftime 3 , using .Xr gmtime 3 , producing the formatted timestamp. If a .Ar timestamp value is not provided or is 0, the current time is used. .It Cm \&:hash Computes a 32-bit hash of the value and encodes it as 8 hex digits. .It Cm \&:localtime Ns Oo Cm = Ns Ar timestamp Oc The value is interpreted as a format string for .Xr strftime 3 , using .Xr localtime 3 , producing the formatted timestamp. If a .Ar timestamp value is not provided or is 0, the current time is used. +.It Cm \&:mtime Ns Oo Cm = Ns Ar timestamp Oc +Call +.Xr stat 2 +with each word as pathname; +use +.Ql st_mtime +as the new value. +If +.Xr stat 2 +fails; use +.Ar timestamp +or current time. +If +.Ar timestamp +is set to +.Ql error , +then +.Xr stat 2 +failure will cause an error. .It Cm \&:tA Attempts to convert the value to an absolute path using .Xr realpath 3 . If that fails, the value is unchanged. .It Cm \&:tl Converts the value to lower-case letters. .It Cm \&:ts Ns Ar c When joining the words after a modifier that treats the value as words, the words are normally separated by a space. This modifier changes the separator to the character .Ar c . If .Ar c is omitted, no separator is used. The common escapes (including octal numeric codes) work as expected. .It Cm \&:tu Converts the value to upper-case letters. .It Cm \&:tW Causes subsequent modifiers to treat the value as a single word (possibly containing embedded whitespace). See also .Sq Cm \&:[*] . .It Cm \&:tw Causes the value to be treated as a list of words. See also .Sq Cm \&:[@] . .Sm off .It Cm \&:S\| No \&/ Ar old_string\| No \&/ Ar new_string\| No \&/ Op Cm 1gW .Sm on Modifies the first occurrence of .Ar old_string in each word of the value, replacing it with .Ar new_string . If a .Ql g is appended to the last delimiter of the pattern, all occurrences in each word are replaced. If a .Ql 1 is appended to the last delimiter of the pattern, only the first occurrence is affected. If a .Ql W is appended to the last delimiter of the pattern, the value is treated as a single word. If .Ar old_string begins with a caret .Pq Ql ^ , .Ar old_string is anchored at the beginning of each word. If .Ar old_string ends with a dollar sign .Pq Ql \&$ , it is anchored at the end of each word. Inside .Ar new_string , an ampersand .Pq Ql & is replaced by .Ar old_string (without the anchoring .Ql ^ or .Ql \&$ ) . Any character may be used as the delimiter for the parts of the modifier string. The anchoring, ampersand and delimiter characters can be escaped with a backslash .Pq Ql \e . .Pp Both .Ar old_string and .Ar new_string may contain nested expressions. To prevent a dollar sign from starting a nested expression, escape it with a backslash. .Sm off .It Cm \&:C\| No \&/ Ar pattern\| No \&/ Ar replacement\| No \&/ Op Cm 1gW .Sm on The .Cm \&:C modifier works like the .Cm \&:S modifier except that the old and new strings, instead of being simple strings, are an extended regular expression .Ar pattern (see .Xr regex 3 ) and an .Xr ed 1 Ns \-style .Ar replacement . Normally, the first occurrence of the pattern .Ar pattern in each word of the value is substituted with .Ar replacement . The .Ql 1 modifier causes the substitution to apply to at most one word; the .Ql g modifier causes the substitution to apply to as many instances of the search pattern .Ar pattern as occur in the word or words it is found in; the .Ql W modifier causes the value to be treated as a single word (possibly containing embedded whitespace). .Pp As for the .Cm \&:S modifier, the .Ar pattern and .Ar replacement are subjected to variable expansion before being parsed as regular expressions. .It Cm \&:T Replaces each word with its last path component (basename). .It Cm \&:u Removes adjacent duplicate words (like .Xr uniq 1 ) . .Sm off .It Cm \&:\&?\| Ar true_string\| Cm \&: Ar false_string .Sm on If the variable name (not its value), when parsed as a .Cm .if conditional expression, evaluates to true, return as its value the .Ar true_string , otherwise return the .Ar false_string . Since the variable name is used as the expression, \&:\&? must be the first modifier after the variable name .No itself Ns \^\(em\^ Ns which, of course, usually contains variable expansions. A common error is trying to use expressions like .Dl ${NUMBERS:M42:?match:no} which actually tests defined(NUMBERS). To determine if any words match .Dq 42 , you need to use something like: .Dl ${"${NUMBERS:M42}" != \&"\&":?match:no} . .It Cm :\| Ns Ar old_string\| Ns Cm = Ns Ar new_string This is the .At V style substitution. It can only be the last modifier specified, as a .Ql \&: in either .Ar old_string or .Ar new_string is treated as a regular character, not as the end of the modifier. .Pp If .Ar old_string does not contain the pattern matching character .Ql % , and the word ends with .Ar old_string or equals it, that suffix is replaced with .Ar new_string . .Pp Otherwise, the first .Ql % in .Ar old_string matches a possibly empty substring of arbitrary characters, and if the whole pattern is found in the word, the matching part is replaced with .Ar new_string , and the first occurrence of .Ql % in .Ar new_string (if any) is replaced with the substring matched by the .Ql % . .Pp Both .Ar old_string and .Ar new_string may contain nested expressions. To prevent a dollar sign from starting a nested expression, escape it with a backslash. .Sm off .It Cm \&:@ Ar varname\| Cm @ Ar string\| Cm @ .Sm on This is the loop expansion mechanism from the OSF Development Environment (ODE) make. Unlike .Cm \&.for loops, expansion occurs at the time of reference. For each word in the value, assign the word to the variable named .Ar varname and evaluate .Ar string . The ODE convention is that .Ar varname should start and end with a period, for example: .Dl ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@} .Pp However, a single-letter variable is often more readable: .Dl ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@} .It Cm \&:_ Ns Oo Cm = Ns Ar var Oc Saves the current variable value in .Ql $_ or the named .Ar var for later reference. Example usage: .Bd -literal -offset indent M_cmpv.units = 1 1000 1000000 M_cmpv = S,., ,g:_:range:@i@+ $${_:[-$$i]} \&\\ \\* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh .Dv .if ${VERSION:${M_cmpv}} < ${3.1.12:L:${M_cmpv}} .Ed Here .Ql $_ is used to save the result of the .Ql :S modifier which is later referenced using the index values from .Ql :range . .It Cm \&:U\| Ns Ar newval If the variable is undefined, .Ar newval is the value. If the variable is defined, the existing value is returned. This is another ODE make feature. It is handy for setting per-target CFLAGS for instance: .Dl ${_${.TARGET:T}_CFLAGS:U${DEF_CFLAGS}} If a value is only required if the variable is undefined, use: .Dl ${VAR:D:Unewval} .It Cm \&:D\| Ns Ar newval If the variable is defined, .Ar newval is the value. .It Cm \&:L The name of the variable is the value. .It Cm \&:P The path of the node which has the same name as the variable is the value. If no such node exists or its path is null, the name of the variable is used. In order for this modifier to work, the name (node) must at least have appeared on the right-hand side of a dependency. .Sm off .It Cm \&:\&! Ar cmd\| Cm \&! .Sm on The output of running .Ar cmd is the value. .It Cm \&:sh The value is run as a command, and the output becomes the new value. .It Cm \&::= Ns Ar str The variable is assigned the value .Ar str after substitution. This modifier and its variations are useful in obscure situations such as wanting to set a variable at a point where a target's shell commands are being parsed. These assignment modifiers always expand to nothing. .Pp The .Sq Cm \&:: helps avoid false matches with the .At V style .Ql \&:= modifier and since substitution always occurs, the .Ql \&::= form is vaguely appropriate. .It Cm \&::?= Ns Ar str As for .Cm \&::= but only if the variable does not already have a value. .It Cm \&::+= Ns Ar str Append .Ar str to the variable. .It Cm \&::!= Ns Ar cmd Assign the output of .Ar cmd to the variable. .It Cm \&:\&[ Ns Ar range Ns Cm \&] Selects one or more words from the value, or performs other operations related to the way in which the value is split into words. .Pp An empty value, or a value that consists entirely of white-space, is treated as a single word. For the purposes of the .Sq Cm \&:[] modifier, the words are indexed both forwards using positive integers (where index 1 represents the first word), and backwards using negative integers (where index \-1 represents the last word). .Pp The .Ar range is subjected to variable expansion, and the expanded result is then interpreted as follows: .Bl -tag -width index .\" :[n] .It Ar index Selects a single word from the value. .\" :[start..end] .It Ar start Ns Cm \&.. Ns Ar end Selects all words from .Ar start to .Ar end , inclusive. For example, .Sq Cm \&:[2..-1] selects all words from the second word to the last word. If .Ar start is greater than .Ar end , the words are output in reverse order. For example, .Sq Cm \&:[-1..1] selects all the words from last to first. If the list is already ordered, this effectively reverses the list, but it is more efficient to use .Sq Cm \&:Or instead of .Sq Cm \&:O:[-1..1] . .\" :[*] .It Cm \&* Causes subsequent modifiers to treat the value as a single word (possibly containing embedded whitespace). Analogous to the effect of .Li \&$* in Bourne shell. .\" :[0] .It 0 Means the same as .Sq Cm \&:[*] . .\" :[*] .It Cm \&@ Causes subsequent modifiers to treat the value as a sequence of words delimited by whitespace. Analogous to the effect of .Li \&$@ in Bourne shell. .\" :[#] .It Cm \&# Returns the number of words in the value. .El \" :[range] .El .Sh DIRECTIVES .Nm offers directives for including makefiles, conditionals and for loops. All these directives are identified by a line beginning with a single dot .Pq Ql \&. character, followed by the keyword of the directive, such as .Cm include or .Cm if . .Ss File inclusion Files are included with either .Cm \&.include \&< Ns Ar file Ns Cm \&> or .Cm \&.include \&\*q Ns Ar file Ns Cm \&\*q . Variables between the angle brackets or double quotes are expanded to form the file name. If angle brackets are used, the included makefile is expected to be in the system makefile directory. If double quotes are used, the including makefile's directory and any directories specified using the .Fl I option are searched before the system makefile directory. .Pp For compatibility with other make variants, .Sq Cm include Ar file No ... (without leading dot) is also accepted. .Pp If the include statement is written as .Cm .-include or as .Cm .sinclude , errors locating and/or opening include files are ignored. .Pp If the include statement is written as .Cm .dinclude , not only are errors locating and/or opening include files ignored, but stale dependencies within the included file are ignored just like in .Va .MAKE.DEPENDFILE . .Ss Exporting variables The directives for exporting and unexporting variables are: .Bl -tag -width Ds .It Ic .export Ar variable No ... Export the specified global variable. If no variable list is provided, all globals are exported except for internal variables (those that start with .Ql \&. ) . This is not affected by the .Fl X flag, so should be used with caution. For compatibility with other make programs, .Cm export Ar variable\| Ns Cm \&= Ns Ar value (without leading dot) is also accepted. .Pp Appending a variable name to .Va .MAKE.EXPORTED is equivalent to exporting a variable. .It Ic .export-env Ar variable No ... The same as .Ql .export , except that the variable is not appended to .Va .MAKE.EXPORTED . This allows exporting a value to the environment which is different from that used by .Nm internally. .It Ic .export-literal Ar variable No ... The same as .Ql .export-env , except that variables in the value are not expanded. .It Ic .unexport Ar variable No ... The opposite of .Ql .export . The specified global .Ar variable is removed from .Va .MAKE.EXPORTED . If no variable list is provided, all globals are unexported, and .Va .MAKE.EXPORTED deleted. .It Ic .unexport-env Unexport all globals previously exported and clear the environment inherited from the parent. This operation causes a memory leak of the original environment, so should be used sparingly. Testing for .Va .MAKE.LEVEL being 0 would make sense. Also note that any variables which originated in the parent environment should be explicitly preserved if desired. For example: .Bd -literal -offset indent .Li .if ${.MAKE.LEVEL} == 0 PATH := ${PATH} .Li .unexport-env .Li .export PATH .Li .endif .Pp .Ed Would result in an environment containing only .Sq Ev PATH , which is the minimal useful environment. .\" TODO: Check the below sentence, environment variables don't start with '.'. Actually .Sq Va .MAKE.LEVEL is also pushed into the new environment. .El .Ss Messages The directives for printing messages to the output are: .Bl -tag -width Ds .It Ic .info Ar message The message is printed along with the name of the makefile and line number. .It Ic .warning Ar message The message prefixed by .Sq Li warning: is printed along with the name of the makefile and line number. .It Ic .error Ar message The message is printed along with the name of the makefile and line number, .Nm exits immediately. .El .Ss Conditionals The directives for conditionals are: .ds maybenot Oo Ic \&! Oc Ns .Bl -tag .It Ic .if \*[maybenot] Ar expression Op Ar operator expression No ... Test the value of an expression. .It Ic .ifdef \*[maybenot] Ar variable Op Ar operator variable No ... Test whether a variable is defined. .It Ic .ifndef \*[maybenot] Ar variable Op Ar operator variable No ... Test whether a variable is not defined. .It Ic .ifmake \*[maybenot] Ar target Op Ar operator target No ... Test the target being requested. .It Ic .ifnmake \*[maybenot] Ar target Op Ar operator target No ... Test the target being requested. .It Ic .else Reverse the sense of the last conditional. .It Ic .elif \*[maybenot] Ar expression Op Ar operator expression No ... A combination of .Sq Ic .else followed by .Sq Ic .if . .It Ic .elifdef \*[maybenot] Ar variable Op Ar operator variable No ... A combination of .Sq Ic .else followed by .Sq Ic .ifdef . .It Ic .elifndef \*[maybenot] Ar variable Op Ar operator variable No ... A combination of .Sq Ic .else followed by .Sq Ic .ifndef . .It Ic .elifmake \*[maybenot] Ar target Op Ar operator target No ... A combination of .Sq Ic .else followed by .Sq Ic .ifmake . .It Ic .elifnmake \*[maybenot] Ar target Op Ar operator target No ... A combination of .Sq Ic .else followed by .Sq Ic .ifnmake . .It Ic .endif End the body of the conditional. .El .Pp The .Ar operator may be any one of the following: .Bl -tag .It Ic \&|\&| Logical OR. .It Ic \&&& Logical AND; of higher precedence than .Sq Ic \&|\&| . .El .Pp .Nm only evaluates a conditional as far as is necessary to determine its value. Parentheses can be used to override the operator precedence. The boolean operator .Sq Ic \&! may be used to logically negate an entire conditional. It is of higher precedence than .Sq Ic \&&& . .Pp The value of .Ar expression may be any of the following function call expressions: .Bl -tag .Sm off .It Ic defined Li \&( Ar varname Li \&) .Sm on Evaluates to true if the variable .Ar varname has been defined. .Sm off .It Ic make Li \&( Ar target Li \&) .Sm on Evaluates to true if the target was specified as part of .Nm Ns 's command line or was declared the default target (either implicitly or explicitly, see .Va .MAIN ) before the line containing the conditional. .Sm off .It Ic empty Li \&( Ar varname Oo Li : Ar modifiers Oc Li \&) .Sm on Evaluates to true if the expansion of the variable, after applying the modifiers, results in an empty string. .Sm off .It Ic exists Li \&( Ar pathname Li \&) .Sm on Evaluates to true if the given pathname exists. If relative, the pathname is searched for on the system search path (see .Va .PATH ) . .Sm off .It Ic target Li \&( Ar target Li \&) .Sm on Evaluates to true if the target has been defined. .Sm off .It Ic commands Li \&( Ar target Li \&) .Sm on Evaluates to true if the target has been defined and has commands associated with it. .El .Pp .Ar Expression may also be an arithmetic or string comparison. Variable expansion is performed on both sides of the comparison. If both sides are numeric and neither is enclosed in quotes, the comparison is done numerically, otherwise lexicographically. A string is interpreted as hexadecimal integer if it is preceded by .Li 0x , otherwise it is a decimal floating-point number; octal numbers are not supported. .Pp All comparisons may use the operators .Sq Ic \&== and .Sq Ic \&!= . Numeric comparisons may also use the operators .Sq Ic \&< , .Sq Ic \&<= , .Sq Ic \&> and .Sq Ic \&>= . .Pp If the comparison has neither a comparison operator nor a right side, the expression evaluates to true if it is nonempty and its numeric value (if any) is not zero. .Pp When .Nm is evaluating one of these conditional expressions, and it encounters a (whitespace separated) word it doesn't recognize, either the .Dq make or .Dq defined function is applied to it, depending on the form of the conditional. If the form is .Sq Ic .ifdef , .Sq Ic .ifndef or .Sq Ic .if , the .Dq defined function is applied. Similarly, if the form is .Sq Ic .ifmake or .Sq Ic .ifnmake , the .Dq make function is applied. .Pp If the conditional evaluates to true, parsing of the makefile continues as before. If it evaluates to false, the following lines are skipped. In both cases, this continues until the corresponding .Sq Ic .else or .Sq Ic .endif is found. .Ss For loops For loops are typically used to apply a set of rules to a list of files. The syntax of a for loop is: .Pp .Bl -tag -compact -width Ds .It Ic \&.for Ar variable Oo Ar variable No ... Oc Ic in Ar expression .It Aq Ar make-lines .It Ic \&.endfor .El .Pp The .Ar expression is expanded and then split into words. On each iteration of the loop, one word is taken and assigned to each .Ar variable , in order, and these .Ar variables are substituted into the .Ar make-lines inside the body of the for loop. The number of words must come out even; that is, if there are three iteration variables, the number of words provided must be a multiple of three. .Pp If .Sq Ic .break is encountered within a .Cm \&.for loop, it causes early termination of the loop, otherwise a parse error. .\" TODO: Describe limitations with defined/empty. .Ss Other directives .Bl -tag -width Ds .It Ic .undef Ar variable No ... Un-define the specified global variables. Only global variables can be un-defined. .El .Sh COMMENTS Comments begin with a hash .Pq Ql \&# character, anywhere but in a shell command line, and continue to the end of an unescaped new line. .Sh SPECIAL SOURCES (ATTRIBUTES) .Bl -tag -width .IGNOREx .It Ic .EXEC Target is never out of date, but always execute commands anyway. .It Ic .IGNORE Ignore any errors from the commands associated with this target, exactly as if they all were preceded by a dash .Pq Ql \- . .\" .It Ic .INVISIBLE .\" XXX .\" .It Ic .JOIN .\" XXX .It Ic .MADE Mark all sources of this target as being up to date. .It Ic .MAKE Execute the commands associated with this target even if the .Fl n or .Fl t options were specified. Normally used to mark recursive .Nm Ns s . .It Ic .META Create a meta file for the target, even if it is flagged as .Ic .PHONY , .Ic .MAKE , or .Ic .SPECIAL . Usage in conjunction with .Ic .MAKE is the most likely case. In .Dq meta mode, the target is out-of-date if the meta file is missing. .It Ic .NOMETA Do not create a meta file for the target. Meta files are also not created for .Ic .PHONY , .Ic .MAKE , or .Ic .SPECIAL targets. .It Ic .NOMETA_CMP Ignore differences in commands when deciding if target is out of date. This is useful if the command contains a value which always changes. If the number of commands change, though, the target is still considered out of date. The same effect applies to any command line that uses the variable .Va .OODATE , which can be used for that purpose even when not otherwise needed or desired: .Bd -literal -offset indent skip-compare-for-some: @echo this is compared @echo this is not ${.OODATE:M.NOMETA_CMP} @echo this is also compared .Ed The .Cm \&:M pattern suppresses any expansion of the unwanted variable. .It Ic .NOPATH Do not search for the target in the directories specified by .Va .PATH . .It Ic .NOTMAIN Normally .Nm selects the first target it encounters as the default target to be built if no target was specified. This source prevents this target from being selected. .It Ic .OPTIONAL If a target is marked with this attribute and .Nm can't figure out how to create it, it ignores this fact and assumes the file isn't needed or already exists. .It Ic .PHONY The target does not correspond to an actual file; it is always considered to be out of date, and is not created with the .Fl t option. Suffix-transformation rules are not applied to .Ic .PHONY targets. .It Ic .PRECIOUS When .Nm is interrupted, it normally removes any partially made targets. This source prevents the target from being removed. .It Ic .RECURSIVE Synonym for .Ic .MAKE . .It Ic .SILENT Do not echo any of the commands associated with this target, exactly as if they all were preceded by an at sign .Pq Ql @ . .It Ic .USE Turn the target into .Nm Ns 's version of a macro. When the target is used as a source for another target, the other target acquires the commands, sources, and attributes (except for .Ic .USE ) of the source. If the target already has commands, the .Ic .USE target's commands are appended to them. .It Ic .USEBEFORE Like .Ic .USE , but instead of appending, prepend the .Ic .USEBEFORE target commands to the target. .It Ic .WAIT If .Ic .WAIT appears in a dependency line, the sources that precede it are made before the sources that succeed it in the line. Since the dependents of files are not made until the file itself could be made, this also stops the dependents being built unless they are needed for another branch of the dependency tree. So given: .Bd -literal x: a .WAIT b echo x a: echo a b: b1 echo b b1: echo b1 .Ed the output is always .Ql a , .Ql b1 , .Ql b , .Ql x . .Pp The ordering imposed by .Ic .WAIT is only relevant for parallel makes. .El .Sh SPECIAL TARGETS Special targets may not be included with other targets, i.e. they must be the only target specified. .Bl -tag -width .BEGINx .It Ic .BEGIN Any command lines attached to this target are executed before anything else is done. .It Ic .DEFAULT This is sort of a .Ic .USE rule for any target (that was used only as a source) that .Nm can't figure out any other way to create. Only the shell script is used. The .Va .IMPSRC variable of a target that inherits .Ic .DEFAULT Ns 's commands is set to the target's own name. .It Ic .DELETE_ON_ERROR If this target is present in the makefile, it globally causes make to delete targets whose commands fail. (By default, only targets whose commands are interrupted during execution are deleted. This is the historical behavior.) This setting can be used to help prevent half-finished or malformed targets from being left around and corrupting future rebuilds. .It Ic .END Any command lines attached to this target are executed after everything else is done successfully. .It Ic .ERROR Any command lines attached to this target are executed when another target fails. The .Va .ERROR_TARGET variable is set to the target that failed. See also .Va MAKE_PRINT_VAR_ON_ERROR . .It Ic .IGNORE Mark each of the sources with the .Ic .IGNORE attribute. If no sources are specified, this is the equivalent of specifying the .Fl i option. .It Ic .INTERRUPT If .Nm is interrupted, the commands for this target are executed. .It Ic .MAIN If no target is specified when .Nm is invoked, this target is built. .It Ic .MAKEFLAGS This target provides a way to specify flags for .Nm at the time when the makefiles are read. The flags are as if typed to the shell, though the .Fl f option has no effect. .\" XXX: NOT YET!!!! .\" .It Ic .NOTPARALLEL .\" The named targets are executed in non parallel mode. .\" If no targets are .\" specified, all targets are executed in non parallel mode. .It Ic .NOPATH Apply the .Ic .NOPATH attribute to any specified sources. .It Ic .NOTPARALLEL Disable parallel mode. .It Ic .NO_PARALLEL Synonym for .Ic .NOTPARALLEL , for compatibility with other pmake variants. .It Ic .NOREADONLY clear the read-only attribute from the global variables specified as sources. .It Ic .OBJDIR The source is a new value for .Sq Va .OBJDIR . If it exists, .Nm changes the current working directory to it and updates the value of .Sq Va .OBJDIR . .It Ic .ORDER In parallel mode, the named targets are made in sequence. This ordering does not add targets to the list of targets to be made. .Pp Since the dependents of a target do not get built until the target itself could be built, unless .Ql a is built by another part of the dependency graph, the following is a dependency loop: .Bd -literal \&.ORDER: b a b: a .Ed .Pp .\" XXX: NOT YET!!!! .\" .It Ic .PARALLEL .\" The named targets are executed in parallel mode. .\" If no targets are .\" specified, all targets are executed in parallel mode. .It Ic .PATH The sources are directories which are to be searched for files not found in the current directory. If no sources are specified, any previously specified directories are removed from the search path. If the source is the special .Ic .DOTLAST target, the current working directory is searched last. .It Ic .PATH. Ns Ar suffix Like .Ic .PATH but applies only to files with a particular suffix. The suffix must have been previously declared with .Ic .SUFFIXES . .It Ic .PHONY Apply the .Ic .PHONY attribute to any specified sources. .It Ic .POSIX If this is the first non-comment line in the main makefile, the variable .Va %POSIX is set to the value .Ql 1003.2 and the makefile .Ql is included if it exists, to provide POSIX-compatible default rules. If .Nm is run with the .Fl r flag, only .Ql posix.mk contributes to the default rules. .It Ic .PRECIOUS Apply the .Ic .PRECIOUS attribute to any specified sources. If no sources are specified, the .Ic .PRECIOUS attribute is applied to every target in the file. .It Ic .READONLY set the read-only attribute on the global variables specified as sources. .It Ic .SHELL Sets the shell that .Nm uses to execute commands in jobs mode. The sources are a set of .Ar field\| Ns Cm \&= Ns Ar value pairs. .Bl -tag -width ".Li hasErrCtls" .It Li name This is the minimal specification, used to select one of the built-in shell specs; .Li sh , .Li ksh , and .Li csh . .It Li path Specifies the absolute path to the shell. .It Li hasErrCtl Indicates whether the shell supports exit on error. .It Li check The command to turn on error checking. .It Li ignore The command to disable error checking. .It Li echo The command to turn on echoing of commands executed. .It Li quiet The command to turn off echoing of commands executed. .It Li filter The output to filter after issuing the .Li quiet command. It is typically identical to .Li quiet . .It Li errFlag The flag to pass the shell to enable error checking. .It Li echoFlag The flag to pass the shell to enable command echoing. .It Li newline The string literal to pass the shell that results in a single newline character when used outside of any quoting characters. .El Example: .Bd -literal \&.SHELL: name=ksh path=/bin/ksh hasErrCtl=true \e check="set \-e" ignore="set +e" \e echo="set \-v" quiet="set +v" filter="set +v" \e echoFlag=v errFlag=e newline="'\en'" .Ed .It Ic .SILENT Apply the .Ic .SILENT attribute to any specified sources. If no sources are specified, the .Ic .SILENT attribute is applied to every command in the file. .It Ic .STALE This target gets run when a dependency file contains stale entries, having .Va .ALLSRC set to the name of that dependency file. .It Ic .SUFFIXES Each source specifies a suffix to .Nm . If no sources are specified, any previously specified suffixes are deleted. It allows the creation of suffix-transformation rules. .Pp Example: .Bd -literal \&.SUFFIXES: .c .o \&.c.o: cc \-o ${.TARGET} \-c ${.IMPSRC} .Ed .It Ic .SYSPATH The sources are directories which are to be added to the system include path which .Nm searches for makefiles. If no sources are specified, any previously specified directories are removed from the system include path. .El .Sh ENVIRONMENT .Nm uses the following environment variables, if they exist: .Ev MACHINE , .Ev MACHINE_ARCH , .Ev MAKE , .Ev MAKEFLAGS , .Ev MAKEOBJDIR , .Ev MAKEOBJDIRPREFIX , .Ev MAKESYSPATH , .Ev PWD , and .Ev TMPDIR . .Pp .Ev MAKEOBJDIRPREFIX and .Ev MAKEOBJDIR may only be set in the environment or on the command line to .Nm and not as makefile variables; see the description of .Sq Va .OBJDIR for more details. .Sh FILES .Bl -tag -width /usr/share/mk -compact .It .depend list of dependencies .It makefile first default makefile if no makefile is specified on the command line .It Makefile second default makefile if no makefile is specified on the command line .It sys.mk system makefile .It /usr/share/mk system makefile directory .El .Sh COMPATIBILITY The basic make syntax is compatible between different make variants; however the special variables, variable modifiers and conditionals are not. .Ss Older versions An incomplete list of changes in older versions of .Nm : .Pp The way that .for loop variables are substituted changed after NetBSD 5.0 so that they still appear to be variable expansions. In particular this stops them being treated as syntax, and removes some obscure problems using them in .if statements. .Pp The way that parallel makes are scheduled changed in NetBSD 4.0 so that .ORDER and .WAIT apply recursively to the dependent nodes. The algorithms used may change again in the future. .Ss Other make dialects Other make dialects (GNU make, SVR4 make, POSIX make, etc.) do not support most of the features of .Nm as described in this manual. Most notably: .Bl -bullet -offset indent .It The .Ic .WAIT and .Ic .ORDER declarations and most functionality pertaining to parallelization. (GNU make supports parallelization but lacks the features needed to control it effectively.) .It Directives, including for loops and conditionals and most of the forms of include files. (GNU make has its own incompatible and less powerful syntax for conditionals.) .\" The "less powerful" above means that GNU make does not have the .\" make(target), target(target) and commands(target) functions. .It All built-in variables that begin with a dot. .It Most of the special sources and targets that begin with a dot, with the notable exception of .Ic .PHONY , .Ic .PRECIOUS , and .Ic .SUFFIXES . .It Variable modifiers, except for the .Ql :old=new string substitution, which does not portably support globbing with .Ql % and historically only works on declared suffixes. .It The .Ic $> variable even in its short form; most makes support this functionality but its name varies. .El .Pp Some features are somewhat more portable, such as assignment with .Ic += , .Ic ?= , and .Ic != . The .Va .PATH functionality is based on an older feature .Ic VPATH found in GNU make and many versions of SVR4 make; however, historically its behavior is too ill-defined (and too buggy) to rely upon. .Pp The .Ic $@ and .Ic $< variables are more or less universally portable, as is the .Ic $(MAKE) variable. Basic use of suffix rules (for files only in the current directory, not trying to chain transformations together, etc.) is also reasonably portable. .Sh SEE ALSO .Xr mkdep 1 .Sh HISTORY .Nm is derived from NetBSD .Xr make 1 . It uses autoconf to facilitate portability to other platforms. .Pp A make command appeared in .At v7 . This make implementation is based on Adam de Boor's pmake program, which was written for Sprite at Berkeley. It was designed to be a parallel distributed make running jobs on different machines using a daemon called .Dq customs . .Pp Historically the target/dependency .Ic FRC has been used to FoRCe rebuilding (since the target/dependency does not exist ... unless someone creates an .Pa FRC file). .Sh BUGS The make syntax is difficult to parse. For instance, finding the end of a variable's use should involve scanning each of the modifiers, using the correct terminator for each field. In many places make just counts {} and () in order to find the end of a variable expansion. .Pp There is no way of escaping a space character in a filename. .Pp In jobs mode, when a target fails; make will put an error token into the job token pool. This will cause all other instances of make using that token pool to abort the build and exit with error code 6. Sometimes the attempt to suppress a cascade of unnecessary errors, can result in a seemingly unexplained .Ql *** Error code 6 - - diff --git a/bmake.cat1 b/bmake.cat1 index 9715bd908f18..6f69dfb9f3ad 100644 --- a/bmake.cat1 +++ b/bmake.cat1 @@ -1,1755 +1,1756 @@ BMAKE(1) FreeBSD General Commands Manual BMAKE(1) NAME bmake -- maintain program dependencies SYNOPSIS bmake [-BeikNnqrSstWwX] [-C directory] [-D variable] [-d flags] [-f makefile] [-I directory] [-J private] [-j max_jobs] [-m directory] [-T file] [-V variable] [-v variable] [variable=value] [target ...] DESCRIPTION bmake is a program designed to simplify the maintenance of other pro- grams. Its input is a list of specifications as to the files upon which programs and other files depend. If no -f makefile option is given, bmake tries to open `makefile' then `Makefile' in order to find the spec- ifications. If the file `.depend' exists, it is read, see mkdep(1). This manual page is intended as a reference document only. For a more thorough description of bmake and makefiles, please refer to PMake - A Tutorial (from 1993). bmake prepends the contents of the MAKEFLAGS environment variable to the command line arguments before parsing them. The options are as follows: -B Try to be backwards compatible by executing a single shell per command and by making the sources of a dependency line in se- quence. -C directory Change to directory before reading the makefiles or doing any- thing else. If multiple -C options are specified, each is inter- preted relative to the previous one: -C / -C etc is equivalent to -C /etc. -D variable Define variable to be 1, in the global scope. -d [-]flags Turn on debugging, and specify which portions of bmake are to print debugging information. Unless the flags are preceded by `-', they are added to the MAKEFLAGS environment variable and are passed on to any child make processes. By default, debugging in- formation is printed to standard error, but this can be changed using the F debugging flag. The debugging output is always un- buffered; in addition, if debugging is enabled but debugging out- put is not directed to standard output, the standard output is line buffered. The available flags are: A Print all possible debugging information; equivalent to specifying all of the debugging flags. a Print debugging information about archive searching and caching. C Print debugging information about the current working di- rectory. c Print debugging information about conditional evaluation. d Print debugging information about directory searching and caching. e Print debugging information about failed commands and targets. F[+]filename Specify where debugging output is written. This must be the last flag, because it consumes the remainder of the argument. If the character immediately after the F flag is `+', the file is opened in append mode; otherwise the file is overwritten. If the file name is `stdout' or `stderr', debugging output is written to the standard output or standard error output respectively (and the `+' option has no effect). Otherwise, the output is written to the named file. If the file name ends with `.%d', the `%d' is replaced by the pid. f Print debugging information about loop evaluation. g1 Print the input graph before making anything. g2 Print the input graph after making everything, or before exiting on error. g3 Print the input graph before exiting on error. h Print debugging information about hash table operations. j Print debugging information about running multiple shells. L Turn on lint checks. This throws errors for variable as- signments that do not parse correctly, at the time of as- signment, so the file and line number are available. l Print commands in Makefiles regardless of whether or not they are prefixed by `@' or other "quiet" flags. Also known as "loud" behavior. M Print debugging information about "meta" mode decisions about targets. m Print debugging information about making targets, includ- ing modification dates. n Don't delete the temporary command scripts created when running commands. These temporary scripts are created in the directory referred to by the TMPDIR environment vari- able, or in /tmp if TMPDIR is unset or set to the empty string. The temporary scripts are created by mkstemp(3), and have names of the form makeXXXXXX. NOTE: This can create many files in TMPDIR or /tmp, so use with care. p Print debugging information about makefile parsing. s Print debugging information about suffix-transformation rules. t Print debugging information about target list mainte- nance. V Force the -V option to print raw values of variables, overriding the default behavior set via .MAKE.EXPAND_VARIABLES. v Print debugging information about variable assignment and expansion. x Run shell commands with -x so the actual commands are printed as they are executed. -e Let environment variables override global variables within make- files. -f makefile Specify a makefile to read instead of the default makefile or Makefile. If makefile is `-', standard input is read. Multiple makefiles may be specified, and are read in the order specified. -I directory Specify a directory in which to search for makefiles and included makefiles. The system makefile directory (or directories, see the -m option) is automatically included as part of this list. -i Ignore non-zero exit of shell commands in the makefile. Equiva- lent to specifying `-' before each command line in the makefile. -J private This option should not be specified by the user. When the -j option is in use in a recursive build, this option is passed by a make to child makes to allow all the make processes in the build to cooperate to avoid overloading the system. -j max_jobs Specify the maximum number of jobs that bmake may have running at any one time. The value of max_jobs is saved in .MAKE.JOBS. Turns compatibility mode off, unless the -B option is also speci- fied. When compatibility mode is off, all commands associated with a target are executed in a single shell invocation as op- posed to the traditional one shell invocation per line. This can break traditional scripts which change directories on each com- mand invocation and then expect to start with a fresh environment on the next line. It is more efficient to correct the scripts rather than turn backwards compatibility on. A job token pool with max_jobs tokens is used to control the to- tal number of jobs running. Each instance of bmake will wait for a token from the pool before running a new job. -k Continue processing after errors are encountered, but only on those targets that do not depend on the target whose creation caused the error. -m directory Specify a directory in which to search for sys.mk and makefiles included via the <file>-style include statement. The -m option can be used multiple times to form a search path. This path overrides the default system include path /usr/share/mk. Fur- thermore, the system include path is appended to the search path used for "file"-style include statements (see the -I option). The system include path can be referenced via the read-only vari- able .SYSPATH. If a directory name in the -m argument (or the MAKESYSPATH envi- ronment variable) starts with the string `.../', bmake searches for the specified file or directory named in the remaining part of the argument string. The search starts with the current di- rectory and then works upward towards the root of the file sys- tem. If the search is successful, the resulting directory re- places the `.../' specification in the -m argument. This feature allows bmake to easily search in the current source tree for cus- tomized sys.mk files (e.g., by using `.../mk/sys.mk' as an argu- ment). -n Display the commands that would have been executed, but do not actually execute them unless the target depends on the .MAKE spe- cial source (see below) or the command is prefixed with `+'. -N Display the commands that would have been executed, but do not actually execute any of them; useful for debugging top-level makefiles without descending into subdirectories. -q Do not execute any commands, instead exit 0 if the specified tar- gets are up to date, and 1 otherwise. -r Do not use the built-in rules specified in the system makefile. -S Stop processing if an error is encountered. This is the default behavior and the opposite of -k. -s Do not echo any commands as they are executed. Equivalent to specifying `@' before each command line in the makefile. -T tracefile When used with the -j flag, append a trace record to tracefile for each job started and completed. -t Rather than re-building a target as specified in the makefile, create it or update its modification time to make it appear up- to-date. -V variable Print the value of variable. Do not build any targets. Multiple instances of this option may be specified; the variables are printed one per line, with a blank line for each null or unde- fined variable. The value printed is extracted from the global scope after all makefiles have been read. By default, the raw variable contents (which may include addi- tional unexpanded variable references) are shown. If variable contains a `$', it is not interpreted as a variable name but rather as an expression. Its value is expanded before printing. The value is also expanded before printing if .MAKE.EXPAND_VARIABLES is set to true and the -dV option has not been used to override it. Note that loop-local and target-local variables, as well as val- ues taken temporarily by global variables during makefile pro- cessing, are not accessible via this option. The -dv debug mode can be used to see these at the cost of generating substantial extraneous output. -v variable Like -V, but all printed variables are always expanded to their complete value. The last occurrence of -V or -v decides whether all variables are expanded or not. -W Treat any warnings during makefile parsing as errors. -w Print entering and leaving directory messages, pre and post pro- cessing. -X Don't export variables passed on the command line to the environ- ment individually. Variables passed on the command line are still exported via the MAKEFLAGS environment variable. This op- tion may be useful on systems which have a small limit on the size of command arguments. variable=value Set the value of the variable variable to value. Normally, all values passed on the command line are also exported to sub-makes in the environment. The -X flag disables this behavior. Vari- able assignments should follow options for POSIX compatibility but no ordering is enforced. There are several different types of lines in a makefile: dependency specifications, shell commands, variable assignments, include statements, conditional directives, for loops, other directives, and comments. Lines may be continued from one line to the next by ending them with a backslash (`\'). The trailing newline character and initial whitespace on the following line are compressed into a single space. FILE DEPENDENCY SPECIFICATIONS Dependency lines consist of one or more targets, an operator, and zero or more sources. This creates a relationship where the targets "depend" on the sources and are customarily created from them. A target is consid- ered out of date if it does not exist, or if its modification time is less than that of any of its sources. An out-of-date target is re-cre- ated, but not until all sources have been examined and themselves re-cre- ated as needed. Three operators may be used: : Many dependency lines may name this target but only one may have attached shell commands. All sources named in all dependency lines are considered together, and if needed the attached shell commands are run to create or re-create the target. If bmake is inter- rupted, the target is removed. ! The same, but the target is always re-created whether or not it is out of date. :: Any dependency line may have attached shell commands, but each one is handled independently: its sources are considered and the at- tached shell commands are run if the target is out of date with re- spect to (only) those sources. Thus, different groups of the at- tached shell commands may be run depending on the circumstances. Furthermore, unlike :, for dependency lines with no sources, the attached shell commands are always run. Also unlike :, the target is not removed if bmake is interrupted. All dependency lines mentioning a particular target must use the same op- erator. Targets and sources may contain the shell wildcard values `?', `*', `[]', and `{}'. The values `?', `*', and `[]' may only be used as part of the final component of the target or source, and only match existing files. The value `{}' need not necessarily be used to describe existing files. Expansion is in directory order, not alphabetically as done in the shell. SHELL COMMANDS Each target may have associated with it one or more lines of shell com- mands, normally used to create the target. Each of the lines in this script must be preceded by a tab. (For historical reasons, spaces are not accepted.) While targets can occur in many dependency lines if de- sired, by default only one of these rules may be followed by a creation script. If the `::' operator is used, however, all rules may include scripts, and the respective scripts are executed in the order found. Each line is treated as a separate shell command, unless the end of line is escaped with a backslash `\', in which case that line and the next are combined. If the first characters of the command are any combination of `@', `+', or `-', the command is treated specially. @ causes the command not to be echoed before it is executed. + causes the command to be executed even when -n is given. This is similar to the effect of the .MAKE special source, except that the effect can be limited to a single line of a script. - in compatibility mode causes any non-zero exit status of the command line to be ignored. When bmake is run in jobs mode with -j max_jobs, the entire script for the target is fed to a single instance of the shell. In compatibility (non-jobs) mode, each command is run in a separate process. If the com- mand contains any shell meta characters (`#=|^(){};&<>*?[]:$`\\n'), it is passed to the shell; otherwise bmake attempts direct execution. If a line starts with `-' and the shell has ErrCtl enabled, failure of the command line is ignored as in compatibility mode. Otherwise `-' affects the entire job; the script stops at the first command line that fails, but the target is not deemed to have failed. Makefiles should be written so that the mode of bmake operation does not change their behavior. For example, any command which uses "cd" or "chdir" without the intention of changing the directory for subsequent commands should be put in parentheses so it executes in a subshell. To force the use of a single shell, escape the line breaks so as to make the whole script one command. For example: avoid-chdir-side-effects: @echo "Building $@ in $$(pwd)" @(cd ${.CURDIR} && ${MAKE} $@) @echo "Back in $$(pwd)" ensure-one-shell-regardless-of-mode: @echo "Building $@ in $$(pwd)"; \ (cd ${.CURDIR} && ${MAKE} $@); \ echo "Back in $$(pwd)" Since bmake changes the current working directory to `.OBJDIR' before ex- ecuting any targets, each child process starts with that as its current working directory. VARIABLE ASSIGNMENTS Variables in make behave much like macros in the C preprocessor. Variable assignments have the form `NAME op value', where: NAME is a single-word variable name, consisting, by tradition, of all upper-case letters, op is one of the variable assignment operators described be- low, and value is interpreted according to the variable assignment opera- tor. Whitespace around NAME, op and value is discarded. Variable assignment operators The five operators that assign values to variables are: = Assign the value to the variable. Any previous value is over- written. += Append the value to the current value of the variable, separating them by a single space. ?= Assign the value to the variable if it is not already defined. := Expand the value, then assign it to the variable. NOTE: References to undefined variables are not expanded. This can cause problems when variable modifiers are used. != Expand the value and pass it to the shell for execution, then as- sign the output from the child's standard output to the variable. Any newlines in the result are replaced with spaces. Expansion of variables In most contexts where variables are expanded, `$$' expands to a single dollar sign. In other contexts (most variable modifiers, string literals in conditions), `\$' expands to a single dollar sign. References to variables have the form ${name[:modifiers]} or $(name[:modifiers]). If the variable name consists of only a single character and the expression contains no modifiers, the surrounding curly braces or parentheses are not required. This shorter form is not recom- mended. If the variable name contains a dollar, the name itself is expanded first. This allows almost arbitrary variable names, however names con- taining dollar, braces, parentheses or whitespace are really best avoided. If the result of expanding a nested variable expression contains a dollar sign (`$'), the result is subject to further expansion. Variable substitution occurs at four distinct times, depending on where the variable is being used. 1. Variables in dependency lines are expanded as the line is read. 2. Variables in conditionals are expanded individually, but only as far as necessary to determine the result of the conditional. 3. Variables in shell commands are expanded when the shell command is executed. 4. .for loop index variables are expanded on each loop iteration. Note that other variables are not expanded when composing the body of a loop, so the following example code: .for i in 1 2 3 a+= ${i} j= ${i} b+= ${j} .endfor all: @echo ${a} @echo ${b} prints: 1 2 3 3 3 3 After the loop is executed: a contains `${:U1} ${:U2} ${:U3}', which expands to `1 2 3'. j contains `${:U3}', which expands to `3'. b contains `${j} ${j} ${j}', which expands to `${:U3} ${:U3} ${:U3}' and further to `3 3 3'. Variable classes The four different classes of variables (in order of increasing prece- dence) are: Environment variables Variables defined as part of bmake's environment. Global variables Variables defined in the makefile or in included makefiles. Command line variables Variables defined as part of the command line. Local variables Variables that are defined specific to a certain target. Local variables can be set on a dependency line, unless .MAKE.TARGET_LOCAL_VARIABLES is set to `false'. The rest of the line (which already has had global variables expanded) is the variable value. For example: COMPILER_WRAPPERS= ccache distcc icecc ${OBJS}: .MAKE.META.CMP_FILTER=${COMPILER_WRAPPERS:S,^,N,} Only the targets `${OBJS}' are impacted by that filter (in "meta" mode) and simply enabling/disabling any of the compiler wrappers does not ren- der all of those targets out-of-date. NOTE: target-local variable assignments behave differently in that; += Only appends to a previous local assignment for the same target and variable. := Is redundant with respect to global variables, which have already been expanded. The seven built-in local variables are: .ALLSRC The list of all sources for this target; also known as `>'. .ARCHIVE The name of the archive file; also known as `!'. .IMPSRC In suffix-transformation rules, the name/path of the source from which the target is to be transformed (the "implied" source); also known as `<'. It is not defined in explicit rules. .MEMBER The name of the archive member; also known as `%'. .OODATE The list of sources for this target that were deemed out- of-date; also known as `?'. - .PREFIX The file prefix of the target, containing only the file - portion, no suffix or preceding directory components; - also known as `*'. The suffix must be one of the known - suffixes declared with .SUFFIXES, or it is not recog- - nized. + .PREFIX The name of the target with suffix (if declared in + .SUFFIXES) removed; also known as `*'. .TARGET The name of the target; also known as `@'. For compati- bility with other makes this is an alias for .ARCHIVE in archive member rules. The shorter forms (`>', `!', `<', `%', `?', `*', and `@') are permitted for backward compatibility with historical makefiles and legacy POSIX make and are not recommended. Variants of these variables with the punctuation followed immediately by `D' or `F', e.g. `$(@D)', are legacy forms equivalent to using the `:H' and `:T' modifiers. These forms are accepted for compatibility with AT&T System V UNIX makefiles and POSIX but are not recommended. Four of the local variables may be used in sources on dependency lines because they expand to the proper value for each target on the line. These variables are `.TARGET', `.PREFIX', `.ARCHIVE', and `.MEMBER'. Additional built-in variables In addition, bmake sets or knows about the following variables: .ALLTARGETS The list of all targets encountered in the makefiles. If evalu- ated during makefile parsing, lists only those targets encoun- tered thus far. .CURDIR A path to the directory where bmake was executed. Refer to the description of `PWD' for more details. .ERROR_CMD Is used in error handling, see MAKE_PRINT_VAR_ON_ERROR. .ERROR_CWD Is used in error handling, see MAKE_PRINT_VAR_ON_ERROR. .ERROR_META_FILE Is used in error handling in "meta" mode, see MAKE_PRINT_VAR_ON_ERROR. .ERROR_TARGET Is used in error handling, see MAKE_PRINT_VAR_ON_ERROR. .INCLUDEDFROMDIR The directory of the file this makefile was included from. .INCLUDEDFROMFILE The filename of the file this makefile was included from. MACHINE The machine hardware name, see uname(1). MACHINE_ARCH The machine processor architecture name, see uname(1). MAKE The name that bmake was executed with (argv[0]). .MAKE The same as MAKE, for compatibility. The preferred variable to use is the environment variable MAKE because it is more compati- ble with other make variants and cannot be confused with the spe- cial target with the same name. .MAKE.DEPENDFILE Names the makefile (default `.depend') from which generated de- pendencies are read. .MAKE.DIE_QUIETLY If set to `true', do not print error information at the end. .MAKE.EXPAND_VARIABLES A boolean that controls the default behavior of the -V option. If true, variable values printed with -V are fully expanded; if false, the raw variable contents (which may include additional unexpanded variable references) are shown. .MAKE.EXPORTED The list of variables exported by bmake. MAKEFILE The top-level makefile that is currently read, as given in the command line. .MAKEFLAGS The environment variable `MAKEFLAGS' may contain anything that may be specified on bmake's command line. Anything specified on bmake's command line is appended to the .MAKEFLAGS variable, which is then added to the environment for all programs that bmake executes. .MAKE.GID The numeric group ID of the user running bmake. It is read-only. .MAKE.JOB.PREFIX If bmake is run with -j, the output for each target is prefixed with a token --- target --- the first part of which can be controlled via .MAKE.JOB.PREFIX. If .MAKE.JOB.PREFIX is empty, no token is printed. For example, setting .MAKE.JOB.PREFIX to `${.newline}---${.MAKE:T}[${.MAKE.PID}]' would produce tokens like ---make[1234] target --- making it easier to track the degree of parallelism being achieved. .MAKE.JOBS The argument to the -j option. .MAKE.LEVEL The recursion depth of bmake. The top-level instance of bmake has level 0, and each child make has its parent level plus 1. This allows tests like: .if ${.MAKE.LEVEL} == 0 to protect things which should only be evaluated in the top-level instance of bmake. .MAKE.LEVEL.ENV The name of the environment variable that stores the level of nested calls to bmake. .MAKE.MAKEFILE_PREFERENCE The ordered list of makefile names (default `makefile', `Makefile') that bmake looks for. .MAKE.MAKEFILES The list of makefiles read by bmake, which is useful for tracking dependencies. Each makefile is recorded only once, regardless of the number of times read. .MAKE.META.BAILIWICK In "meta" mode, provides a list of prefixes which match the di- rectories controlled by bmake. If a file that was generated out- side of .OBJDIR but within said bailiwick is missing, the current target is considered out-of-date. .MAKE.META.CMP_FILTER In "meta" mode, it can (very rarely!) be useful to filter command lines before comparison. This variable can be set to a set of modifiers that are applied to each line of the old and new com- mand that differ, if the filtered commands still differ, the tar- get is considered out-of-date. .MAKE.META.CREATED In "meta" mode, this variable contains a list of all the meta files updated. If not empty, it can be used to trigger process- ing of .MAKE.META.FILES. .MAKE.META.FILES In "meta" mode, this variable contains a list of all the meta files used (updated or not). This list can be used to process the meta files to extract dependency information. .MAKE.META.IGNORE_FILTER Provides a list of variable modifiers to apply to each pathname. Ignore if the expansion is an empty string. .MAKE.META.IGNORE_PATHS Provides a list of path prefixes that should be ignored; because the contents are expected to change over time. The default list includes: `/dev /etc /proc /tmp /var/run /var/tmp' .MAKE.META.IGNORE_PATTERNS Provides a list of patterns to match against pathnames. Ignore any that match. .MAKE.META.PREFIX Defines the message printed for each meta file updated in "meta verbose" mode. The default value is: Building ${.TARGET:H:tA}/${.TARGET:T} .MAKE.MODE Processed after reading all makefiles. Affects the mode that bmake runs in. It can contain these keywords: compat Like -B, puts bmake into "compat" mode. meta Puts bmake into "meta" mode, where meta files are created for each target to capture the command run, the output generated, and if filemon(4) is available, the system calls which are of interest to bmake. The captured out- put can be useful when diagnosing errors. curdirOk=bf By default, bmake does not create .meta files in `.CURDIR'. This can be overridden by setting bf to a value which represents true. missing-meta=bf If bf is true, a missing .meta file makes the target out- of-date. missing-filemon=bf If bf is true, missing filemon data makes the target out- of-date. nofilemon Do not use filemon(4). env For debugging, it can be useful to include the environ- ment in the .meta file. verbose If in "meta" mode, print a clue about the target being built. This is useful if the build is otherwise running silently. The message printed is the expanded value of .MAKE.META.PREFIX. ignore-cmd Some makefiles have commands which are simply not stable. This keyword causes them to be ignored for determining whether a target is out of date in "meta" mode. See also .NOMETA_CMP. silent=bf If bf is true, when a .meta file is created, mark the target .SILENT. randomize-targets In both compat and parallel mode, do not make the targets in the usual order, but instead randomize their order. This mode can be used to detect undeclared dependencies between files. MAKEOBJDIR Used to create files in a separate directory, see .OBJDIR. MAKE_OBJDIR_CHECK_WRITABLE Used to force a separate directory for the created files, even if that directory is not writable, see .OBJDIR. MAKEOBJDIRPREFIX Used to create files in a separate directory, see .OBJDIR. .MAKE.OS The name of the operating system, see uname(1). It is read-only. .MAKEOVERRIDES This variable is used to record the names of variables assigned to on the command line, so that they may be exported as part of `MAKEFLAGS'. This behavior can be disabled by assigning an empty value to `.MAKEOVERRIDES' within a makefile. Extra variables can be exported from a makefile by appending their names to `.MAKEOVERRIDES'. `MAKEFLAGS' is re-exported whenever `.MAKEOVERRIDES' is modified. .MAKE.PATH_FILEMON If bmake was built with filemon(4) support, this is set to the path of the device node. This allows makefiles to test for this support. .MAKE.PID The process ID of bmake. It is read-only. .MAKE.PPID The parent process ID of bmake. It is read-only. MAKE_PRINT_VAR_ON_ERROR When bmake stops due to an error, it sets `.ERROR_TARGET' to the name of the target that failed, `.ERROR_CMD' to the commands of the failed target, and in "meta" mode, it also sets `.ERROR_CWD' to the getcwd(3), and `.ERROR_META_FILE' to the path of the meta file (if any) describing the failed target. It then prints its name and the value of `.CURDIR' as well as the value of any vari- ables named in `MAKE_PRINT_VAR_ON_ERROR'. .MAKE.SAVE_DOLLARS If true, `$$' are preserved when doing `:=' assignments. The de- fault is false, for backwards compatibility. Set to true for compatability with other makes. If set to false, `$$' becomes `$' per normal evaluation rules. .MAKE.TARGET_LOCAL_VARIABLES If set to `false', apparent variable assignments in dependency lines are treated as normal sources. .MAKE.UID The numeric ID of the user running bmake. It is read-only. .newline This variable is simply assigned a newline character as its value. It is read-only. This allows expansions using the :@ modifier to put a newline between iterations of the loop rather than a space. For example, in case of an error, bmake prints the variable names and their values using: ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@} .OBJDIR A path to the directory where the targets are built. Its value is determined by trying to chdir(2) to the following directories in order and using the first match: 1. ${MAKEOBJDIRPREFIX}${.CURDIR} (Only if `MAKEOBJDIRPREFIX' is set in the environment or on the command line.) 2. ${MAKEOBJDIR} (Only if `MAKEOBJDIR' is set in the environment or on the command line.) 3. ${.CURDIR}/obj.${MACHINE} 4. ${.CURDIR}/obj 5. /usr/obj/${.CURDIR} 6. ${.CURDIR} Variable expansion is performed on the value before it is used, so expressions such as ${.CURDIR:S,^/usr/src,/var/obj,} may be used. This is especially useful with `MAKEOBJDIR'. `.OBJDIR' may be modified in the makefile via the special target `.OBJDIR'. In all cases, bmake changes to the specified direc- tory if it exists, and sets `.OBJDIR' and `PWD' to that directory before executing any targets. Except in the case of an explicit `.OBJDIR' target, bmake checks that the specified directory is writable and ignores it if not. This check can be skipped by setting the environment variable `MAKE_OBJDIR_CHECK_WRITABLE' to "no". .PARSEDIR The directory name of the current makefile being parsed. .PARSEFILE The basename of the current makefile being parsed. This variable and `.PARSEDIR' are both set only while the makefiles are being parsed. To retain their current values, assign them to a vari- able using assignment with expansion `:='. .PATH The space-separated list of directories that bmake searches for files. To update this search list, use the special target `.PATH' rather than modifying the variable directly. %POSIX Is set in POSIX mode, see the special `.POSIX' target. PWD Alternate path to the current directory. bmake normally sets `.CURDIR' to the canonical path given by getcwd(3). However, if the environment variable `PWD' is set and gives a path to the current directory, bmake sets `.CURDIR' to the value of `PWD' in- stead. This behavior is disabled if `MAKEOBJDIRPREFIX' is set or `MAKEOBJDIR' contains a variable transform. `PWD' is set to the value of `.OBJDIR' for all programs which bmake executes. .SHELL The pathname of the shell used to run target scripts. It is read-only. .SUFFIXES The list of known suffixes. It is read-only. .SYSPATH The space-separated list of directories that bmake searches for makefiles, referred to as the system include path. To update this search list, use the special target `.SYSPATH' rather than modifying the variable which is read-only. .TARGETS The list of targets explicitly specified on the command line, if any. VPATH The colon-separated (":") list of directories that bmake searches for files. This variable is supported for compatibility with old make programs only, use `.PATH' instead. Variable modifiers The general format of a variable expansion is: ${variable[:modifier[:...]]} Each modifier begins with a colon. To escape a colon, precede it with a backslash `\'. A list of indirect modifiers can be specified via a variable, as follows: modifier_variable = modifier[:...] ${variable:${modifier_variable}[:...]} In this case, the first modifier in the modifier_variable does not start with a colon, since that colon already occurs in the referencing vari- able. If any of the modifiers in the modifier_variable contains a dollar sign (`$'), these must be doubled to avoid early expansion. Some modifiers interpret the expression value as a single string, others treat the expression value as a whitespace-separated list of words. When splitting a string into words, whitespace can be escaped using double quotes, single quotes and backslashes, like in the shell. The quotes and backslashes are retained in the words. The supported modifiers are: :E Replaces each word with its suffix. :H Replaces each word with its dirname. :Mpattern Selects only those words that match pattern. The standard shell wildcard characters (`*', `?', and `[]') may be used. The wildcard characters may be escaped with a backslash (`\'). As a consequence of the way values are split into words, matched, and then joined, the construct `${VAR:M*}' removes all leading and trailing white- space and normalizes the inter-word spacing to a single space. :Npattern This is the opposite of `:M', selecting all words which do not match pattern. :O Orders the words lexicographically. :On Orders the words numerically. A number followed by one of `k', `M' or `G' is multiplied by the appropriate factor, which is 1024 for `k', 1048576 for `M', or 1073741824 for `G'. Both upper- and lower- case letters are accepted. :Or Orders the words in reverse lexicographical order. :Orn Orders the words in reverse numerical order. :Ox Shuffles the words. The results are different each time you are re- ferring to the modified variable; use the assignment with expansion `:=' to prevent such behavior. For example, LIST= uno due tre quattro RANDOM_LIST= ${LIST:Ox} STATIC_RANDOM_LIST:= ${LIST:Ox} all: @echo "${RANDOM_LIST}" @echo "${RANDOM_LIST}" @echo "${STATIC_RANDOM_LIST}" @echo "${STATIC_RANDOM_LIST}" may produce output similar to: quattro due tre uno tre due quattro uno due uno quattro tre due uno quattro tre :Q Quotes every shell meta-character in the value, so that it can be passed safely to the shell. :q Quotes every shell meta-character in the value, and also doubles `$' characters so that it can be passed safely through recursive invoca- tions of bmake. This is equivalent to `:S/\$/&&/g:Q'. :R Replaces each word with everything but its suffix. :range[=count] The value is an integer sequence representing the words of the orig- inal value, or the supplied count. :gmtime[=timestamp] The value is interpreted as a format string for strftime(3), using gmtime(3), producing the formatted timestamp. If a timestamp value is not provided or is 0, the current time is used. :hash Computes a 32-bit hash of the value and encodes it as 8 hex digits. :localtime[=timestamp] The value is interpreted as a format string for strftime(3), using localtime(3), producing the formatted timestamp. If a timestamp value is not provided or is 0, the current time is used. + :mtime[=timestamp] + Call stat(2) with each word as pathname; use `st_mtime' as the new + value. If stat(2) fails; use timestamp or current time. If + timestamp is set to `error', then stat(2) failure will cause an er- + ror. + :tA Attempts to convert the value to an absolute path using realpath(3). If that fails, the value is unchanged. :tl Converts the value to lower-case letters. :tsc When joining the words after a modifier that treats the value as words, the words are normally separated by a space. This modifier changes the separator to the character c. If c is omitted, no sepa- rator is used. The common escapes (including octal numeric codes) work as expected. :tu Converts the value to upper-case letters. :tW Causes subsequent modifiers to treat the value as a single word (possibly containing embedded whitespace). See also `:[*]'. :tw Causes the value to be treated as a list of words. See also `:[@]'. :S/old_string/new_string/[1gW] Modifies the first occurrence of old_string in each word of the value, replacing it with new_string. If a `g' is appended to the last delimiter of the pattern, all occurrences in each word are re- placed. If a `1' is appended to the last delimiter of the pattern, only the first occurrence is affected. If a `W' is appended to the last delimiter of the pattern, the value is treated as a single word. If old_string begins with a caret (`^'), old_string is an- chored at the beginning of each word. If old_string ends with a dollar sign (`$'), it is anchored at the end of each word. Inside new_string, an ampersand (`&') is replaced by old_string (without the anchoring `^' or `$'). Any character may be used as the delim- iter for the parts of the modifier string. The anchoring, ampersand and delimiter characters can be escaped with a backslash (`\'). Both old_string and new_string may contain nested expressions. To prevent a dollar sign from starting a nested expression, escape it with a backslash. :C/pattern/replacement/[1gW] The :C modifier works like the :S modifier except that the old and new strings, instead of being simple strings, are an extended regu- lar expression pattern (see regex(3)) and an ed(1)-style replacement. Normally, the first occurrence of the pattern pattern in each word of the value is substituted with replacement. The `1' modifier causes the substitution to apply to at most one word; the `g' modifier causes the substitution to apply to as many instances of the search pattern pattern as occur in the word or words it is found in; the `W' modifier causes the value to be treated as a sin- gle word (possibly containing embedded whitespace). As for the :S modifier, the pattern and replacement are subjected to variable expansion before being parsed as regular expressions. :T Replaces each word with its last path component (basename). :u Removes adjacent duplicate words (like uniq(1)). :?true_string:false_string If the variable name (not its value), when parsed as a .if condi- tional expression, evaluates to true, return as its value the true_string, otherwise return the false_string. Since the variable name is used as the expression, :? must be the first modifier after the variable name itself--which, of course, usually contains vari- able expansions. A common error is trying to use expressions like ${NUMBERS:M42:?match:no} which actually tests defined(NUMBERS). To determine if any words match "42", you need to use something like: ${"${NUMBERS:M42}" != "":?match:no}. :old_string=new_string This is the AT&T System V UNIX style substitution. It can only be the last modifier specified, as a `:' in either old_string or new_string is treated as a regular character, not as the end of the modifier. If old_string does not contain the pattern matching character `%', and the word ends with old_string or equals it, that suffix is re- placed with new_string. Otherwise, the first `%' in old_string matches a possibly empty sub- string of arbitrary characters, and if the whole pattern is found in the word, the matching part is replaced with new_string, and the first occurrence of `%' in new_string (if any) is replaced with the substring matched by the `%'. Both old_string and new_string may contain nested expressions. To prevent a dollar sign from starting a nested expression, escape it with a backslash. :@varname@string@ This is the loop expansion mechanism from the OSF Development Envi- ronment (ODE) make. Unlike .for loops, expansion occurs at the time of reference. For each word in the value, assign the word to the variable named varname and evaluate string. The ODE convention is that varname should start and end with a period, for example: ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@} However, a single-letter variable is often more readable: ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@} :_[=var] Saves the current variable value in `$_' or the named var for later reference. Example usage: M_cmpv.units = 1 1000 1000000 M_cmpv = S,., ,g:_:range:@i@+ $${_:[-$$i]} \ \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh .if ${VERSION:${M_cmpv}} < ${3.1.12:L:${M_cmpv}} Here `$_' is used to save the result of the `:S' modifier which is later referenced using the index values from `:range'. :Unewval If the variable is undefined, newval is the value. If the variable is defined, the existing value is returned. This is another ODE make feature. It is handy for setting per-target CFLAGS for in- stance: ${_${.TARGET:T}_CFLAGS:U${DEF_CFLAGS}} If a value is only required if the variable is undefined, use: ${VAR:D:Unewval} :Dnewval If the variable is defined, newval is the value. :L The name of the variable is the value. :P The path of the node which has the same name as the variable is the value. If no such node exists or its path is null, the name of the variable is used. In order for this modifier to work, the name (node) must at least have appeared on the right-hand side of a de- pendency. :!cmd! The output of running cmd is the value. :sh The value is run as a command, and the output becomes the new value. ::=str The variable is assigned the value str after substitution. This modifier and its variations are useful in obscure situations such as wanting to set a variable at a point where a target's shell commands are being parsed. These assignment modifiers always expand to noth- ing. The `::' helps avoid false matches with the AT&T System V UNIX style `:=' modifier and since substitution always occurs, the `::=' form is vaguely appropriate. ::?=str As for ::= but only if the variable does not already have a value. ::+=str Append str to the variable. ::!=cmd Assign the output of cmd to the variable. :[range] Selects one or more words from the value, or performs other opera- tions related to the way in which the value is split into words. An empty value, or a value that consists entirely of white-space, is treated as a single word. For the purposes of the `:[]' modifier, the words are indexed both forwards using positive integers (where index 1 represents the first word), and backwards using negative in- tegers (where index -1 represents the last word). The range is subjected to variable expansion, and the expanded re- sult is then interpreted as follows: index Selects a single word from the value. start..end Selects all words from start to end, inclusive. For example, `:[2..-1]' selects all words from the second word to the last word. If start is greater than end, the words are output in reverse order. For example, `:[-1..1]' selects all the words from last to first. If the list is already ordered, this ef- fectively reverses the list, but it is more efficient to use `:Or' instead of `:O:[-1..1]'. * Causes subsequent modifiers to treat the value as a single word (possibly containing embedded whitespace). Analogous to the effect of $* in Bourne shell. 0 Means the same as `:[*]'. @ Causes subsequent modifiers to treat the value as a sequence of words delimited by whitespace. Analogous to the effect of $@ in Bourne shell. # Returns the number of words in the value. DIRECTIVES bmake offers directives for including makefiles, conditionals and for loops. All these directives are identified by a line beginning with a single dot (`.') character, followed by the keyword of the directive, such as include or if. File inclusion Files are included with either .include <file> or .include "file". Vari- ables between the angle brackets or double quotes are expanded to form the file name. If angle brackets are used, the included makefile is ex- pected to be in the system makefile directory. If double quotes are used, the including makefile's directory and any directories specified using the -I option are searched before the system makefile directory. For compatibility with other make variants, `include file ...' (without leading dot) is also accepted. If the include statement is written as .-include or as .sinclude, errors locating and/or opening include files are ignored. If the include statement is written as .dinclude, not only are errors lo- cating and/or opening include files ignored, but stale dependencies within the included file are ignored just like in .MAKE.DEPENDFILE. Exporting variables The directives for exporting and unexporting variables are: .export variable ... Export the specified global variable. If no variable list is provided, all globals are exported except for internal variables (those that start with `.'). This is not affected by the -X flag, so should be used with caution. For compatibility with other make programs, export variable=value (without leading dot) is also accepted. Appending a variable name to .MAKE.EXPORTED is equivalent to ex- porting a variable. .export-env variable ... The same as `.export', except that the variable is not appended to .MAKE.EXPORTED. This allows exporting a value to the environ- ment which is different from that used by bmake internally. .export-literal variable ... The same as `.export-env', except that variables in the value are not expanded. .unexport variable ... The opposite of `.export'. The specified global variable is re- moved from .MAKE.EXPORTED. If no variable list is provided, all globals are unexported, and .MAKE.EXPORTED deleted. .unexport-env Unexport all globals previously exported and clear the environ- ment inherited from the parent. This operation causes a memory leak of the original environment, so should be used sparingly. Testing for .MAKE.LEVEL being 0 would make sense. Also note that any variables which originated in the parent environment should be explicitly preserved if desired. For example: .if ${.MAKE.LEVEL} == 0 PATH := ${PATH} .unexport-env .export PATH .endif Would result in an environment containing only `PATH', which is the minimal useful environment. Actually `.MAKE.LEVEL' is also pushed into the new environment. Messages The directives for printing messages to the output are: .info message The message is printed along with the name of the makefile and line number. .warning message The message prefixed by `warning:' is printed along with the name of the makefile and line number. .error message The message is printed along with the name of the makefile and line number, bmake exits immediately. Conditionals The directives for conditionals are: .if [!]expression [operator expression ...] Test the value of an expression. .ifdef [!]variable [operator variable ...] Test whether a variable is defined. .ifndef [!]variable [operator variable ...] Test whether a variable is not defined. .ifmake [!]target [operator target ...] Test the target being requested. .ifnmake [!]target [operator target ...] Test the target being requested. .else Reverse the sense of the last conditional. .elif [!]expression [operator expression ...] A combination of `.else' followed by `.if'. .elifdef [!]variable [operator variable ...] A combination of `.else' followed by `.ifdef'. .elifndef [!]variable [operator variable ...] A combination of `.else' followed by `.ifndef'. .elifmake [!]target [operator target ...] A combination of `.else' followed by `.ifmake'. .elifnmake [!]target [operator target ...] A combination of `.else' followed by `.ifnmake'. .endif End the body of the conditional. The operator may be any one of the following: || Logical OR. && Logical AND; of higher precedence than `||'. bmake only evaluates a conditional as far as is necessary to determine its value. Parentheses can be used to override the operator precedence. The boolean operator `!' may be used to logically negate an entire condi- tional. It is of higher precedence than `&&'. The value of expression may be any of the following function call expres- sions: defined(varname) Evaluates to true if the variable varname has been defined. make(target) Evaluates to true if the target was specified as part of bmake's command line or was declared the default target (either implic- itly or explicitly, see .MAIN) before the line containing the conditional. empty(varname[:modifiers]) Evaluates to true if the expansion of the variable, after apply- ing the modifiers, results in an empty string. exists(pathname) Evaluates to true if the given pathname exists. If relative, the pathname is searched for on the system search path (see .PATH). target(target) Evaluates to true if the target has been defined. commands(target) Evaluates to true if the target has been defined and has commands associated with it. Expression may also be an arithmetic or string comparison. Variable ex- pansion is performed on both sides of the comparison. If both sides are numeric and neither is enclosed in quotes, the comparison is done numeri- cally, otherwise lexicographically. A string is interpreted as hexadeci- mal integer if it is preceded by 0x, otherwise it is a decimal floating- point number; octal numbers are not supported. All comparisons may use the operators `==' and `!='. Numeric comparisons may also use the operators `<', `<=', `>' and `>='. If the comparison has neither a comparison operator nor a right side, the expression evaluates to true if it is nonempty and its numeric value (if any) is not zero. When bmake is evaluating one of these conditional expressions, and it en- counters a (whitespace separated) word it doesn't recognize, either the "make" or "defined" function is applied to it, depending on the form of the conditional. If the form is `.ifdef', `.ifndef' or `.if', the "defined" function is applied. Similarly, if the form is `.ifmake' or `.ifnmake', the "make" function is applied. If the conditional evaluates to true, parsing of the makefile continues as before. If it evaluates to false, the following lines are skipped. In both cases, this continues until the corresponding `.else' or `.endif' is found. For loops For loops are typically used to apply a set of rules to a list of files. The syntax of a for loop is: .for variable [variable ...] in expression <make-lines> .endfor The expression is expanded and then split into words. On each iteration of the loop, one word is taken and assigned to each variable, in order, and these variables are substituted into the make-lines inside the body of the for loop. The number of words must come out even; that is, if there are three iteration variables, the number of words provided must be a multiple of three. If `.break' is encountered within a .for loop, it causes early termina- tion of the loop, otherwise a parse error. Other directives .undef variable ... Un-define the specified global variables. Only global variables can be un-defined. COMMENTS Comments begin with a hash (`#') character, anywhere but in a shell com- mand line, and continue to the end of an unescaped new line. SPECIAL SOURCES (ATTRIBUTES) .EXEC Target is never out of date, but always execute commands any- way. .IGNORE Ignore any errors from the commands associated with this tar- get, exactly as if they all were preceded by a dash (`-'). .MADE Mark all sources of this target as being up to date. .MAKE Execute the commands associated with this target even if the -n or -t options were specified. Normally used to mark recursive bmakes. .META Create a meta file for the target, even if it is flagged as .PHONY, .MAKE, or .SPECIAL. Usage in conjunction with .MAKE is the most likely case. In "meta" mode, the target is out-of- date if the meta file is missing. .NOMETA Do not create a meta file for the target. Meta files are also not created for .PHONY, .MAKE, or .SPECIAL targets. .NOMETA_CMP Ignore differences in commands when deciding if target is out of date. This is useful if the command contains a value which always changes. If the number of commands change, though, the target is still considered out of date. The same effect ap- plies to any command line that uses the variable .OODATE, which can be used for that purpose even when not otherwise needed or desired: skip-compare-for-some: @echo this is compared @echo this is not ${.OODATE:M.NOMETA_CMP} @echo this is also compared The :M pattern suppresses any expansion of the unwanted vari- able. .NOPATH Do not search for the target in the directories specified by .PATH. .NOTMAIN Normally bmake selects the first target it encounters as the default target to be built if no target was specified. This source prevents this target from being selected. .OPTIONAL If a target is marked with this attribute and bmake can't fig- ure out how to create it, it ignores this fact and assumes the file isn't needed or already exists. .PHONY The target does not correspond to an actual file; it is always considered to be out of date, and is not created with the -t option. Suffix-transformation rules are not applied to .PHONY targets. .PRECIOUS When bmake is interrupted, it normally removes any partially made targets. This source prevents the target from being re- moved. .RECURSIVE Synonym for .MAKE. .SILENT Do not echo any of the commands associated with this target, exactly as if they all were preceded by an at sign (`@'). .USE Turn the target into bmake's version of a macro. When the tar- get is used as a source for another target, the other target acquires the commands, sources, and attributes (except for .USE) of the source. If the target already has commands, the .USE target's commands are appended to them. .USEBEFORE Like .USE, but instead of appending, prepend the .USEBEFORE target commands to the target. .WAIT If .WAIT appears in a dependency line, the sources that precede it are made before the sources that succeed it in the line. Since the dependents of files are not made until the file it- self could be made, this also stops the dependents being built unless they are needed for another branch of the dependency tree. So given: x: a .WAIT b echo x a: echo a b: b1 echo b b1: echo b1 the output is always `a', `b1', `b', `x'. The ordering imposed by .WAIT is only relevant for parallel makes. SPECIAL TARGETS Special targets may not be included with other targets, i.e. they must be the only target specified. .BEGIN Any command lines attached to this target are executed before anything else is done. .DEFAULT This is sort of a .USE rule for any target (that was used only as a source) that bmake can't figure out any other way to cre- ate. Only the shell script is used. The .IMPSRC variable of a target that inherits .DEFAULT's commands is set to the target's own name. .DELETE_ON_ERROR If this target is present in the makefile, it globally causes make to delete targets whose commands fail. (By default, only targets whose commands are interrupted during execution are deleted. This is the historical behavior.) This setting can be used to help prevent half-finished or malformed targets from be- ing left around and corrupting future rebuilds. .END Any command lines attached to this target are executed after ev- erything else is done successfully. .ERROR Any command lines attached to this target are executed when an- other target fails. The .ERROR_TARGET variable is set to the target that failed. See also MAKE_PRINT_VAR_ON_ERROR. .IGNORE Mark each of the sources with the .IGNORE attribute. If no sources are specified, this is the equivalent of specifying the -i option. .INTERRUPT If bmake is interrupted, the commands for this target are exe- cuted. .MAIN If no target is specified when bmake is invoked, this target is built. .MAKEFLAGS This target provides a way to specify flags for bmake at the time when the makefiles are read. The flags are as if typed to the shell, though the -f option has no effect. .NOPATH Apply the .NOPATH attribute to any specified sources. .NOTPARALLEL Disable parallel mode. .NO_PARALLEL Synonym for .NOTPARALLEL, for compatibility with other pmake variants. .NOREADONLY clear the read-only attribute from the global variables speci- fied as sources. .OBJDIR The source is a new value for `.OBJDIR'. If it exists, bmake changes the current working directory to it and updates the value of `.OBJDIR'. .ORDER In parallel mode, the named targets are made in sequence. This ordering does not add targets to the list of targets to be made. Since the dependents of a target do not get built until the tar- get itself could be built, unless `a' is built by another part of the dependency graph, the following is a dependency loop: .ORDER: b a b: a .PATH The sources are directories which are to be searched for files not found in the current directory. If no sources are speci- fied, any previously specified directories are removed from the search path. If the source is the special .DOTLAST target, the current working directory is searched last. .PATH.suffix Like .PATH but applies only to files with a particular suffix. The suffix must have been previously declared with .SUFFIXES. .PHONY Apply the .PHONY attribute to any specified sources. .POSIX If this is the first non-comment line in the main makefile, the variable %POSIX is set to the value `1003.2' and the makefile `' is included if it exists, to provide POSIX-compati- ble default rules. If bmake is run with the -r flag, only `posix.mk' contributes to the default rules. .PRECIOUS Apply the .PRECIOUS attribute to any specified sources. If no sources are specified, the .PRECIOUS attribute is applied to ev- ery target in the file. .READONLY set the read-only attribute on the global variables specified as sources. .SHELL Sets the shell that bmake uses to execute commands in jobs mode. The sources are a set of field=value pairs. name This is the minimal specification, used to select one of the built-in shell specs; sh, ksh, and csh. path Specifies the absolute path to the shell. hasErrCtl Indicates whether the shell supports exit on error. check The command to turn on error checking. ignore The command to disable error checking. echo The command to turn on echoing of commands executed. quiet The command to turn off echoing of commands exe- cuted. filter The output to filter after issuing the quiet com- mand. It is typically identical to quiet. errFlag The flag to pass the shell to enable error checking. echoFlag The flag to pass the shell to enable command echo- ing. newline The string literal to pass the shell that results in a single newline character when used outside of any quoting characters. Example: .SHELL: name=ksh path=/bin/ksh hasErrCtl=true \ check="set -e" ignore="set +e" \ echo="set -v" quiet="set +v" filter="set +v" \ echoFlag=v errFlag=e newline="'\n'" .SILENT Apply the .SILENT attribute to any specified sources. If no sources are specified, the .SILENT attribute is applied to every command in the file. .STALE This target gets run when a dependency file contains stale en- tries, having .ALLSRC set to the name of that dependency file. .SUFFIXES Each source specifies a suffix to bmake. If no sources are specified, any previously specified suffixes are deleted. It allows the creation of suffix-transformation rules. Example: .SUFFIXES: .c .o .c.o: cc -o ${.TARGET} -c ${.IMPSRC} .SYSPATH The sources are directories which are to be added to the system include path which bmake searches for makefiles. If no sources are specified, any previously specified directories are removed from the system include path. ENVIRONMENT bmake uses the following environment variables, if they exist: MACHINE, MACHINE_ARCH, MAKE, MAKEFLAGS, MAKEOBJDIR, MAKEOBJDIRPREFIX, MAKESYSPATH, PWD, and TMPDIR. MAKEOBJDIRPREFIX and MAKEOBJDIR may only be set in the environment or on the command line to bmake and not as makefile variables; see the descrip- tion of `.OBJDIR' for more details. FILES .depend list of dependencies makefile first default makefile if no makefile is specified on the command line Makefile second default makefile if no makefile is specified on the command line sys.mk system makefile /usr/share/mk system makefile directory COMPATIBILITY The basic make syntax is compatible between different make variants; how- ever the special variables, variable modifiers and conditionals are not. Older versions An incomplete list of changes in older versions of bmake: The way that .for loop variables are substituted changed after NetBSD 5.0 so that they still appear to be variable expansions. In particular this stops them being treated as syntax, and removes some obscure problems us- ing them in .if statements. The way that parallel makes are scheduled changed in NetBSD 4.0 so that .ORDER and .WAIT apply recursively to the dependent nodes. The algo- rithms used may change again in the future. Other make dialects Other make dialects (GNU make, SVR4 make, POSIX make, etc.) do not sup- port most of the features of bmake as described in this manual. Most no- tably: +o The .WAIT and .ORDER declarations and most functionality per- taining to parallelization. (GNU make supports parallelization but lacks the features needed to control it effectively.) +o Directives, including for loops and conditionals and most of the forms of include files. (GNU make has its own incompatible and less powerful syntax for conditionals.) +o All built-in variables that begin with a dot. +o Most of the special sources and targets that begin with a dot, with the notable exception of .PHONY, .PRECIOUS, and .SUFFIXES. +o Variable modifiers, except for the `:old=new' string substitu- tion, which does not portably support globbing with `%' and historically only works on declared suffixes. +o The $> variable even in its short form; most makes support this functionality but its name varies. Some features are somewhat more portable, such as assignment with +=, ?=, and !=. The .PATH functionality is based on an older feature VPATH found in GNU make and many versions of SVR4 make; however, historically its be- havior is too ill-defined (and too buggy) to rely upon. The $@ and $< variables are more or less universally portable, as is the $(MAKE) variable. Basic use of suffix rules (for files only in the cur- rent directory, not trying to chain transformations together, etc.) is also reasonably portable. SEE ALSO mkdep(1) HISTORY bmake is derived from NetBSD make(1). It uses autoconf to facilitate portability to other platforms. A make command appeared in Version 7 AT&T UNIX. This make implementation is based on Adam de Boor's pmake program, which was written for Sprite at Berkeley. It was designed to be a parallel distributed make running jobs on different machines using a daemon called "customs". Historically the target/dependency FRC has been used to FoRCe rebuilding (since the target/dependency does not exist ... unless someone creates an FRC file). BUGS The make syntax is difficult to parse. For instance, finding the end of a variable's use should involve scanning each of the modifiers, using the correct terminator for each field. In many places make just counts {} and () in order to find the end of a variable expansion. There is no way of escaping a space character in a filename. In jobs mode, when a target fails; make will put an error token into the job token pool. This will cause all other instances of make using that token pool to abort the build and exit with error code 6. Sometimes the attempt to suppress a cascade of unnecessary errors, can result in a seemingly unexplained `*** Error code 6' - - -FreeBSD 13.0 March 22, 2023 FreeBSD 13.0 +FreeBSD 13.0 May 10, 2023 FreeBSD 13.0 diff --git a/compat.c b/compat.c index 521c3a364028..221eb64959e6 100644 --- a/compat.c +++ b/compat.c @@ -1,800 +1,800 @@ -/* $NetBSD: compat.c,v 1.246 2023/03/18 22:20:11 sjg Exp $ */ +/* $NetBSD: compat.c,v 1.247 2023/05/04 22:31:17 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. * All rights reserved. * * This code is derived from software contributed to Berkeley by * Adam de Boor. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * Copyright (c) 1988, 1989 by Adam de Boor * Copyright (c) 1989 by Berkeley Softworks * All rights reserved. * * This code is derived from software contributed to Berkeley by * Adam de Boor. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * This file implements the full-compatibility mode of make, which makes the * targets without parallelism and without a custom shell. * * Interface: * Compat_MakeAll Initialize this module and make the given targets. */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include #include "wait.h" #include #include #include "make.h" #include "dir.h" #include "job.h" #include "metachar.h" #include "pathnames.h" /* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: compat.c,v 1.246 2023/03/18 22:20:11 sjg Exp $"); +MAKE_RCSID("$NetBSD: compat.c,v 1.247 2023/05/04 22:31:17 sjg Exp $"); static GNode *curTarg = NULL; static pid_t compatChild; static int compatSigno; /* * Delete the file of a failed, interrupted, or otherwise duffed target, * unless inhibited by .PRECIOUS. */ static void CompatDeleteTarget(GNode *gn) { if (gn != NULL && !GNode_IsPrecious(gn) && (gn->type & OP_PHONY) == 0) { const char *file = GNode_VarTarget(gn); if (!opts.noExecute && unlink_file(file) == 0) { Error("*** %s removed", file); } } } /* * Interrupt the creation of the current target and remove it if it ain't * precious. Then exit. * * If .INTERRUPT exists, its commands are run first WITH INTERRUPTS IGNORED. * * XXX: is .PRECIOUS supposed to inhibit .INTERRUPT? I doubt it, but I've * left the logic alone for now. - dholland 20160826 */ static void CompatInterrupt(int signo) { CompatDeleteTarget(curTarg); if (curTarg != NULL && !GNode_IsPrecious(curTarg)) { /* * Run .INTERRUPT only if hit with interrupt signal */ if (signo == SIGINT) { GNode *gn = Targ_FindNode(".INTERRUPT"); if (gn != NULL) { Compat_Make(gn, gn); } } } if (signo == SIGQUIT) _exit(signo); /* * If there is a child running, pass the signal on. * We will exist after it has exited. */ compatSigno = signo; if (compatChild > 0) { KILLPG(compatChild, signo); } else { bmake_signal(signo, SIG_DFL); kill(myPid, signo); } } static void DebugFailedTarget(const char *cmd, const GNode *gn) { const char *p = cmd; debug_printf("\n*** Failed target: %s\n*** Failed command: ", gn->name); /* * Replace runs of whitespace with a single space, to reduce the * amount of whitespace for multi-line command lines. */ while (*p != '\0') { if (ch_isspace(*p)) { debug_printf(" "); cpp_skip_whitespace(&p); } else { debug_printf("%c", *p); p++; } } debug_printf("\n"); } static bool UseShell(const char *cmd MAKE_ATTR_UNUSED) { #if defined(FORCE_USE_SHELL) || !defined(MAKE_NATIVE) /* * In a non-native build, the host environment might be weird enough * that it's necessary to go through a shell to get the correct * behaviour. Or perhaps the shell has been replaced with something * that does extra logging, and that should not be bypassed. */ return true; #else /* * Search for meta characters in the command. If there are no meta * characters, there's no need to execute a shell to execute the * command. * * Additionally variable assignments and empty commands * go to the shell. Therefore treat '=' and ':' like shell * meta characters as documented in make(1). */ return needshell(cmd); #endif } /* * Execute the next command for a target. If the command returns an error, * the node's made field is set to ERROR and creation stops. * * Input: * cmdp Command to execute * gn Node from which the command came * ln List node that contains the command * * Results: * true if the command succeeded. */ bool Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln) { char *cmdStart; /* Start of expanded command */ - char *bp; + char *volatile bp; bool silent; /* Don't print command */ bool doIt; /* Execute even if -n */ volatile bool errCheck; /* Check errors */ WAIT_T reason; /* Reason for child's death */ WAIT_T status; /* Description of child's death */ pid_t cpid; /* Child actually found */ pid_t retstat; /* Result of wait */ const char **volatile av; /* Argument vector for thing to exec */ char **volatile mav; /* Copy of the argument vector for freeing */ bool useShell; /* True if command should be executed using a * shell */ const char *volatile cmd = cmdp; silent = (gn->type & OP_SILENT) != OP_NONE; errCheck = !(gn->type & OP_IGNORE); doIt = false; cmdStart = Var_Subst(cmd, gn, VARE_WANTRES); /* TODO: handle errors */ if (cmdStart[0] == '\0') { free(cmdStart); return true; } cmd = cmdStart; LstNode_Set(ln, cmdStart); if (gn->type & OP_SAVE_CMDS) { GNode *endNode = Targ_GetEndNode(); if (gn != endNode) { /* * Append the expanded command, to prevent the * local variables from being interpreted in the * scope of the .END node. * * A probably unintended side effect of this is that * the expanded command will be expanded again in the * .END node. Therefore, a literal '$' in these * commands must be written as '$$$$' instead of the * usual '$$'. */ Lst_Append(&endNode->commands, cmdStart); return true; } } if (strcmp(cmdStart, "...") == 0) { gn->type |= OP_SAVE_CMDS; return true; } for (;;) { if (*cmd == '@') silent = !DEBUG(LOUD); else if (*cmd == '-') errCheck = false; else if (*cmd == '+') { doIt = true; if (shellName == NULL) /* we came here from jobs */ Shell_Init(); } else if (!ch_isspace(*cmd)) /* Ignore whitespace for compatibility with gnu make */ break; cmd++; } while (ch_isspace(*cmd)) cmd++; /* * If we did not end up with a command, just skip it. */ if (cmd[0] == '\0') return true; useShell = UseShell(cmd); /* * Print the command before echoing if we're not supposed to be quiet * for this one. We also print the command if -n given. */ if (!silent || !GNode_ShouldExecute(gn)) { printf("%s\n", cmd); fflush(stdout); } /* * If we're not supposed to execute any commands, this is as far as * we go... */ if (!doIt && !GNode_ShouldExecute(gn)) return true; DEBUG1(JOB, "Execute: '%s'\n", cmd); if (useShell) { /* * We need to pass the command off to the shell, typically * because the command contains a "meta" character. */ static const char *shargv[5]; /* The following work for any of the builtin shell specs. */ int shargc = 0; shargv[shargc++] = shellPath; if (errCheck && shellErrFlag != NULL) shargv[shargc++] = shellErrFlag; shargv[shargc++] = DEBUG(SHELL) ? "-xc" : "-c"; shargv[shargc++] = cmd; shargv[shargc] = NULL; av = shargv; bp = NULL; mav = NULL; } else { /* * No meta-characters, so no need to exec a shell. Break the * command into words to form an argument vector we can * execute. */ Words words = Str_Words(cmd, false); mav = words.words; bp = words.freeIt; av = (void *)mav; } #ifdef USE_META if (useMeta) meta_compat_start(); #endif Var_ReexportVars(); compatChild = cpid = vfork(); if (cpid < 0) Fatal("Could not fork"); if (cpid == 0) { #ifdef USE_META if (useMeta) meta_compat_child(); #endif (void)execvp(av[0], (char *const *)UNCONST(av)); execDie("exec", av[0]); } free(mav); free(bp); /* XXX: Memory management looks suspicious here. */ /* XXX: Setting a list item to NULL is unexpected. */ LstNode_SetNull(ln); #ifdef USE_META if (useMeta) meta_compat_parent(cpid); #endif /* * The child is off and running. Now all we can do is wait... */ while ((retstat = wait(&reason)) != cpid) { if (retstat > 0) JobReapChild(retstat, reason, false); /* not ours? */ if (retstat == -1 && errno != EINTR) { break; } } if (retstat < 0) Fatal("error in wait: %d: %s", retstat, strerror(errno)); if (WIFSTOPPED(reason)) { status = WSTOPSIG(reason); /* stopped */ } else if (WIFEXITED(reason)) { status = WEXITSTATUS(reason); /* exited */ #if defined(USE_META) && defined(USE_FILEMON_ONCE) if (useMeta) meta_cmd_finish(NULL); #endif if (status != 0) { if (DEBUG(ERROR)) DebugFailedTarget(cmd, gn); printf("*** Error code %d", status); } } else { status = WTERMSIG(reason); /* signaled */ printf("*** Signal %d", status); } if (!WIFEXITED(reason) || status != 0) { if (errCheck) { #ifdef USE_META if (useMeta) meta_job_error(NULL, gn, false, status); #endif gn->made = ERROR; if (opts.keepgoing) { /* * Abort the current target, * but let others continue. */ printf(" (continuing)\n"); } else { printf("\n"); } if (deleteOnError) CompatDeleteTarget(gn); } else { /* * Continue executing commands for this target. * If we return 0, this will happen... */ printf(" (ignored)\n"); status = 0; } } free(cmdStart); compatChild = 0; if (compatSigno != 0) { bmake_signal(compatSigno, SIG_DFL); kill(myPid, compatSigno); } return status == 0; } static void RunCommands(GNode *gn) { StringListNode *ln; for (ln = gn->commands.first; ln != NULL; ln = ln->next) { const char *cmd = ln->datum; if (!Compat_RunCommand(cmd, gn, ln)) break; } } static void MakeInRandomOrder(GNode **gnodes, GNode **end, GNode *pgn) { GNode **it; size_t r; for (r = (size_t)(end - gnodes); r >= 2; r--) { /* Biased, but irrelevant in practice. */ size_t i = (size_t)random() % r; GNode *t = gnodes[r - 1]; gnodes[r - 1] = gnodes[i]; gnodes[i] = t; } for (it = gnodes; it != end; it++) Compat_Make(*it, pgn); } static void MakeWaitGroupsInRandomOrder(GNodeList *gnodes, GNode *pgn) { Vector vec; GNodeListNode *ln; GNode **nodes; size_t i, n, start; Vector_Init(&vec, sizeof(GNode *)); for (ln = gnodes->first; ln != NULL; ln = ln->next) *(GNode **)Vector_Push(&vec) = ln->datum; nodes = vec.items; n = vec.len; start = 0; for (i = 0; i < n; i++) { if (nodes[i]->type & OP_WAIT) { MakeInRandomOrder(nodes + start, nodes + i, pgn); Compat_Make(nodes[i], pgn); start = i + 1; } } MakeInRandomOrder(nodes + start, nodes + i, pgn); Vector_Done(&vec); } static void MakeNodes(GNodeList *gnodes, GNode *pgn) { GNodeListNode *ln; if (Lst_IsEmpty(gnodes)) return; if (opts.randomizeTargets) { MakeWaitGroupsInRandomOrder(gnodes, pgn); return; } for (ln = gnodes->first; ln != NULL; ln = ln->next) { GNode *cgn = ln->datum; Compat_Make(cgn, pgn); } } static bool MakeUnmade(GNode *gn, GNode *pgn) { assert(gn->made == UNMADE); /* * First mark ourselves to be made, then apply whatever transformations * the suffix module thinks are necessary. Once that's done, we can * descend and make all our children. If any of them has an error * but the -k flag was given, our 'make' field will be set to false * again. This is our signal to not attempt to do anything but abort * our parent as well. */ gn->flags.remake = true; gn->made = BEINGMADE; if (!(gn->type & OP_MADE)) Suff_FindDeps(gn); MakeNodes(&gn->children, gn); if (!gn->flags.remake) { gn->made = ABORTED; pgn->flags.remake = false; return false; } if (Lst_FindDatum(&gn->implicitParents, pgn) != NULL) Var_Set(pgn, IMPSRC, GNode_VarTarget(gn)); /* * All the children were made ok. Now youngestChild->mtime contains the * modification time of the newest child, we need to find out if we * exist and when we were modified last. The criteria for datedness * are defined by GNode_IsOODate. */ DEBUG1(MAKE, "Examining %s...", gn->name); if (!GNode_IsOODate(gn)) { gn->made = UPTODATE; DEBUG0(MAKE, "up-to-date.\n"); return false; } /* * If the user is just seeing if something is out-of-date, exit now * to tell him/her "yes". */ DEBUG0(MAKE, "out-of-date.\n"); if (opts.query && gn != Targ_GetEndNode()) exit(1); /* * We need to be re-made. * Ensure that $? (.OODATE) and $> (.ALLSRC) are both set. */ GNode_SetLocalVars(gn); /* * Alter our type to tell if errors should be ignored or things * should not be printed so Compat_RunCommand knows what to do. */ if (opts.ignoreErrors) gn->type |= OP_IGNORE; if (opts.silent) gn->type |= OP_SILENT; if (Job_CheckCommands(gn, Fatal)) { /* * Our commands are ok, but we still have to worry about * the -t flag. */ if (!opts.touch || (gn->type & OP_MAKE)) { curTarg = gn; #ifdef USE_META if (useMeta && GNode_ShouldExecute(gn)) meta_job_start(NULL, gn); #endif RunCommands(gn); curTarg = NULL; } else { Job_Touch(gn, (gn->type & OP_SILENT) != OP_NONE); } } else { gn->made = ERROR; } #ifdef USE_META if (useMeta && GNode_ShouldExecute(gn)) { if (meta_job_finish(NULL) != 0) gn->made = ERROR; } #endif if (gn->made != ERROR) { /* * If the node was made successfully, mark it so, update * its modification time and timestamp all its parents. * This is to keep its state from affecting that of its parent. */ gn->made = MADE; if (Make_Recheck(gn) == 0) pgn->flags.force = true; if (!(gn->type & OP_EXEC)) { pgn->flags.childMade = true; GNode_UpdateYoungestChild(pgn, gn); } } else if (opts.keepgoing) { pgn->flags.remake = false; } else { PrintOnError(gn, "\nStop.\n"); exit(1); } return true; } static void MakeOther(GNode *gn, GNode *pgn) { if (Lst_FindDatum(&gn->implicitParents, pgn) != NULL) { const char *target = GNode_VarTarget(gn); Var_Set(pgn, IMPSRC, target != NULL ? target : ""); } switch (gn->made) { case BEINGMADE: Error("Graph cycles through %s", gn->name); gn->made = ERROR; pgn->flags.remake = false; break; case MADE: if (!(gn->type & OP_EXEC)) { pgn->flags.childMade = true; GNode_UpdateYoungestChild(pgn, gn); } break; case UPTODATE: if (!(gn->type & OP_EXEC)) GNode_UpdateYoungestChild(pgn, gn); break; default: break; } } /* * Make a target. * * If an error is detected and not being ignored, the process exits. * * Input: * gn The node to make * pgn Parent to abort if necessary * * Output: * gn->made * UPTODATE gn was already up-to-date. * MADE gn was recreated successfully. * ERROR An error occurred while gn was being created, * either due to missing commands or in -k mode. * ABORTED gn was not remade because one of its * dependencies could not be made due to errors. */ void Compat_Make(GNode *gn, GNode *pgn) { if (shellName == NULL) /* we came here from jobs */ Shell_Init(); if (gn->made == UNMADE && (gn == pgn || !(pgn->type & OP_MADE))) { if (!MakeUnmade(gn, pgn)) goto cohorts; /* XXX: Replace with GNode_IsError(gn) */ } else if (gn->made == ERROR) { /* * Already had an error when making this. * Tell the parent to abort. */ pgn->flags.remake = false; } else { MakeOther(gn, pgn); } cohorts: MakeNodes(&gn->cohorts, pgn); } static void MakeBeginNode(void) { GNode *gn = Targ_FindNode(".BEGIN"); if (gn == NULL) return; Compat_Make(gn, gn); if (GNode_IsError(gn)) { PrintOnError(gn, "\nStop.\n"); exit(1); } } static void InitSignals(void) { if (bmake_signal(SIGINT, SIG_IGN) != SIG_IGN) bmake_signal(SIGINT, CompatInterrupt); if (bmake_signal(SIGTERM, SIG_IGN) != SIG_IGN) bmake_signal(SIGTERM, CompatInterrupt); if (bmake_signal(SIGHUP, SIG_IGN) != SIG_IGN) bmake_signal(SIGHUP, CompatInterrupt); if (bmake_signal(SIGQUIT, SIG_IGN) != SIG_IGN) bmake_signal(SIGQUIT, CompatInterrupt); } void Compat_MakeAll(GNodeList *targs) { GNode *errorNode = NULL; if (shellName == NULL) Shell_Init(); InitSignals(); /* * Create the .END node now, to keep the (debug) output of the * counter.mk test the same as before 2020-09-23. This * implementation detail probably doesn't matter though. */ (void)Targ_GetEndNode(); if (!opts.query) MakeBeginNode(); /* * Expand .USE nodes right now, because they can modify the structure * of the tree. */ Make_ExpandUse(targs); while (!Lst_IsEmpty(targs)) { GNode *gn = Lst_Dequeue(targs); Compat_Make(gn, gn); if (gn->made == UPTODATE) { printf("`%s' is up to date.\n", gn->name); } else if (gn->made == ABORTED) { printf("`%s' not remade because of errors.\n", gn->name); } if (GNode_IsError(gn) && errorNode == NULL) errorNode = gn; } /* If the user has defined a .END target, run its commands. */ if (errorNode == NULL) { GNode *endNode = Targ_GetEndNode(); Compat_Make(endNode, endNode); if (GNode_IsError(endNode)) errorNode = endNode; } if (errorNode != NULL) { if (DEBUG(GRAPH2)) Targ_PrintGraph(2); else if (DEBUG(GRAPH3)) Targ_PrintGraph(3); PrintOnError(errorNode, "\nStop.\n"); exit(1); } } diff --git a/for.c b/for.c index 089d32efed74..7c090bab5e42 100644 --- a/for.c +++ b/for.c @@ -1,515 +1,539 @@ -/* $NetBSD: for.c,v 1.171 2023/02/14 21:38:31 rillig Exp $ */ +/* $NetBSD: for.c,v 1.174 2023/05/09 19:43:12 rillig Exp $ */ /* * Copyright (c) 1992, The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * Handling of .for/.endfor loops in a makefile. * * For loops have the form: * * .for in * # the body * .endfor * * When a .for line is parsed, the following lines are copied to the body of * the .for loop, until the corresponding .endfor line is reached. In this * phase, the body is not yet evaluated. This also applies to any nested * .for loops. * * After reaching the .endfor, the values from the .for line are grouped * according to the number of variables. For each such group, the unexpanded * body is scanned for variable expressions, and those that match the * variable names are replaced with expressions of the form ${:U...}. After * that, the body is treated like a file from an .include directive. * * Interface: * For_Eval Evaluate the loop in the passed line. * * For_Run Run accumulated loop */ #include "make.h" /* "@(#)for.c 8.1 (Berkeley) 6/6/93" */ -MAKE_RCSID("$NetBSD: for.c,v 1.171 2023/02/14 21:38:31 rillig Exp $"); +MAKE_RCSID("$NetBSD: for.c,v 1.174 2023/05/09 19:43:12 rillig Exp $"); typedef struct ForLoop { Vector /* of 'char *' */ vars; /* Iteration variables */ SubstringWords items; /* Substitution items */ Buffer body; /* Unexpanded body of the loop */ unsigned int nextItem; /* Where to continue iterating */ } ForLoop; static ForLoop *accumFor; /* Loop being accumulated */ +/* See LK_FOR_BODY. */ +static void +skip_whitespace_or_line_continuation(const char **pp) +{ + const char *p = *pp; + for (;;) { + if (ch_isspace(*p)) + p++; + else if (p[0] == '\\' && p[1] == '\n') + p += 2; + else + break; + } + *pp = p; +} + static ForLoop * ForLoop_New(void) { ForLoop *f = bmake_malloc(sizeof *f); Vector_Init(&f->vars, sizeof(char *)); SubstringWords_Init(&f->items); Buf_Init(&f->body); f->nextItem = 0; return f; } void ForLoop_Free(ForLoop *f) { while (f->vars.len > 0) free(*(char **)Vector_Pop(&f->vars)); Vector_Done(&f->vars); SubstringWords_Free(f->items); Buf_Done(&f->body); free(f); } char * ForLoop_Details(ForLoop *f) { size_t i, n; const char **vars; const Substring *items; Buffer buf; n = f->vars.len; vars = f->vars.items; assert(f->nextItem >= n); items = f->items.words + f->nextItem - n; Buf_Init(&buf); for (i = 0; i < n; i++) { if (i > 0) Buf_AddStr(&buf, ", "); Buf_AddStr(&buf, vars[i]); Buf_AddStr(&buf, " = "); Buf_AddBytesBetween(&buf, items[i].start, items[i].end); } return Buf_DoneData(&buf); } static bool +IsValidInVarname(char c) +{ + return c != '$' && c != ':' && c != '\\' && + c != '(' && c != '{' && c != ')' && c != '}'; +} + +static void ForLoop_ParseVarnames(ForLoop *f, const char **pp) { const char *p = *pp; for (;;) { size_t len; cpp_skip_whitespace(&p); if (*p == '\0') { Parse_Error(PARSE_FATAL, "missing `in' in for"); - return false; + f->vars.len = 0; + return; } - /* - * XXX: This allows arbitrary variable names; - * see directive-for.mk. - */ - for (len = 1; p[len] != '\0' && !ch_isspace(p[len]); len++) - continue; + for (len = 0; p[len] != '\0' && !ch_isspace(p[len]); len++) { + if (!IsValidInVarname(p[len])) { + Parse_Error(PARSE_FATAL, + "invalid character '%c' " + "in .for loop variable name", + p[len]); + f->vars.len = 0; + return; + } + } if (len == 2 && p[0] == 'i' && p[1] == 'n') { p += 2; break; } *(char **)Vector_Push(&f->vars) = bmake_strldup(p, len); p += len; } if (f->vars.len == 0) { Parse_Error(PARSE_FATAL, "no iteration variables in for"); - return false; + return; } *pp = p; - return true; } static bool ForLoop_ParseItems(ForLoop *f, const char *p) { char *items; cpp_skip_whitespace(&p); items = Var_Subst(p, SCOPE_GLOBAL, VARE_WANTRES); if (items == var_Error) { /* TODO: Make this part of the code reachable. */ Parse_Error(PARSE_FATAL, "Error in .for loop items"); return false; } f->items = Substring_Words(items, false); free(items); if (f->items.len == 1 && Substring_IsEmpty(f->items.words[0])) f->items.len = 0; /* .for var in ${:U} */ if (f->items.len % f->vars.len != 0) { Parse_Error(PARSE_FATAL, "Wrong number of words (%u) in .for " "substitution list with %u variables", (unsigned)f->items.len, (unsigned)f->vars.len); return false; } return true; } static bool IsFor(const char *p) { return p[0] == 'f' && p[1] == 'o' && p[2] == 'r' && ch_isspace(p[3]); } static bool IsEndfor(const char *p) { return p[0] == 'e' && strncmp(p, "endfor", 6) == 0 && (p[6] == '\0' || ch_isspace(p[6])); } /* * Evaluate the for loop in the passed line. The line looks like this: * .for in * * Results: * 0 not a .for directive * 1 found a .for directive * -1 erroneous .for directive */ int For_Eval(const char *line) { const char *p; ForLoop *f; p = line + 1; /* skip the '.' */ - cpp_skip_whitespace(&p); + skip_whitespace_or_line_continuation(&p); if (IsFor(p)) { p += 3; f = ForLoop_New(); - if (!ForLoop_ParseVarnames(f, &p)) { - ForLoop_Free(f); - return -1; - } - if (!ForLoop_ParseItems(f, p)) + ForLoop_ParseVarnames(f, &p); + if (f->vars.len > 0 && !ForLoop_ParseItems(f, p)) f->items.len = 0; /* don't iterate */ accumFor = f; return 1; } else if (IsEndfor(p)) { Parse_Error(PARSE_FATAL, "for-less endfor"); return -1; } else return 0; } /* * Add another line to the .for loop that is being built up. * Returns false when the matching .endfor is reached. */ bool For_Accum(const char *line, int *forLevel) { const char *p = line; if (*p == '.') { p++; - cpp_skip_whitespace(&p); + skip_whitespace_or_line_continuation(&p); if (IsEndfor(p)) { DEBUG1(FOR, "For: end for %d\n", *forLevel); if (--*forLevel == 0) return false; } else if (IsFor(p)) { (*forLevel)++; DEBUG1(FOR, "For: new loop %d\n", *forLevel); } } Buf_AddStr(&accumFor->body, line); Buf_AddByte(&accumFor->body, '\n'); return true; } /* * When the body of a '.for i' loop is prepared for an iteration, each * occurrence of $i in the body is replaced with ${:U...}, inserting the * value of the item. If this item contains a '$', it may be the start of a * variable expression. This expression is copied verbatim, its length is * determined here, in a rather naive way, ignoring escape characters and * funny delimiters in modifiers like ':S}from}to}'. */ static size_t ExprLen(const char *s, const char *e) { char expr_open, expr_close; int depth; const char *p; if (s == e) return 0; /* just escape the '$' */ expr_open = s[0]; if (expr_open == '(') expr_close = ')'; else if (expr_open == '{') expr_close = '}'; else return 1; /* Single char variable */ depth = 1; for (p = s + 1; p != e; p++) { if (*p == expr_open) depth++; else if (*p == expr_close && --depth == 0) return (size_t)(p + 1 - s); } /* Expression end not found, escape the $ */ return 0; } /* * The .for loop substitutes the items as ${:U...}, which means * that characters that break this syntax must be backslash-escaped. */ static bool NeedsEscapes(Substring value, char endc) { const char *p; for (p = value.start; p != value.end; p++) { if (*p == ':' || *p == '$' || *p == '\\' || *p == endc || *p == '\n') return true; } return false; } /* * While expanding the body of a .for loop, write the item in the ${:U...} * expression, escaping characters as needed. The result is later unescaped * by ApplyModifier_Defined. */ static void AddEscaped(Buffer *cmds, Substring item, char endc) { const char *p; char ch; if (!NeedsEscapes(item, endc)) { Buf_AddBytesBetween(cmds, item.start, item.end); return; } for (p = item.start; p != item.end;) { ch = *p; if (ch == '$') { size_t len = ExprLen(p + 1, item.end); if (len != 0) { /* * XXX: Should a '\' be added here? * See directive-for-escape.mk, ExprLen. */ Buf_AddBytes(cmds, p, 1 + len); p += 1 + len; continue; } Buf_AddByte(cmds, '\\'); } else if (ch == ':' || ch == '\\' || ch == endc) Buf_AddByte(cmds, '\\'); else if (ch == '\n') { Parse_Error(PARSE_FATAL, "newline in .for value"); ch = ' '; /* prevent newline injection */ } Buf_AddByte(cmds, ch); p++; } } /* * When expanding the body of a .for loop, replace the variable name of an * expression like ${i} or ${i:...} or $(i) or $(i:...) with ":Uvalue". */ static void ForLoop_SubstVarLong(ForLoop *f, unsigned int firstItem, Buffer *body, const char **pp, char endc, const char **inout_mark) { size_t i; const char *start = *pp; const char **vars = Vector_Get(&f->vars, 0); for (i = 0; i < f->vars.len; i++) { const char *p = start; if (!cpp_skip_string(&p, vars[i])) continue; /* XXX: why test for backslash here? */ if (*p != ':' && *p != endc && *p != '\\') continue; /* * Found a variable match. Skip over the variable name and * instead add ':U' to the current body. */ Buf_AddBytesBetween(body, *inout_mark, start); Buf_AddStr(body, ":U"); AddEscaped(body, f->items.words[firstItem + i], endc); *inout_mark = p; *pp = p; return; } } /* * When expanding the body of a .for loop, replace single-character * variable expressions like $i with their ${:U...} expansion. */ static void ForLoop_SubstVarShort(ForLoop *f, unsigned int firstItem, Buffer *body, const char *p, const char **inout_mark) { const char ch = *p; const char **vars; size_t i; /* Skip $$ and stupid ones. */ if (ch == '}' || ch == ')' || ch == ':' || ch == '$') return; vars = Vector_Get(&f->vars, 0); for (i = 0; i < f->vars.len; i++) { const char *varname = vars[i]; if (varname[0] == ch && varname[1] == '\0') goto found; } return; found: Buf_AddBytesBetween(body, *inout_mark, p); *inout_mark = p + 1; /* Replace $ with ${:U} */ Buf_AddStr(body, "{:U"); AddEscaped(body, f->items.words[firstItem + i], '}'); Buf_AddByte(body, '}'); } /* * Compute the body for the current iteration by copying the unexpanded body, * replacing the expressions for the iteration variables on the way. * * Using variable expressions ensures that the .for loop can't generate * syntax, and that the later parsing will still see a variable. * This code assumes that the variable with the empty name will never be * defined, see unit-tests/varname-empty.mk for more details. * * The detection of substitutions of the loop control variables is naive. * Many of the modifiers use '\$' instead of '$$' to escape '$', so it is * possible to contrive a makefile where an unwanted substitution happens. */ static void ForLoop_SubstBody(ForLoop *f, unsigned int firstItem, Buffer *body) { const char *p, *end; const char *mark; /* where the last substitution left off */ Buf_Clear(body); mark = f->body.data; end = f->body.data + f->body.len; for (p = mark; (p = strchr(p, '$')) != NULL;) { if (p[1] == '{' || p[1] == '(') { char endc = p[1] == '{' ? '}' : ')'; p += 2; ForLoop_SubstVarLong(f, firstItem, body, &p, endc, &mark); } else if (p[1] != '\0') { ForLoop_SubstVarShort(f, firstItem, body, p + 1, &mark); p += 2; } else break; } Buf_AddBytesBetween(body, mark, end); } /* * Compute the body for the current iteration by copying the unexpanded body, * replacing the expressions for the iteration variables on the way. */ bool For_NextIteration(ForLoop *f, Buffer *body) { if (f->nextItem == f->items.len) return false; f->nextItem += (unsigned int)f->vars.len; ForLoop_SubstBody(f, f->nextItem - (unsigned int)f->vars.len, body); DEBUG1(FOR, "For: loop body:\n%s", body->data); return true; } /* Break out of the .for loop. */ void For_Break(ForLoop *f) { f->nextItem = (unsigned int)f->items.len; } /* Run the .for loop, imitating the actions of an include file. */ void For_Run(unsigned headLineno, unsigned bodyReadLines) { Buffer buf; ForLoop *f = accumFor; accumFor = NULL; if (f->items.len > 0) { Buf_Init(&buf); Parse_PushInput(NULL, headLineno, bodyReadLines, buf, f); } else ForLoop_Free(f); } diff --git a/make.1 b/make.1 index c9cb38313030..eff8fed491fa 100644 --- a/make.1 +++ b/make.1 @@ -1,2734 +1,2749 @@ -.\" $NetBSD: make.1,v 1.361 2023/03/23 03:29:28 sjg Exp $ +.\" $NetBSD: make.1,v 1.366 2023/05/10 18:22:33 sjg Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" -.Dd March 22, 2023 +.Dd May 10, 2023 .Dt MAKE 1 .Os .Sh NAME .Nm make .Nd maintain program dependencies .Sh SYNOPSIS .Nm .Op Fl BeikNnqrSstWwX .Op Fl C Ar directory .Op Fl D Ar variable .Op Fl d Ar flags .Op Fl f Ar makefile .Op Fl I Ar directory .Op Fl J Ar private .Op Fl j Ar max_jobs .Op Fl m Ar directory .Op Fl T Ar file .Op Fl V Ar variable .Op Fl v Ar variable .Op Ar variable\| Ns Cm \&= Ns Ar value .Op Ar target No ... .Sh DESCRIPTION .Nm is a program designed to simplify the maintenance of other programs. Its input is a list of specifications as to the files upon which programs and other files depend. If no .Fl f Ar makefile option is given, .Nm tries to open .Sq Pa makefile then .Sq Pa Makefile in order to find the specifications. If the file .Sq Pa .depend exists, it is read, see .Xr mkdep 1 . .Pp This manual page is intended as a reference document only. For a more thorough description of .Nm and makefiles, please refer to .%T "PMake \- A Tutorial" (from 1993). .Pp .Nm prepends the contents of the .Ev MAKEFLAGS environment variable to the command line arguments before parsing them. .Pp The options are as follows: .Bl -tag -width Ds .It Fl B Try to be backwards compatible by executing a single shell per command and by making the sources of a dependency line in sequence. .It Fl C Ar directory Change to .Ar directory before reading the makefiles or doing anything else. If multiple .Fl C options are specified, each is interpreted relative to the previous one: .Fl C Pa / Fl C Pa etc is equivalent to .Fl C Pa /etc . .It Fl D Ar variable Define .Ar variable to be 1, in the global scope. .It Fl d Oo Cm \- Oc Ns Ar flags Turn on debugging, and specify which portions of .Nm are to print debugging information. Unless the flags are preceded by .Ql \- , they are added to the .Ev MAKEFLAGS environment variable and are passed on to any child make processes. By default, debugging information is printed to standard error, but this can be changed using the .Cm F debugging flag. The debugging output is always unbuffered; in addition, if debugging is enabled but debugging output is not directed to standard output, the standard output is line buffered. The available .Ar flags are: .Bl -tag -width Ds .It Cm A Print all possible debugging information; equivalent to specifying all of the debugging flags. .It Cm a Print debugging information about archive searching and caching. .It Cm C Print debugging information about the current working directory. .It Cm c Print debugging information about conditional evaluation. .It Cm d Print debugging information about directory searching and caching. .It Cm e Print debugging information about failed commands and targets. .It Cm F Ns Oo Cm \&+ Oc Ns Ar filename Specify where debugging output is written. This must be the last flag, because it consumes the remainder of the argument. If the character immediately after the .Cm F flag is .Ql \&+ , the file is opened in append mode; otherwise the file is overwritten. If the file name is .Ql stdout or .Ql stderr , debugging output is written to the standard output or standard error output respectively (and the .Ql \&+ option has no effect). Otherwise, the output is written to the named file. If the file name ends with .Ql .%d , the .Ql %d is replaced by the pid. .It Cm f Print debugging information about loop evaluation. .It Cm g1 Print the input graph before making anything. .It Cm g2 Print the input graph after making everything, or before exiting on error. .It Cm g3 Print the input graph before exiting on error. .It Cm h Print debugging information about hash table operations. .It Cm j Print debugging information about running multiple shells. .It Cm L Turn on lint checks. This throws errors for variable assignments that do not parse correctly, at the time of assignment, so the file and line number are available. .It Cm l Print commands in Makefiles regardless of whether or not they are prefixed by .Ql @ or other .Dq quiet flags. Also known as .Dq loud behavior. .It Cm M Print debugging information about .Dq meta mode decisions about targets. .It Cm m Print debugging information about making targets, including modification dates. .It Cm n Don't delete the temporary command scripts created when running commands. These temporary scripts are created in the directory referred to by the .Ev TMPDIR environment variable, or in .Pa /tmp if .Ev TMPDIR is unset or set to the empty string. The temporary scripts are created by .Xr mkstemp 3 , and have names of the form .Pa makeXXXXXX . .Em NOTE : This can create many files in .Ev TMPDIR or .Pa /tmp , so use with care. .It Cm p Print debugging information about makefile parsing. .It Cm s Print debugging information about suffix-transformation rules. .It Cm t Print debugging information about target list maintenance. .It Cm V Force the .Fl V option to print raw values of variables, overriding the default behavior set via .Va .MAKE.EXPAND_VARIABLES . .It Cm v Print debugging information about variable assignment and expansion. .It Cm x Run shell commands with .Fl x so the actual commands are printed as they are executed. .El .It Fl e Let environment variables override global variables within makefiles. .It Fl f Ar makefile Specify a makefile to read instead of the default .Pa makefile or .Pa Makefile . If .Ar makefile is .Ql \&- , standard input is read. Multiple makefiles may be specified, and are read in the order specified. .It Fl I Ar directory Specify a directory in which to search for makefiles and included makefiles. The system makefile directory (or directories, see the .Fl m option) is automatically included as part of this list. .It Fl i Ignore non-zero exit of shell commands in the makefile. Equivalent to specifying .Ql \&- before each command line in the makefile. .It Fl J Ar private This option should .Em not be specified by the user. .Pp When the .Fl j option is in use in a recursive build, this option is passed by a make to child makes to allow all the make processes in the build to cooperate to avoid overloading the system. .It Fl j Ar max_jobs Specify the maximum number of jobs that .Nm may have running at any one time. The value of .Ar max_jobs is saved in .Va .MAKE.JOBS . Turns compatibility mode off, unless the .Fl B option is also specified. When compatibility mode is off, all commands associated with a target are executed in a single shell invocation as opposed to the traditional one shell invocation per line. This can break traditional scripts which change directories on each command invocation and then expect to start with a fresh environment on the next line. It is more efficient to correct the scripts rather than turn backwards compatibility on. .Pp A job token pool with .Ar max_jobs tokens is used to control the total number of jobs running. Each instance of .Nm will wait for a token from the pool before running a new job. .It Fl k Continue processing after errors are encountered, but only on those targets that do not depend on the target whose creation caused the error. .It Fl m Ar directory Specify a directory in which to search for .Pa sys.mk and makefiles included via the .Li \&< Ns Ar file Ns Li \&> Ns -style include statement. The .Fl m option can be used multiple times to form a search path. This path overrides the default system include path .Pa /usr/share/mk . Furthermore, the system include path is appended to the search path used for .Li \*q Ns Ar file Ns Li \*q Ns -style include statements (see the .Fl I option). The system include path can be referenced via the read-only variable .Va .SYSPATH . .Pp If a directory name in the .Fl m argument (or the .Ev MAKESYSPATH environment variable) starts with the string .Ql \&.../ , .Nm searches for the specified file or directory named in the remaining part of the argument string. The search starts with the current directory and then works upward towards the root of the file system. If the search is successful, the resulting directory replaces the .Ql \&.../ specification in the .Fl m argument. This feature allows .Nm to easily search in the current source tree for customized .Pa sys.mk files (e.g., by using .Ql \&.../mk/sys.mk as an argument). .It Fl n Display the commands that would have been executed, but do not actually execute them unless the target depends on the .Va .MAKE special source (see below) or the command is prefixed with .Sq Cm + . .It Fl N Display the commands that would have been executed, but do not actually execute any of them; useful for debugging top-level makefiles without descending into subdirectories. .It Fl q Do not execute any commands, instead exit 0 if the specified targets are up to date, and 1 otherwise. .It Fl r Do not use the built-in rules specified in the system makefile. .It Fl S Stop processing if an error is encountered. This is the default behavior and the opposite of .Fl k . .It Fl s Do not echo any commands as they are executed. Equivalent to specifying .Sq Ic @ before each command line in the makefile. .It Fl T Ar tracefile When used with the .Fl j flag, append a trace record to .Ar tracefile for each job started and completed. .It Fl t Rather than re-building a target as specified in the makefile, create it or update its modification time to make it appear up-to-date. .It Fl V Ar variable Print the value of .Ar variable . Do not build any targets. Multiple instances of this option may be specified; the variables are printed one per line, with a blank line for each null or undefined variable. The value printed is extracted from the global scope after all makefiles have been read. .Pp By default, the raw variable contents (which may include additional unexpanded variable references) are shown. If .Ar variable contains a .Ql \&$ , it is not interpreted as a variable name but rather as an expression. Its value is expanded before printing. The value is also expanded before printing if .Va .MAKE.EXPAND_VARIABLES is set to true and the .Fl dV option has not been used to override it. .Pp Note that loop-local and target-local variables, as well as values taken temporarily by global variables during makefile processing, are not accessible via this option. The .Fl dv debug mode can be used to see these at the cost of generating substantial extraneous output. .It Fl v Ar variable Like .Fl V , but all printed variables are always expanded to their complete value. The last occurrence of .Fl V or .Fl v decides whether all variables are expanded or not. .It Fl W Treat any warnings during makefile parsing as errors. .It Fl w Print entering and leaving directory messages, pre and post processing. .It Fl X Don't export variables passed on the command line to the environment individually. Variables passed on the command line are still exported via the .Ev MAKEFLAGS environment variable. This option may be useful on systems which have a small limit on the size of command arguments. .It Ar variable\| Ns Cm \&= Ns Ar value Set the value of the variable .Ar variable to .Ar value . Normally, all values passed on the command line are also exported to sub-makes in the environment. The .Fl X flag disables this behavior. Variable assignments should follow options for POSIX compatibility but no ordering is enforced. .El .Pp There are several different types of lines in a makefile: dependency specifications, shell commands, variable assignments, include statements, conditional directives, for loops, other directives, and comments. .Pp Lines may be continued from one line to the next by ending them with a backslash .Pq Ql \e . The trailing newline character and initial whitespace on the following line are compressed into a single space. .Sh FILE DEPENDENCY SPECIFICATIONS Dependency lines consist of one or more targets, an operator, and zero or more sources. This creates a relationship where the targets .Dq depend on the sources and are customarily created from them. A target is considered out of date if it does not exist, or if its modification time is less than that of any of its sources. An out-of-date target is re-created, but not until all sources have been examined and themselves re-created as needed. Three operators may be used: .Bl -tag -width flag .It Ic \&: Many dependency lines may name this target but only one may have attached shell commands. All sources named in all dependency lines are considered together, and if needed the attached shell commands are run to create or re-create the target. If .Nm is interrupted, the target is removed. .It Ic \&! The same, but the target is always re-created whether or not it is out of date. .It Ic \&:: Any dependency line may have attached shell commands, but each one is handled independently: its sources are considered and the attached shell commands are run if the target is out of date with respect to (only) those sources. Thus, different groups of the attached shell commands may be run depending on the circumstances. Furthermore, unlike .Ic \&: , for dependency lines with no sources, the attached shell commands are always run. Also unlike .Ic \&: , the target is not removed if .Nm is interrupted. .El .Pp All dependency lines mentioning a particular target must use the same operator. .Pp Targets and sources may contain the shell wildcard values .Ql \&? , .Ql * , .Ql [] , and .Ql {} . The values .Ql \&? , .Ql * , and .Ql [] may only be used as part of the final component of the target or source, and only match existing files. The value .Ql {} need not necessarily be used to describe existing files. Expansion is in directory order, not alphabetically as done in the shell. .Sh SHELL COMMANDS Each target may have associated with it one or more lines of shell commands, normally used to create the target. Each of the lines in this script .Em must be preceded by a tab. (For historical reasons, spaces are not accepted.) While targets can occur in many dependency lines if desired, by default only one of these rules may be followed by a creation script. If the .Sq Ic \&:: operator is used, however, all rules may include scripts, and the respective scripts are executed in the order found. .Pp Each line is treated as a separate shell command, unless the end of line is escaped with a backslash .Ql \e , in which case that line and the next are combined. If the first characters of the command are any combination of .Sq Ic @ , .Sq Ic + , or .Sq Ic \- , the command is treated specially. .Bl -tag -offset indent -width indent .It Ic @ causes the command not to be echoed before it is executed. .It Ic + causes the command to be executed even when .Fl n is given. This is similar to the effect of the .Va .MAKE special source, except that the effect can be limited to a single line of a script. .It Ic \- in compatibility mode causes any non-zero exit status of the command line to be ignored. .El .Pp When .Nm is run in jobs mode with .Fl j Ar max_jobs , the entire script for the target is fed to a single instance of the shell. In compatibility (non-jobs) mode, each command is run in a separate process. If the command contains any shell meta characters .Pq Ql #=|^(){};&<>*?[]:$`\e\en , it is passed to the shell; otherwise .Nm attempts direct execution. If a line starts with .Sq Ic \- and the shell has ErrCtl enabled, failure of the command line is ignored as in compatibility mode. Otherwise .Sq Ic \- affects the entire job; the script stops at the first command line that fails, but the target is not deemed to have failed. .Pp Makefiles should be written so that the mode of .Nm operation does not change their behavior. For example, any command which uses .Dq cd or .Dq chdir without the intention of changing the directory for subsequent commands should be put in parentheses so it executes in a subshell. To force the use of a single shell, escape the line breaks so as to make the whole script one command. For example: .Bd -literal -offset indent avoid-chdir-side-effects: @echo "Building $@ in $$(pwd)" @(cd ${.CURDIR} && ${MAKE} $@) @echo "Back in $$(pwd)" ensure-one-shell-regardless-of-mode: @echo "Building $@ in $$(pwd)"; \e (cd ${.CURDIR} && ${MAKE} $@); \e echo "Back in $$(pwd)" .Ed .Pp Since .Nm changes the current working directory to .Sq Va .OBJDIR before executing any targets, each child process starts with that as its current working directory. .Sh VARIABLE ASSIGNMENTS Variables in make behave much like macros in the C preprocessor. .Pp Variable assignments have the form .Sq Ar NAME Ar op Ar value , where: .Bl -tag -offset Ds -width Ds .It Ar NAME is a single-word variable name, consisting, by tradition, of all upper-case letters, .It Ar op is one of the variable assignment operators described below, and .It Ar value is interpreted according to the variable assignment operator. .El .Pp Whitespace around .Ar NAME , .Ar op and .Ar value is discarded. .Ss Variable assignment operators The five operators that assign values to variables are: .Bl -tag -width Ds .It Ic \&= Assign the value to the variable. Any previous value is overwritten. .It Ic \&+= Append the value to the current value of the variable, separating them by a single space. .It Ic \&?= Assign the value to the variable if it is not already defined. .It Ic \&:= Expand the value, then assign it to the variable. .Pp .Em NOTE : References to undefined variables are .Em not expanded. This can cause problems when variable modifiers are used. .\" See var-op-expand.mk, the section with LATER and INDIRECT. .It Ic \&!= Expand the value and pass it to the shell for execution, then assign the output from the child's standard output to the variable. Any newlines in the result are replaced with spaces. .El .Ss Expansion of variables In most contexts where variables are expanded, .Ql \&$$ expands to a single dollar sign. In other contexts (most variable modifiers, string literals in conditions), .Ql \&\e$ expands to a single dollar sign. .Pp References to variables have the form .Cm \&${ Ns Ar name Ns Oo Ns Cm \&: Ns Ar modifiers Oc Ns Cm \&} or .Cm \&$( Ns Ar name Ns Oo Ns Cm \&: Ns Ar modifiers Oc Ns Cm \&) . If the variable name consists of only a single character and the expression contains no modifiers, the surrounding curly braces or parentheses are not required. This shorter form is not recommended. .Pp If the variable name contains a dollar, the name itself is expanded first. This allows almost arbitrary variable names, however names containing dollar, braces, parentheses or whitespace are really best avoided. .Pp If the result of expanding a nested variable expression contains a dollar sign .Pq Ql \&$ , the result is subject to further expansion. .Pp Variable substitution occurs at four distinct times, depending on where the variable is being used. .Bl -enum .It Variables in dependency lines are expanded as the line is read. .It Variables in conditionals are expanded individually, but only as far as necessary to determine the result of the conditional. .It Variables in shell commands are expanded when the shell command is executed. .It .Ic .for loop index variables are expanded on each loop iteration. Note that other variables are not expanded when composing the body of a loop, so the following example code: .Bd -literal -offset indent \&.for i in 1 2 3 a+= ${i} j= ${i} b+= ${j} \&.endfor all: @echo ${a} @echo ${b} .Ed .Pp prints: .Bd -literal -offset indent 1 2 3 3 3 3 .Ed .Pp After the loop is executed: .Bl -tag -offset indent -width indent .It Va a contains .Ql ${:U1} ${:U2} ${:U3} , which expands to .Ql 1 2 3 . .It Va j contains .Ql ${:U3} , which expands to .Ql 3 . .It Va b contains .Ql ${j} ${j} ${j} , which expands to .Ql ${:U3} ${:U3} ${:U3} and further to .Ql 3 3 3 . .El .El .Ss Variable classes The four different classes of variables (in order of increasing precedence) are: .Bl -tag -width Ds .It Environment variables Variables defined as part of .Nm Ns 's environment. .It Global variables Variables defined in the makefile or in included makefiles. .It Command line variables Variables defined as part of the command line. .It Local variables Variables that are defined specific to a certain target. .El .Pp Local variables can be set on a dependency line, unless .Va .MAKE.TARGET_LOCAL_VARIABLES is set to .Ql false . The rest of the line (which already has had global variables expanded) is the variable value. For example: .Bd -literal -offset indent COMPILER_WRAPPERS= ccache distcc icecc ${OBJS}: .MAKE.META.CMP_FILTER=${COMPILER_WRAPPERS:S,^,N,} .Ed .Pp Only the targets .Ql ${OBJS} are impacted by that filter (in .Dq meta mode) and simply enabling/disabling any of the compiler wrappers does not render all of those targets out-of-date. .Pp .Em NOTE : target-local variable assignments behave differently in that; .Bl -tag -width Ds -offset indent .It Ic \&+= Only appends to a previous local assignment for the same target and variable. .It Ic \&:= Is redundant with respect to global variables, which have already been expanded. .El .Pp The seven built-in local variables are: .Bl -tag -width ".Va .ARCHIVE" -offset indent .It Va .ALLSRC The list of all sources for this target; also known as .Sq Va \&> . .It Va .ARCHIVE The name of the archive file; also known as .Sq Va \&! . .It Va .IMPSRC In suffix-transformation rules, the name/path of the source from which the target is to be transformed (the .Dq implied source); also known as .Sq Va \&< . It is not defined in explicit rules. .It Va .MEMBER The name of the archive member; also known as .Sq Va % . .It Va .OODATE The list of sources for this target that were deemed out-of-date; also known as .Sq Va \&? . .It Va .PREFIX -The file prefix of the target, containing only the file portion, no suffix -or preceding directory components; also known as +The name of the target with suffix (if declared in +.Ic .SUFFIXES ) +removed; also known as .Sq Va * . -The suffix must be one of the known suffixes declared with -.Ic .SUFFIXES , -or it is not recognized. .It Va .TARGET The name of the target; also known as .Sq Va @ . For compatibility with other makes this is an alias for .Va .ARCHIVE in archive member rules. .El .Pp The shorter forms .Po .Sq Va \&> , .Sq Va \&! , .Sq Va \&< , .Sq Va \&% , .Sq Va \&? , .Sq Va \&* , and .Sq Va \&@ .Pc are permitted for backward compatibility with historical makefiles and legacy POSIX make and are not recommended. .Pp Variants of these variables with the punctuation followed immediately by .Ql D or .Ql F , e.g.\& .Ql $(@D) , are legacy forms equivalent to using the .Ql :H and .Ql :T modifiers. These forms are accepted for compatibility with .At V makefiles and POSIX but are not recommended. .Pp Four of the local variables may be used in sources on dependency lines because they expand to the proper value for each target on the line. These variables are .Sq Va .TARGET , .Sq Va .PREFIX , .Sq Va .ARCHIVE , and .Sq Va .MEMBER . .Ss Additional built-in variables In addition, .Nm sets or knows about the following variables: .Bl -tag .\" NB: This list is sorted case-insensitive, ignoring punctuation. .\" NB: To find all built-in variables in make's source code, .\" NB: search for Var_*, Global_*, SetVarObjdir, GetBooleanExpr, .\" NB: and the implementation of Var_SetWithFlags. .\" NB: Last synced on 2023-01-01. .It Va .ALLTARGETS The list of all targets encountered in the makefiles. If evaluated during makefile parsing, lists only those targets encountered thus far. .It Va .CURDIR A path to the directory where .Nm was executed. Refer to the description of .Sq Va PWD for more details. .It Va .ERROR_CMD Is used in error handling, see .Va MAKE_PRINT_VAR_ON_ERROR . .It Va .ERROR_CWD Is used in error handling, see .Va MAKE_PRINT_VAR_ON_ERROR . .It Va .ERROR_META_FILE Is used in error handling in .Dq meta mode, see .Va MAKE_PRINT_VAR_ON_ERROR . .It Va .ERROR_TARGET Is used in error handling, see .Va MAKE_PRINT_VAR_ON_ERROR . .It Va .INCLUDEDFROMDIR The directory of the file this makefile was included from. .It Va .INCLUDEDFROMFILE The filename of the file this makefile was included from. .\" .INCLUDES is intentionally undocumented, as it is obsolete. .\" .LIBS is intentionally undocumented, as it is obsolete. .It Va MACHINE The machine hardware name, see .Xr uname 1 . .It Va MACHINE_ARCH The machine processor architecture name, see .Xr uname 1 . .It Va MAKE The name that .Nm was executed with .Pq Va argv[0] . .It Va .MAKE The same as .Va MAKE , for compatibility. The preferred variable to use is the environment variable .Ev MAKE because it is more compatible with other make variants and cannot be confused with the special target with the same name. .\" '.MAKE.cmd_filtered' is intentionally undocumented, .\" as it is an internal implementation detail. .It Va .MAKE.DEPENDFILE Names the makefile (default .Sq Pa .depend ) from which generated dependencies are read. .It Va .MAKE.DIE_QUIETLY If set to .Ql true , do not print error information at the end. .It Va .MAKE.EXPAND_VARIABLES A boolean that controls the default behavior of the .Fl V option. If true, variable values printed with .Fl V are fully expanded; if false, the raw variable contents (which may include additional unexpanded variable references) are shown. .It Va .MAKE.EXPORTED The list of variables exported by .Nm . .It Va MAKEFILE The top-level makefile that is currently read, as given in the command line. .It Va .MAKEFLAGS The environment variable .Sq Ev MAKEFLAGS may contain anything that may be specified on .Nm Ns 's command line. Anything specified on .Nm Ns 's command line is appended to the .Va .MAKEFLAGS variable, which is then added to the environment for all programs that .Nm executes. .It Va .MAKE.GID The numeric group ID of the user running .Nm . It is read-only. .It Va .MAKE.JOB.PREFIX If .Nm is run with .Fl j , the output for each target is prefixed with a token .Dl --- Ar target Li --- the first part of which can be controlled via .Va .MAKE.JOB.PREFIX . If .Va .MAKE.JOB.PREFIX is empty, no token is printed. For example, setting .Va .MAKE.JOB.PREFIX to .Ql ${.newline}---${.MAKE:T}[${.MAKE.PID}] would produce tokens like .Dl ---make[1234] Ar target Li --- making it easier to track the degree of parallelism being achieved. .It Va .MAKE.JOBS The argument to the .Fl j option. .It Va .MAKE.LEVEL The recursion depth of .Nm . The top-level instance of .Nm has level 0, and each child make has its parent level plus 1. This allows tests like: .Li .if ${.MAKE.LEVEL} == 0 to protect things which should only be evaluated in the top-level instance of .Nm . .It Va .MAKE.LEVEL.ENV The name of the environment variable that stores the level of nested calls to .Nm . .It Va .MAKE.MAKEFILE_PREFERENCE The ordered list of makefile names (default .Sq Pa makefile , .Sq Pa Makefile ) that .Nm looks for. .It Va .MAKE.MAKEFILES The list of makefiles read by .Nm , which is useful for tracking dependencies. Each makefile is recorded only once, regardless of the number of times read. .It Va .MAKE.META.BAILIWICK In .Dq meta mode, provides a list of prefixes which match the directories controlled by .Nm . If a file that was generated outside of .Va .OBJDIR but within said bailiwick is missing, the current target is considered out-of-date. .It Va .MAKE.META.CMP_FILTER In .Dq meta mode, it can (very rarely!) be useful to filter command lines before comparison. This variable can be set to a set of modifiers that are applied to each line of the old and new command that differ, if the filtered commands still differ, the target is considered out-of-date. .It Va .MAKE.META.CREATED In .Dq meta mode, this variable contains a list of all the meta files updated. If not empty, it can be used to trigger processing of .Va .MAKE.META.FILES . .It Va .MAKE.META.FILES In .Dq meta mode, this variable contains a list of all the meta files used (updated or not). This list can be used to process the meta files to extract dependency information. .It Va .MAKE.META.IGNORE_FILTER Provides a list of variable modifiers to apply to each pathname. Ignore if the expansion is an empty string. .It Va .MAKE.META.IGNORE_PATHS Provides a list of path prefixes that should be ignored; because the contents are expected to change over time. The default list includes: .Sq Pa /dev /etc /proc /tmp /var/run /var/tmp .It Va .MAKE.META.IGNORE_PATTERNS Provides a list of patterns to match against pathnames. Ignore any that match. .It Va .MAKE.META.PREFIX Defines the message printed for each meta file updated in .Dq meta verbose mode. The default value is: .Dl Building ${.TARGET:H:tA}/${.TARGET:T} .It Va .MAKE.MODE Processed after reading all makefiles. Affects the mode that .Nm runs in. It can contain these keywords: .Bl -tag -width indent .It Cm compat Like .Fl B , puts .Nm into .Dq compat mode. .It Cm meta Puts .Nm into .Dq meta mode, where meta files are created for each target to capture the command run, the output generated, and if .Xr filemon 4 is available, the system calls which are of interest to .Nm . The captured output can be useful when diagnosing errors. .It Cm curdirOk= Ns Ar bf By default, .Nm does not create .Pa .meta files in .Sq Va .CURDIR . This can be overridden by setting .Ar bf to a value which represents true. .It Cm missing-meta= Ns Ar bf If .Ar bf is true, a missing .Pa .meta file makes the target out-of-date. .It Cm missing-filemon= Ns Ar bf If .Ar bf is true, missing filemon data makes the target out-of-date. .It Cm nofilemon Do not use .Xr filemon 4 . .It Cm env For debugging, it can be useful to include the environment in the .Pa .meta file. .It Cm verbose If in .Dq meta mode, print a clue about the target being built. This is useful if the build is otherwise running silently. The message printed is the expanded value of .Va .MAKE.META.PREFIX . .It Cm ignore-cmd Some makefiles have commands which are simply not stable. This keyword causes them to be ignored for determining whether a target is out of date in .Dq meta mode. See also .Ic .NOMETA_CMP . .It Cm silent= Ns Ar bf If .Ar bf is true, when a .meta file is created, mark the target .Ic .SILENT . .It Cm randomize-targets In both compat and parallel mode, do not make the targets in the usual order, but instead randomize their order. This mode can be used to detect undeclared dependencies between files. .El .It Va MAKEOBJDIR Used to create files in a separate directory, see .Va .OBJDIR . .It Va MAKE_OBJDIR_CHECK_WRITABLE Used to force a separate directory for the created files, even if that directory is not writable, see .Va .OBJDIR . .It Va MAKEOBJDIRPREFIX Used to create files in a separate directory, see .Va .OBJDIR . .It Va .MAKE.OS The name of the operating system, see .Xr uname 1 . It is read-only. .It Va .MAKEOVERRIDES This variable is used to record the names of variables assigned to on the command line, so that they may be exported as part of .Sq Ev MAKEFLAGS . This behavior can be disabled by assigning an empty value to .Sq Va .MAKEOVERRIDES within a makefile. Extra variables can be exported from a makefile by appending their names to .Sq Va .MAKEOVERRIDES . .Sq Ev MAKEFLAGS is re-exported whenever .Sq Va .MAKEOVERRIDES is modified. .It Va .MAKE.PATH_FILEMON If .Nm was built with .Xr filemon 4 support, this is set to the path of the device node. This allows makefiles to test for this support. .It Va .MAKE.PID The process ID of .Nm . It is read-only. .It Va .MAKE.PPID The parent process ID of .Nm . It is read-only. .It Va MAKE_PRINT_VAR_ON_ERROR When .Nm stops due to an error, it sets .Sq Va .ERROR_TARGET to the name of the target that failed, .Sq Va .ERROR_CMD to the commands of the failed target, and in .Dq meta mode, it also sets .Sq Va .ERROR_CWD to the .Xr getcwd 3 , and .Sq Va .ERROR_META_FILE to the path of the meta file (if any) describing the failed target. It then prints its name and the value of .Sq Va .CURDIR as well as the value of any variables named in .Sq Va MAKE_PRINT_VAR_ON_ERROR . .It Va .MAKE.SAVE_DOLLARS If true, .Ql $$ are preserved when doing .Ql := assignments. The default is false, for backwards compatibility. Set to true for compatability with other makes. If set to false, .Ql $$ becomes .Ql $ per normal evaluation rules. .It Va .MAKE.TARGET_LOCAL_VARIABLES If set to .Ql false , apparent variable assignments in dependency lines are treated as normal sources. .It Va .MAKE.UID The numeric ID of the user running .Nm . It is read-only. .\" 'MAKE_VERSION' is intentionally undocumented .\" since it is only defined in the bmake distribution, .\" but not in NetBSD's native make. .\" '.meta.%d.lcwd' is intentionally undocumented .\" since it is an internal implementation detail. .\" '.meta.%d.ldir' is intentionally undocumented .\" since it is an internal implementation detail. .\" 'MFLAGS' is intentionally undocumented .\" since it is obsolete. .It Va .newline This variable is simply assigned a newline character as its value. It is read-only. This allows expansions using the .Cm \&:@ modifier to put a newline between iterations of the loop rather than a space. For example, in case of an error, .Nm prints the variable names and their values using: .Dl ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@} .It Va .OBJDIR A path to the directory where the targets are built. Its value is determined by trying to .Xr chdir 2 to the following directories in order and using the first match: .Bl -enum .It .Cm ${MAKEOBJDIRPREFIX} Ns Cm ${.CURDIR} .Pp (Only if .Sq Ev MAKEOBJDIRPREFIX is set in the environment or on the command line.) .It .Cm ${MAKEOBJDIR} .Pp (Only if .Sq Ev MAKEOBJDIR is set in the environment or on the command line.) .It .Cm ${.CURDIR} Ns Pa /obj. Ns Cm ${MACHINE} .It .Cm ${.CURDIR} Ns Pa /obj .It .Pa /usr/obj/ Ns Cm ${.CURDIR} .It .Cm ${.CURDIR} .El .Pp Variable expansion is performed on the value before it is used, so expressions such as .Cm ${.CURDIR:S,^/usr/src,/var/obj,} may be used. This is especially useful with .Sq Ev MAKEOBJDIR . .Pp .Sq Va .OBJDIR may be modified in the makefile via the special target .Sq Ic .OBJDIR . In all cases, .Nm changes to the specified directory if it exists, and sets .Sq Va .OBJDIR and .Sq Va PWD to that directory before executing any targets. .Pp Except in the case of an explicit .Sq Ic .OBJDIR target, .Nm checks that the specified directory is writable and ignores it if not. This check can be skipped by setting the environment variable .Sq Ev MAKE_OBJDIR_CHECK_WRITABLE to .Dq no . .It Va .PARSEDIR The directory name of the current makefile being parsed. .It Va .PARSEFILE The basename of the current makefile being parsed. This variable and .Sq Va .PARSEDIR are both set only while the makefiles are being parsed. To retain their current values, assign them to a variable using assignment with expansion .Sq Cm \&:= . .It Va .PATH The space-separated list of directories that .Nm searches for files. To update this search list, use the special target .Sq Ic .PATH rather than modifying the variable directly. .It Va %POSIX Is set in POSIX mode, see the special .Ql Va .POSIX target. .\" XXX: There is no make variable named 'PWD', .\" XXX: make only reads and writes the environment variable 'PWD'. .It Va PWD Alternate path to the current directory. .Nm normally sets .Sq Va .CURDIR to the canonical path given by .Xr getcwd 3 . However, if the environment variable .Sq Ev PWD is set and gives a path to the current directory, .Nm sets .Sq Va .CURDIR to the value of .Sq Ev PWD instead. This behavior is disabled if .Sq Ev MAKEOBJDIRPREFIX is set or .Sq Ev MAKEOBJDIR contains a variable transform. .Sq Va PWD is set to the value of .Sq Va .OBJDIR for all programs which .Nm executes. .It Va .SHELL The pathname of the shell used to run target scripts. It is read-only. .It Va .SUFFIXES The list of known suffixes. It is read-only. .It Va .SYSPATH The space-separated list of directories that .Nm searches for makefiles, referred to as the system include path. To update this search list, use the special target .Sq Ic .SYSPATH rather than modifying the variable which is read-only. .It Va .TARGETS The list of targets explicitly specified on the command line, if any. .It Va VPATH The colon-separated .Pq Dq \&: list of directories that .Nm searches for files. This variable is supported for compatibility with old make programs only, use .Sq Va .PATH instead. .El .Ss Variable modifiers The general format of a variable expansion is: .Pp .Sm off .D1 Ic \&${ Ar variable\| Oo Ic \&: Ar modifier\| Oo Ic \&: No ... Oc Oc Ic \&} .Sm on .Pp Each modifier begins with a colon. To escape a colon, precede it with a backslash .Ql \e . .Pp A list of indirect modifiers can be specified via a variable, as follows: .Pp .Bd -literal -offset indent .Ar modifier_variable\^ Li \&= Ar modifier Ns Oo Ic \&: Ns No ... Oc .Sm off .Ic \&${ Ar variable Ic \&:${ Ar modifier_variable Ic \&} Oo Ic \&: No ... Oc Ic \&} .Sm on .Ed .Pp In this case, the first modifier in the .Ar modifier_variable does not start with a colon, since that colon already occurs in the referencing variable. If any of the modifiers in the .Ar modifier_variable contains a dollar sign .Pq Ql $ , these must be doubled to avoid early expansion. .Pp Some modifiers interpret the expression value as a single string, others treat the expression value as a whitespace-separated list of words. When splitting a string into words, whitespace can be escaped using double quotes, single quotes and backslashes, like in the shell. The quotes and backslashes are retained in the words. .Pp The supported modifiers are: .Bl -tag -width EEE .It Cm \&:E Replaces each word with its suffix. .It Cm \&:H Replaces each word with its dirname. .It Cm \&:M\| Ns Ar pattern Selects only those words that match .Ar pattern . The standard shell wildcard characters .Pf ( Ql * , .Ql \&? , and .Ql \&[] ) may be used. The wildcard characters may be escaped with a backslash .Pq Ql \e . As a consequence of the way values are split into words, matched, and then joined, the construct .Ql ${VAR:M*} removes all leading and trailing whitespace and normalizes the inter-word spacing to a single space. .It Cm \&:N\| Ns Ar pattern This is the opposite of .Sq Cm \&:M , selecting all words which do .Em not match .Ar pattern . .It Cm \&:O Orders the words lexicographically. .It Cm \&:On Orders the words numerically. A number followed by one of .Ql k , .Ql M or .Ql G is multiplied by the appropriate factor, which is 1024 for .Ql k , 1048576 for .Ql M , or 1073741824 for .Ql G . Both upper- and lower-case letters are accepted. .It Cm \&:Or Orders the words in reverse lexicographical order. .It Cm \&:Orn Orders the words in reverse numerical order. .It Cm \&:Ox Shuffles the words. The results are different each time you are referring to the modified variable; use the assignment with expansion .Sq Cm \&:= to prevent such behavior. For example, .Bd -literal -offset indent LIST= uno due tre quattro RANDOM_LIST= ${LIST:Ox} STATIC_RANDOM_LIST:= ${LIST:Ox} all: @echo "${RANDOM_LIST}" @echo "${RANDOM_LIST}" @echo "${STATIC_RANDOM_LIST}" @echo "${STATIC_RANDOM_LIST}" .Ed may produce output similar to: .Bd -literal -offset indent quattro due tre uno tre due quattro uno due uno quattro tre due uno quattro tre .Ed .It Cm \&:Q Quotes every shell meta-character in the value, so that it can be passed safely to the shell. .It Cm \&:q Quotes every shell meta-character in the value, and also doubles .Sq $ characters so that it can be passed safely through recursive invocations of .Nm . This is equivalent to .Sq Cm \&:S/\e\&$/&&/g:Q . .It Cm \&:R Replaces each word with everything but its suffix. .It Cm \&:range Ns Oo Cm = Ns Ar count Oc The value is an integer sequence representing the words of the original value, or the supplied .Ar count . .It Cm \&:gmtime Ns Oo Cm = Ns Ar timestamp Oc The value is interpreted as a format string for .Xr strftime 3 , using .Xr gmtime 3 , producing the formatted timestamp. If a .Ar timestamp value is not provided or is 0, the current time is used. .It Cm \&:hash Computes a 32-bit hash of the value and encodes it as 8 hex digits. .It Cm \&:localtime Ns Oo Cm = Ns Ar timestamp Oc The value is interpreted as a format string for .Xr strftime 3 , using .Xr localtime 3 , producing the formatted timestamp. If a .Ar timestamp value is not provided or is 0, the current time is used. +.It Cm \&:mtime Ns Oo Cm = Ns Ar timestamp Oc +Call +.Xr stat 2 +with each word as pathname; +use +.Ql st_mtime +as the new value. +If +.Xr stat 2 +fails; use +.Ar timestamp +or current time. +If +.Ar timestamp +is set to +.Ql error , +then +.Xr stat 2 +failure will cause an error. .It Cm \&:tA Attempts to convert the value to an absolute path using .Xr realpath 3 . If that fails, the value is unchanged. .It Cm \&:tl Converts the value to lower-case letters. .It Cm \&:ts Ns Ar c When joining the words after a modifier that treats the value as words, the words are normally separated by a space. This modifier changes the separator to the character .Ar c . If .Ar c is omitted, no separator is used. The common escapes (including octal numeric codes) work as expected. .It Cm \&:tu Converts the value to upper-case letters. .It Cm \&:tW Causes subsequent modifiers to treat the value as a single word (possibly containing embedded whitespace). See also .Sq Cm \&:[*] . .It Cm \&:tw Causes the value to be treated as a list of words. See also .Sq Cm \&:[@] . .Sm off .It Cm \&:S\| No \&/ Ar old_string\| No \&/ Ar new_string\| No \&/ Op Cm 1gW .Sm on Modifies the first occurrence of .Ar old_string in each word of the value, replacing it with .Ar new_string . If a .Ql g is appended to the last delimiter of the pattern, all occurrences in each word are replaced. If a .Ql 1 is appended to the last delimiter of the pattern, only the first occurrence is affected. If a .Ql W is appended to the last delimiter of the pattern, the value is treated as a single word. If .Ar old_string begins with a caret .Pq Ql ^ , .Ar old_string is anchored at the beginning of each word. If .Ar old_string ends with a dollar sign .Pq Ql \&$ , it is anchored at the end of each word. Inside .Ar new_string , an ampersand .Pq Ql & is replaced by .Ar old_string (without the anchoring .Ql ^ or .Ql \&$ ) . Any character may be used as the delimiter for the parts of the modifier string. The anchoring, ampersand and delimiter characters can be escaped with a backslash .Pq Ql \e . .Pp Both .Ar old_string and .Ar new_string may contain nested expressions. To prevent a dollar sign from starting a nested expression, escape it with a backslash. .Sm off .It Cm \&:C\| No \&/ Ar pattern\| No \&/ Ar replacement\| No \&/ Op Cm 1gW .Sm on The .Cm \&:C modifier works like the .Cm \&:S modifier except that the old and new strings, instead of being simple strings, are an extended regular expression .Ar pattern (see .Xr regex 3 ) and an .Xr ed 1 Ns \-style .Ar replacement . Normally, the first occurrence of the pattern .Ar pattern in each word of the value is substituted with .Ar replacement . The .Ql 1 modifier causes the substitution to apply to at most one word; the .Ql g modifier causes the substitution to apply to as many instances of the search pattern .Ar pattern as occur in the word or words it is found in; the .Ql W modifier causes the value to be treated as a single word (possibly containing embedded whitespace). .Pp As for the .Cm \&:S modifier, the .Ar pattern and .Ar replacement are subjected to variable expansion before being parsed as regular expressions. .It Cm \&:T Replaces each word with its last path component (basename). .It Cm \&:u Removes adjacent duplicate words (like .Xr uniq 1 ) . .Sm off .It Cm \&:\&?\| Ar true_string\| Cm \&: Ar false_string .Sm on If the variable name (not its value), when parsed as a .Cm .if conditional expression, evaluates to true, return as its value the .Ar true_string , otherwise return the .Ar false_string . Since the variable name is used as the expression, \&:\&? must be the first modifier after the variable name .No itself Ns \^\(em\^ Ns which, of course, usually contains variable expansions. A common error is trying to use expressions like .Dl ${NUMBERS:M42:?match:no} which actually tests defined(NUMBERS). To determine if any words match .Dq 42 , you need to use something like: .Dl ${"${NUMBERS:M42}" != \&"\&":?match:no} . .It Cm :\| Ns Ar old_string\| Ns Cm = Ns Ar new_string This is the .At V style substitution. It can only be the last modifier specified, as a .Ql \&: in either .Ar old_string or .Ar new_string is treated as a regular character, not as the end of the modifier. .Pp If .Ar old_string does not contain the pattern matching character .Ql % , and the word ends with .Ar old_string or equals it, that suffix is replaced with .Ar new_string . .Pp Otherwise, the first .Ql % in .Ar old_string matches a possibly empty substring of arbitrary characters, and if the whole pattern is found in the word, the matching part is replaced with .Ar new_string , and the first occurrence of .Ql % in .Ar new_string (if any) is replaced with the substring matched by the .Ql % . .Pp Both .Ar old_string and .Ar new_string may contain nested expressions. To prevent a dollar sign from starting a nested expression, escape it with a backslash. .Sm off .It Cm \&:@ Ar varname\| Cm @ Ar string\| Cm @ .Sm on This is the loop expansion mechanism from the OSF Development Environment (ODE) make. Unlike .Cm \&.for loops, expansion occurs at the time of reference. For each word in the value, assign the word to the variable named .Ar varname and evaluate .Ar string . The ODE convention is that .Ar varname should start and end with a period, for example: .Dl ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@} .Pp However, a single-letter variable is often more readable: .Dl ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@} .It Cm \&:_ Ns Oo Cm = Ns Ar var Oc Saves the current variable value in .Ql $_ or the named .Ar var for later reference. Example usage: .Bd -literal -offset indent M_cmpv.units = 1 1000 1000000 M_cmpv = S,., ,g:_:range:@i@+ $${_:[-$$i]} \&\\ \\* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh .Dv .if ${VERSION:${M_cmpv}} < ${3.1.12:L:${M_cmpv}} .Ed Here .Ql $_ is used to save the result of the .Ql :S modifier which is later referenced using the index values from .Ql :range . .It Cm \&:U\| Ns Ar newval If the variable is undefined, .Ar newval is the value. If the variable is defined, the existing value is returned. This is another ODE make feature. It is handy for setting per-target CFLAGS for instance: .Dl ${_${.TARGET:T}_CFLAGS:U${DEF_CFLAGS}} If a value is only required if the variable is undefined, use: .Dl ${VAR:D:Unewval} .It Cm \&:D\| Ns Ar newval If the variable is defined, .Ar newval is the value. .It Cm \&:L The name of the variable is the value. .It Cm \&:P The path of the node which has the same name as the variable is the value. If no such node exists or its path is null, the name of the variable is used. In order for this modifier to work, the name (node) must at least have appeared on the right-hand side of a dependency. .Sm off .It Cm \&:\&! Ar cmd\| Cm \&! .Sm on The output of running .Ar cmd is the value. .It Cm \&:sh The value is run as a command, and the output becomes the new value. .It Cm \&::= Ns Ar str The variable is assigned the value .Ar str after substitution. This modifier and its variations are useful in obscure situations such as wanting to set a variable at a point where a target's shell commands are being parsed. These assignment modifiers always expand to nothing. .Pp The .Sq Cm \&:: helps avoid false matches with the .At V style .Ql \&:= modifier and since substitution always occurs, the .Ql \&::= form is vaguely appropriate. .It Cm \&::?= Ns Ar str As for .Cm \&::= but only if the variable does not already have a value. .It Cm \&::+= Ns Ar str Append .Ar str to the variable. .It Cm \&::!= Ns Ar cmd Assign the output of .Ar cmd to the variable. .It Cm \&:\&[ Ns Ar range Ns Cm \&] Selects one or more words from the value, or performs other operations related to the way in which the value is split into words. .Pp An empty value, or a value that consists entirely of white-space, is treated as a single word. For the purposes of the .Sq Cm \&:[] modifier, the words are indexed both forwards using positive integers (where index 1 represents the first word), and backwards using negative integers (where index \-1 represents the last word). .Pp The .Ar range is subjected to variable expansion, and the expanded result is then interpreted as follows: .Bl -tag -width index .\" :[n] .It Ar index Selects a single word from the value. .\" :[start..end] .It Ar start Ns Cm \&.. Ns Ar end Selects all words from .Ar start to .Ar end , inclusive. For example, .Sq Cm \&:[2..-1] selects all words from the second word to the last word. If .Ar start is greater than .Ar end , the words are output in reverse order. For example, .Sq Cm \&:[-1..1] selects all the words from last to first. If the list is already ordered, this effectively reverses the list, but it is more efficient to use .Sq Cm \&:Or instead of .Sq Cm \&:O:[-1..1] . .\" :[*] .It Cm \&* Causes subsequent modifiers to treat the value as a single word (possibly containing embedded whitespace). Analogous to the effect of .Li \&$* in Bourne shell. .\" :[0] .It 0 Means the same as .Sq Cm \&:[*] . .\" :[*] .It Cm \&@ Causes subsequent modifiers to treat the value as a sequence of words delimited by whitespace. Analogous to the effect of .Li \&$@ in Bourne shell. .\" :[#] .It Cm \&# Returns the number of words in the value. .El \" :[range] .El .Sh DIRECTIVES .Nm offers directives for including makefiles, conditionals and for loops. All these directives are identified by a line beginning with a single dot .Pq Ql \&. character, followed by the keyword of the directive, such as .Cm include or .Cm if . .Ss File inclusion Files are included with either .Cm \&.include \&< Ns Ar file Ns Cm \&> or .Cm \&.include \&\*q Ns Ar file Ns Cm \&\*q . Variables between the angle brackets or double quotes are expanded to form the file name. If angle brackets are used, the included makefile is expected to be in the system makefile directory. If double quotes are used, the including makefile's directory and any directories specified using the .Fl I option are searched before the system makefile directory. .Pp For compatibility with other make variants, .Sq Cm include Ar file No ... (without leading dot) is also accepted. .Pp If the include statement is written as .Cm .-include or as .Cm .sinclude , errors locating and/or opening include files are ignored. .Pp If the include statement is written as .Cm .dinclude , not only are errors locating and/or opening include files ignored, but stale dependencies within the included file are ignored just like in .Va .MAKE.DEPENDFILE . .Ss Exporting variables The directives for exporting and unexporting variables are: .Bl -tag -width Ds .It Ic .export Ar variable No ... Export the specified global variable. If no variable list is provided, all globals are exported except for internal variables (those that start with .Ql \&. ) . This is not affected by the .Fl X flag, so should be used with caution. For compatibility with other make programs, .Cm export Ar variable\| Ns Cm \&= Ns Ar value (without leading dot) is also accepted. .Pp Appending a variable name to .Va .MAKE.EXPORTED is equivalent to exporting a variable. .It Ic .export-env Ar variable No ... The same as .Ql .export , except that the variable is not appended to .Va .MAKE.EXPORTED . This allows exporting a value to the environment which is different from that used by .Nm internally. .It Ic .export-literal Ar variable No ... The same as .Ql .export-env , except that variables in the value are not expanded. .It Ic .unexport Ar variable No ... The opposite of .Ql .export . The specified global .Ar variable is removed from .Va .MAKE.EXPORTED . If no variable list is provided, all globals are unexported, and .Va .MAKE.EXPORTED deleted. .It Ic .unexport-env Unexport all globals previously exported and clear the environment inherited from the parent. This operation causes a memory leak of the original environment, so should be used sparingly. Testing for .Va .MAKE.LEVEL being 0 would make sense. Also note that any variables which originated in the parent environment should be explicitly preserved if desired. For example: .Bd -literal -offset indent .Li .if ${.MAKE.LEVEL} == 0 PATH := ${PATH} .Li .unexport-env .Li .export PATH .Li .endif .Pp .Ed Would result in an environment containing only .Sq Ev PATH , which is the minimal useful environment. .\" TODO: Check the below sentence, environment variables don't start with '.'. Actually .Sq Va .MAKE.LEVEL is also pushed into the new environment. .El .Ss Messages The directives for printing messages to the output are: .Bl -tag -width Ds .It Ic .info Ar message The message is printed along with the name of the makefile and line number. .It Ic .warning Ar message The message prefixed by .Sq Li warning: is printed along with the name of the makefile and line number. .It Ic .error Ar message The message is printed along with the name of the makefile and line number, .Nm exits immediately. .El .Ss Conditionals The directives for conditionals are: .ds maybenot Oo Ic \&! Oc Ns .Bl -tag .It Ic .if \*[maybenot] Ar expression Op Ar operator expression No ... Test the value of an expression. .It Ic .ifdef \*[maybenot] Ar variable Op Ar operator variable No ... Test whether a variable is defined. .It Ic .ifndef \*[maybenot] Ar variable Op Ar operator variable No ... Test whether a variable is not defined. .It Ic .ifmake \*[maybenot] Ar target Op Ar operator target No ... Test the target being requested. .It Ic .ifnmake \*[maybenot] Ar target Op Ar operator target No ... Test the target being requested. .It Ic .else Reverse the sense of the last conditional. .It Ic .elif \*[maybenot] Ar expression Op Ar operator expression No ... A combination of .Sq Ic .else followed by .Sq Ic .if . .It Ic .elifdef \*[maybenot] Ar variable Op Ar operator variable No ... A combination of .Sq Ic .else followed by .Sq Ic .ifdef . .It Ic .elifndef \*[maybenot] Ar variable Op Ar operator variable No ... A combination of .Sq Ic .else followed by .Sq Ic .ifndef . .It Ic .elifmake \*[maybenot] Ar target Op Ar operator target No ... A combination of .Sq Ic .else followed by .Sq Ic .ifmake . .It Ic .elifnmake \*[maybenot] Ar target Op Ar operator target No ... A combination of .Sq Ic .else followed by .Sq Ic .ifnmake . .It Ic .endif End the body of the conditional. .El .Pp The .Ar operator may be any one of the following: .Bl -tag .It Ic \&|\&| Logical OR. .It Ic \&&& Logical AND; of higher precedence than .Sq Ic \&|\&| . .El .Pp .Nm only evaluates a conditional as far as is necessary to determine its value. Parentheses can be used to override the operator precedence. The boolean operator .Sq Ic \&! may be used to logically negate an entire conditional. It is of higher precedence than .Sq Ic \&&& . .Pp The value of .Ar expression may be any of the following function call expressions: .Bl -tag .Sm off .It Ic defined Li \&( Ar varname Li \&) .Sm on Evaluates to true if the variable .Ar varname has been defined. .Sm off .It Ic make Li \&( Ar target Li \&) .Sm on Evaluates to true if the target was specified as part of .Nm Ns 's command line or was declared the default target (either implicitly or explicitly, see .Va .MAIN ) before the line containing the conditional. .Sm off .It Ic empty Li \&( Ar varname Oo Li : Ar modifiers Oc Li \&) .Sm on Evaluates to true if the expansion of the variable, after applying the modifiers, results in an empty string. .Sm off .It Ic exists Li \&( Ar pathname Li \&) .Sm on Evaluates to true if the given pathname exists. If relative, the pathname is searched for on the system search path (see .Va .PATH ) . .Sm off .It Ic target Li \&( Ar target Li \&) .Sm on Evaluates to true if the target has been defined. .Sm off .It Ic commands Li \&( Ar target Li \&) .Sm on Evaluates to true if the target has been defined and has commands associated with it. .El .Pp .Ar Expression may also be an arithmetic or string comparison. Variable expansion is performed on both sides of the comparison. If both sides are numeric and neither is enclosed in quotes, the comparison is done numerically, otherwise lexicographically. A string is interpreted as hexadecimal integer if it is preceded by .Li 0x , otherwise it is a decimal floating-point number; octal numbers are not supported. .Pp All comparisons may use the operators .Sq Ic \&== and .Sq Ic \&!= . Numeric comparisons may also use the operators .Sq Ic \&< , .Sq Ic \&<= , .Sq Ic \&> and .Sq Ic \&>= . .Pp If the comparison has neither a comparison operator nor a right side, the expression evaluates to true if it is nonempty and its numeric value (if any) is not zero. .Pp When .Nm is evaluating one of these conditional expressions, and it encounters a (whitespace separated) word it doesn't recognize, either the .Dq make or .Dq defined function is applied to it, depending on the form of the conditional. If the form is .Sq Ic .ifdef , .Sq Ic .ifndef or .Sq Ic .if , the .Dq defined function is applied. Similarly, if the form is .Sq Ic .ifmake or .Sq Ic .ifnmake , the .Dq make function is applied. .Pp If the conditional evaluates to true, parsing of the makefile continues as before. If it evaluates to false, the following lines are skipped. In both cases, this continues until the corresponding .Sq Ic .else or .Sq Ic .endif is found. .Ss For loops For loops are typically used to apply a set of rules to a list of files. The syntax of a for loop is: .Pp .Bl -tag -compact -width Ds .It Ic \&.for Ar variable Oo Ar variable No ... Oc Ic in Ar expression .It Aq Ar make-lines .It Ic \&.endfor .El .Pp The .Ar expression is expanded and then split into words. On each iteration of the loop, one word is taken and assigned to each .Ar variable , in order, and these .Ar variables are substituted into the .Ar make-lines inside the body of the for loop. The number of words must come out even; that is, if there are three iteration variables, the number of words provided must be a multiple of three. .Pp If .Sq Ic .break is encountered within a .Cm \&.for loop, it causes early termination of the loop, otherwise a parse error. .\" TODO: Describe limitations with defined/empty. .Ss Other directives .Bl -tag -width Ds .It Ic .undef Ar variable No ... Un-define the specified global variables. Only global variables can be un-defined. .El .Sh COMMENTS Comments begin with a hash .Pq Ql \&# character, anywhere but in a shell command line, and continue to the end of an unescaped new line. .Sh SPECIAL SOURCES (ATTRIBUTES) .Bl -tag -width .IGNOREx .It Ic .EXEC Target is never out of date, but always execute commands anyway. .It Ic .IGNORE Ignore any errors from the commands associated with this target, exactly as if they all were preceded by a dash .Pq Ql \- . .\" .It Ic .INVISIBLE .\" XXX .\" .It Ic .JOIN .\" XXX .It Ic .MADE Mark all sources of this target as being up to date. .It Ic .MAKE Execute the commands associated with this target even if the .Fl n or .Fl t options were specified. Normally used to mark recursive .Nm Ns s . .It Ic .META Create a meta file for the target, even if it is flagged as .Ic .PHONY , .Ic .MAKE , or .Ic .SPECIAL . Usage in conjunction with .Ic .MAKE is the most likely case. In .Dq meta mode, the target is out-of-date if the meta file is missing. .It Ic .NOMETA Do not create a meta file for the target. Meta files are also not created for .Ic .PHONY , .Ic .MAKE , or .Ic .SPECIAL targets. .It Ic .NOMETA_CMP Ignore differences in commands when deciding if target is out of date. This is useful if the command contains a value which always changes. If the number of commands change, though, the target is still considered out of date. The same effect applies to any command line that uses the variable .Va .OODATE , which can be used for that purpose even when not otherwise needed or desired: .Bd -literal -offset indent skip-compare-for-some: @echo this is compared @echo this is not ${.OODATE:M.NOMETA_CMP} @echo this is also compared .Ed The .Cm \&:M pattern suppresses any expansion of the unwanted variable. .It Ic .NOPATH Do not search for the target in the directories specified by .Va .PATH . .It Ic .NOTMAIN Normally .Nm selects the first target it encounters as the default target to be built if no target was specified. This source prevents this target from being selected. .It Ic .OPTIONAL If a target is marked with this attribute and .Nm can't figure out how to create it, it ignores this fact and assumes the file isn't needed or already exists. .It Ic .PHONY The target does not correspond to an actual file; it is always considered to be out of date, and is not created with the .Fl t option. Suffix-transformation rules are not applied to .Ic .PHONY targets. .It Ic .PRECIOUS When .Nm is interrupted, it normally removes any partially made targets. This source prevents the target from being removed. .It Ic .RECURSIVE Synonym for .Ic .MAKE . .It Ic .SILENT Do not echo any of the commands associated with this target, exactly as if they all were preceded by an at sign .Pq Ql @ . .It Ic .USE Turn the target into .Nm Ns 's version of a macro. When the target is used as a source for another target, the other target acquires the commands, sources, and attributes (except for .Ic .USE ) of the source. If the target already has commands, the .Ic .USE target's commands are appended to them. .It Ic .USEBEFORE Like .Ic .USE , but instead of appending, prepend the .Ic .USEBEFORE target commands to the target. .It Ic .WAIT If .Ic .WAIT appears in a dependency line, the sources that precede it are made before the sources that succeed it in the line. Since the dependents of files are not made until the file itself could be made, this also stops the dependents being built unless they are needed for another branch of the dependency tree. So given: .Bd -literal x: a .WAIT b echo x a: echo a b: b1 echo b b1: echo b1 .Ed the output is always .Ql a , .Ql b1 , .Ql b , .Ql x . .Pp The ordering imposed by .Ic .WAIT is only relevant for parallel makes. .El .Sh SPECIAL TARGETS Special targets may not be included with other targets, i.e. they must be the only target specified. .Bl -tag -width .BEGINx .It Ic .BEGIN Any command lines attached to this target are executed before anything else is done. .It Ic .DEFAULT This is sort of a .Ic .USE rule for any target (that was used only as a source) that .Nm can't figure out any other way to create. Only the shell script is used. The .Va .IMPSRC variable of a target that inherits .Ic .DEFAULT Ns 's commands is set to the target's own name. .It Ic .DELETE_ON_ERROR If this target is present in the makefile, it globally causes make to delete targets whose commands fail. (By default, only targets whose commands are interrupted during execution are deleted. This is the historical behavior.) This setting can be used to help prevent half-finished or malformed targets from being left around and corrupting future rebuilds. .It Ic .END Any command lines attached to this target are executed after everything else is done successfully. .It Ic .ERROR Any command lines attached to this target are executed when another target fails. The .Va .ERROR_TARGET variable is set to the target that failed. See also .Va MAKE_PRINT_VAR_ON_ERROR . .It Ic .IGNORE Mark each of the sources with the .Ic .IGNORE attribute. If no sources are specified, this is the equivalent of specifying the .Fl i option. .It Ic .INTERRUPT If .Nm is interrupted, the commands for this target are executed. .It Ic .MAIN If no target is specified when .Nm is invoked, this target is built. .It Ic .MAKEFLAGS This target provides a way to specify flags for .Nm at the time when the makefiles are read. The flags are as if typed to the shell, though the .Fl f option has no effect. .\" XXX: NOT YET!!!! .\" .It Ic .NOTPARALLEL .\" The named targets are executed in non parallel mode. .\" If no targets are .\" specified, all targets are executed in non parallel mode. .It Ic .NOPATH Apply the .Ic .NOPATH attribute to any specified sources. .It Ic .NOTPARALLEL Disable parallel mode. .It Ic .NO_PARALLEL Synonym for .Ic .NOTPARALLEL , for compatibility with other pmake variants. .It Ic .NOREADONLY clear the read-only attribute from the global variables specified as sources. .It Ic .OBJDIR The source is a new value for .Sq Va .OBJDIR . If it exists, .Nm changes the current working directory to it and updates the value of .Sq Va .OBJDIR . .It Ic .ORDER In parallel mode, the named targets are made in sequence. This ordering does not add targets to the list of targets to be made. .Pp Since the dependents of a target do not get built until the target itself could be built, unless .Ql a is built by another part of the dependency graph, the following is a dependency loop: .Bd -literal \&.ORDER: b a b: a .Ed .Pp .\" XXX: NOT YET!!!! .\" .It Ic .PARALLEL .\" The named targets are executed in parallel mode. .\" If no targets are .\" specified, all targets are executed in parallel mode. .It Ic .PATH The sources are directories which are to be searched for files not found in the current directory. If no sources are specified, any previously specified directories are removed from the search path. If the source is the special .Ic .DOTLAST target, the current working directory is searched last. .It Ic .PATH. Ns Ar suffix Like .Ic .PATH but applies only to files with a particular suffix. The suffix must have been previously declared with .Ic .SUFFIXES . .It Ic .PHONY Apply the .Ic .PHONY attribute to any specified sources. .It Ic .POSIX If this is the first non-comment line in the main makefile, the variable .Va %POSIX is set to the value .Ql 1003.2 and the makefile .Ql is included if it exists, to provide POSIX-compatible default rules. If .Nm is run with the .Fl r flag, only .Ql posix.mk contributes to the default rules. .It Ic .PRECIOUS Apply the .Ic .PRECIOUS attribute to any specified sources. If no sources are specified, the .Ic .PRECIOUS attribute is applied to every target in the file. .It Ic .READONLY set the read-only attribute on the global variables specified as sources. .It Ic .SHELL Sets the shell that .Nm uses to execute commands in jobs mode. The sources are a set of .Ar field\| Ns Cm \&= Ns Ar value pairs. .Bl -tag -width ".Li hasErrCtls" .It Li name This is the minimal specification, used to select one of the built-in shell specs; .Li sh , .Li ksh , and .Li csh . .It Li path Specifies the absolute path to the shell. .It Li hasErrCtl Indicates whether the shell supports exit on error. .It Li check The command to turn on error checking. .It Li ignore The command to disable error checking. .It Li echo The command to turn on echoing of commands executed. .It Li quiet The command to turn off echoing of commands executed. .It Li filter The output to filter after issuing the .Li quiet command. It is typically identical to .Li quiet . .It Li errFlag The flag to pass the shell to enable error checking. .It Li echoFlag The flag to pass the shell to enable command echoing. .It Li newline The string literal to pass the shell that results in a single newline character when used outside of any quoting characters. .El Example: .Bd -literal \&.SHELL: name=ksh path=/bin/ksh hasErrCtl=true \e check="set \-e" ignore="set +e" \e echo="set \-v" quiet="set +v" filter="set +v" \e echoFlag=v errFlag=e newline="'\en'" .Ed .It Ic .SILENT Apply the .Ic .SILENT attribute to any specified sources. If no sources are specified, the .Ic .SILENT attribute is applied to every command in the file. .It Ic .STALE This target gets run when a dependency file contains stale entries, having .Va .ALLSRC set to the name of that dependency file. .It Ic .SUFFIXES Each source specifies a suffix to .Nm . If no sources are specified, any previously specified suffixes are deleted. It allows the creation of suffix-transformation rules. .Pp Example: .Bd -literal \&.SUFFIXES: .c .o \&.c.o: cc \-o ${.TARGET} \-c ${.IMPSRC} .Ed .It Ic .SYSPATH The sources are directories which are to be added to the system include path which .Nm searches for makefiles. If no sources are specified, any previously specified directories are removed from the system include path. .El .Sh ENVIRONMENT .Nm uses the following environment variables, if they exist: .Ev MACHINE , .Ev MACHINE_ARCH , .Ev MAKE , .Ev MAKEFLAGS , .Ev MAKEOBJDIR , .Ev MAKEOBJDIRPREFIX , .Ev MAKESYSPATH , .Ev PWD , and .Ev TMPDIR . .Pp .Ev MAKEOBJDIRPREFIX and .Ev MAKEOBJDIR may only be set in the environment or on the command line to .Nm and not as makefile variables; see the description of .Sq Va .OBJDIR for more details. .Sh FILES .Bl -tag -width /usr/share/mk -compact .It .depend list of dependencies .It makefile first default makefile if no makefile is specified on the command line .It Makefile second default makefile if no makefile is specified on the command line .It sys.mk system makefile .It /usr/share/mk system makefile directory .El .Sh COMPATIBILITY The basic make syntax is compatible between different make variants; however the special variables, variable modifiers and conditionals are not. .Ss Older versions An incomplete list of changes in older versions of .Nm : .Pp The way that .for loop variables are substituted changed after .Nx 5.0 so that they still appear to be variable expansions. In particular this stops them being treated as syntax, and removes some obscure problems using them in .if statements. .Pp The way that parallel makes are scheduled changed in .Nx 4.0 so that .ORDER and .WAIT apply recursively to the dependent nodes. The algorithms used may change again in the future. .Ss Other make dialects Other make dialects (GNU make, SVR4 make, POSIX make, etc.) do not support most of the features of .Nm as described in this manual. Most notably: .Bl -bullet -offset indent .It The .Ic .WAIT and .Ic .ORDER declarations and most functionality pertaining to parallelization. (GNU make supports parallelization but lacks the features needed to control it effectively.) .It Directives, including for loops and conditionals and most of the forms of include files. (GNU make has its own incompatible and less powerful syntax for conditionals.) .\" The "less powerful" above means that GNU make does not have the .\" make(target), target(target) and commands(target) functions. .It All built-in variables that begin with a dot. .It Most of the special sources and targets that begin with a dot, with the notable exception of .Ic .PHONY , .Ic .PRECIOUS , and .Ic .SUFFIXES . .It Variable modifiers, except for the .Ql :old=new string substitution, which does not portably support globbing with .Ql % and historically only works on declared suffixes. .It The .Ic $> variable even in its short form; most makes support this functionality but its name varies. .El .Pp Some features are somewhat more portable, such as assignment with .Ic += , .Ic ?= , and .Ic != . The .Va .PATH functionality is based on an older feature .Ic VPATH found in GNU make and many versions of SVR4 make; however, historically its behavior is too ill-defined (and too buggy) to rely upon. .Pp The .Ic $@ and .Ic $< variables are more or less universally portable, as is the .Ic $(MAKE) variable. Basic use of suffix rules (for files only in the current directory, not trying to chain transformations together, etc.) is also reasonably portable. .Sh SEE ALSO .Xr mkdep 1 .Sh HISTORY A .Nm command appeared in .At v7 . This .Nm implementation is based on Adam de Boor's pmake program, which was written for Sprite at Berkeley. It was designed to be a parallel distributed make running jobs on different machines using a daemon called .Dq customs . .Pp Historically the target/dependency .Ic FRC has been used to FoRCe rebuilding (since the target/dependency does not exist ... unless someone creates an .Pa FRC file). .Sh BUGS The .Nm syntax is difficult to parse. For instance, finding the end of a variable's use should involve scanning each of the modifiers, using the correct terminator for each field. In many places .Nm just counts {} and () in order to find the end of a variable expansion. .Pp There is no way of escaping a space character in a filename. .Pp In jobs mode, when a target fails; .Nm will put an error token into the job token pool. This will cause all other instances of .Nm using that token pool to abort the build and exit with error code 6. Sometimes the attempt to suppress a cascade of unnecessary errors, can result in a seemingly unexplained .Ql *** Error code 6 - - diff --git a/mk/ChangeLog b/mk/ChangeLog index 2e4b6516c5cc..15c3861ea701 100644 --- a/mk/ChangeLog +++ b/mk/ChangeLog @@ -1,2116 +1,2151 @@ +2023-05-10 Simon J Gerraty + + * meta.autodep.mk: if LOCAL_DEPENDS_GUARD is "no" + suppress processing of .depend + +2023-05-09 Simon J Gerraty + + * dirdeps.mk: do not add _CURDIR to DIRDEPS for SRCTOP + + * meta.sys.mk sys.dirdeps.mk: + originally DIRDEPS_BUILD and META_MODE were the same thing, + but META_MODE is useful by itself. + Move things from meta.sys.mk which actually pertain to + DIRDEPS_BUILD to sys.dirdeps.mk + +2023-05-04 Simon J Gerraty + + * install-mk (MK_VERSION): 20230504 May the Forth be with you + + * dirdeps.mk: as with meta.sys.mk we treat "host" as special. + DEP_TARGET_SPEC is just ${DEP_MACHINE} + + * meta.sys.mk: ensure DEP_* for TARGET_SPEC_VARS are set at + level > 0 since these are often refered to in Makefile.depend* + +2023-04-26 Simon J Gerraty + + * jobs.mk: report ${.TARGET} ${JOB_ARGS} ${JOB_LOG} and + anything in ${JOB_LOG_START} + + * jobs.mk: look for newlog.sh in ${.SYSPATH:U${.PARSEDIR}} + or a scripts subdir before searching $PATH. + + * FILES: include newlog.sh for jobs.mk + 2023-04-20 Simon J Gerraty * install-mk (MK_VERSION): 20230420 * lib.mk: include LDFLAGS and LDADD when linking shared libs * gendirdeps.mk: document setting GENDIRDEPS_FILTER_VARS etc via local.meta.sys.mk rather than local.gendirdeps.mk so DEP_* variables can be set at level 1+ to avoid syntax errors when used in conditionals in manually maintained Makefile.depend files. * dirdeps.mk: ensure M_dep_qual_fixes is applied to all _machines 2023-04-18 Simon J Gerraty * dirdeps.mk: check we were not included by Makefile.depend.options as the result is bad. 2023-04-14 Simon J Gerraty * install-mk (MK_VERSION): 20230414 * meta.sys.mk: since we have :range we can put the logic for processing TARGET_SPEC from env here. * dirdeps.mk: reset DIRDEPS and DEP_RELDIR before including local.dirdeps-missing.mk, also improve debug output. * dirdeps.mk: to allow make -f dirdeps.mk include.$TARGET_SPEC we need to use :M*[/.]* same as for when actually setting DIRDEPS from the targets on command line. 2023-04-12 Simon J Gerraty * Add jobs.mk 2023-03-21 Simon J Gerraty * install-mk (MK_VERSION): 20230321 * meta.stage.mk: allow STAGE_SHLIB_LINKS_FILTER to filter STAGE_LIBS for SHLIB_LINKS. * autoconf.mk: add .WAIT after config.status 2023-02-17 Simon J Gerraty * sys.vars.mk: add M_Index to report the index of a word in a list. 2023-02-15 Simon J Gerraty * install-mk (MK_VERSION): 20230215 * warnings.mk: allow better control of -Werror allow -Wno-error or similar to be added if WARNINGS_SET < WERROR_SET account for COMPILER_TYPE 2023-01-29 Simon J Gerraty * autoconf.mk: hook config.status to beforebuild. * whats.mk: what*.c is NOTMAIN 2023-01-27 Simon J Gerraty * install-mk (MK_VERSION): 20230127 control umask so directories are created with suitable mode. 2023-01-20 Simon J Gerraty * install-mk (MK_VERSION): 20230120 * sys.vars.mk: add M_On and M_Onr also cleanup to be more consistent wrt testing MAKE_VERSION 2023-01-12 Simon J Gerraty * install-mk (MK_VERSION): 20230112 * meta2deps.{py,sh}: assert if filemon data is truncated we should see the '# Bye bye' record - assert if we do not. 2022-09-09 Simon J Gerraty * install-mk (MK_VERSION): 20220909 * sys/Linux.mk set EGREP to grep -E to avoid deprecation warnings 2022-09-06 Simon J Gerraty * dirdeps-options.mk: explain the need to use ${DEP_${TARGET_SPEC_VAR}:U${TARGET_SPEC_VAR}} when refering to ${TARGET_SPEC_VAR} 2022-09-03 Simon J Gerraty * install-mk (MK_VERSION): 20220903 * M_cmpv handle more than 3 dots and clear leading 0's 2022-07-20 Simon J Gerraty * install-mk (MK_VERSION): 20220720 * prog.mk: handle PROG_CXX for more than just NetBSD 2022-06-20 Simon J Gerraty * install-mk (MK_VERSION): 20220620 * yacc.mk: when we have *.y in SRCS used explicit rules and .ORDER rather than just suffix rules 2022-04-23 Simon J Gerraty * install-mk (MK_VERSION): 20220422 * gendirdeps.mk: If LOCAL_DEPENDS_GUARD is set to "no" do not capture any local depends in Makefile.depend 2022-03-25 Simon J Gerraty * install-mk (MK_VERSION): 20220323 * posix.mk: default rules for .POSIX: 2022-03-17 Simon J Gerraty * sys/*.mk: remove l from ARFLAGS 2022-03-14 Simon J Gerraty * install-mk (MK_VERSION): 20220314 * dirdeps-options.mk: allow options to be per RELDIR try DIRDEPS_OPTIONS_QUALIFIER_LIST first prefixed with ${DEP_RELDIR}. 2022-02-14 Simon J Gerraty * install-mk (MK_VERSION): 20220214 * cc-wrap.mk: fix :@ modifier 2022-02-06 Simon J Gerraty * install-mk (MK_VERSION): 20220206 * cc-wrap.mk: docuement how CCACHE etc might be set for maximum flexibility 2022-02-05 Simon J Gerraty * sys.vars.mk: use JOT_CMD (jot or seq) if available for M_JOT 2022-02-04 Simon J Gerraty * install-mk (MK_VERSION): 20220204 * host-target.mk: use .MAKE.OS if available 2022-02-02 Simon J Gerraty * install-mk (MK_VERSION): 20220202 * cc-wrap.mk: allow other entries in CC_WRAP_FILTER We add our filter on extensions last, so prior filters can apply to the whole value of .IMPSRC 2022-02-01 Simon J Gerraty * cc-wrap.mk: take advantage of target local variables to wrap compilers like CC CXX with wrappers like ccache distcc etc 2022-01-28 Simon J Gerraty * meta2deps: we do not expect any trace data for setid apps 2022-01-26 Simon J Gerraty * dirdeps.mk: ensure TARGET_SPEC and TARGET_SPEC_VARS are passed to sub-make using DIRDEPS_CACHE 2022-01-07 Simon J Gerraty * dirdeps.mk: use _cache_script to minimize the number of shells forked when generating dirdeps.cache 2022-01-02 Simon J Gerraty * install-mk (MK_VERSION): 20220101 * dirdeps.mk: initialize DEP_* and _debug_reldir earlier. If initial DIRDEPS are from command line, create the target _dirdeps_cmdline as an indication. 2022-01-01 Simon J Gerraty * init.mk (_SKIP_BUILD): when doing DIRDEPS_BUILD at top-level only some targets are allowed at level 0, for leaf makefiles only the default (all) target is restricted 2021-12-28 Simon J Gerraty * install-mk (MK_VERSION): 20211228 * meta2deps.py: filemon on Linux is not as reliable as we might like, we do not want to update DIRDEPS if filemon output is incomplete. Track pids that we 'E'xec and make sure we see an e'X'it for each one. Throw an error if we are missing any 'X' records. 2021-12-12 Simon J Gerraty * sys.mk: simplify; include meta.sys.mk if MK_META_MODE is yes. * meta.sys.mk: do not check for /dev/filemon if .MAKE.PATH_FILEMON is something else. * meta.autodep.mk: we can now reference ${.SUFFIXES} * meta2deps.py: derive a list of dirdep extensions from TARGET_SPEC to trim from dirdeps. * dirdeps.mk: flip the computation of qualified vs unqualified dirdeps - it is much simpler to check for unqualified first. 2021-12-11 Simon J Gerraty * install-mk (MK_VERSION): 20211212 * auto.dep.mk: rearrange so that the trivial implementation for recent bmake is more obvious. 2021-12-07 Simon J Gerraty * install-mk (MK_VERSION): 20211207 * Ensure guard targets are .NOTMAIN * meta.sys.mk: check for nofilemon support when we skip level 0 * auto.dep.mk: make this usable in meta mode for platforms that cannot use meta.autodep.mk * meta2deps.py: avoid confusion if MACHINE and another TARGET_SPEC_VAR have same value. 2021-11-27 Simon J Gerraty * dirdeps.mk: when building dirdeps.cache, minimize the amount of data put into env, by stripping ${SRCTOP}/ from each entry. A long sandbox name can double the amount of memory consumed and in extreme cases cause failure. While we are at it, strip ${SRCTOP}/ from a lot of the debug output. 2021-11-11 Simon J Gerraty * install-mk (MK_VERSION): 20211111 * meta.stage.mk (LN_CP_SCRIPT): if staging to NFS cp -p can fail so fallback to cp if necessary. 2021-10-30 Simon J Gerraty * man.mk (CMT2DOC): use cmt2doc.py rather than the 30 year old cmt2doc.pl 2021-10-24 Simon J Gerraty * meta.stage.mk: stage_as_and_symlink use ${STAGE_LINK_AS_$f:U$f} as the symlink (rare) 2021-10-16 Simon J Gerraty * autoconf.mk: if AUTOCONF_GENERATED_MAKEFILE is set and has not been read, throw an error after running configure telling user to restart. 2021-10-13 Simon J Gerraty * install-mk (MK_VERSION): 20211011 * Add support for SCO_SV 2021-10-01 Simon J Gerraty * install-mk (MK_VERSION): 20211001 * man.mk: use MAN_SUFFIXES and CMT2DOC_SUFFIXES for more flexibility 2021-09-13 Simon J Gerraty * options.mk (describe-options): print options and their values and optional description 2021-09-11 Simon J Gerraty * install-mk (MK_VERSION): 20210911 * options.mk (show-options): print options and their values 2021-09-08 Simon J Gerraty * install-mk (MK_VERSION): 20210909 * lib.mk: apply patch from to fix shared libs on Linux 2021-08-08 Simon J Gerraty * install-mk (MK_VERSION): 20210808 * options.mk: issue warning for WITH_*=no 2021-06-16 Simon J Gerraty * install-mk (MK_VERSION): 20210616 * dirdeps.mk: when using .MAKE.DEPENDFILE_PREFERENCE to find depend files to read, anchor MACHINE at , or end of string to avoid prefix match. 2021-05-04 Simon J Gerraty * install-mk (MK_VERSION): 20210504 * dirdeps.mk: re-implement ALL_MACHINES support to better cater for local complexities, when ONLY_TARGET_SPEC_LIST is not set. local.dirdeps.mk can set DIRDEPS_ALL_MACHINES_FILTER and/or DIRDEPS_ALL_MACHINES_FILTER_XTRAS to filter the results we get from listing all existing Makefile.depend.* 2021-04-20 Simon J Gerraty * install-mk (MK_VERSION): 20210420 * dirdeps.mk: revert previous - not always safe. 2021-03-20 Simon J Gerraty * install-mk (MK_VERSION): 20210321 * dirdeps.mk: when generating dirdeps.cache we only need to hook the initial DIRDEPS to the dirdeps target. That and any _build_xtra_dirs (like tests which should not be hooked directly to the dependency graph - to avoid cycles) 2021-01-30 Simon J Gerraty * install-mk (MK_VERSION): 20210130 * dirdeps.mk: expr 2 - 1 - 1 exits with a bad status we need to guard against this in DIRDEP_LOADAVG_REPORT. * dirdeps.mk: restore respect for TARGET_MACHINE 2021-01-06 Simon J Gerraty * install-mk (MK_VERSION): 20210101 * dirdeps.mk: first time we are read, just use TARGET_SPEC for _DEP_TARGET_SPEC 2020-12-22 Simon J Gerraty * sys.mk (MAKE_SHELL): use ${.SHELL:Ush} and use := when setting SHELL 2020-12-21 Simon J Gerraty * install-mk (MK_VERSION): 20201221 * dirdeps-options.mk: latest bmake allows only one arg to .undef 2020-12-11 Simon J Gerraty * dirdeps-targets.mk: allow for "." in DIRDEPS_TARGETS_DIRS so that any directory can be treated as a target. 2020-11-26 Simon J Gerraty * install-mk (MK_VERSION): 20201126 * own.mk: use .MAKE.{UID,GID} if available. * init.mk: suppress _SKIP_BUILD warning if doing -V 2020-11-20 Simon J Gerraty * install-mk (MK_VERSION): 20201120 * init.mk: rename LEVEL0_TARGETS to DIRDEPS_BUILD_LEVEL0_TARGETS * dirdeps-targets.mk: fix typo in comment 2020-11-06 Simon J Gerraty * install-mk (MK_VERSION): 20201106 * meta.autodep.mk: use OBJ_EXTENSIONS rather than hardcode sed args to tweak extensions for local deps. 2020-11-01 Simon J Gerraty * install-mk (MK_VERSION): 20201101 * dirdeps.mk: most leaf makefiles are not suitable for building dirdeps.cache so if RELDIR is not "." use dirdeps.mk 2020-10-28 Simon J Gerraty * install-mk (MK_VERSION): 20201028 * dirdeps.mk: if we don't have :range use equivalent of M_RANGE when building dirdeps.cache for leaf directory use -f dirdeps.mk * sys.vars.mk: add M_JOT and M_RANGE 2020-10-01 Simon J Gerraty * install-mk (MK_VERSION): 20201001 * meta2deps.{py,sh}: throw an error if we don't see filemon version 2020-09-09 Simon J Gerraty * install-mk (MK_VERSION): 20200909 * dirdeps-cache-update.mk: use cache_update_dirdep as guard target 2020-08-26 Simon J Gerraty * dirdeps.mk: ensure we cannot confuse a static cache for dynamic (even more rare that use of static cache is playing clever tricks with it) 2020-08-16 Simon J Gerraty * dirdeps-cache-update.mk: allow MK_STATIC_DIRDEPS_CACHE_UPDATE_IMMEDIATE to control when we actually update STATIC_DIRDEPS_CACHE. * stage-install.sh: create dest directory if needed before running install(1) 2020-08-10 Simon J Gerraty * dirdeps-targets.mk: include Makefile.dirdeps.options * dirdeps.mk: use _TARGETS if defined for DIRDEPS_CACHE 2020-08-09 Simon J Gerraty * dirdeps.mk: default BUILD_DIRDEPS_MAKEFILE to empty * dirdeps-cache-update.mk: building parallel cache update under the context of dirdeps-cached would be ideal, but is problematic, so it runs as a sibling. Use cache-built target to ensure we wait for it to complete if necessary. 2020-08-06 Simon J Gerraty * install-mk (MK_VERSION): 20200806 * dirdeps-options: allow TARGET_SPEC to affect option values. Use DIRDEPS_OPTIONS_QUALIFIER_LIST before using bare MK_* * dirdeps-targets.mk: check for MK_STATIC_DIRDEPS_CACHE defined before looking for STATIC_DIRDEPS_CACHE 2020-08-05 Simon J Gerraty * host-target.mk: Darwin use MACHINE for HOST_ARCH too * dirdeps-options.mk: improve debug output 2020-07-22 Simon J Gerraty * dirdeps.mk: set and export DYNAMIC_DIRDEPS_CACHE for use by dirdeps-cache-update.mk * dirdeps-targets.mk: set and export STATIC_DIRDEPS_CACHE for use by dirdeps-cache-update.mk even if we don't use it. * dirdeps-cache-update.mk: we only need worry about the background update case, with the above, the update from DIRDEPS_CACHE is simple. * meta2deps.py: R 1234 . is not interesting 2020-07-20 Simon J Gerraty * sys.mk: default MK_STATIC_DIRDEPS_CACHE from MK_DIRDEPS_CACHE * dirdeps-options.mk: do not :tu DIRDEPS_OPTIONS allows use of lower case for pseudo options. * dirdeps-cache-update.mk: magic to deal with STATIC_DIRDEPS_CACHE 2020-07-18 Simon J Gerraty * dirdeps-targets.mk: Look for Makefile.dirdeps.cache which allows us to have a static cache for expensive targets. Use -DWITHOUT_STATIC_DIRDEPS_CACHE -DWITH_DIRDEPS_CACHE to regenerate the dirdeps.cache it is a copy of. 2020-07-17 Simon J Gerraty * Get rid of BUILD_AT_LEVEL0, MK_DIRDEPS_BUILD makes more sense. 2020-07-16 Simon J Gerraty * dirdeps.mk (DIRDEP_LOADAVG_REPORT): make it easy to record load averages at intervals during build. 2020-07-15 Simon J Gerraty * install-mk (MK_VERSION): 20200715 * dirdeps.mk: tweak Checking line to make matching Finished lines for post-build analysis easier. * meta.autodep.mk: use !defined(WITHOUT_META_STATS) * progs.mk: avoid prog.mk outputting multiple Finished lines 2020-07-11 Simon J Gerraty * dirdeps.mk: further optimize dirdeps.cache generate a DIRDEPS.${.TARGET} list for other purposes and improve the layout. 2020-07-10 Simon J Gerraty * dirdeps.mk: optimize content of dirdeps.cache 2020-06-28 Simon J Gerraty * sys/*.mk: make it easier for local*sys.mk to customize by using ?= 2020-06-22 Simon J Gerraty * gendirdeps.mk (LOCAL_DEPENDS_GUARD): if we don't build at level 0 it is much safer to guard local depends with a simple check for .MAKE.LEVEL > 0 2020-06-10 Simon J Gerraty * install-mk (MK_VERSION): 20200610 * mkopt.sh: this needs posix shell so #!/bin/sh should be ok 2020-06-06 Simon J Gerraty * install-mk (MK_VERSION): 20200606 * dirdeps-targets.mk: allow for filtering of .TARGETS * meta2deps.py: fix bug in processing 'L'ink and 'M'ove entries - and we don't care about 'W'rite entries. Also ignore absolute paths that do not exist. 2020-05-25 Simon J Gerraty * install-mk (MK_VERSION): 20200525 * init.mk: expand and simplify handling of qualified vars like CPPFLAGS.${.TARGET:T} 2020-05-15 Simon J Gerraty * install-mk (MK_VERSION): 20200515 * dirdeps.mk: set _debug_* earlier and allow passing -d* flags to submake when building DIRDEPS_CACHE 2020-05-09 Simon J Gerraty * whats.mk: more easily extensible 2020-05-02 Simon J Gerraty * whats.mk: greatly simplify by adding what.c to SRCS 2020-05-01 Simon J Gerraty * whats.mk: for libs take care how we add to *OBJS * lib.mk: : works better with whats.mk 2020-04-25 Simon J Gerraty * install-mk (MK_VERSION): 20200420 * meta.stage.mk: it is not a STAGE_CONFLICT if some-target.dirdep contains the same ${RELDIR} and a prefix match for our ${TARGET_SPEC} 2020-04-16 Simon J Gerraty * install-mk (MK_VERSION): 20200416 * sys/*.mk: set MAKE_SHELL rather than SHELL so as not to interfere with user env. * sys.mk: default MAKE_SHELL to sh and SHELL to MAKE_SHELL * autodep.mk: use MAKE_SHELL. 2019-11-21 Simon J Gerraty * gendirdeps.mk: clear .SUFFIXES to avoid a lot of wasted effort, and unexport _meta_files when no longer needed as it consumes space we need for command line. 2019-11-11 Simon J Gerraty * dirdeps.mk _DIRDEP_USE: use DIRDEP_DIR and add DIRDEP_USE_PRELUDE at start - facilitates job distribution 2019-10-04 Simon J Gerraty * dirdeps-targets.mk: Use TARGET_SPEC_LAST_LIST defaults to ${${TARGET_SPEC_VARS:[-1]}_LIST} to match valid TARGET_SPEC qualified depend files. 2019-10-02 Simon J Gerraty * dirdeps-targets.mk: encapsulate logic for finding top-level targets to set initial DIRDEPS for DIRDEPS_BUILD 2019-09-27 Simon J Gerraty * install-mk (MK_VERSION): 20190911 * compiler.mk: set COMPILER_TYPE 2019-07-17 Simon J Gerraty * install-mk (MK_VERSION): 20190704 * sys/Darwin.mk: support for Objective-C and clang 2019-05-30 Simon J Gerraty * dirdeps.mk: avoid insanely long command line when generating cache 2019-05-23 Simon J Gerraty * install-mk (MK_VERSION): 20190505 * whats.mk: handle corner case SHLIB defined but not LIB 2018-09-19 Simon J Gerraty * install-mk (MK_VERSION): 20180919 * dirdeps-options.mk: .undef cannot handle var that expands to more than one var. 2018-07-08 Simon J Gerraty * meta.stage.mk: allow wildcards in STAGE_FILES.* etc. 2018-06-01 Simon J Gerraty * meta.autodep.mk: export META_FILES to avoid command line limit * gendirdeps.mk: if we have lots of .meta files put them in an @list 2018-05-28 Simon J Gerraty * dirdeps-options.mk: use local.dirdeps-options.mk not local.dirdeps-option.mk 2018-04-20 Simon J Gerraty * install-mk (MK_VERSION): 20180420 * dirdeps.mk: include local.dirdeps-build.mk when .MAKE.LEVEL > 0 ie. we are building something. 2018-04-14 Simon J Gerraty * FILES: add dirdeps-options.mk to deal with optional DIRDEPS. 2018-04-05 Simon J Gerraty * install-mk (MK_VERSION): 20180405 * ldorder.mk: describe how to use LDORDER_EXTERN_BARRIER if needed. 2018-01-18 Simon J Gerraty * install-mk (MK_VERSION): 20180118 * ldorder.mk: let make compute correct link order 2017-12-12 Simon J Gerraty * install-mk (MK_VERSION): 20171212 * gendirdeps.mk: guard against bogus entries in GENDIRDEPS_FILTER 2017-11-14 Simon J. Gerraty * install-mk (MK_VERSION): 20171111 * lib.mk: ensure META_NOECHO is set 2017-10-25 Simon J. Gerraty * Allow for host32 on rare occasions. 2017-10-18 Simon J. Gerraty * install-mk (MK_VERSION): 20171018 * whats.mk: include what_thing in what_uuid to avoid problem when building multiple apps in the same directory. 2017-08-12 Simon J. Gerraty * install-mk (MK_VERSION): 20170812 * autoconf.mk: Use CONFIGURE_DEPS so Makefile can add dependencies for config.recheck and config.gen 2017-06-30 Simon J. Gerraty * install-mk (MK_VERSION): 20170630 * meta.stage.mk: avoid triggering stage_* targets with nothing to do. 2017-05-23 Simon J. Gerraty * meta2deps.py: take special care of '..' 2017-05-15 Simon J. Gerraty * install-mk (MK_VERSION): 20170515 * dirdeps.mk (DEP_EXPORT_VARS): on rare occasions it is useful/necessary for a Makefile.depend file to export some knobs. This is complicated when we are doing DIRDEPS_CACHE, so we will handle export of any variables listed in DEP_EXPORT_VARS. 2017-05-08 Simon J. Gerraty * install-mk (MK_VERSION): 20170505 * meta2deps.py: fix botched indenation. 2017-05-05 Simon J. Gerraty * sys/*.mk: Remove setting of MAKE it is unnecessary and in many cases wrong (basname rather than full path) * scripts.mk (SCRIPTSGROUPS): make this more like files.mk and inc.mk * init.mk: define realbuild to simplify logic in {lib,prog}.mk etc 2017-05-01 Simon J. Gerraty * install-mk (MK_VERSION): 20170501 * doc.mk: fix typo in DOC_INSTALL_OWN * inc.mk: handle INCGROUPS similar to freebsd * files.mk: add something for files too * add staging logic to lib.mk prog.mk etc. 2017-04-24 Simon J. Gerraty * install-mk (MK_VERSION): 20170424 * dirdeps.mk: set NO_DIRDEPS when bootstrapping. also target of bootstrap-this when sed is needed should be ${_want:T} 2017-04-18 Simon J. Gerraty * install-mk (MK_VERSION): 20170418 * auto.obj.mk: if using MAKEOBJDIRPREFIX check if it is a prefix match for .CURDIR - in which case .CURDIR *is* __objdir. 2017-04-01 Simon J. Gerraty * install-mk (MK_VERSION): 20170401 * meta2deps.py: add is_src so we can check if obj dependency is also a src dependency. 2017-03-26 Simon J. Gerraty * install-mk (MK_VERSION): 20170326 * meta.stage.mk: do nothing if NO_STAGING is defined. 2017-03-24 Simon J. Gerraty * auto.obj.mk: handle the case of __objdir=obj or obj.${MACHINE} etc. 2017-03-18 Simon J. Gerraty * mkopt.sh: treat WITH_*=NO like no; ie. WITHOUT_* 2017-03-01 Simon J. Gerraty * install-mk (MK_VERSION): 20170301 * dirdeps.mk (_build_all_dirs): update this outside test for empty DIRDEPS. * meta.stage.mk: allow multiple inclusion to the extent it makes sense. 2017-02-14 Simon J. Gerraty * prog.mk (install_links): depends on realinstall 2017-02-12 Simon J. Gerraty * install-mk (MK_VERSION): 20170212 * dpadd.mk: avoid applying :T:R twice to DPLIBS entries 2017-01-30 Simon J. Gerraty * install-mk (MK_VERSION): 20170130 * dirdeps.mk: use :range if we can. * sys.vars.mk: provide M_cmpv if MAKE_VERSION >= 20170130 * meta2deps.py: clean paths without using realpath() where possible. fix sort_unique. 2016-12-12 Simon J. Gerraty * install-mk (MK_VERSION): 20161212 * meta2deps.py: set pid_cwd[pid] when we process 'C'hdir, rather than when we detect pid change. 2016-12-07 Simon J. Gerraty * install-mk (MK_VERSION): 20161207 * meta.stage.mk: add stage_as_and_symlink for staging packages. We build foo.tgz stage_as foo-${VERSION}.tgz but want to be able to use foo.tgz to reference the latest staged version - so we make foo.tgz a symlink to it. Using a target to do both operations ensures we stay in sync. 2016-11-26 Simon J. Gerraty * install-mk (MK_VERSION): 20161126 * dirdeps.mk: set DIRDEPS_CACHE before we include local.dirdeps.mk so it can add dependencies. 2016-10-10 Simon J. Gerraty * dirdeps.mk: set DEP_* before we expand .MAKE.DEPENDFILE_PREFERENCE do that they can influence the result correctly. * dirdeps.mk (${DIRDEPS_CACHE}): make sure we pass on TARGET_SPEC * dirdeps.mk: Add ONLY_TARGET_SPEC_LIST and NOT_TARGET_SPEC_LIST similar to ONLY_MACHINE_LIST and NOT_MACHINE_LIST 2016-10-05 Simon J. Gerraty * dirdeps.mk: remove dependence on jot (normal situations anyway). Before we read another Makefile.depend* set DEP_* vars from _DEP_TARGET_SPEC in case it uses any of them with := When bootstrapping, trim any ,* from extention of chosen _src Makefile.depend* to get the machine value we subst for. 2016-09-30 Simon J. Gerraty * dirdeps.mk: use TARGET_SPEC_VARS to qualify components added to DEP_SKIP_DIR and DEP_DIRDEPS_FILTER * sys.mk: extract some bits to sys.{debug,vars}.mk for easier re-use by others. 2016-09-23 Simon Gerraty * lib.mk: Use ${PICO} for extension for PIC objects. default to .pico (like NetBSD) safe on case insensitive filesystem. 2016-08-19 Simon J. Gerraty * meta.sys.mk (META_COOKIE_TOUCH): use ${.OBJDIR}/${.TARGET:T} as default 2016-08-15 Simon J. Gerraty * install-mk (MK_VERSION): 20160815 * dirdeps.mk (.MAKE.META.IGNORE_FILTER): set filter to only consider Makefile.depend* when checking if DIRDEPS_CACHE is up-to-date. 2016-08-13 Simon J. Gerraty * meta.sys.mk (.MAKE.META.IGNORE_PATHS): in meta mode we can ignore the mtime of makefiles 2016-08-02 Simon J. Gerraty * install-mk (MK_VERSION): 20160802 * lib.mk (libinstall): depends on beforinstall * prog.mk (proginstall): depends on beforinstall patch from Lauri Tirkkonen * dirdeps.mk (bootstrap): When bootstrapping; creat .MAKE.DEPENDFILE_DEFAULT and allow additional filtering via .MAKE.DEPENDFILE_BOOTSTRAP_SED * dirdeps.mk: move some comments to where they make sense. 2016-07-27 Simon J. Gerraty * dirdeps.mk (DIRDEPS_CACHE): no dirname. 2016-06-02 Simon J. Gerraty * install-mk (MK_VERSION): 20160602 * meta.autodep.mk: when passing META_FILES to gendirdeps.mk do not apply :T to META_XTRAS patch from Bryan Drewery at FreeBSD.org. 2016-05-30 Simon J. Gerraty * install-mk (MK_VERSION): 20160530 * meta.stage.mk: we assume ${CLEANFILES} gets .NOPATH make it so. 2016-05-12 Simon J. Gerraty * install-mk (MK_VERSION): 20160512 * dpadd.mk: always include local.dpadd.mk if it exists remove some things that better belong in local.dpadd.mk skip INCLUDES_* for staged libs unless SRC_* defined. * own.mk: add INCLUDEDIR 2016-04-18 Simon J. Gerraty * dirdeps.mk: when doing -f dirdeps.mk if target suppies no TARGET_MACHINE - :E will be empty or match part of path, use ${MACHINE} 2016-04-07 Simon J. Gerraty * meta.autodep.mk: issue a warning if UPDATE_DEPENDFILE=NO due to NO_FILEMON_COOKIE * dirdeps.mk: move the logic that allows for make -f dirdeps.mk some/dir.${TARGET_SPEC} inside the check for !target(_DIRDEP_USE) 2016-04-04 Simon J. Gerraty * Use <> when including local*.mk and others which may exist elsewhere so that user can better control what they get. * meta.autodep.mk (NO_FILEMON_COOKIE): create a cookie if we ever build dir with nofilemon so that UPDATE_DEPENDFILE will be forced to NO until cleaned. 2016-04-01 Simon J. Gerraty * install-mk (MK_VERSION): 20160401 * meta2deps.py: fix old print statement when debugging. * gendirdeps.mk: META2DEPS_CMD append M2D_EXCLUDES with -X patch from Bryan Drewery 2016-03-22 Simon J. Gerraty * install-mk (MK_VERSION): 20160317 (St. Pats) * warnings.mk: g++ does not like -Wimplicit * sys.mk sys/*.mk lib.mk prog.mk: use CXX_SUFFIXES to handle the pelthora of common suffixes for C++ * lib.mk: use .So for shared objects 2016-03-15 Simon J. Gerraty * install-mk (MK_VERSION): 20160315 * meta.stage.mk (LN_CP_SCRIPT): do not ln(1) if we have to chmod(1) normally only applies to scripts. * dirdeps.mk: NO_DIRDEPS_BELOW to supress DIRDEPS below RELDIR as well as outside it. 2016-03-10 Simon J. Gerraty * install-mk (MK_VERSION): 20160310 * dirdeps.mk: use targets rather than a list to track DIRDEPS that we have processed; the list gets very inefficient as number of DIRDEPS gets large. * sys.dependfile.mk: fix comment wrt MACHINE * meta.autodep.mk: ignore staged DPADDs when bootstrapping. patch from Bryan Drewery 2016-03-02 Simon J. Gerraty * meta2deps.sh: don't ignore subdirs. patch from Bryan Drewery 2016-02-26 Simon J. Gerraty * install-mk (MK_VERSION): 20160226 * gendirdeps.mk: mark _DEPENDFILE .NOMETA 2016-02-20 Simon J. Gerraty * dirdeps.mk: we shouldn't normally include .depend but if we do use .dinclude if we can. 2016-02-18 Simon J. Gerraty * install-mk (MK_VERSION): 20160218 * sys.clean-env.mk: with recent change to Var_Subst() we cannot use the '$$' trick, but .export-literal does the job we need. * auto.dep.mk: make use .dinclude if we can. 2016-02-05 Simon J. Gerraty * dirdeps.mk: Add _build_all_dirs such that local.dirdeps.mk can add fully qualified dirs to it. These will be built normally but the current DEP_RELDIR will not depend on then (to avoid cycles). This makes it easy to hook things like unit-tests into build. 2016-01-21 Simon J. Gerraty * dirdeps.mk: add bootstrap-empty 2015-12-12 Simon J. Gerraty * install-mk (MK_VERSION): 20151212 * auto.obj.mk: do not require MAKEOBJDIRPREFIX to exist. only apply :tA to __objdir when comparing to .OBJDIR 2015-11-14 Simon J. Gerraty * install-mk (MK_VERSION): 20151111 * meta.sys.mk: include sys.dependfile.mk * sys.mk (OPTIONS_DEFAULT_NO): use options.mk to set MK_AUTO_OBJ and MK_DIRDEPS_BUILD include local.sys.env.mk early include local.sys.mk later * own.mk (OPTIONS_DEFAULT_NO): AUTO_OBJ etc moved to sys.mk 2015-11-13 Simon J. Gerraty * meta.sys.mk (META_COOKIE_TOUCH): add ${META_COOKIE_TOUCH} to the end of scripts to touch cookie * meta.stage.mk: stage_libs should ignore SYMLINKS. 2015-10-23 Simon J. Gerraty * install-mk (MK_VERSION): 20151022 * sys.mk: BSD/OS does not have 'type' as a shell builtin. 2015-10-20 Simon J. Gerraty * install-mk (MK_VERSION): 20151020 * dirdeps.mk: Add logic for make -f dirdeps.mk some/dir.${TARGET_SPEC} 2015-10-14 Simon J. Gerraty * install-mk (MK_VERSION): 20151010 2015-10-02 Simon J. Gerraty * meta.stage.mk: use staging: ${STAGE_TARGETS:... to have stage_lins run last in non-jobs mode. Use .ORDER only for jobs mode. 2015-09-02 Simon J. Gerraty * rst2htm.mk: allow for per target flags etc. 2015-09-01 Simon J. Gerraty * install-mk (MK_VERSION): 20150901 * doc.mk: create dir if needed use DOC_INSTALL_OWN 2015-06-15 Simon J. Gerraty * install-mk (MK_VERSION): 20150615 * auto.obj.mk: allow use of MAKEOBJDIRPREFIX too. Follow make's normal precedence rules. * gendirdeps.mk: allow customization of the header. eg. for FreeBSD: GENDIRDEPS_HEADER= echo '\# ${FreeBSD:L:@v@$$$v$$ @:M*F*}'; * meta.autodep.mk: ignore dirdeps.cache* * meta.stage.mk: when bootstrapping options it can be handy to throw warnings rather than errors for staging conflicts. * meta.sys.mk: include local.meta.sys.mk for customization 2015-06-06 Simon J. Gerraty * install-mk (MK_VERSION): 20150606 * dirdeps.mk: don't rely on manually maintained Makefile.depend to set DEP_RELDIR and reset DIRDEPS. By setting DEP_RELDIR ourselves we can skip :tA * gendirdeps.mk: skip setting DEP_RELDIR. 2015-05-24 Simon J. Gerraty * dirdeps.mk: avoid wildcards like make(bootstrap*) 2015-05-20 Simon J. Gerraty * install-mk (MK_VERSION): 20150520 * dirdeps.mk: when we are building dirdeps cache file we *want* meta_oodate to look at all the Makefile.depend files, so set .MAKE.DEPENDFILE to something that won't match. * meta.stage.mk: for STAGE_AS_* basename of file may not be unique so first use absolute path as key. Also skip staging at level 0. 2015-04-30 Simon J. Gerraty * install-mk (MK_VERSION): 20150430 * dirdeps.mk: fix _count_dirdeps for non-cache case. 2015-04-16 Simon J. Gerraty * install-mk (MK_VERSION): 20150411 bump version * own.mk: put AUTO_OBJ in OPTIONS_DEFAULT_NO rather than YES. it is here mainly for documentation purposes, since if using auto.obj.mk it is better done via sys.mk 2015-04-01 Simon J. Gerraty * install-mk (MK_VERSION): 20150401 * meta2deps.sh: support @list * meta2deps.py: updates from Juniper o add EXCLUDES o skip bogus input files. o treat 'M' and 'L' as both an 'R' and a 'W' 2015-03-03 Simon J. Gerraty * install-mk (MK_VERSION): 20150303 * dirdeps.mk: if MK_DIRDEPS_CACHE is yes, use dirdeps-cache which is built via sub-make so we have a .meta file to tell if it is out-of-date. The dirdeps-cache contains the same dependency rules that we normaly construct on the fly. This adds a few seconds overhead when the cache is out of date, but for a large target, the savings can be significant (10-20min). 2014-11-18 Simon J. Gerraty * install-mk (MK_VERSION): 20141118 * meta.stage.mk: add stale_staged * dirdeps.mk (_DIRDEP_USE_LEVEL): allow this to be tweaked only useful under very rare conditions such as FreeBSD's make universe. * auto.obj.mk: Allow MK_AUTO_OBJ to set MKOBJDIRS=auto 2014-11-11 Simon J. Gerraty * install-mk (MK_VERSION): 20141111 * mkopt.sh: use consistent semantics for _mk_opt and _mk_opts 2014-11-09 Simon J. Gerraty * FILES: include mkopt.sh which allows handling options in shell scripts in a manner compatible with options.mk 2014-10-12 Simon J. Gerraty * meta.stage.mk: ensure only _STAGED_DIRS under objroot are used for GENDIRDEPS_FILTER to avoid surprises. 2014-10-10 Simon J. Gerraty * dirdeps.mk (NSkipHostDir): this needs SRCTOP prepended since by the time it is applied to __depdirs they have. * dirdeps.mk fix filtering of _machines since M_dep_qual_fixes expects patterns like *.${MACHINE} * cython.mk (pyprefix?): use pyprefix to find python bits since prefix might be something else (where we install our stuff) 2014-09-11 Simon J. Gerraty * install-mk (MK_VERSION): 20140911 * dirdeps.mk: add bootstrap target to simplify adding support for new MACHINE. 2014-09-01 Simon J. Gerraty * gendirdeps.mk: Add handling of GENDIRDEPS_FILTER_DIR_VARS and GENDIRDEPS_FILTER_VARS to make it easier to produce sharable Makefile.depend files. 2014-08-28 Simon J. Gerraty * install-mk (MK_VERSION): 20140828 * cython.mk: capture logic for building python extension modules with Cython. 2014-08-08 Simon J. Gerraty * meta.stage.mk (_STAGE_AS_BASENAME_USE): Add StageAs variant 2014-08-02 Simon J. Gerraty * install-mk (MK_VERSION): 20140801 * dep.mk: use explicit MKDEP_MK rather than overload MKDEP to identify the autodep.mk variant. * sys.dependfile.mk: delete .MAKE.DEPENDFILE if its initial value does not match .MAKE.DEPENDFILE_PREFIX * meta.autodep.mk: if _bootstrap_dirdeps add RELDIR to DIRDEPS 2014-05-22 Simon J. Gerraty * install-mk (MK_VERSION): 20140522 * lib.mk: use CC to link shlib for linux too patch from Brendan MacDonell 2014-05-05 Simon J. Gerraty * meta.autodep.mk: add _reldir_{finish,failed} for gathering stats if WITH_META_STATS is defined. 2014-05-02 Simon J. Gerraty * dirdeps.mk: accept -DWITHOUT_DIRDEPS (same a as -DNO_DIRDEPS) to supress dirdeps outside of .CURDIR. 2014-04-05 Simon J. Gerraty * Fix spelling errors - patch from Pedro Giffuni 2014-03-14 Simon J. Gerraty * install-mk (MK_VERSION): 20140314 * dirdeps.mk (beforedirdeps): a handy hook * dirdeps.mk (DIRDEP_MAKE): allow the actual command we run to visit leaf dirs to be intercepted (eg. for distributed build). * dirdeps.mk (__depdirs): ensure // don't sneak in * gendirdeps.mk (DIRDEPS): ensure // don't sneak in 2014-02-21 Simon J. Gerraty * rst2htm.mk (RST2PDF): add support for rst2pdf 2014-02-14 Simon J. Gerraty * install-mk (MK_VERSION): bump version * dirdeps.mk (_last_dependfile): use .INCLUDEDFROMFILE if available. 2014-02-10 Simon J. Gerraty * options.mk: avoid :U so this isn't bmake dependent 2014-02-09 Simon J. Gerraty * options.mk: cleanup and simplify semanitcs NO_* dominates all, if both WITH_* and WITHOUT_* are defined then result is DOMINATE_* which defaults to "no". Ie. WITHOUT_ normally wins. 2013-12-12 Simon J. Gerraty * install-mk (MK_VERSION): bump version * meta2deps.py: convert to print function for python3 compat. we also need to open files with mode 'r' rather than 'rb' otherwise we get bytes instead of strings. 2013-10-10 Simon J. Gerraty * install-mk (MK_VERSION): bump version * dirdeps.mk: when TARGET_SPEC_VARS is more than just MACHINE apply the same filtering (M_dep_qual_fixes) when setting _machines as _build_dirs. Also fix the filtering of Makefile.depend files - for reporting what we are looking for (M_dep_qual_fixes can get confused by Makefile.depend) Add some more debug info. 2013-09-04 Simon J. Gerraty * gendirdeps.mk (_objtops): fix typo also while processing M2D_OBJROOTS to gather qualdir_list qualify $ql with loop iterator to ensure correct results. 2013-08-01 Simon J. Gerraty * install-mk (MK_VERSION): 20130801 * libs.mk: update to match progs.mk 2013-07-26 Simon J. Gerraty * install-mk (MK_VERSION): 20130726 some updates from Juniper and FreeBSD o meta2deps.py: indicate file and line number when we hit parse errors also allow @file to provide huge list of .meta files. * meta2deps.py: add try_parse() to cleanup the above. 2013-07-16 Simon J. Gerraty * install-mk (MK_VERSION): 20130716 * own.mk: add GPROG as an option * prog.mk: honor MK_GPROF==yes 2013-05-10 Simon J. Gerraty * install-mk (MK_VERSION): 20130505 * gendirdeps.mk, meta2deps.py, meta2deps.sh: handle $TARGET_SPEC for when $MACHINE isn't enough for objdir distinction. Bring meta2deps.sh closer to par with meta2deps.py. 2013-04-18 Simon J. Gerraty * meta.stage.mk: set INSTALL to STAGE_INSTALL when making 'all' also if the target 'beforeinstall' exists, make it depend on .dirdep (incase it uses STAGE_INSTALL). 2013-04-17 Simon J. Gerraty * install-mk (MK_VERSION): 20130401 ;-) * meta.stage.mk (STAGE_INSTALL_SH): add stage-install.sh as wrapper around install(1). * options.mk (OPTION_PREFIX): Allow a prefix other than MK_ 2013-03-30 Simon J. Gerraty * meta2deps.py (MetaFile.__init__): ensure self.cwd is initialized. * install-mk (MK_VERSION): bump version 2013-03-21 Simon J. Gerraty * install-mk (MK_VERSION): bump version * gendirdeps.mk: do not apply :tA to DPADD entries, since we lose any trailing /., rather apply :tA only when needed. * gendirdeps.mk: better mimic meta2deps handling of .dirdep files. * meta.stage.mk (LN_CP_SCRIPT): Add LnCp to do the ln||cp dance consistently. * dirdeps.mk: better describe the dance in sys.mk for TARGET_SPEC. 2013-03-18 Simon J. Gerraty * gendirdeps.mk: revert the dance around .MAKE.DEPENDFILE_DEFAULT it is simpler to just not update when say building for "host" (where we know we apply filters to DIRDEPS), and using a non-machine qualified dependfile. 2013-03-16 Simon J. Gerraty * dirdeps.mk: improve DIRDEPS filtering by allowing DEP_SKIP_DIR and DEP_DIRDEPS_FILTER to vary by DEP_MACHINE and DEP_TARGET_SPEC * gendirdeps.mk: ensure _objroot has trailing / if it needs it. * meta2deps.py: if machine is "host", then also trim self.host_target from any OBJROOTS. 2013-03-11 Simon J. Gerraty * gendirdeps.mk: if .MAKE.DEPENDFILE_DEFAULT is not machine qualified but _DEPENDFILE is, and .MAKE.DEPENDFILE_DEFAULT exists but _DEPENDFILE does not, compare the new _DEPENDFILE against .MAKE.DEPENDFILE_DEFAULT and discard if the same. 2013-03-08 Simon J. Gerraty * meta.stage.mk: use STAGE_TARGETS to control .ORDER and hook to all: via staging: 2013-03-07 Simon J. Gerraty * sys.dependfile.mk (.MAKE.DEPENDFILE_DEFAULT): use a separate variable for the default .MAKE.DEPENDFILE value so that it can be controlled independently of .MAKE.DEPENDFILE_PREFERENCE * meta.stage.mk: throw error if cp fails etc. Stage*() return early if passed no args. .ORDER stage_* 2013-03-03 Simon J. Gerraty * install-mk (MK_VERSION): bump version * gendirdeps.mk: handle multiple M2D_OBJROOTS better. 2013-02-10 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20130210 * import latest dirdeps.mk, gendirdeps.mk and meta2deps.py from Juniper. o dirdeps.mk now fully supports TARGET_SPEC consisting of more than just MACHINE. o no longer use DEP_MACHINE from Makefile.depend* so remove it. 2013-01-23 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20130123 * meta.stage.mk: add stage_links (hard links). if doing hard links, we add dest to link as well. Default the stage dir for [sym]links to STAGE_OBJTOP since these are typically specified as absolute paths. Add -m "mode" flag to StageFiles and StageAs. 2012-11-11 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20121111 * autoconf.mk: avoid meta mode seeing changed commands for config.status * meta.autodep.mk: pass resolved MAKESYSPATH to gendirdeps in case we were found via .../mk * sys.clean-env.mk: move it from examples, we and others use it "as is". * FILES: add srctop.mk and options.mk * own.mk: convert to using options.mk which is modeled after FreeBSD's handling of MK_* but more flexible. This allows MK_* for boolean knobs to not be confused with MK* which can be commands. * examples/sys.clean-env.mk: add WITH[OUT]_ to MAKE_ENV_SAVE_PREFIX_LIST. Mention that HOME=/var/empty might be a good idea. 2012-11-08 Simon J. Gerraty * sys.dependfile.mk: if not depend file exists, $MACHINE specific ones are supported but not the default, check if any exist and follow suit. 2012-11-06 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20121106 2012-11-05 Simon J. Gerraty * import latest dirdeps.mk and meta2deps.py from Juniper. * progs.mk: add MAN and CXXFLAGS to PROG_VARS also add PROGS_TARGETS and pass on PROG_CXX if it seems appropriate. 2012-11-04 Simon J. Gerraty * meta.stage.mk: update CLEANFILES remove redundant cp of .dirdep from STAGE_AS_SCRIPT. * progs.mk: Add LDADD to PROG_VARS 2012-10-12 Simon J. Gerraty * meta.stage.mk (STAGE_DIR_FILTER): track dirs we stage to in _STAGED_DIRS so that these can be turned into filters for GENDIRDEPS_FILTER. 2012-10-10 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20121010 * meta.stage.mk (STAGE_DIRDEP_SCRIPT): check that an existing target.dirdep matches .dirdep 2012-08-08 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20120808 * import latest meta2deps.py from Juniper. 2012-07-11 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20120711 * dep.mk: add explicit dependencies on SRCS after applying SRCS_DEP_FILTER * meta.autodep.mk: add explicit dependencies on SRCS after applying SRCS_DEP_FILTER * meta.autodep.mk: ensure GENDIRDEPS_FILTER is exported if needed. 2012-06-26 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20120626 * meta.sys.mk: ignore PYTHON if it does not exist compare ${.MAKE.DEPENDFILE:E} against ${MACHINE} is more reliable. * meta.stage.mk: examine .MAKE.DEPENDFILE_PREFERENCE for any entries ending in .${MACHINE} to decide if qualified _dirdep is needed. * gendirdeps.mk: only produce unqualified deps if no .MAKE.DEPENDFILE_PREFERENCE ends in .${MACHINE} * meta.subdir.mk: apply SUBDIRDEPS_FILTER 2012-04-20 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20120420 * add sys.dependfile.mk so we can experiment with .MAKE.DEPENDFILE_PREFERENCE * meta.autodep.mk: _DEPENDFILE is precious! 2012-03-15 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20120315 * install-new.mk: avoid being interrupted 2012-02-26 Simon J. Gerraty * man.mk: MAN might have multiple values so be careful with exists(). 2012-01-19 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20120112 * fix examples/sys.clean-env.mk so that MAKEOBJDIR is handled as: MAKEOBJDIR='${.CURDIR:S,${SRCTOP},${OBJTOP},}' 2011-12-03 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20111201 * import dirdeps.mk from Juniper sjg@ o more consistent handling of DEP_MACHINE, especially when dealing with an odd Makefile.depend, when normally using Makefile.depend.${MACHINE} 2011-11-22 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20111122 * meta.autodep.mk: add some debug output, be more crisp about updating. Use ${.ALLTARGETS:M*.o} as a clue for .depend 2011-11-13 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20111111 it's too cool to miss * import meta* updates from Juniper sjg@ o dirdeps.mk set DEP_MACHINE for Makefile.depend (when we are normally using Makefile.depend.${MACHINE}), handy for read-only manually maintained dependencies. o meta2deps.py add a clear 'ERROR:' token if an exception is raised. o gendirdeps.mk if ERROR: from meta2deps.py do not update anything. 2011-10-30 Simon J. Gerraty * install-new.mk separate the cmp and copy logic to its own function. 2011-10-28 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20111028 * sys.mk: include auto.obj.mk if MKOBJDIRS is set to auto * subdir.mk: ensure _SUBDIRUSE is provided * meta.autodep.mk: remove dependency of gendirdeps.mk on auto.obj.mk * meta.subdir.mk: always allow for Makefile.depend 2011-10-10 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20111010 o minor tweak to *dirdeps.mk from Juniper sjg@ 2011-10-01 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20111001 o add meta2deps.py from Juniper sjg@ o tweak gendirdeps.mk to work with meta2deps.py when not cross-building * autoconf.mk: add autoconf-input as a hook for regenerating AUTOCONF_INPUTS (configure). 2011-08-24 Simon J. Gerraty * meta.autodep.mk: if we do not have OBJS, .depend isn't a useful trigger for updating Makefile.depend* 2011-08-08 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20110808 * obj.mk: minor cleanup * auto.obj.mk: improve description of Mkdirs and honor NO_OBJ too. 2011-08-01 Simon J. Gerraty * auto.obj.mk (.OBJDIR): throw an error if we cannot use the specified dir. 2011-06-28 Simon J. Gerraty * meta.autodep.mk: if XMAKE_META_FILE is set the makefile uses a foreign make, and so dependencies can only be gathered from a clean tree build. 2011-06-24 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20110622 * meta.autodep.mk: improve bootstraping 2011-06-10 Simon J. Gerraty * yacc.mk: handle the corner case of .c being removed while .h remains. 2011-06-08 Simon J. Gerraty * yacc.mk: do .y.h and .y.c separately 2011-06-04 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20110606 * don't store SRC_DIRDEPS in Makefile.depend* by default not everyone needs it. 2011-05-04 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20110505 first release including meta mode makefiles 2011-05-02 Simon J. Gerraty * meta.stage.mk: add STAGE_AS_SETS and stage_as for things that need to be staged with different names. 2011-05-01 Simon J. Gerraty * meta.stage.mk: add notion of STAGE_SETS so a makefile can stage to multiple dirs 2011-04-03 Simon J. Gerraty * rst2htm.mk: convert rst to s5 (slides) or plain html depending on target name. 2011-03-30 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20110330 2011-03-29 Simon J. Gerraty * sys.mk (_DEBUG_MAKE_FLAGS): use indirection so that DEBUG_MAKE_FLAGS0 can be used to debug level 0 only and DEBUG_MAKE_FLAGS for the rest. * sys.mk: re-define M_whence in terms of M_type. M_type is useful for checking if something is a builtin. 2011-03-16 Simon J. Gerraty * meta.stage.mk: add stage_symlinks and leverage StageLinks for stage_libs 2011-03-10 Simon J. Gerraty * dirdeps.mk: correct value for _depdir_files depends on .MAKE.DEPENDFILE Add our copyright - just to make it clear we have frobbed this quite a bit. DEP_MACHINE needs to be set to MACHINE each time, if using only Makefile.depend (cf. Makefile.depend.${MACHINE}) * meta.stage.mk: meta mode version of staging * init.mk, final.mk: include local.*.mk to simplify customization 2011-03-03 Simon J. Gerraty * auto.obj.mk: just because we are doing mk destroy, we should still set .OBJDIR correctly if it exists. * install-mk (mksrc): do not exclude meta.sys.mk 2011-03-01 Simon J. Gerraty * host-target.mk: set/export _HOST_ARCH etc separately, catch junk resulting from uname -p, so we can find sys/Linux.mk correctly. 2011-02-18 Simon J. Gerraty * meta.sys.mk: throw an error if /dev/filemon is missing and we expected to be updating Makefile.depend* 2011-02-14 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20110214 * meta.subdir.mk: add support for -DBOOTSTRAP_DEPENDFILES 2010-09-25 Simon J. Gerraty * meta.sys.mk: not valid for older bmake 2010-09-24 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20100919 include dirdeps.mk et al from Juniper Networks, for meta mode - requires filemon(9). * sys.mk, subdir.mk: Add hooks for meta mode. we do this as meta.sys.mk, meta.autodep.mk and meta.subdir.mk to make turning it on/off simple. 2010-06-16 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20100616 * fix typo in sys.mk 2010-06-12 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20100612 * lib.mk: remove duplicate addition to SOBJS 2010-06-10 Simon J. Gerraty * sys.mk: Add a means of selectively turning on debug flags. Eg. DEBUG_MAKE_FLAGS=-dv DEBUG_MAKE_DIRS="*lib/sjg" will act as if we did make -dv if .CURDIR ends in lib/sjg DEBUG_MAKE_SYS_DIRS does the same thing, but we set the flags at the start of sys.mk rather than the end. This only makes sense for leaf dirs, so we check that .MAKE.LEVEL > 0 2010-06-09 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20100608 * sys.mk: include sys.env.mk later so it can use M_ListToSkip et al. * examples/sys.clean-env.mk: require MAKE_VERIONS >= 20100606 also make it easier for folk to tweak 2010-06-08 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20100606 do not install examples/* * FILES: add examples/sys.clean-env.mk * examples/sys.clean-env.mk: use .export-env to handle MAKEOBJDIR this requires bmake-20100606 or later to work. 2010-05-13 Simon J. Gerraty * sys.mk (M_tA): better simulate the result of :tA if not available. 2010-05-04 Simon J. Gerraty * sys.mk: canonicalize MAKE_VERSION old versions reported bmake- build- whereas we only care about 2010-04-25 Simon J. Gerraty * install-mk: just warn about FORCE_{BSD,SYS}_MK being ignored * lib.mk: we only build the shared lib if SHLIB_FULLVERSION is !empty 2010-04-22 Simon J. Gerraty * dpadd.mk: use LDADD_* if defined. 2010-04-21 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20100420 * sys/NetBSD.mk: add MACHINE_CPU to keep netbsd makefiles happy * autoconf.mk allow AUTO_AUTOCONF 2010-04-19 Simon J. Gerraty * obj.mk: add objwarn to keep freebsd makefiles happy * auto.obj.mk: ensure Mkdirs is available. * FILES: add auto.dep.mk - a simpler version of autodep.mk * dep.mk: auto.dep.mk does not do 'make depend' so ignore it if asked to do that. fix/simplify the tests for when to run mkdep. * auto.dep.mk: add some explanation of how/what we do. * autodep.mk: skip the .OPTIONAL frobbing of .depend bmake's FROM_DEPEND flag makes it redundant. 2010-04-13 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20100404 * subdir.mk: protect from multiple inclusion using _SUBDIRUSE. * obj.mk: protect from multiple inclusion even as bsd.obj.mk Also create a target _SUBDIRUSE so that we can be used without subdir.mk 2010-04-12 Simon J. Gerraty * dep.mk: use <> when .including so can override. 2010-01-11 Simon J. Gerraty * lib.mk (SHLIB_LINKS): ensure a string comparison. 2010-01-04 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20100102 * own.mk: ensure PRINTOBJDIR works * autoconf.mk: pass on CONFIGURE_ARGS * init.mk: handle COPTS.${.IMPSRC:T} etc. * lib.mk: allow sys.mk to control SHLIB_FULLVERSION fix handling of symlinks for darwin * libnames.mk: add DSHLIBEXT for libs which only exist as shared. * man.mk: suppress chown when not root. * rst2htm.mk: allow srcs from multiple locations. * sys.mk: M_whence, stop after 1st line of output. * sys/Darwin.mk: Use .dylib for DSHLIBEXT and HOST_LIBEXT * sys/SunOS.mk: we need to export PATH 2009-12-23 Simon J. Gerraty * install-mk (MK_VERSION): bump version include rst2htm.mk 2009-12-17 Simon J. Gerraty * sys.mk,libnames.mk add .-include this allows local customization without the need to edit the distributed files. 2009-12-14 Simon J. Gerraty * dpadd.mk (__dpadd_libdirs): order -L's to avoid picking up older versions already installed. 2009-12-13 Simon J. Gerraty * stage.mk (.stage-install): generalize lib.mk's .libinstall * rules.mk rules for generic Makefile. * inc.mk install for includes. 2009-12-11 Simon J. Gerraty * sys/NetBSD.mk (MAKE_VERSION): some of our *.mk want to check this, so provide it if using native make. 2009-12-10 Simon J. Gerraty * FILES: move all the platform *.sys.mk files to sys/*.mk * Rename Generic.sys.mk to sys.mk - we always want it. 2009-11-17 Simon J. Gerraty * install-mk (MK_VERSION): bump version * host-target.mk: only export the expensive stuff * Generic.sys.mk (sys_mk): for SunOS we need to look for ${HOST_OS}.${HOST_OSMAJOR} too! 2009-11-07 Simon J. Gerraty * install-mk (MK_VERSION): bump version * lib.mk: if sys.mk doesn't give us an lorder, don't use it. based on patch from Greg Olszewski. * Generic.sys.mk: if we have nothing to work with set LORDER etc only if we can find it. 2009-09-08 Simon J. Gerraty * install-mk (MK_VERSION): bump version * man.mk: cleanman: remove CLEANMAN if defined. 2009-09-04 Simon J. Gerraty * SunOS.5.sys.mk (CC): Use ?= like the other *sys.mk 2009-07-17 Simon J. Gerraty * install-mk (MK_VERSION): bump version include auto.obj.mk 2009-03-26 Simon J. Gerraty * prog.mk,lib.mk: ensure test of USE_DPADD_MK doesn't fail. 2008-11-11 Simon J. Gerraty * install-mk (MK_VERSION): bump version man.mk: ensure we generate *.cat1 etc in . 2008-07-16 Simon J. Gerraty * install-mk (MK_VERSION): bump version add prlist.mk 2007-11-25 Simon J. Gerraty * Generic.sys.mk: Allow os specific sys.mk to be in a subdir of ${.PARSEDIR} 2007-11-22 Simon J. Gerraty * install-mk (MK_VERSION): bump version * general cleanup * dpadd.mk introduce DPMAGIC_LIBS_* 2007-04-30 Simon J. Gerraty * install-mk (MK_VERSION): bump version * libs.mk, progs.mk, autodep.mk: allow for per lib/prog depend files and ensure clean is called for each lib/prog. 2007-03-27 Simon J. Gerraty * autodep.mk (.depend): delete lines that do not start with space and do not contain ':' 2007-02-16 Simon J. Gerraty * autodep.mk (.depend): gcc may wrap lines if pathnames are long so make sure the transform for .OPTIONAL copes. 2007-02-03 Simon J. Gerraty * install-mk (MK_VERSION): bump version * own.mk: make sure RM and LN are defined. * obj.mk: fix a typo, and objlink target. 2006-12-30 Simon J. Gerraty * install-mk (MK_VERSION): bump version * added libs.mk - analogous to progs.mk make both of them always inlcude {lib,prog}.mk 2006-12-28 Simon J. Gerraty * progs.mk: add a means of building multiple apps in one dir. 2006-11-26 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20061126 * warnings.mk: detect invalid WARNINGS_SET * warnings.mk: use ${.TARGET:T:R}.o when looking for target specific warnings. * For .cc sources, turn off warnings that g++ vomits on. 2006-11-08 Simon J. Gerraty * own.mk: if __initialized__ target doesn't exist and we are FreeBSD we got here directly from sys.mk 2006-11-06 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20061106 add scripts.mk 2006-03-18 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20060318 * autodep.mk: avoid := when modifying OBJS into __dependsrcs 2006-03-02 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20060302 * autodep.mk: use -MF et al to help gcc+ccache DTRT. 2006-03-01 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20060301 * autodep.mk (.depend): if MAKE_VERSION is newer than 20050530 we can make .END depend on .depend and make .depend depend on __depsrcs that exist. * dpadd.mk: add SRC_PATHADD 2005-11-04 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20051104 * prog.mk: remove all the LIBC?= junk, use .-include libnames.mk instead (none by default). also if USE_DPADD_MK is set, include that. 2005-10-09 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20051001 Add UnixWare.sys.mk from Klaus Heinz. 2005-04-05 Simon J. Gerraty * install-mk: always install *.sys.mk and if need be symlink one to sys.mk 2005-03-22 Simon J. Gerraty * subdir.mk, own.mk: use .MAKE rather than MAKE 2004-02-15 Simon J. Gerraty * own.mk: don't use NetBSD's _SRC_TOP_ it can cause confusion. Also don't take just 'mk' as a srctop indicator. 2004-02-14 Simon J. Gerraty * warnings.mk: overhauled, now very powerful. 2004-02-03 Simon J. Gerraty * Generic.sys.mk: need to use ${.PARSEDIR} with exists(). 2004-02-01 Simon J. Gerraty * install-mk (MK_VERSION): bump version to 20040201 * extract HOST_TARGET stuff to host-target.mk so own.mk and Generic.sys.mk can share. * fix typo in autodep.mk _SUBDIRUSE not _SUBDIR. 2003-09-30 Simon J. Gerraty * install-mk (MK_VERSION): 20030930 * rename generic.sys.mk to Generic.sys.mk so that it does not get installed (unless being used as sys.mk) * set OS and ROOT_GROUP for those that we know the value. for others (eg. Generic.sys.mk) wrap the != in an .ifndef so we don't do it again for each sub-make. 2003-09-28 Simon J. Gerraty * install-mk (MK_VERSION): 20030928 Add some extra *.sys.mk from bootstrap-pkgsrc some of these likely still need work. Make everything default to root:wheel ownership, sys.mk can set ROOT_GROUP accordingly. 2003-08-07 Simon J. Gerraty * install-mk: if FORCE_BSD_MK={cp,ln} use the ones in SYS_MK_DIR not the portable ones. 2003-07-31 Simon J. Gerraty * install-mk: add ability to use cp -f when updating destination .mk files. Also now possible to play games with FORCE_SYS_MK=ln etc on *BSD machines to link /usr/share/mk/sys.mk into dest - not recommended unless you seriously want to. 2003-07-28 Simon J. Gerraty * own.mk (IMPFLAGS): add support for COPTS.${IMPSRC:T} etc for semi-compatability with NetBSD. 2003-07-23 Simon J. Gerraty * install-mk: add a version indicator 2003-07-22 Simon J. Gerraty * prog.mk: don't try and use ${LIBCRT0} if its /dev/null * install-mk: Allow FORCE_SYS_MK to come from env diff --git a/mk/FILES b/mk/FILES index 45450595f390..aa84d59dd8cf 100644 --- a/mk/FILES +++ b/mk/FILES @@ -1,78 +1,80 @@ ChangeLog FILES LICENSE README auto.obj.mk autoconf.mk autodep.mk auto.dep.mk cc-wrap.mk compiler.mk cython.mk dep.mk doc.mk dpadd.mk files.mk final.mk host-target.mk host.libnames.mk inc.mk init.mk install-mk java.mk jobs.mk ldorder.mk lib.mk libnames.mk libs.mk links.mk man.mk manifest.mk mk-files.txt mkopt.sh +newlog.sh nls.mk obj.mk options.mk own.mk posix.mk prlist.mk prog.mk progs.mk rst2htm.mk scripts.mk srctop.mk stage-install.sh subdir.mk sys.mk sys.clean-env.mk sys.debug.mk sys.dependfile.mk +sys.dirdeps.mk sys.vars.mk sys/AIX.mk sys/Darwin.mk sys/Generic.mk sys/HP-UX.mk sys/IRIX.mk sys/Linux.mk sys/NetBSD.mk sys/OSF1.mk sys/OpenBSD.mk sys/SCO_SV.mk sys/SunOS.mk sys/UnixWare.mk target-flags.mk warnings.mk whats.mk yacc.mk dirdeps.mk dirdeps-cache-update.mk dirdeps-options.mk dirdeps-targets.mk gendirdeps.mk install-new.mk meta2deps.py meta2deps.sh meta.sys.mk meta.autodep.mk meta.stage.mk meta.subdir.mk diff --git a/mk/dirdeps-targets.mk b/mk/dirdeps-targets.mk index 6201efe1e402..821ae50e3ffa 100644 --- a/mk/dirdeps-targets.mk +++ b/mk/dirdeps-targets.mk @@ -1,172 +1,173 @@ # RCSid: -# $Id: dirdeps-targets.mk,v 1.24 2020/12/11 18:15:43 sjg Exp $ +# $Id: dirdeps-targets.mk,v 1.25 2023/05/11 05:07:28 sjg Exp $ # # @(#) Copyright (c) 2019-2020 Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. # Permission to copy, redistribute or otherwise # use this file is hereby granted provided that # the above copyright notice and this notice are # left intact. # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # ## # This makefile is used to set initial DIRDEPS for top-level build # targets. # # The basic idea is that we have a list of directories in # DIRDEPS_TARGETS_DIRS which are relative to SRCTOP. # When asked to make 'foo' we look for any directory named 'foo' # under DIRDEPS_TARGETS_DIRS. # We then search those dirs for any Makefile.depend* # Finally we select any that match conditions like REQUESTED_MACHINE # or TARGET_SPEC and initialize DIRDEPS accordingly. # # We will check each of the initial DIRDEPS for Makefile.dirdeps.options # and include any found. # This makes it feasible to tweak options like MK_DIRDEPS_CACHE # for a specific target. # # If MK_STATIC_DIRDEPS_CACHE is defined we will check if the # initial DIRDEPS has a static cache (Makefile.dirdeps.cache). # This only makes sense for seriously expensive targets. # .if ${.MAKE.LEVEL} == 0 # pickup customizations .-include # for DIRDEPS_BUILD this is how we prime the pump # include . to allow any directory to work as a target DIRDEPS_TARGETS_DIRS ?= targets targets/pseudo # these prefixes can modify how we behave # they need to be stripped when looking for target dirs DIRDEPS_TARGETS_PREFIX_LIST ?= pkg- build- # some .TARGETS need filtering DIRDEPS_TARGETS_FILTER += Nall # matching target dirs if any tdirs := ${.TARGETS:${DIRDEPS_TARGETS_FILTER:ts:}:${DIRDEPS_TARGETS_PREFIX_LIST:@p@S,^$p,,@:ts:}:@t@${DIRDEPS_TARGETS_DIRS:@d@$d/$t@}@:@d@${exists(${SRCTOP}/$d):?$d:}@} .if !empty(DEBUG_DIRDEPS_TARGETS) .info tdirs=${tdirs} .endif .if !empty(tdirs) # some things we know we want to ignore DIRDEPS_TARGETS_SKIP_LIST += \ *~ \ *.bak \ *.inc \ *.old \ *.options \ *.orig \ *.rej \ # the list of MACHINEs we consider DIRDEPS_TARGETS_MACHINE_LIST += \ ${ALL_MACHINE_LIST:U} \ ${PSEUDO_MACHINE_LIST:Ucommon host host32} \ ${TARGET_MACHINE_LIST} DIRDEPS_TARGETS_MACHINE_LIST := ${DIRDEPS_TARGETS_MACHINE_LIST:O:u} # raw Makefile.depend* list tdeps != 'cd' ${SRCTOP} && 'ls' -1 ${tdirs:O:u:@d@$d/${.MAKE.DEPENDFILE_PREFIX}*@:S,^./,,} 2> /dev/null; echo .if ${DEBUG_DIRDEPS_TARGETS:U:Mdep*} != "" .info tdeps=${tdeps} .endif # remove things we know we don't want tdeps := ${tdeps:${DIRDEPS_TARGETS_SKIP_LIST:${M_ListToSkip}}} .if ${DEBUG_DIRDEPS_TARGETS:U:Mdep*} != "" .info tdeps=${tdeps} .endif # plain entries (no qualifiers) these apply to any TARGET_SPEC ptdeps := ${tdeps:M*${.MAKE.DEPENDFILE_PREFIX}:S,/${.MAKE.DEPENDFILE_PREFIX},,} # MACHINE qualified entries mqtdeps := ${DIRDEPS_TARGETS_MACHINE_LIST:@m@${tdeps:M*.$m}@:S,/${.MAKE.DEPENDFILE_PREFIX},,} tqtdeps = .if ${TARGET_SPEC_VARS:[#]} > 1 # TARGET_SPEC qualified entries .if !empty(TARGET_SPEC_LIST) # we have a list of valid TARGET_SPECS; use it tqtdeps := ${TARGET_SPEC_LIST:U:O:u:@t@${tdeps:M*.$t}@:S,/${.MAKE.DEPENDFILE_PREFIX},,} .else # do we have a list of valid tuple members for at least # the last tupple element? if so match on that TARGET_SPEC_LAST_LIST ?= ${${TARGET_SPEC_VARS:[-1]}_LIST} .if !empty(TARGET_SPEC_LAST_LIST) tqtdeps := ${TARGET_SPEC_LAST_LIST:U:O:u:@t@${tdeps:M*,$t}@:S,/${.MAKE.DEPENDFILE_PREFIX},,} .else # this is sub-optimal match MACHINE, tqtdeps := ${DIRDEPS_TARGETS_MACHINE_LIST:@m@${tdeps:M*.$m,*}@:S,/${.MAKE.DEPENDFILE_PREFIX},,} .endif .endif .endif # now work out what we want in DIRDEPS +DIRDEPS = ${ptdeps} .if empty(REQUESTED_MACHINE) # we want them all just as found -DIRDEPS = ${ptdeps} ${mqtdeps} ${tqtdeps} +DIRDEPS += ${mqtdeps} ${tqtdeps} .else # we only want those that match REQUESTED_MACHINE/REQUESTED_TARGET_SPEC # or REQUESTED_TARGET_SPEC (TARGET_SPEC) -DIRDEPS = \ - ${ptdeps:@d@$d.${REQUESTED_TARGET_SPEC:U${TARGET_SPEC:U${REQUESTED_MACHINE}}}@} \ +DIRDEPS += \ ${mqtdeps:M*.${REQUESTED_MACHINE}} \ - ${tqtdeps:M*.${REQUESTED_TARGET_SPEC:U${TARGET_SPEC}}} + ${tqtdeps:M*.${REQUESTED_TARGET_SPEC:U${TARGET_SPEC}}} \ + .endif # clean up DIRDEPS := ${DIRDEPS:O:u} .if !empty(DEBUG_DIRDEPS_TARGETS) .for x in tdeps ptdeps mqtdeps tqtdeps DIRDEPS .info $x=${$x} .endfor .endif .endif # if we got DIRDEPS get to work .if !empty(DIRDEPS) DIRDEPS.dirs := ${DIRDEPS:S,^,${SRCTOP}/,:@d@${exists($d):?$d:${d:R}}@} # some targets want to tweak options we might want to process now .for m in ${DIRDEPS.dirs:S,$,/Makefile.dirdeps.options,} .-include <$m> .endfor .if defined(MK_STATIC_DIRDEPS_CACHE) # some targets are very expensive to compute dirdeps for # so we may have a static cache .for c in ${DIRDEPS.dirs:S,$,/Makefile.dirdeps.cache,} .if exists($c) STATIC_DIRDEPS_CACHE ?= $c .if ${MK_STATIC_DIRDEPS_CACHE} == "yes" DIRDEPS_CACHE ?= $c MK_DIRDEPS_CACHE = yes .endif .endif .endfor .if defined(STATIC_DIRDEPS_CACHE) .export STATIC_DIRDEPS_CACHE .endif .endif # allow a top-level makefile to do other stuff # before including dirdeps.mk .if ${MK_DIRDEPS_TARGETS_INCLUDE_DIRDEPS:Uyes} == "yes" .include .endif DIRDEPS_TARGETS_SKIP += all clean* destroy* .for t in ${.TARGETS:${DIRDEPS_TARGETS_SKIP:${M_ListToSkip}}} $t: dirdeps .endfor .endif .endif diff --git a/mk/dirdeps.mk b/mk/dirdeps.mk index 6fedd00310e9..aafa5ab47557 100644 --- a/mk/dirdeps.mk +++ b/mk/dirdeps.mk @@ -1,947 +1,959 @@ -# $Id: dirdeps.mk,v 1.157 2023/04/22 21:07:51 sjg Exp $ +# $Id: dirdeps.mk,v 1.160 2023/05/10 20:44:58 sjg Exp $ # SPDX-License-Identifier: BSD-2-Clause # # Copyright (c) 2010-2023, Simon J. Gerraty # Copyright (c) 2010-2018, Juniper Networks, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # Much of the complexity here is for supporting cross-building. # If a tree does not support that, simply using plain Makefile.depend # should provide sufficient clue. # Otherwise the recommendation is to use Makefile.depend.${MACHINE} # as expected below. # Note: this file gets multiply included. # This is what we do with DIRDEPS # DIRDEPS: # This is a list of directories - relative to SRCTOP, it is # normally only of interest to .MAKE.LEVEL 0. # In some cases the entry may be qualified with a . # or . suffix (see TARGET_SPEC_VARS below), # for example to force building something for the pseudo # machines "host" or "common" regardless of current ${MACHINE}. # # All unqualified entries end up being qualified with .${TARGET_SPEC} # and partially qualified (if TARGET_SPEC_VARS has multiple # entries) are also expanded to a full .. # The _DIRDEP_USE target uses the suffix to set TARGET_SPEC # correctly when visiting each entry. # # The fully qualified directory entries are used to construct a # dependency graph that will drive the build later. # # Also, for each fully qualified directory target, we will search # using ${.MAKE.DEPENDFILE_PREFERENCE} to find additional # dependencies. We use Makefile.depend (default value for # .MAKE.DEPENDFILE_PREFIX) to refer to these makefiles to # distinguish them from others. # # Before each Makefile.depend file is read, we set # DEP_RELDIR to be the RELDIR (path relative to SRCTOP) for # its directory, and DEP_MACHINE etc according to the . # represented by the suffix of the corresponding target. # # Since each Makefile.depend file includes dirdeps.mk, this # processing is recursive and results in .MAKE.LEVEL 0 learning the # dependencies of the tree wrt the initial directory (_DEP_RELDIR). # # NOTE: given the extent of processing that DIRDEPS undergoes it # is important that any variables in entries use :U to guard # against surprises when undefined. # # TARGET_SPEC_VARS # The default value is just MACHINE, and for most environments # this is sufficient. The _DIRDEP_USE target actually sets # both MACHINE and TARGET_SPEC to the suffix of the current # target so that in the general case TARGET_SPEC can be ignored. # # If more than MACHINE is needed then sys.mk needs to decompose # TARGET_SPEC and set the relevant variables accordingly. # It is important that MACHINE be included in and actually be # the first member of TARGET_SPEC_VARS. This allows other # variables to be considered optional, and some of the treatment # below relies on MACHINE being the first entry. # Note: TARGET_SPEC cannot contain any '.'s so the target # triple used by compiler folk won't work (directly anyway). # # For example: # # # Always list MACHINE first, # # other variables might be optional. # TARGET_SPEC_VARS = MACHINE TARGET_OS # .if ${TARGET_SPEC:Uno:M*,*} != "" # _tspec := ${TARGET_SPEC:S/,/ /g} # MACHINE := ${_tspec:[1]} # TARGET_OS := ${_tspec:[2]} # # etc. # # We need to stop that TARGET_SPEC affecting any submakes # # and deal with MACHINE=${TARGET_SPEC} in the environment. # TARGET_SPEC = # # export but do not track # .export-env TARGET_SPEC # .export ${TARGET_SPEC_VARS} # .for v in ${TARGET_SPEC_VARS:O:u} # .if empty($v) # .undef $v # .endif # .endfor # .endif # # make sure we know what TARGET_SPEC is # # as we may need it to find Makefile.depend* # TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} # # The following variables can influence the initial DIRDEPS # computation with regard to the TARGET_SPECs that will be # built. # Most should also be considered by init.mk # # ONLY_TARGET_SPEC_LIST # Defines a list of TARGET_SPECs for which the current # directory can be built. # If ALL_MACHINES is defined, we build for all the # TARGET_SPECs listed. # # ONLY_MACHINE_LIST # As for ONLY_TARGET_SPEC_LIST but only specifies # MACHINEs. # # NOT_TARGET_SPEC_LIST # A list of TARGET_SPECs for which the current # directory should not be built. # # NOT_MACHINE_LIST # A list of MACHINEs the current directory should not be # built for. # # DIRDEPS_EXPORT_VARS (DEP_EXPORT_VARS) # It is discouraged, but sometimes necessary for a # Makefile.depend file to influence the environment. # Doing this is correctly (especially if using DIRDEPS_CACHE) is # tricky so a Makefile.depend file can set DIRDEPS_EXPORT_VARS # and dirdeps.mk will do the deed: # # MK_UEFI = yes # DIRDEPS_EXPORT_VARS = MK_UEFI # # _build_xtra_dirs # local.dirdeps.mk can add targets to this variable. # They will be hooked into the build, but independent of # any other DIRDEP. # # This allows for adding TESTS to the build, such that the build # if any test fails, but without the risk of introducing # circular dependencies. now_utc ?= ${%s:L:gmtime} .if !defined(start_utc) start_utc := ${now_utc} .endif .if !target(bootstrap) && (make(bootstrap) || \ make(bootstrap-this) || \ make(bootstrap-recurse) || \ make(bootstrap-empty)) # disable most of below .MAKE.LEVEL = 1 .endif # touch this at your peril _DIRDEP_USE_LEVEL?= 0 .if ${.MAKE.LEVEL} == ${_DIRDEP_USE_LEVEL} # only the first instance is interested in all this # the first time we are included the _DIRDEP_USE target will not be defined # we can use this as a clue to do initialization and other one time things. .if !target(_DIRDEP_USE) # do some setup we only need once _CURDIR ?= ${.CURDIR} _OBJDIR ?= ${.OBJDIR} .if ${MAKEFILE:T} == ${.PARSEFILE} && empty(DIRDEPS) && ${.TARGETS:Uall:M*[/.]*} != "" # This little trick let's us do # # mk -f dirdeps.mk some/dir.${TARGET_SPEC} # all: ${.TARGETS:Nall}: all DIRDEPS := ${.TARGETS:M*[/.]*} # so that -DNO_DIRDEPS works DEP_RELDIR := ${DIRDEPS:[1]:R} # this will become DEP_MACHINE below TARGET_MACHINE := ${DIRDEPS:[1]:E:C/,.*//} .if ${TARGET_MACHINE:N*/*} == "" TARGET_MACHINE := ${MACHINE} .endif # disable DIRDEPS_CACHE as it does not like this trick MK_DIRDEPS_CACHE = no # incase anyone needs to know _dirdeps_cmdline: .endif # make sure we get the behavior we expect .MAKE.SAVE_DOLLARS = no # make sure these are empty to start with _DEP_TARGET_SPEC = # If TARGET_SPEC_VARS is other than just MACHINE # it should be set by sys.mk or similar by now. # TARGET_SPEC must not contain any '.'s. TARGET_SPEC_VARS ?= MACHINE # this is what we started with TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} # this is what we mostly use below DEP_TARGET_SPEC = ${TARGET_SPEC_VARS:S,^,DEP_,:@v@${$v:U}@:ts,} # make sure we have defaults .for v in ${TARGET_SPEC_VARS} DEP_$v ?= ${$v} .endfor .if ${TARGET_SPEC_VARS:[#]} > 1 # Ok, this gets more complex (putting it mildly). # In order to stay sane, we need to ensure that all the build_dirs # we compute below are fully qualified wrt DEP_TARGET_SPEC. # The makefiles may only partially specify (eg. MACHINE only), # so we need to construct a set of modifiers to fill in the gaps. .if ${MAKE_VERSION} >= 20170130 _tspec_x := ${TARGET_SPEC_VARS:range} .else # do it the hard way _tspec_x := ${TARGET_SPEC_VARS:[#]:@x@i=1;while [ $$i -le $x ]; do echo $$i; i=$$((i + 1)); done;@:sh} .endif # this handles unqualified entries M_dep_qual_fixes = C;(/[^/.,]+)$$;\1.$${DEP_TARGET_SPEC}; # there needs to be at least one item missing for these to make sense .for i in ${_tspec_x:[2..-1]} _tspec_m$i := ${TARGET_SPEC_VARS:[2..$i]:@w@[^,]+@:ts,} _tspec_a$i := ,${TARGET_SPEC_VARS:[$i..-1]:@v@$$$${DEP_$v}@:ts,} M_dep_qual_fixes += C;(\.${_tspec_m$i})$$;\1${_tspec_a$i}; .endfor TARGET_SPEC_VARSr := ${TARGET_SPEC_VARS:[-1..1]} .else # A harmless? default. M_dep_qual_fixes = U .endif .if !defined(.MAKE.DEPENDFILE_PREFERENCE) # .MAKE.DEPENDFILE_PREFERENCE makes the logic below neater? # you really want this set by sys.mk or similar .MAKE.DEPENDFILE_PREFERENCE = ${_CURDIR}/${.MAKE.DEPENDFILE:T} .if ${.MAKE.DEPENDFILE:E} == "${TARGET_SPEC}" .if ${TARGET_SPEC} != ${MACHINE} .MAKE.DEPENDFILE_PREFERENCE += ${_CURDIR}/${.MAKE.DEPENDFILE:T:R}.$${MACHINE} .endif .MAKE.DEPENDFILE_PREFERENCE += ${_CURDIR}/${.MAKE.DEPENDFILE:T:R} .endif .endif _default_dependfile := ${.MAKE.DEPENDFILE_PREFERENCE:[1]:T} _machine_dependfiles := ${.MAKE.DEPENDFILE_PREFERENCE:T:M*${MACHINE}*} # for machine specific dependfiles we require ${MACHINE} to be at the end # also for the sake of sanity we require a common prefix .if !defined(.MAKE.DEPENDFILE_PREFIX) # knowing .MAKE.DEPENDFILE_PREFIX helps .if !empty(_machine_dependfiles) .MAKE.DEPENDFILE_PREFIX := ${_machine_dependfiles:[1]:T:R} .else .MAKE.DEPENDFILE_PREFIX := ${_default_dependfile:T} .endif .endif +# turn a list into a set of :N modifiers +# NskipFoo = ${Foo:${M_ListToSkip}} +M_ListToSkip ?= O:u:S,^,N,:ts: + # this is how we identify non-machine specific dependfiles N_notmachine := ${.MAKE.DEPENDFILE_PREFERENCE:E:N*${MACHINE}*:${M_ListToSkip}} # this gets reset for each dirdep we check DEP_RELDIR ?= ${RELDIR} # remember the initial value of DEP_RELDIR - we test for it below. _DEP_RELDIR := ${DEP_RELDIR} # this can cause lots of output! # set to a set of glob expressions that might match RELDIR DEBUG_DIRDEPS ?= no # make sure this target exists dirdeps: beforedirdeps .WAIT beforedirdeps: .endif # !target(_DIRDEP_USE) .if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.${DEP_MACHINE}:L:M$x}@} != "" _debug_reldir = 1 .else _debug_reldir = 0 .endif .if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.depend depend:L:M$x}@} != "" _debug_search = 1 .else _debug_search = 0 .endif # First off, we want to know what ${MACHINE} to build for. # This can be complicated if we are using a mixture of ${MACHINE} specific # and non-specific Makefile.depend* # if we were included recursively _DEP_TARGET_SPEC should be valid. .if empty(_DEP_TARGET_SPEC) DEP_MACHINE = ${TARGET_MACHINE:U${MACHINE}} _DEP_TARGET_SPEC := ${DEP_TARGET_SPEC} .if ${.INCLUDEDFROMFILE:U:M${.MAKE.DEPENDFILE_PREFIX}*} != "" # record that we've read dependfile for this _dirdeps_checked.${_CURDIR}.${TARGET_SPEC}: .endif .endif # by now _DEP_TARGET_SPEC should be set, parse it. .if ${TARGET_SPEC_VARS:[#]} > 1 # we need to parse DEP_MACHINE may or may not contain more info _tspec := ${_DEP_TARGET_SPEC:S/,/ /g} .for i in ${_tspec_x} DEP_${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]} .endfor .for v in ${TARGET_SPEC_VARS:O:u} .if empty(DEP_$v) .undef DEP_$v .endif .endfor .else DEP_MACHINE := ${_DEP_TARGET_SPEC} .endif +# host is special +.if ${DEP_MACHINE:Mhost*} != "" +DEP_TARGET_SPEC = ${DEP_MACHINE} +.for v in ${TARGET_SPEC_VARS:O:u:NMACHINE} +.undef DEP_$v +.endfor +.endif + # reset each time through _build_all_dirs = _build_xtra_dirs = # DIRDEPS_CACHE can be very handy for debugging. # Also if repeatedly building the same target, # we can avoid the overhead of re-computing the tree dependencies. MK_DIRDEPS_CACHE ?= no BUILD_DIRDEPS_CACHE ?= no BUILD_DIRDEPS ?= yes .if ${MK_DIRDEPS_CACHE} == "yes" # this is where we will cache all our work DIRDEPS_CACHE ?= ${_OBJDIR:tA}/dirdeps.cache${_TARGETS:U${.TARGETS}:Nall:O:u:ts-:S,/,_,g:S,^,.,:N.} .endif # sanity check: Makefile.depend.options should *not* include us .if ${.INCLUDEDFROMFILE:U:M${.MAKE.DEPENDFILE_PREFIX}.options} != "" .error ${DEP_RELDIR}/${.MAKE.DEPENDFILE_PREFIX}.options: should include dirdeps-options.mk .endif # pickup customizations # as below you can use !target(_DIRDEP_USE) to protect things # which should only be done once. .-include .if !target(_DIRDEP_USE) # things we skip for host tools SKIP_HOSTDIR ?= NSkipHostDir = ${SKIP_HOSTDIR:N*.host*:S,$,.host*,:N.host*:S,^,${SRCTOP}/,:${M_ListToSkip}} # things we always skip # SKIP_DIRDEPS allows for adding entries on command line. SKIP_DIR += .host *.WAIT ${SKIP_DIRDEPS} SKIP_DIR.host += ${SKIP_HOSTDIR} DEP_SKIP_DIR = ${SKIP_DIR} \ ${SKIP_DIR.${DEP_TARGET_SPEC}:U} \ ${TARGET_SPEC_VARS:@v@${SKIP_DIR.${DEP_$v}:U}@} \ ${SKIP_DIRDEPS.${DEP_TARGET_SPEC}:U} \ ${TARGET_SPEC_VARS:@v@${SKIP_DIRDEPS.${DEP_$v}:U}@} NSkipDir = ${DEP_SKIP_DIR:${M_ListToSkip}} .if defined(NODIRDEPS) || defined(WITHOUT_DIRDEPS) NO_DIRDEPS = .elif defined(WITHOUT_DIRDEPS_BELOW) NO_DIRDEPS_BELOW = .endif .if defined(NO_DIRDEPS) # confine ourselves to the original dir and below. DIRDEPS_FILTER += M${_DEP_RELDIR}* .elif defined(NO_DIRDEPS_BELOW) DIRDEPS_FILTER += M${_DEP_RELDIR} .endif # this is what we run below DIRDEP_MAKE ?= ${.MAKE} DIRDEP_DIR ?= ${.TARGET:R} # if you want us to report load averages during build # DIRDEP_USE_PRELUDE += ${DIRDEP_LOADAVG_REPORT}; DIRDEP_LOADAVG_CMD ?= ${UPTIME:Uuptime} | sed 's,.*\(load\),\1,' DIRDEP_LOADAVG_LAST = 0 # yes the expression here is a bit complicated, # the trick is to only eval ${DIRDEP_LOADAVG_LAST::=${now_utc}} # when we want to report. # Note: expr(1) will exit 1 if the expression evaluates to 0 # hence the || true DIRDEP_LOADAVG_REPORT = \ test -z "${"${expr ${now_utc} - ${DIRDEP_LOADAVG_INTERVAL:U60} - ${DIRDEP_LOADAVG_LAST} || true:L:sh:N-*}":?yes${DIRDEP_LOADAVG_LAST::=${now_utc}}:}" || \ echo "${TRACER}`${DIRDEP_LOADAVG_CMD}`" # we suppress SUBDIR when visiting the leaves # we assume sys.mk will set MACHINE_ARCH # you can add extras to DIRDEP_USE_ENV # if there is no makefile in the target directory, we skip it. _DIRDEP_USE: .USE .MAKE @for m in ${.MAKE.MAKEFILE_PREFERENCE}; do \ test -s ${.TARGET:R}/$$m || continue; \ echo "${TRACER}Checking ${.TARGET:S,^${SRCTOP}/,,} for ${.TARGET:E} ..."; \ ${DIRDEP_USE_PRELUDE} \ MACHINE_ARCH= NO_SUBDIR=1 ${DIRDEP_USE_ENV} \ TARGET_SPEC=${.TARGET:E} \ MACHINE=${.TARGET:E} \ ${DIRDEP_MAKE} -C ${DIRDEP_DIR} || exit 1; \ break; \ done .ifdef ALL_MACHINES .if empty(ONLY_TARGET_SPEC_LIST) && empty(ONLY_MACHINE_LIST) # we start with everything _machine_list != echo; 'ls' -1 ${_CURDIR}/${.MAKE.DEPENDFILE_PREFIX}* 2> /dev/null # some things we know we want to ignore DIRDEPS_TARGETS_SKIP_LIST += \ *~ \ *.bak \ *.inc \ *.old \ *.options \ *.orig \ *.rej \ # first trim things we know we want to skip # and provide canonical form _machine_list := ${_machine_list:${DIRDEPS_TARGETS_SKIP_LIST:${M_ListToSkip}}:T:E} # cater for local complexities # local.dirdeps.mk can set # DIRDEPS_ALL_MACHINES_FILTER and # DIRDEPS_ALL_MACHINES_FILTER_XTRAS for final tweaks .if !empty(ALL_TARGET_SPEC_LIST) .if ${_debug_reldir} .info ALL_TARGET_SPEC_LIST=${ALL_TARGET_SPEC_LIST} .endif DIRDEPS_ALL_MACHINES_FILTER += \ @x@$${ALL_TARGET_SPEC_LIST:@s@$${x:M$$s}@}@ .elif !empty(ALL_MACHINE_LIST) .if ${_debug_reldir} .info ALL_MACHINE_LIST=${ALL_MACHINE_LIST} .endif .if ${TARGET_SPEC_VARS:[#]} > 1 # the space below can result in extraneous ':' DIRDEPS_ALL_MACHINES_FILTER += \ @x@$${ALL_MACHINE_LIST:@m@$${x:M$$m,*} $${x:M$$m}@}@ .else DIRDEPS_ALL_MACHINES_FILTER += \ @x@$${ALL_MACHINE_LIST:@m@$${x:M$$m}@}@ .endif .endif # add local XTRAS - default to something benign DIRDEPS_ALL_MACHINES_FILTER += \ ${DIRDEPS_ALL_MACHINES_FILTER_XTRAS:UNbak} .if ${_debug_reldir} .info _machine_list=${_machine_list} .info DIRDEPS_ALL_MACHINES_FILTER=${DIRDEPS_ALL_MACHINES_FILTER} .endif _only_machines := ${_machine_list:${DIRDEPS_ALL_MACHINES_FILTER:ts:}:S,:, ,g} .else _only_machines := ${ONLY_TARGET_SPEC_LIST:U} ${ONLY_MACHINE_LIST:U} .endif .if empty(_only_machines) # we must be boot-strapping _only_machines := ${TARGET_MACHINE:U${ALL_TARGET_SPEC_LIST:U${ALL_MACHINE_LIST:U${DEP_MACHINE}}}} .endif # cleanup the result _only_machines := ${_only_machines:O:u} .if ${_debug_reldir} .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: ALL_MACHINES _only_machines=${_only_machines} .endif .else # ! ALL_MACHINES # if ONLY_TARGET_SPEC_LIST or ONLY_MACHINE_LIST is set, we are limited to that. # Note that ONLY_TARGET_SPEC_LIST should be fully qualified. # if TARGET_MACHINE is set - it is really the same as ONLY_MACHINE_LIST # otherwise DEP_MACHINE is it - so DEP_MACHINE will match. _only_machines := ${ONLY_TARGET_SPEC_LIST:U:M${DEP_MACHINE},*} .if empty(_only_machines) _only_machines := ${ONLY_MACHINE_LIST:U${TARGET_MACHINE:U${DEP_MACHINE}}:M${DEP_MACHINE}} .endif .endif .if !empty(NOT_MACHINE_LIST) _only_machines := ${_only_machines:${NOT_MACHINE_LIST:${M_ListToSkip}}} .endif .if !empty(NOT_TARGET_SPEC_LIST) # we must first qualify _dm := ${DEP_MACHINE} _only_machines := ${_only_machines:M*,*} ${_only_machines:N*,*:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:${M_dep_qual_fixes:ts:}:O:u:S,^.,,} DEP_MACHINE := ${_dm} _only_machines := ${_only_machines:${NOT_TARGET_SPEC_LIST:${M_ListToSkip}}} .endif # clean up _only_machines := ${_only_machines:O:u} .if ${_debug_reldir} .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _only_machines=${_only_machines} .endif # make sure we have a starting place? DIRDEPS ?= ${RELDIR} .endif # target .if !defined(NO_DIRDEPS) && !defined(NO_DIRDEPS_BELOW) .if ${MK_DIRDEPS_CACHE} == "yes" # just ensure this exists build-dirdeps: M_oneperline = @x@\\${.newline} $$x@ .if ${BUILD_DIRDEPS_CACHE} == "no" .if !target(dirdeps-cached) # we do this via sub-make BUILD_DIRDEPS = no # ignore anything but these .MAKE.META.IGNORE_FILTER = M*/${.MAKE.DEPENDFILE_PREFIX}* dirdeps: dirdeps-cached dirdeps-cached: ${DIRDEPS_CACHE} .MAKE @echo "${TRACER}Using ${DIRDEPS_CACHE}" @MAKELEVEL=${.MAKE.LEVEL} \ TARGET_SPEC=${TARGET_SPEC} \ ${TARGET_SPEC_VARS:@v@$v=${$v}@} \ ${.MAKE} -C ${_CURDIR} -f ${DIRDEPS_CACHE} \ dirdeps MK_DIRDEPS_CACHE=no BUILD_DIRDEPS=no # leaf makefiles rarely work for building DIRDEPS_CACHE .if ${RELDIR} != "." BUILD_DIRDEPS_MAKEFILE ?= -f dirdeps.mk .endif # these should generally do BUILD_DIRDEPS_MAKEFILE ?= BUILD_DIRDEPS_TARGETS ?= ${.TARGETS} .if ${DIRDEPS_CACHE} != ${STATIC_DIRDEPS_CACHE:Uno} && ${DIRDEPS_CACHE:M${SRCTOP}/*} == "" # export this for dirdeps-cache-update.mk DYNAMIC_DIRDEPS_CACHE := ${DIRDEPS_CACHE} .export DYNAMIC_DIRDEPS_CACHE # we need the .meta file to ensure we update if # any of the Makefile.depend* changed. # We do not want to compare the command line though. ${DIRDEPS_CACHE}: .META .NOMETA_CMP +@{ echo '# Autogenerated - do NOT edit!'; echo; \ echo 'BUILD_DIRDEPS=no'; echo; \ echo '.include '; echo; \ } > ${.TARGET}.new +@MAKELEVEL=${.MAKE.LEVEL} DIRDEPS_CACHE=${DIRDEPS_CACHE} \ DIRDEPS="${DIRDEPS}" \ TARGET_SPEC=${TARGET_SPEC} \ MAKEFLAGS= ${DIRDEP_CACHE_MAKE:U${.MAKE}} -C ${_CURDIR} \ ${BUILD_DIRDEPS_MAKEFILE} \ ${BUILD_DIRDEPS_TARGETS} BUILD_DIRDEPS_CACHE=yes \ .MAKE.DEPENDFILE=.none \ ${"${DEBUG_DIRDEPS:Nno}":?DEBUG_DIRDEPS='${DEBUG_DIRDEPS}':} \ ${.MAKEFLAGS:tW:S,-D ,-D,g:tw:M*WITH*} \ ${.MAKEFLAGS:tW:S,-d ,-d,g:tw:M-d*} \ 3>&1 1>&2 | sed 's,${SRCTOP},_{SRCTOP},g;s,_{SRCTOP}/_{SRCTOP},_{SRCTOP},g;s,_{,$${,g' >> ${.TARGET}.new && \ mv ${.TARGET}.new ${.TARGET} .endif .endif .elif !target(_count_dirdeps) # we want to capture the dirdeps count in the cache .END: _count_dirdeps _count_dirdeps: .NOMETA @{ echo; echo '.info $${.newline}$${TRACER}Makefiles read: total=${.MAKE.MAKEFILES:[#]} depend=${.MAKE.MAKEFILES:M*depend*:[#]} dirdeps=${.ALLTARGETS:M${SRCTOP}*:O:u:[#]} ${DIRDEP_INFO_XTRAS}'; } >&3 .endif .elif !make(dirdeps) && !target(_count_dirdeps) beforedirdeps: _count_dirdeps _count_dirdeps: .NOMETA @echo "${TRACER}Makefiles read: total=${.MAKE.MAKEFILES:[#]} depend=${.MAKE.MAKEFILES:M*depend*:[#]} dirdeps=${.ALLTARGETS:M${SRCTOP}*:O:u:[#]} ${DIRDEP_INFO_XTRAS} seconds=`expr ${now_utc} - ${start_utc}`" .endif .endif .if ${BUILD_DIRDEPS} == "yes" # the rest is done repeatedly for every Makefile.depend we read. # if we are anything but the original dir we care only about the # machine type we were included for.. .if ${DEP_RELDIR} == "." _this_dir := ${SRCTOP} .else _this_dir := ${SRCTOP}/${DEP_RELDIR} .endif # on rare occasions, there can be a need for extra help _dep_hack := ${_this_dir}/${.MAKE.DEPENDFILE_PREFIX}.inc .-include <${_dep_hack}> .-include <${_dep_hack:R}.options> .if ${DEP_RELDIR} != ${_DEP_RELDIR} || ${DEP_TARGET_SPEC} != ${TARGET_SPEC} # this should be all _machines := ${DEP_MACHINE} .else # this is the machine list we actually use below _machines := ${_only_machines} .if defined(HOSTPROG) || ${DEP_MACHINE:Nhost*} == "" # we need to build this guy's dependencies for host as well. .if ${DEP_MACHINE:Nhost*} == "" _machines += ${DEP_MACHINE} .else _machines += host .endif .endif _machines := ${_machines:O:u} .endif .if ${TARGET_SPEC_VARS:[#]} > 1 # we need to tweak _machines _dm := ${DEP_MACHINE} # apply the same filtering that we do when qualifying DIRDEPS. # M_dep_qual_fixes expects .${MACHINE}* so add (and remove) '.' # Again we expect that any already qualified machines are fully qualified. _machines := ${_machines:M*,*} ${_machines:N*,*:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:S,^.,,} DEP_MACHINE := ${_dm} _machines := ${_machines:${M_dep_qual_fixes:ts:}:O:u} .endif # reset each time through _build_dirs = -.if ${DEP_RELDIR} == ${_DEP_RELDIR} +.if ${DEP_RELDIR} == ${_DEP_RELDIR} && ${_CURDIR} != ${SRCTOP} # pickup other machines for this dir if necessary _build_dirs += ${_machines:@m@${_CURDIR}.$m@} .endif .if ${_debug_reldir} .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: nDIRDEPS=${DIRDEPS:[#]} .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: DIRDEPS='${DIRDEPS}' .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _machines='${_machines}' .endif .if !empty(DIRDEPS) # these we reset each time through as they can depend on DEP_MACHINE DEP_DIRDEPS_FILTER = \ ${DIRDEPS_FILTER.${DEP_TARGET_SPEC}:U} \ ${TARGET_SPEC_VARS:@v@${DIRDEPS_FILTER.${DEP_$v}:U}@} \ ${DIRDEPS_FILTER:U} .if empty(DEP_DIRDEPS_FILTER) # something harmless DEP_DIRDEPS_FILTER = U .endif # this is what we start with __depdirs := ${DIRDEPS:${NSkipDir}:${DEP_DIRDEPS_FILTER:ts:}:C,//+,/,g:O:u:@d@${SRCTOP}/$d@} # some entries may be qualified with . or . # we can tell the unqualified ones easily - because they exist __unqual_depdirs := ${__depdirs:@d@${exists($d):?$d:}@} __qual_depdirs := ${__depdirs:${__unqual_depdirs:Uno:${M_ListToSkip}}} .if ${DEP_RELDIR} == ${_DEP_RELDIR} # if it was called out - we likely need it. __hostdpadd := ${DPADD:U.:M${HOST_OBJTOP}/*:S,${HOST_OBJTOP}/,,:H:${NSkipDir}:${DIRDEPS_FILTER:ts:}:S,$,.host,:N.*:@d@${SRCTOP}/$d@} \ ${DPADD:U.:M${HOST_OBJTOP32:Uno}/*:S,${HOST_OBJTOP32:Uno}/,,:H:${NSkipDir}:${DIRDEPS_FILTER:ts:}:S,$,.host32,:N.*:@d@${SRCTOP}/$d@} __qual_depdirs += ${__hostdpadd} .endif .if ${_debug_reldir} .info DEP_DIRDEPS_FILTER=${DEP_DIRDEPS_FILTER:ts:} .info depdirs=${__depdirs:S,^${SRCTOP}/,,} .info qualified=${__qual_depdirs:S,^${SRCTOP}/,,} .info unqualified=${__unqual_depdirs:S,^${SRCTOP}/,,} .endif # _build_dirs is what we will feed to _DIRDEP_USE _build_dirs += \ ${__qual_depdirs:M*.host:${NSkipHostDir}:N.host} \ ${__qual_depdirs:N*.host} \ ${_machines:Mhost*:@m@${__unqual_depdirs:@d@$d.$m@}@:${NSkipHostDir}:N.host} \ ${_machines:Nhost*:@m@${__unqual_depdirs:@d@$d.$m@}@} # qualify everything now _build_dirs := ${_build_dirs:${M_dep_qual_fixes:ts:}:O:u} .endif # empty DIRDEPS _build_all_dirs += ${_build_dirs} ${_build_xtra_dirs} _build_all_dirs := ${_build_all_dirs:O:u} # Normally if doing make -V something, # we do not want to waste time chasing DIRDEPS # but if we want to count the number of Makefile.depend* read, we do. .if ${.MAKEFLAGS:M-V${_V_READ_DIRDEPS:U}} == "" .if !empty(_build_all_dirs) .if ${BUILD_DIRDEPS_CACHE} == "yes" # we use _cache_script to minimize the number of times we fork the shell _cache_script = echo '\# ${DEP_RELDIR}.${DEP_TARGET_SPEC}'; # guard against _new_dirdeps being too big for a single command line _new_dirdeps := ${_build_all_dirs:@x@${target($x):?:$x}@:S,^${SRCTOP}/,,} _cache_xtra_deps := ${_build_xtra_dirs:S,^${SRCTOP}/,,} .export _cache_xtra_deps _new_dirdeps .if !empty(DIRDEPS_EXPORT_VARS) || !empty(DEP_EXPORT_VARS) # Discouraged, but there are always exceptions. # Handle it here rather than explain how. DIRDEPS_EXPORT_VARS ?= ${DEP_EXPORT_VARS} _cache_xvars := echo; ${DIRDEPS_EXPORT_VARS:@v@echo '$v = ${$v}';@} echo '.export ${DIRDEPS_EXPORT_VARS}'; echo; _cache_script += ${_cache_xvars} .endif .else # this makes it all happen dirdeps: ${_build_all_dirs} .endif ${_build_all_dirs}: _DIRDEP_USE .if ${_debug_reldir} .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: needs: ${_build_dirs:S,^${SRCTOP}/,,} .endif .if !empty(DIRDEPS_EXPORT_VARS) || !empty(DEP_EXPORT_VARS) .export ${DIRDEPS_EXPORT_VARS} ${DEP_EXPORT_VARS} DIRDEPS_EXPORT_VARS = DEP_EXPORT_VARS = .endif # this builds the dependency graph .for m in ${_machines} .if ${BUILD_DIRDEPS_CACHE} == "yes" && !empty(_build_dirs) _cache_deps = _cache_script += echo; echo 'DIRDEPS.${_this_dir}.$m = \'; .endif # it would be nice to do :N${.TARGET} .if !empty(__qual_depdirs) .for q in ${__qual_depdirs:${M_dep_qual_fixes:ts:}:E:O:u:N$m} .if ${_debug_reldir} || ${DEBUG_DIRDEPS:@x@${${DEP_RELDIR}.$m:L:M$x}${${DEP_RELDIR}.$q:L:M$x}@} != "" .info ${DEP_RELDIR}.$m: graph: ${_build_dirs:M*.$q:S,^${SRCTOP}/,,} .endif .if ${BUILD_DIRDEPS_CACHE} == "yes" _cache_deps += ${_build_dirs:M*.$q:S,^${SRCTOP}/,,} .else ${_this_dir}.$m: ${_build_dirs:M*.$q} .endif .endfor .endif .if ${_debug_reldir} .info ${DEP_RELDIR}.$m: graph: ${_build_dirs:M*.$m:N${_this_dir}.$m:S,^${SRCTOP}/,,} .endif .if ${BUILD_DIRDEPS_CACHE} == "yes" .if !empty(_build_dirs) _cache_deps += ${_build_dirs:M*.$m:N${_this_dir}.$m:S,^${SRCTOP}/,,} .if !empty(_cache_deps) .export _cache_deps _cache_script += for x in $$_cache_deps; do echo " _{SRCTOP}/$$x \\"; done; .endif # anything in _{build,env}_xtra_dirs is hooked to dirdeps: only x!= echo; { echo; ${_cache_script} echo; echo '${_this_dir}.$m: $${DIRDEPS.${_this_dir}.$m}'; \ echo; echo 'dirdeps: ${_this_dir}.$m \'; \ for x in $$_cache_xtra_deps; do echo " _{SRCTOP}/$$x \\"; done; \ echo; for x in $$_new_dirdeps; do echo "_{SRCTOP}/$$x: _DIRDEP_USE"; done; } >&3 .endif .else ${_this_dir}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m} .endif .endfor .endif # Now find more dependencies - and recurse. .for d in ${_build_all_dirs} .if !target(_dirdeps_checked.$d) # once only _dirdeps_checked.$d: _dr := ${d:S,^${SRCTOP}/,,} .if ${_debug_search} .info checking ${_dr} .endif # Note: _build_all_dirs is fully qualifed so d:R is always the directory .if exists(${d:R}) # we pass _DEP_TARGET_SPEC to tell the next step what we want _DEP_TARGET_SPEC := ${d:E} # some makefiles may still look at this _DEP_MACHINE := ${d:E:C/,.*//} # set these too in case Makefile.depend* uses them .if ${TARGET_SPEC_VARS:[#]} > 1 _dtspec := ${_DEP_TARGET_SPEC:S/,/ /g} .for i in ${_tspec_x} DEP_${TARGET_SPEC_VARS:[$i]} := ${_dtspec:[$i]} .endfor .else DEP_MACHINE := ${_DEP_MACHINE} .endif # Warning: there is an assumption here that MACHINE is always # the first entry in TARGET_SPEC_VARS. # If TARGET_SPEC and MACHINE are insufficient, you have a problem. _m := ${.MAKE.DEPENDFILE_PREFERENCE:T:S;${TARGET_SPEC}$;${d:E};:C;${MACHINE}((,.+)?)$;${d:E:C/,.*//}\1;:@m@${exists(${d:R}/$m):?${d:R}/$m:}@:[1]} .if !empty(_m) # M_dep_qual_fixes isn't geared to Makefile.depend _qm := ${_m:C;(\.depend)$;\1.${d:E};:${M_dep_qual_fixes:ts:}} .if ${_debug_search} .info Looking for ${_qm} .endif # set this "just in case" # we can skip :tA since we computed the path above DEP_RELDIR := ${_m:H:S,^${SRCTOP}/,,} # and reset this DIRDEPS = .if ${_debug_reldir} && ${_qm} != ${_m} .info loading ${_m:S,${SRCTOP}/,,} for ${_dr} .endif .include <${_m}> .else # set these as if we found Makefile.depend* DEP_RELDIR := ${_dr:R} DIRDEPS = .if ${_debug_reldir} .info loading local.dirdeps-missing.mk for ${_dr} .endif .-include .endif .endif .endif .endfor .endif # -V .endif # BUILD_DIRDEPS .elif ${.MAKE.LEVEL} > 42 .error You should have stopped recursing by now. .else # we are building something DEP_RELDIR := ${RELDIR} _DEP_RELDIR := ${RELDIR} # Since we are/should be included by .MAKE.DEPENDFILE # This is a final opportunity to add/hook global rules. .-include # skip _reldir_{finish,failed} if not included from Makefile.depend* # or not in meta mode .if !defined(WITHOUT_META_STATS) && ${.INCLUDEDFROMFILE:U:M${.MAKE.DEPENDFILE_PREFIX}*} != "" && ${.MAKE.MODE:Mmeta} != "" meta_stats= meta=${empty(.MAKE.META.FILES):?0:${.MAKE.META.FILES:[#]}} \ created=${empty(.MAKE.META.CREATED):?0:${.MAKE.META.CREATED:[#]}} .if !target(_reldir_finish) .END: _reldir_finish _reldir_finish: .NOMETA @echo "${TRACER}Finished ${RELDIR}.${TARGET_SPEC} seconds=$$(( ${now_utc} - ${start_utc} )) ${meta_stats}" .endif .if !target(_reldir_failed) .ERROR: _reldir_failed _reldir_failed: .NOMETA @echo "${TRACER}Failed ${RELDIR}.${TARGET_SPEC} seconds=$$(( ${now_utc} - ${start_utc} )) ${meta_stats}" .endif .endif # pickup local dependencies .if ${MAKE_VERSION} < 20160220 .-include <.depend> .else .dinclude <.depend> .endif .endif # bootstrapping new dependencies made easy? .if !target(bootstrap-empty) .if !target(bootstrap) && (make(bootstrap) || \ make(bootstrap-this) || \ make(bootstrap-recurse) || \ make(bootstrap-empty)) # if we are bootstrapping create the default _want = ${.CURDIR}/${.MAKE.DEPENDFILE_DEFAULT:T} .if exists(${_want}) # stop here ${.TARGETS:Mboot*}: .elif !make(bootstrap-empty) # find a Makefile.depend to use as _src _src != cd ${.CURDIR} && for m in ${.MAKE.DEPENDFILE_PREFERENCE:T:S,${MACHINE},*,}; do test -s $$m || continue; echo $$m; break; done; echo .if empty(_src) .error cannot find any of ${.MAKE.DEPENDFILE_PREFERENCE:T}${.newline}Use: bootstrap-empty .endif _src?= ${.MAKE.DEPENDFILE} .MAKE.DEPENDFILE_BOOTSTRAP_SED+= -e 's/${_src:E:C/,.*//}/${MACHINE}/g' # just create Makefile.depend* for this dir bootstrap-this: .NOTMAIN @echo Bootstrapping ${RELDIR}/${_want:T} from ${_src:T}; \ echo You need to build ${RELDIR} to correctly populate it. .if ${_src:T} != ${.MAKE.DEPENDFILE_PREFIX:T} (cd ${.CURDIR} && sed ${.MAKE.DEPENDFILE_BOOTSTRAP_SED} ${_src} > ${_want:T}) .else cp ${.CURDIR}/${_src:T} ${_want} .endif # create Makefile.depend* for this dir and its dependencies bootstrap: bootstrap-recurse bootstrap-recurse: bootstrap-this _mf := ${.PARSEFILE} bootstrap-recurse: .NOTMAIN .MAKE @cd ${SRCTOP} && \ for d in `cd ${RELDIR} && ${.MAKE} -B -f ${"${.MAKEFLAGS:M-n}":?${_src}:${.MAKE.DEPENDFILE:T}} -V DIRDEPS`; do \ test -d $$d || d=$${d%.*}; \ test -d $$d || continue; \ echo "Checking $$d for bootstrap ..."; \ (cd $$d && ${.MAKE} -f ${_mf} bootstrap-recurse); \ done .endif # create an empty Makefile.depend* to get the ball rolling. bootstrap-empty: .NOTMAIN .NOMETA @echo Creating empty ${RELDIR}/${_want:T}; \ echo You need to build ${RELDIR} to correctly populate it. @{ echo DIRDEPS=; echo ".include "; } > ${_want} .endif .endif diff --git a/mk/install-mk b/mk/install-mk index 89c222cd0ee3..e198d52a8702 100644 --- a/mk/install-mk +++ b/mk/install-mk @@ -1,198 +1,198 @@ : # NAME: # install-mk - install mk files # # SYNOPSIS: # install-mk [options] [var=val] [dest] # # DESCRIPTION: # This tool installs mk files in a semi-intelligent manner into # "dest". # # Options: # # -n just say what we want to do, but don't touch anything. # # -f use -f when copying sys,mk. # # -v be verbose # # -q be quiet # # -m "mode" # Use "mode" for installed files (444). # # -o "owner" # Use "owner" for installed files. # # -g "group" # Use "group" for installed files. # # -U "umask" # Use "umask" so directories are created with suitable # mode (default is 022). # # var=val # Set "var" to "val". See below. # # All our *.mk files are copied to "dest" with appropriate # ownership and permissions. # # By default if a sys.mk can be found in a standard location # (that bmake will find) then no sys.mk will be put in "dest". # # SKIP_SYS_MK: # If set, we will avoid installing our 'sys.mk' # This is probably a bad idea. # # SKIP_BSD_MK: # If set, we will skip making bsd.*.mk links to *.mk # # sys.mk: # # By default (and provided we are not installing to the system # mk dir - '/usr/share/mk') we install our own 'sys.mk' which # includes a sys specific file, or a generic one. # # # AUTHOR: # Simon J. Gerraty # RCSid: -# $Id: install-mk,v 1.231 2023/04/20 17:45:03 sjg Exp $ +# $Id: install-mk,v 1.234 2023/05/13 15:52:24 sjg Exp $ # # @(#) Copyright (c) 1994-2023 Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. # Permission to copy, redistribute or otherwise # use this file is hereby granted provided that # the above copyright notice and this notice are # left intact. # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # -MK_VERSION=20230420 +MK_VERSION=20230510 OWNER= GROUP= MODE=444 BINMODE=555 ECHO=: SKIP= cp_f=-f umask 022 while : do case "$1" in *=*) eval "$1"; shift;; +f) cp_f=; shift;; -f) cp_f=-f; shift;; -m) MODE=$2; shift 2;; -o) OWNER=$2; shift 2;; -g) GROUP=$2; shift 2;; -v) ECHO=echo; shift;; -q) ECHO=:; shift;; -n) ECHO=echo SKIP=:; shift;; -U) umask $2; shift;; --) shift; break;; *) break;; esac done case $# in 0) echo "$0 [options] []" echo "eg." echo "$0 -o bin -g bin -m 444 /usr/local/share/mk" exit 1 ;; esac dest=$1 os=${2:-`uname`} osrel=${3:-`uname -r`} Do() { $ECHO "$@" $SKIP "$@" } Error() { echo "ERROR: $@" >&2 exit 1 } Warning() { echo "WARNING: $@" >&2 } [ "$FORCE_SYS_MK" ] && Warning "ignoring: FORCE_{BSD,SYS}_MK (no longer supported)" SYS_MK_DIR=${SYS_MK_DIR:-/usr/share/mk} SYS_MK=${SYS_MK:-$SYS_MK_DIR/sys.mk} realpath() { [ -d $1 ] && cd $1 && 'pwd' && return echo $1 } # some Linux systems have deprecated egrep in favor of grep -E case "`echo bmake | egrep 'a' 2>&1`" in *"grep -E"*) egrep='grep -E';; *) egrep=egrep;; esac if [ -s $SYS_MK -a -d $dest ]; then # if this is a BSD system we don't want to touch $SYS_MK dest=`realpath $dest` sys_mk_dir=`realpath $SYS_MK_DIR` if [ $dest = $sys_mk_dir ]; then case "$os" in *BSD*) SKIP_SYS_MK=: SKIP_BSD_MK=: ;; *) # could be fake? if [ ! -d $dest/sys -a ! -s $dest/Generic.sys.mk ]; then SKIP_SYS_MK=: # play safe SKIP_BSD_MK=: fi ;; esac fi fi [ -d $dest/sys ] || Do mkdir -p $dest/sys [ -d $dest/sys ] || Do mkdir $dest/sys || exit 1 [ -z "$SKIP" ] && dest=`realpath $dest` cd `dirname $0` mksrc=`'pwd'` if [ $mksrc = $dest ]; then SKIP_MKFILES=: else # we do not install the examples mk_files=`grep '^[a-z].*\.mk' FILES | $egrep -v '(examples/|^sys\.mk|sys/)'` mk_scripts=`$egrep '^[a-z].*\.(sh|py)' FILES | $egrep -v '/'` sys_mk_files=`grep 'sys/.*\.mk' FILES` SKIP_MKFILES= [ -z "$SKIP_SYS_MK" ] && mk_files="sys.mk $mk_files" fi $SKIP_MKFILES Do cp $cp_f $mk_files $dest $SKIP_MKFILES Do cp $cp_f $sys_mk_files $dest/sys $SKIP_MKFILES Do cp $cp_f $mk_scripts $dest $SKIP cd $dest $SKIP_MKFILES Do chmod $MODE $mk_files $sys_mk_files $SKIP_MKFILES Do chmod $BINMODE $mk_scripts [ "$GROUP" ] && $SKIP_MKFILES Do chgrp $GROUP $mk_files $sys_mk_files [ "$OWNER" ] && $SKIP_MKFILES Do chown $OWNER $mk_files $sys_mk_files # if this is a BSD system the bsd.*.mk should exist and be used. if [ -z "$SKIP_BSD_MK" ]; then for f in dep doc files inc init lib links man nls obj own prog subdir do b=bsd.$f.mk [ -s $b ] || Do ln -s $f.mk $b done fi exit 0 diff --git a/mk/jobs.mk b/mk/jobs.mk index f465ea06310b..62fe9eeae030 100644 --- a/mk/jobs.mk +++ b/mk/jobs.mk @@ -1,88 +1,97 @@ -# $Id: jobs.mk,v 1.7 2023/04/18 23:32:28 sjg Exp $ +# $Id: jobs.mk,v 1.9 2023/04/27 18:10:27 sjg Exp $ # # @(#) Copyright (c) 2012-2023, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. # Permission to copy, redistribute or otherwise # use this file is hereby granted provided that # the above copyright notice and this notice are # left intact. # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # # This makefile is used by top-level makefile. # With the following: # # .if make(*-jobs) # .include # .endif # # # Then if you do: # # mk target-jobs # # We will run: # # ${MAKE} -j${JOB_MAX} target > ${JOB_LOGDIR}/target.log 2>&1 # # JOB_MAX defaults to 8 but should normally be derrived based on the # number of cpus available. The wrapper script 'mk' makes that easy. # now_utc ?= ${%s:L:gmtime} .if !defined(start_utc) start_utc := ${now_utc} .endif -.info ${.newline}${TIME_STAMP} Start ${.TARGETS} - .if make(*-jobs) +.info ${.newline}${TIME_STAMP} Start ${.TARGETS} JOB_LOGDIR ?= ${SRCTOP:H} JOB_LOG = ${JOB_LOGDIR}/${.TARGET:S,-jobs,,:S,/,_,g}.log JOB_LOG_GENS ?= 4 # we like to rotate logs .if empty(NEWLOG_SH) +.for d in ${.SYSPATH:U${.PARSEDIR}:@x@$x $x/scripts@} +.if exists($d/newlog.sh) +NEWLOG_SH := $d/newlog.sh +.if ${MAKE_VERSION} > 20220924 +.break +.endif +.endif +.endfor +.if empty(NEWLOG_SH) .ifdef M_whence NEWLOG_SH := ${newlog.sh:L:${M_whence}} .else NEWLOG_SH := ${(type newlog.sh) 2> /dev/null:L:sh:M/*} .endif .endif +.endif .if !empty(NEWLOG_SH) && exists(${NEWLOG_SH}) NEWLOG := sh ${NEWLOG_SH} JOB_NEWLOG_ARGS ?= -S -n ${JOB_LOG_GENS} .else NEWLOG = : .endif .if ${.MAKE.JOBS:U0} > 0 JOB_MAX= ${.MAKE.JOBS} .else # This should be derrived from number of cpu's JOB_MAX?= 8 JOB_ARGS+= -j${JOB_MAX} .endif # we need to reset .MAKE.LEVEL to 0 do that # build orchestration works as expected (DIRDEPS_BUILD) ${.TARGETS:M*-jobs}: @${NEWLOG} ${JOB_NEWLOG_ARGS} ${JOB_LOG} - @echo Logging to ${JOB_LOG} + @echo "${TIME_STAMP} Start ${.TARGET:S,-jobs,,} ${JOB_ARGS} ${JOB_LOG_START} log=${JOB_LOG}" | tee ${JOB_LOG} @cd ${.CURDIR} && env MAKELEVEL=0 \ ${.MAKE} ${JOB_ARGS} _TARGETS=${.TARGET:S,-jobs,,} ${.TARGET:S,-jobs,,} >> ${JOB_LOG} 2>&1 .endif .END: _build_finish .ERROR: _build_failed _build_finish: .NOMETA @echo "${TIME_STAMP} Finished ${.TARGETS} seconds=`expr ${now_utc} - ${start_utc}`" _build_failed: .NOMETA @echo "${TIME_STAMP} Failed ${.TARGETS} seconds=`expr ${now_utc} - ${start_utc}`" diff --git a/mk/meta.autodep.mk b/mk/meta.autodep.mk index cd08ac3b3520..5f012cdec003 100644 --- a/mk/meta.autodep.mk +++ b/mk/meta.autodep.mk @@ -1,329 +1,333 @@ -# $Id: meta.autodep.mk,v 1.56 2022/09/09 17:44:29 sjg Exp $ +# $Id: meta.autodep.mk,v 1.57 2023/05/13 15:52:24 sjg Exp $ # # @(#) Copyright (c) 2010, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. # Permission to copy, redistribute or otherwise # use this file is hereby granted provided that # the above copyright notice and this notice are # left intact. # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # _this ?= ${.PARSEFILE} .if !target(__${_this}__) __${_this}__: .NOTMAIN .-include PICO?= .pico .if defined(SRCS) .if ${MAKE_VERSION:U0} >= 20211212 OBJ_EXTENSIONS += ${.SUFFIXES:M*o} .else # it would be nice to be able to query .SUFFIXES OBJ_EXTENSIONS += .o .po .lo ${PICO} .endif # explicit dependencies help short-circuit .SUFFIX searches SRCS_DEP_FILTER+= N*.[hly] .for s in ${SRCS:${SRCS_DEP_FILTER:O:u:ts:}} .for e in ${OBJ_EXTENSIONS:O:u} .if !target(${s:T:R}$e) ${s:T:R}$e: $s .endif .endfor .endfor .endif .if make(gendirdeps) # you are supposed to know what you are doing! UPDATE_DEPENDFILE = yes .elif !empty(.TARGETS) && !make(all) # do not update the *depend* files # unless we are building the entire directory or the default target. # NO means don't update .depend - or Makefile.depend* # no means update .depend but not Makefile.depend* UPDATE_DEPENDFILE = NO .elif ${.MAKEFLAGS:M-k} != "" # it is a bad idea to update anything UPDATE_DEPENDFILE = NO .endif _CURDIR ?= ${.CURDIR} _OBJDIR ?= ${.OBJDIR} _OBJTOP ?= ${OBJTOP} _OBJROOT ?= ${OBJROOT:U${_OBJTOP}} _DEPENDFILE := ${_CURDIR}/${.MAKE.DEPENDFILE:T} .if ${.MAKE.LEVEL} > 0 # do not allow auto update if we ever built this dir without filemon NO_FILEMON_COOKIE = .nofilemon CLEANFILES += ${NO_FILEMON_COOKIE} .if ${.MAKE.MODE:Uno:Mnofilemon} != "" UPDATE_DEPENDFILE = NO all: ${NO_FILEMON_COOKIE} ${NO_FILEMON_COOKIE}: .NOMETA @echo UPDATE_DEPENDFILE=NO > ${.TARGET} .elif exists(${NO_FILEMON_COOKIE}) UPDATE_DEPENDFILE = NO .warning ${RELDIR} built with nofilemon; UPDATE_DEPENDFILE=NO .endif .endif .if ${.MAKE.LEVEL} == 0 UPDATE_DEPENDFILE = NO .endif .if !exists(${_DEPENDFILE}) _bootstrap_dirdeps = yes .endif _bootstrap_dirdeps ?= no UPDATE_DEPENDFILE ?= yes .if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" .info ${_DEPENDFILE:S,${SRCTOP}/,,} update=${UPDATE_DEPENDFILE} .endif .if !empty(XMAKE_META_FILE) .if exists(${.OBJDIR}/${XMAKE_META_FILE}) # we cannot get accurate dependencies from an update build UPDATE_DEPENDFILE = NO .else META_XTRAS += ${XMAKE_META_FILE} .endif .endif .if ${_bootstrap_dirdeps} == "yes" || exists(${_DEPENDFILE}) # if it isn't supposed to be touched by us the Makefile should have # UPDATE_DEPENDFILE = no WANT_UPDATE_DEPENDFILE ?= yes .endif .if ${WANT_UPDATE_DEPENDFILE:Uno:tl} != "no" .if ${.MAKE.MODE:Uno:Mmeta*} == "" || ${.MAKE.MODE:Uno:M*read*} != "" UPDATE_DEPENDFILE = no .endif .if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" .info ${_DEPENDFILE:S,${SRCTOP}/,,} update=${UPDATE_DEPENDFILE} .endif .if ${UPDATE_DEPENDFILE:tl} == "yes" # sometimes we want .meta files generated to aid debugging/error detection # but do not want to consider them for dependencies # for example the result of running configure # just make sure this is not empty META_FILE_FILTER ?= N.meta # never consider these META_FILE_FILTER += Ndirdeps.cache* .if !empty(DPADD) # if we have any non-libs in DPADD, # they probably need to be paid attention to .if !empty(DPLIBS) FORCE_DPADD = ${DPADD:${DPLIBS:${M_ListToSkip}}:${DPADD_LAST:${M_ListToSkip}}} .else _nonlibs := ${DPADD:T:Nlib*:N*include} .if !empty(_nonlibs) FORCE_DPADD += ${_nonlibs:@x@${DPADD:M*/$x}@} .endif .endif .endif .if !make(gendirdeps) .END: gendirdeps .endif +.if ${LOCAL_DEPENDS_GUARD:U} == "no" +.depend: +.endif + # if we don't have OBJS, then .depend isn't useful .if !target(.depend) && (!empty(OBJS) || ${.ALLTARGETS:M*.o} != "") # some makefiles and/or targets contain # circular dependencies if you dig too deep # (as meta mode is apt to do) # so we provide a means of suppressing them. # the input to the loop below is target: dependency # with just one dependency per line. # Also some targets are not really local, or use random names. # Use local.autodep.mk to provide local additions! SUPPRESS_DEPEND += \ ${SB:S,/,_,g}* \ *:y.tab.c \ *.c:*.c \ *.h:*.h .NOPATH: .depend # we use ${.MAKE.META.CREATED} to trigger an update but # we process using ${.MAKE.META.FILES} # the double $$ defers initial evaluation # if necessary, we fake .po dependencies, just so the result # in Makefile.depend* is stable # The current objdir may be referred to in various ways OBJDIR_REFS += ${.OBJDIR} ${.OBJDIR:tA} ${_OBJDIR} ${RELOBJTOP}/${RELDIR} _depend = .depend # it would be nice to be able to get .SUFFIXES as ${.SUFFIXES} # we actually only care about the .SUFFIXES of files that might be # generated by tools like yacc. .if ${MAKE_VERSION:U0} >= 20211212 DEPEND_SUFFIXES += ${.SUFFIXES:N.sh:N*[0-9aFfglopmnrSsty]} .else DEPEND_SUFFIXES += .c .h .cpp .hpp .cxx .hxx .cc .hh .endif .depend: .NOMETA $${.MAKE.META.CREATED} ${_this} @echo "Updating $@: ${.OODATE:T:[1..8]}" @${EGREP:Uegrep} -i '^R .*\.(${DEPEND_SUFFIXES:tl:O:u:S,^.,,:ts|})$$' /dev/null ${.MAKE.META.FILES:T:O:u:${META_FILE_FILTER:ts:}:M*o.meta} | \ sed -e 's, \./, ,${OBJDIR_REFS:O:u:@d@;s, $d/, ,@};/\//d' \ -e 's,^\([^/][^/]*\).meta...[0-9]* ,\1: ,' | \ sort -u | \ while read t d; do \ case "$$d:" in $$t) continue;; esac; \ case "$$t$$d" in ${SUPPRESS_DEPEND:U.:O:u:ts|}) continue;; esac; \ echo $$t $$d; \ done > $@.${.MAKE.PID} @case "${.MAKE.META.FILES:T:M*.po.*}" in \ *.po.*) mv $@.${.MAKE.PID} $@;; \ *) { cat $@.${.MAKE.PID}; \ sed ${OBJ_EXTENSIONS:N.o:N.po:@o@-e 's,\$o:,.o:,'@} \ -e 's,\.o:,.po:,' $@.${.MAKE.PID}; } | sort -u > $@; \ rm -f $@.${.MAKE.PID};; \ esac .else # make sure this exists .depend: # do _not_ assume that .depend is in any fit state for us to use CAT_DEPEND = /dev/null .if ${.MAKE.LEVEL} > 0 .export CAT_DEPEND .endif _depend = .endif .if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" .info ${_DEPENDFILE:S,${SRCTOP}/,,} _depend=${_depend} .endif .if ${UPDATE_DEPENDFILE} == "yes" gendirdeps: ${_DEPENDFILE} .endif .if !target(${_DEPENDFILE}) .if ${_bootstrap_dirdeps} == "yes" # We are boot-strapping a new directory # Use DPADD to seed DIRDEPS .if !empty(DPADD) # anything which matches ${_OBJROOT}* but not ${_OBJTOP}* # needs to be qualified in DIRDEPS # The pseudo machine "host" is used for HOST_TARGET DIRDEPS += \ ${DPADD:M${_OBJTOP}*:H:C,${_OBJTOP}[^/]*/,,:N.:O:u} \ ${DPADD:M${_OBJROOT}*:N${_OBJTOP}*:N${STAGE_ROOT:U${_OBJTOP}}/*:H:S,${_OBJROOT},,:C,^([^/]+)/(.*),\2.\1,:S,${HOST_TARGET}$,host,:N.*:O:u} .endif .endif _gendirdeps_mutex = .if defined(NEED_GENDIRDEPS_MUTEX) # If a src dir gets built with multiple object dirs, # we need a mutex. Obviously, this is best avoided. # Note if .MAKE.DEPENDFILE is common for all ${MACHINE} # you either need to mutex, or ensure only one machine builds at a time! # lockf is an example of a suitable tool LOCKF ?= /usr/bin/lockf .if exists(${LOCKF}) GENDIRDEPS_MUTEXER ?= ${LOCKF} -k .endif .if empty(GENDIRDEPS_MUTEXER) .error NEED_GENDIRDEPS_MUTEX defined, but GENDIRDEPS_MUTEXER not set .else _gendirdeps_mutex = ${GENDIRDEPS_MUTEXER} ${GENDIRDEPS_MUTEX:U${_CURDIR}/Makefile} .endif .endif # If we have META_XTRAS we most likely did not create them # but we need to behave as if we did. # Avoid adding glob patterns to .MAKE.META.CREATED though. .MAKE.META.CREATED += ${META_XTRAS:N*\**:O:u} .if make(gendirdeps) META_FILES = *.meta .elif ${OPTIMIZE_OBJECT_META_FILES:Uno:tl} == "no" META_FILES = ${.MAKE.META.FILES:T:N.depend*:O:u} .else # if we have 1000's of .o.meta, ${PICO}.meta etc we need only look at one set # it is left as an exercise for the reader to work out what this does META_FILES = ${.MAKE.META.FILES:T:N.depend*:N*o.meta:O:u} \ ${.MAKE.META.FILES:T:M*.${.MAKE.META.FILES:M*o.meta:R:E:O:u:[1]}.meta:O:u} .endif .if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" .info ${_DEPENDFILE:S,${SRCTOP}/,,}: ${_depend} ${.PARSEDIR}/gendirdeps.mk ${META2DEPS} xtras=${META_XTRAS} .endif .if ${.MAKE.LEVEL} > 0 .if ${UPDATE_DEPENDFILE} == "yes" .-include <${.CURDIR}/${.MAKE.DEPENDFILE_PREFIX}.options> .endif .if !empty(GENDIRDEPS_FILTER) .export GENDIRDEPS_FILTER .endif # export to avoid blowing command line limit META_FILES := ${META_XTRAS:U:O:u} ${META_FILES:U:T:O:u:${META_FILE_FILTER:ts:}} .export META_FILES .endif # we might have .../ in MAKESYSPATH _makesyspath:= ${_PARSEDIR} ${_DEPENDFILE}: ${_depend} ${.PARSEDIR}/gendirdeps.mk ${META2DEPS} $${.MAKE.META.CREATED} @echo Checking $@: ${.OODATE:T:[1..8]} @(cd . && ${GENDIRDEPS_ENV} \ SKIP_GENDIRDEPS='${SKIP_GENDIRDEPS:O:u}' \ DPADD='${FORCE_DPADD:O:u}' ${_gendirdeps_mutex} \ MAKESYSPATH=${_makesyspath} \ ${.MAKE} -f gendirdeps.mk RELDIR=${RELDIR} _DEPENDFILE=${_DEPENDFILE}) @test -s $@ && touch $@; : .endif .endif .endif .if ${_bootstrap_dirdeps} == "yes" DIRDEPS+= ${RELDIR}.${TARGET_SPEC:U${MACHINE}} # make sure this is included at least once .include .else ${_DEPENDFILE}: .PRECIOUS .endif CLEANFILES += *.meta filemon.* *.db # these make it easy to gather some stats now_utc = ${%s:L:gmtime} start_utc := ${now_utc} meta_stats= meta=${empty(.MAKE.META.FILES):?0:${.MAKE.META.FILES:[#]}} \ created=${empty(.MAKE.META.CREATED):?0:${.MAKE.META.CREATED:[#]}} .if !target(_reldir_finish) #.END: _reldir_finish .if target(gendirdeps) _reldir_finish: gendirdeps .endif _reldir_finish: .NOMETA @echo "${TIME_STAMP} Finished ${RELDIR}.${TARGET_SPEC} seconds=$$(( ${now_utc} - ${start_utc} )) ${meta_stats}" .endif .if !target(_reldir_failed) #.ERROR: _reldir_failed _reldir_failed: .NOMETA @echo "${TIME_STAMP} Failed ${RELDIR}.${TARGET_SPEC} seconds=$$(( ${now_utc} - ${start_utc} )) ${meta_stats}" .endif .if !defined(WITHOUT_META_STATS) && ${.MAKE.LEVEL} > 0 .END: _reldir_finish .ERROR: _reldir_failed .endif .endif diff --git a/mk/meta.sys.mk b/mk/meta.sys.mk index 1fc58a226cb1..ba213dd49da4 100644 --- a/mk/meta.sys.mk +++ b/mk/meta.sys.mk @@ -1,218 +1,153 @@ -# $Id: meta.sys.mk,v 1.46 2023/04/18 18:43:00 sjg Exp $ +# $Id: meta.sys.mk,v 1.51 2023/05/11 20:05:32 sjg Exp $ # -# @(#) Copyright (c) 2010-2021, Simon J. Gerraty +# @(#) Copyright (c) 2010-2023, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. # Permission to copy, redistribute or otherwise # use this file is hereby granted provided that # the above copyright notice and this notice are # left intact. # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # # include this if you want to enable meta mode # for maximum benefit, requires filemon(4) driver. -.if ${MAKE_VERSION:U0} > 20100901 -.if !target(.ERROR) +# absolute path to what we are reading. +_PARSEDIR ?= ${.PARSEDIR:tA} .-include -# If TARGET_SPEC_VARS is other than just MACHINE -# it should be set by now. -# TARGET_SPEC must not contain any '.'s. -TARGET_SPEC_VARS ?= MACHINE - -.if !target(_meta_tspec_env_done_) -_meta_tspec_env_done_: .NOTMAIN -# Allow for local.meta.sys.env.mk to have done this - -.if ${TARGET_SPEC:Uno:M*,*} != "" -# deal with TARGET_SPEC from env -_tspec := ${TARGET_SPEC:S/,/ /g} -.for i in ${TARGET_SPEC_VARS:${M_RANGE:Urange}} -${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]} -.endfor -# We need to stop that TARGET_SPEC affecting any submakes -TARGET_SPEC= -# so export but do not track -.export-env TARGET_SPEC -.export ${TARGET_SPEC_VARS} -.for v in ${TARGET_SPEC_VARS:O:u} -.if empty($v) -.undef $v -.endif -.endfor -.endif -.endif - -# Now make sure we know what TARGET_SPEC is -# as we may need it to find Makefile.depend* -.if ${MACHINE:Mhost*} != "" -# host is special -TARGET_SPEC = ${MACHINE} -.else -TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} -.endif - -# absolute path to what we are reading. -_PARSEDIR = ${.PARSEDIR:tA} - .if !defined(SYS_MK_DIR) SYS_MK_DIR := ${_PARSEDIR} .endif -META_MODE += meta verbose +.if !target(.ERROR) + +META_MODE += meta +.if empty(.MAKEFLAGS:M-s) +META_MODE += verbose +.endif .if ${MAKE_VERSION:U0} > 20130323 && empty(.MAKE.PATH_FILEMON) # we do not support filemon META_MODE += nofilemon MKDEP_MK ?= auto.dep.mk .endif .MAKE.MODE ?= ${META_MODE} _filemon := ${.MAKE.PATH_FILEMON:U/dev/filemon} .if empty(UPDATE_DEPENDFILE) _make_mode := ${.MAKE.MODE} ${META_MODE} .if ${_make_mode:M*read*} != "" || ${_make_mode:M*nofilemon*} != "" # tell everyone we are not updating Makefile.depend* UPDATE_DEPENDFILE = NO .export UPDATE_DEPENDFILE .endif .if ${_filemon:T:Mfilemon} == "filemon" .if ${UPDATE_DEPENDFILE:Uyes:tl} == "no" && !exists(${_filemon}) # we should not get upset META_MODE += nofilemon .export META_MODE .endif .endif .endif .if !defined(NO_SILENT) .if ${MAKE_VERSION} > 20110818 # only be silent when we have a .meta file META_MODE += silent=yes .else .SILENT: .endif .endif -# we use the pseudo machine "host" for the build host. -# this should be taken care of before we get here -.if ${OBJTOP:Ua} == ${HOST_OBJTOP:Ub} -MACHINE = host -.endif - -.if !defined(MACHINE0) -# it can be handy to know which MACHINE kicked off the build -# for example, if using Makefild.depend for multiple machines, -# allowing only MACHINE0 to update can keep things simple. -MACHINE0 := ${MACHINE} -.export MACHINE0 -.endif +.if ${MK_DIRDEPS_BUILD:Uno} == "yes" .if !defined(META2DEPS) .if defined(PYTHON) && exists(${PYTHON}) # we prefer the python version of this - it is much faster META2DEPS ?= ${.PARSEDIR}/meta2deps.py .else META2DEPS ?= ${.PARSEDIR}/meta2deps.sh .endif META2DEPS := ${META2DEPS} .export META2DEPS .endif MAKE_PRINT_VAR_ON_ERROR += \ .ERROR_TARGET \ .ERROR_META_FILE \ .MAKE.LEVEL \ MAKEFILE \ .MAKE.MODE +MK_META_ERROR_TARGET = yes +.endif + +.if ${MK_META_ERROR_TARGET:Uno} == "yes" + .if !defined(SB) && defined(SRCTOP) SB = ${SRCTOP:H} .endif ERROR_LOGDIR ?= ${SB}/error meta_error_log = ${ERROR_LOGDIR}/meta-${.MAKE.PID}.log # we are not interested in make telling us a failure happened elsewhere .ERROR: _metaError _metaError: .NOMETA .NOTMAIN -@[ "${.ERROR_META_FILE}" ] && { \ grep -q 'failure has been detected in another branch' ${.ERROR_META_FILE} && exit 0; \ mkdir -p ${meta_error_log:H}; \ cp ${.ERROR_META_FILE} ${meta_error_log}; \ echo "ERROR: log ${meta_error_log}" >&2; }; : .endif +.endif # Are we, after all, in meta mode? .if ${.MAKE.MODE:Uno:Mmeta*} != "" MKDEP_MK ?= meta.autodep.mk -.if ${.MAKE.MAKEFILES:M*sys.dependfile.mk} == "" -# this does all the smarts of setting .MAKE.DEPENDFILE -.-include -# check if we got anything sane -.if ${.MAKE.DEPENDFILE} == ".depend" -.undef .MAKE.DEPENDFILE -.endif -.MAKE.DEPENDFILE ?= Makefile.depend -.endif - # we can afford to use cookies to prevent some targets # re-running needlessly META_COOKIE_TOUCH?= touch ${COOKIE.${.TARGET}:U${.OBJDIR}/${.TARGET:T}} META_NOPHONY= META_NOECHO= : # some targets involve old pre-built targets # ignore mtime of shell # and mtime of makefiles does not matter in meta mode .MAKE.META.IGNORE_PATHS += \ ${MAKEFILE} \ ${MAKE_SHELL} \ ${SHELL} \ ${SYS_MK_DIR} \ .if ${UPDATE_DEPENDFILE:Uyes:tl} != "no" .if ${.MAKEFLAGS:Uno:M-k} != "" # make this more obvious .warning Setting UPDATE_DEPENDFILE=NO due to -k UPDATE_DEPENDFILE= NO .export UPDATE_DEPENDFILE .elif ${_filemon:T} == "filemon" && !exists(${_filemon}) .error ${.newline}ERROR: The filemon module (${_filemon}) is not loaded. .endif .endif -.if ${.MAKE.LEVEL} == 0 -.if ${MK_DIRDEPS_BUILD:Uyes} == "yes" -# make sure dirdeps target exists and do it first -all: dirdeps .WAIT -dirdeps: -.NOPATH: dirdeps - -.if defined(ALL_MACHINES) -# the first .MAIN: is what counts -# by default dirdeps is all we want at level0 -.MAIN: dirdeps -.endif -.endif +.else # in meta mode? -.endif -.else META_COOKIE_TOUCH= # some targets need to be .PHONY in non-meta mode META_NOPHONY= .PHONY META_NOECHO= echo -.endif -.endif + +.endif # in meta mode? .-include diff --git a/mk/mk-files.txt b/mk/mk-files.txt index 337df19613e0..0afcea189470 100644 --- a/mk/mk-files.txt +++ b/mk/mk-files.txt @@ -1,546 +1,591 @@ mk-files ******** The term ``mk-files`` refers to a collection of ``*.mk`` files. You need bmake_ or a *recent* NetBSD_ make. If in doubt use bmake_. Introduction ============ Many years ago, when building large software projects, I used GNU make (or my own patched version of it), and had developed a set of macros to simplify developing complex build trees. Since the early 90's my main development machines, run BSD (NetBSD_ to be precise, and more recently FreeBSD), and the BSD source tree is good example of a large software project. It quickly became clear that ``/usr/share/mk/*.mk`` were a great model, but at the time were quite tightly linked to building the BSD tree. Much as I liked using NetBSD, my customers were more likely to be using SunOS, HP-UX etc, so I started on bmake_ and a portable collection of mk-files (mk.tar.gz_). NetBSD provided much of the original structure. Since then I've added a lot of features to NetBSD's make and hence to bmake which is kept closely in sync. The mk-files however have diverged quite a bit, though ideas are still picked up from NetBSD and FreeBSD. Basics ------ The BSD build model is very simple. A directory produces one component, which is generally either a library or a program. Library makefiles include ``lib.mk`` and programs include ``prog.mk`` and they *do the right thing*. A simple library makefile might look like:: LIB = sig SRCS = \ sigaction.c \ sigcompat.c \ sighdl.c .include a simple program makefile:: PROG = cat SRCS = cat.c .include in such cases even the ``SRCS`` line is unnecessary as ``prog.mk`` will default it to ``${PROG}.c``. It is the sensible use of defaults and the plethora of macro modifiers provided by bmake_ that allow simple makefiles such as the above to *just work* on many different systems. mk-files ======== This section provides a brief description of some of the ``*.mk`` files. sys.mk ------ When bmake starts, it looks for ``sys.mk`` and reads it before doing anything else. Thus, this is the place to setup the environment for everyone else. In this distribution, ``sys.mk`` avoids doing anything platform or site dependent. It is quite short, and includes a number of other files (which may or may not exists) sys.env.mk If it exists, is expected to do things like conditioning the environment. Since it will only be included by the initial instance of bmake, it should ``.export`` anything that sub-makes might need. examples/sys.clean-env.mk An example of how to clean the environment. See the file for all the details:: .if ${MAKE_VERSION} >= 20100606 && ${.MAKE.LEVEL} == 0 # we save any env var that starts with these MAKE_SAVE_ENV_PREFIX += SB MK MAKE MACHINE NEED_ CCACHE DISTCC USE_ SSH MAKE_SAVE_ENV_VARS += \ PATH HOME USER LOGNAME \ SRCTOP OBJTOP OBJROOT \ ${_env_vars} _env_vars != env | egrep '^(${MAKE_SAVE_ENV_PREFIX:ts|})' | sed 's,=.*,,'; echo _export_list = .for v in ${MAKE_SAVE_ENV_VARS:O:u} .if !empty($v) _export_list += $v $v := ${$v} .endif .endfor # now clobber the environment .unexport-env # list of vars that we handle specially below _tricky_env_vars = MAKEOBJDIR # export our selection - sans tricky ones .export ${_export_list:${_tricky_env_vars:${M_ListToSkip}}} # this next bit may need tweaking .if defined(MAKEOBJDIR) srctop := ${SRCTOP:U${SB_SRC:U${SB}/src}} objroot := ${OBJROOT:U${SB_OBJROOT:U${SB}/${SB_OBJPREFIX}}} # we'll take care of MACHINE below objtop := ${OBJTOP:U${objroot}${MACHINE}} .if !empty(objtop) # we would normally want something like (/bin/sh): # MAKEOBJDIR="\${.CURDIR:S,${SRCTOP},${OBJROOT}\${MACHINE},}" # the $$ below is how we achieve the same result here. # since everything saved from the environment above # has run through := we need to compensate for ${MACHINE} MAKEOBJDIR = $${.CURDIR:S,${srctop},${objtop:S,${MACHINE},\${MACHINE},},} # export these as-is, and do not track... .export-env ${_tricky_env_vars} # now evaluate for ourselves .for v in ${_tricky_env_vars} $v := ${$v} .endfor .endif .endif .endif host-target.mk Is used to set macros like ``HOST_TARGET``, ``HOST_OS`` and ``host_os`` which are used to find the next step. Note: since 20130303 bmake provides ``.MAKE.OS`` set to the equivalent of ``HOST_OS``. sys/\*.mk Platform specific additions, such as ``Darwin.mk`` or ``SunOS.mk`` set things like ``HOST_LIBEXT = .dylib`` for Darwin or ``SHLIB_FULLVERSION = ${SHLIB_MAJOR}`` for SunOS 5. If there is no OS specific file, ``sys/Generic.mk`` is used. local.sys.mk Any ``local.*.mk`` file is not part of the distribution. This provides a hook for sites to do extra setup without having to edit the distributed files. The above arrangement makes it easy for the mk files to be part of a src tree on an NFS volume and to allow building on multiple platforms. options.mk ---------- Inspired by FreeBSD's ``bsd.own.mk`` but more flexible. FreeBSD now have similar functionality in ``bsd.mkopt.mk``. It allows users to express their intent with respect to options ``MK_*`` by setting ``WITH_*`` or ``WITHOUT_*``. Note: ``WITHOUT_*`` wins if both are set, and makefiles can set ``NO_*`` to say they cannot handle that option, or even ``MK_*`` if they really need to. lib.mk ------ This file is used to build a number of different libraries from the same SRCS. ``lib${LIB}.a`` An archive lib of ``.o`` files, this is the default ``lib${LIB}_p.a`` A profiled lib of ``.po`` files. Still an archive lib, but all the objects are built with profiling in mind - hence the different extension. It is skipped if ``MK_PROFILE`` is "no". ``lib${LIB}_pic.a`` An archive of ``.so`` objects compiled for relocation. On NetBSD this is the input to ``lib${LIB}.${LD_so}``, it is skipped if ``MK_PIC`` or ``MK_PICLIB`` are "no". ``lib${LIB}.${LD_so}`` A shared library. The value of ``LD_so`` is very platform specific. For example:: # SunOS 5 and most other ELF systems libsslfd.so.1 # Darwin libsslfd.1.dylib This library will only be built if ``SHLIB_MAJOR`` has a value, and ``MK_PIC`` is not set to "no". There is a lot of platform specific tweaking in ``lib.mk``, largely the result of the original distributions trying to avoid interfering with the system's ``sys.mk``. libnames.mk ----------- This is included by both ``prog.mk`` and ``lib.mk`` and tries to include ``*.libnames.mk`` of which: ``local.libnames.mk`` does not exist unless you create it. It is a handy way for you to customize without touching the distributed files. For example, on a test machine I needed to build openssl but not install it, so put the following in ``local.libnames.mk``:: .if ${host_os} == "sunos" LIBCRYPTO = ${OBJTOP}/openssl/lib/crypto/libcrypto${DLIBEXT} LIBSSL = ${OBJTOP}/openssl/lib/ssl/libssl${DLIBEXT} INCLUDES_libcrypto = -I${OBJ_libcrypto} .endif The makefile created an openssl dir in ``${OBJ_libcrypto}`` to gather all the headers. dpadd.mk_ did the rest. ``host.libnames.mk`` contains logic to find any libs named in ``HOST_LIBS`` in ``HOST_LIBDIRS``. Each file above gets an opportunity to define things like:: LIBSSLFD ?= ${OBJTOP}/ssl/lib/sslfd/libsslfd${DLIBEXT} INCLUDES_libsslfd = -I${SRC_libsslfd}/h -I${OBJ_libslfd} these are used by dpadd.mk_ and will be explained below. dpadd.mk -------- This file looks like line noise, and is best considered read-only. However it provides some very useful functionality, which simplifies the build. Makefiles can use the LIB* macros defined via libnames.mk_ or anywhere else in various ways:: # indicate that we need to include headers from LIBCRYPTO # this would result in ${INCLUDES_libcrypto} being added to CFLAGS. SRC_LIBS += ${LIBCRYPTO} # indicate that libsslfd must be built already. # it also has the same effect as SRC_LIBS DPADD += ${LIBSSLFD} # indicate that not only must libsslfd be built, # but that we need to link with it. # this is almost exactly equivalent to # DPADD += ${LIBSSLFD} # LDADD += -L${LIBSSLFD:H} -lsslfd # and mostly serves to ensure that DPADD and LDADD are in sync. DPLIBS += ${LIBSSLFD} Any library (referenced by its full path) in any of the above, is added to ``DPMAGIC_LIBS`` with the following results, for each lib *foo*. ``SRC_libfoo`` Is set to indicate where the src for libfoo is. By default it is derived from ``LIBFOO`` by replacing ``${OBJTOP}`` with ``${SRCTOP}``. ``OBJ_libfoo`` Not very exciting, is just the dir where libfoo lives. ``INCLUDES_libfoo`` What to add to ``CFLAGS`` to find the public headers. The default varies. If ``${SRC_libfoo}/h`` exists, it is assumed to be the home of all public headers and thus the default is ``-I${SRC_libfoo}/h`` Otherwise we make no assumptions and the default is ``-I${SRC_libfoo} -I${OBJ_libfoo}`` ``LDADD_libfoo`` This only applies to libs reference via ``DPLIBS``. The default is ``-lfoo``, ``LDADD_*`` provides a hook to instantiate other linker flags at the appropriate point without losing the benfits of ``DPLIBS``. prog.mk ------- Compiles the specified SRCS and links them and the nominated libraries into a program. Prog makefiles usually need to list the libraries that need to be linked. We prefer use of ``DPLIBS`` but the more traditional ``DPADD`` and ``LDADD`` work just as well. That is:: DPLIBS += ${LIBCRYPTO} is equivalent to:: DPADD += ${LIBCRYPTO} LDADD += -lcrypto obj.mk ------ One of the cool aspects of BSD make, is its support for separating object files from the src tree. This is also the source of much confusion for people unfamiliar with it. Traditionally one had to do a separate ``make obj`` pass through the tree. If ``MK_AUTO_OBJ`` is set we include auto.obj.mk_. In fact if ``MKOBJDIRS`` is set to "auto", `sys.mk`_ will set ``MK_AUTO_OBJ=yes`` and include auto.obj.mk_ since it is best done early. auto.obj.mk ----------- Creates object dirs and leverages the ``.OBJDIR`` target introduced some years ago to NetBSD make, to use them. subdir.mk --------- This is the traditional means of walking the tree. A makefile sets ``SUBDIR`` to the list of sub-dirs to visit. If ``SUBDIR_MUST_EXIST`` is set, missing directories cause an error, otherwise a warning is issued. If you don't even want the warning, set ``MISSING_DIR=continue``. Traditionally, ``subdir.mk`` prints clues as it visits each subdir:: ===> ssl ===> ssl/lib ===> ssl/lib/sslfd you can suppress that - or enhance it by setting ``ECHO_DIR``:: # suppress subdir noise ECHO_DIR=: # print time stamps ECHO_DIR=echo @ `date "+%s [%Y-%m-%d %T] "` I prefer to use `dirdeps.mk`_ which makes ``subdir.mk`` irrelevant. links.mk -------- Provides rules for processing lists of ``LINKS`` and ``SYMLINKS``. Each is expected to be a list of ``link`` and ``target`` pairs (``link`` -> ``target``). The logic is generally in a ``_*_SCRIPT`` which is referenced in a ``_*_USE`` (``.USE``) target. The ``_BUILD_*`` forms are identical, but do not use ``${DESTDIR}`` and so are useful for creating symlinks during the build phase. For example:: SYMLINKS += ${.CURDIR}/${MACHINE_ARCH}/include machine header_links: _BUILD_SYMLINKS_USE md.o: header_links would create a symlink called ``machine`` in ``${.OBJDIR}`` pointing to ``${.CURDIR}/${MACHINE_ARCH}/include`` before compiling ``md.o`` autoconf.mk ----------- Deals with running (or generating) GNU autoconf ``configure`` scripts. dep.mk ------ Deals with collecting dependencies. Another useful feature of BSD make is the separation of this sort of information into a ``.depend`` file. ``MKDEP_CMD`` needs to point to a suitable tool (like mkdeps.sh_) If ``MK_AUTODEP`` is "yes" it sets ``MKDEP_MK`` to autodep.mk_ by default. ``MKDEP_MK`` can also be set to `auto.dep.mk`_ which is more efficient but does not support an explicit ``depend`` target. autodep.mk ---------- Leverages the ``-MD`` feature of recent GCC to collect dependency information as a side effect of compilation. With this GCC puts dependency info into a ``.d`` file. Unfortunately GCC bases the name of the ``.d`` file on the name of the input rather than the output file, which causes problems when the same source is compiled different ways. The latest GCC supports ``-MF`` to name the ``.d`` file and ``-MT`` to control the name to put as the dependent. Recent bmake allows dependencies for the ``.END`` target (run at the end if everything was successful), and ``autodep.mk`` uses this to post process the ``.d`` files into ``.depend``. auto.dep.mk ----------- A much simpler implementation than autodep.mk_ it uses ``-MF ${.TARGET:T}.d`` to avoid possible conflicts during parallel builds. This precludes the use of suffix rules to drive ``make depend``, so dep.mk_ handles that if specifically requested. If ``bmake`` is 20160218 or newer, ``auto.dep.mk`` uses ``.dinclude`` to includes the ``*.d`` files directly thus avoiding the need to create a ``.depend`` file from them. own.mk ------ Normally included by ``init.mk`` (included by ``lib.mk`` and ``prog.mk`` etc), sets macros for default ownership etc. It includes ``${MAKECONF}`` if it is defined and exists. ldorder.mk ---------- Leverages ``bmake`` to compute optimal link order for libraries. This works nicely and makes refactoring a breeze - so long as you have no (or few) cicular dependencies between libraries. +Consider this experimental. + man.mk ------ Deals with man pages. warnings.mk ----------- This provides a means of fine grained control over warnings on a per ``${MACHINE}`` or even file basis. A makefile sets ``WARNINGS_SET`` to name a list of warnings and individual ``W_*`` macros can be used to tweak them. For example:: WARNINGS_SET = HIGH W_unused_sparc = -Wno-unused would add all the warnings in ``${HIGH_WARNINGS}`` to CFLAGS, but on sparc, ``-Wno-unused`` would replace ``-Wunused``. You should never need to edit ``warnings.mk``, it will include ``warnings-sets.mk`` and/or ``local.warnings.mk`` to pick up customizations. rst2htm.mk ---------- Logic to simplify generating HTML (and PDF) documents from ReStructuredText. cython.mk --------- Logic to build Python C interface modules using Cython_ .. _Cython: http://www.cython.org/ cc-wrap.mk ---------- This makefile leverages two new features in bmake 20220126 and later. First is the ablity to set target local variables (GNU make has done this for ages). The second (only intersting if using `meta mode`_) allows filtering commands before comparison with previous run to decide if a target is out-of-date. In the past, making use of compiler wrappers like ``ccache``, ``distcc`` or the newer ``icecc`` could get quite ugly. Using ``cc-wrap.mk`` it could not be simpler. jobs.mk ------- This should be included by the top-level makefile. If you do:: make something-jobs then ``jobs.mk`` will run:: make -j${JOB_MAX} someting > ${JOB_LOGDIR}/something.log 2>&1 this ensures you get a build log and JOB_MAX is assumed to be set optimally for the host. -Meta mode +META_MODE ========= The 20110505 and later versions of ``mk-files`` include a number of makefiles contributed by Juniper Networks, Inc. These allow the latest version of bmake_ to run in `meta mode`_ -see `dirdeps.mk`_ +see `dirdeps.mk`_ and DIRDEPS_BUILD_ below. .. _`dirdeps.mk`: /help/sjg/dirdeps.htm .. _`meta mode`: bmake-meta-mode.htm +DIRDEPS_BUILD +============= + +When the `meta mode`_ was originally done, there was no distinction +between META_MODE_ and ``DIRDEPS_BUILD``, but as these were integrated +into FreeBSD it became clear that META_MODE_ could be useful to many +developers independently of ``DIRDEPS_BUILD``. + +Thus today we distinguish between the two. +We have the following makefiles which are relevant to +``DIRDEPS_BUILD`` or META_MODE_:: + + share/mk/auto.obj.mk + share/mk/dirdeps-cache-update.mk + share/mk/dirdeps-only.mk + share/mk/dirdeps-options.mk + share/mk/dirdeps-targets.mk + share/mk/dirdeps.mk + share/mk/gendirdeps.mk + share/mk/host-target.mk + share/mk/install-new.mk + share/mk/meta.autodep.mk + share/mk/meta.stage.mk + share/mk/meta.sys.mk + share/mk/meta2deps.py + share/mk/meta2deps.sh + share/mk/sys.dependfile.mk + share/mk/sys.dirdeps.mk + +and the following are typically used for customization. +See `freebsd-meta-mode`_ and `netbsd-meta-mode`_:: + + share/mk/local.dirdeps-build.mk + share/mk/local.dirdeps-missing.mk + share/mk/local.dirdeps.mk + share/mk/local.meta.sys.mk + share/mk/local.sys.dirdeps.env.mk + share/mk/local.sys.dirdeps.mk + share/mk/local.sys.mk + + Install ======= You can use the content of mk.tar.gz_ without installing at all. The script ``install-mk`` takes care of copying ``*.mk`` into a destination directory, and unless told not to, create ``bsd.*.mk`` links for ``lib.mk`` etc. If you just want to create the ``bsd.*.mk`` links in the directory where you unpacked the tar file, you can:: ./mk/install-mk ./mk ------ .. _bmake: bmake.htm .. _NetBSD: http://www.netbsd.org/ -.. _mkdeps.sh: http://www.crufty.net/ftp/pub/sjg/mkdeps.sh -.. _mk.tar.gz: http://www.crufty.net/ftp/pub/sjg/mk.tar.gz +.. _mkdeps.sh: https://www.crufty.net/ftp/pub/sjg/mkdeps.sh +.. _mk.tar.gz: https://www.crufty.net/ftp/pub/sjg/mk.tar.gz +.. _`freebsd-meta-mode`: https://www.crufty.net/sjg/docs/freebsd-meta-mode.htm +.. _`netbsd-meta-mode`: https://www.crufty.net/sjg/docs/netbsd-meta-mode.htm :Author: sjg@crufty.net -:Revision: $Id: mk-files.txt,v 1.22 2023/04/16 23:43:33 sjg Exp $ +:Revision: $Id: mk-files.txt,v 1.23 2023/05/11 22:55:08 sjg Exp $ :Copyright: Crufty.NET diff --git a/mk/newlog.sh b/mk/newlog.sh new file mode 100755 index 000000000000..526d1700d98f --- /dev/null +++ b/mk/newlog.sh @@ -0,0 +1,412 @@ +#!/bin/sh + +# NAME: +# newlog - rotate log files +# +# SYNOPSIS: +# newlog.sh [options] "log"[:"num"] ... +# +# DESCRIPTION: +# This script saves multiple generations of each "log". +# The "logs" are kept compressed except for the current and +# previous ones. +# +# Options: +# +# -C "compress" +# Compact old logs (other than .0) with "compress" +# (default is 'gzip' or 'compress' if no 'gzip'). +# +# -E "ext" +# If "compress" produces a file extention other than +# '.Z' or '.gz' we need to know. +# +# -G "gens" +# "gens" is a comma separated list of "log":"num" pairs +# that allows certain logs to handled differently. +# +# -N Don't actually do anything, just show us. +# +# -R Rotate rather than save logs by default. +# This is the default anyway. +# +# -S Save rather than rotate logs by default. +# Each log is saved to a unique name that remains +# unchanged. This results in far less churn. +# +# -f "fmt" +# Format ('%Y%m%d.%H%M%S') for suffix added to "log" to +# uniquely name it when using the '-S' option. +# If a "log" is saved more than once per second we add +# an extra suffix of our process-id. +# +# -d The "log" to be rotated/saved is a directory. +# We leave the mode of old directories alone. +# +# -e Normally logs are only cycled if non-empty, this +# option forces empty logs to be cycled as well. +# +# -g "group" +# Set the group of "log" to "group". +# +# -m "mode" +# Set the mode of "log". +# +# -M "mode" +# Set the mode of old logs (default 444). +# +# -n "num" +# Keep "num" generations of "log". +# +# -o "owner" +# Set the owner of "log". +# +# Regardless of whether '-R' or '-S' is provided, we attempt to +# choose the correct behavior based on observation of "log.0" if +# it exists; if it is a symbolic link, we save, otherwise +# we rotate. +# +# BUGS: +# 'Newlog.sh' tries to avoid being fooled by symbolic links, but +# multiply indirect symlinks are only handled on machines where +# test(1) supports a check for symlinks. +# +# AUTHOR: +# Simon J. Gerraty +# + +# RCSid: +# $Id: newlog.sh,v 1.26 2021/04/30 16:29:02 sjg Exp $ +# +# @(#) Copyright (c) 1993-2016 Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +Mydir=`dirname $0` +case $Mydir in +/*) ;; +*) Mydir=`cd $Mydir; pwd`;; +esac + +# places to find chown (and setopts.sh) +PATH=$PATH:/usr/etc:/sbin:/usr/sbin:/usr/local/share/bin:/share/bin:$Mydir + +# linux doesn't necessarily have compress, +# and gzip appears in various locations... +Which() { + case "$1" in + -*) t=$1; shift;; + *) t=-x;; + esac + case "$1" in + /*) test $t $1 && echo $1;; + *) + for d in `IFS=:; echo ${2:-$PATH}` + do + test $t $d/$1 && { echo $d/$1; break; } + done + ;; + esac +} + +# shell's typically have test(1) as built-in +# and not all support all options. +test_opt() { + _o=$1 + _a=$2 + _t=${3:-/} + + case `test -$_o $_t 2>&1` in + *:*) eval test_$_o=$_a;; + *) eval test_$_o=-$_o;; + esac +} + +# convert find/ls mode to octal +fmode() { + eval `echo $1 | + sed 's,\(.\)\(...\)\(...\)\(...\),ft=\1 um=\2 gm=\3 om=\4,'` + sm= + case "$um" in + *s*) sm=r + um=`echo $um | sed 's,s,x,'` + ;; + *) sm=-;; + esac + case "$gm" in + *[Ss]*) + sm=${sm}w + gm=`echo $gm | sed 's,s,x,;s,S,-,'` + ;; + *) sm=${sm}-;; + esac + case "$om" in + *t) + sm=${sm}x + om=`echo $om | sed 's,t,x,'` + ;; + *) sm=${sm}-;; + esac + echo $sm $um $gm $om | + sed 's,rwx,7,g;s,rw-,6,g;s,r-x,5,g;s,r--,4,g;s,-wx,3,g;s,-w-,2,g;s,--x,1,g;s,---,0,g;s, ,,g' +} + +get_mode() { + case "$OS,$STAT" in + FreeBSD,*) + $STAT -f %Op $1 | sed 's,.*\(....\),\1,' + return + ;; + esac + # fallback to find + fmode `find $1 -ls -prune | awk '{ print $3 }'` +} + +get_mtime_suffix() { + case "$OS,$STAT" in + FreeBSD,*) + $STAT -t "${2:-$opt_f}" -f %Sm $1 + return + ;; + esac + # this will have to do + date "+${2:-$opt_f}" +} + +case /$0 in +*/newlog*) rotate_func=rotate_log;; +*/save*) rotate_func=save_log;; +*) rotate_func=rotate_log;; +esac + +opt_n=7 +opt_m= +opt_M=444 +opt_f=%Y%m%d.%H%M%S +opt_str=dNn:o:g:G:C:M:m:eE:f:RS + +. setopts.sh + +test $# -gt 0 || exit 0 # nothing to do. + +OS=${OS:-`uname`} +STAT=${STAT:-`Which stat`} + +# sorry, setops semantics for booleans changed. +case "${opt_d:-0}" in +0) rm_f=-f + opt_d=-f + for x in $opt_C gzip compress + do + opt_C=`Which $x "/bin:/usr/bin:$PATH"` + test -x $opt_C && break + done + empty() { test ! -s $1; } + ;; +*) rm_f=-rf + opt_d=-d + opt_M= + opt_C=: + empty() { + if [ -d $1 ]; then + n=`'ls' -a1 $1/. | wc -l` + [ $n -gt 2 ] && return 1 + fi + return 0 + } + ;; +esac +case "${opt_N:-0}" in +0) ECHO=;; +*) ECHO=echo;; +esac +case "${opt_e:-0}" in +0) force=;; +*) force=yes;; +esac +case "${opt_R:-0}" in +0) ;; +*) rotate_func=rotate_log;; +esac +case "${opt_S:-0}" in +0) ;; +*) rotate_func=save_log opt_S=;; +esac + +# see whether test handles -h or -L +test_opt L -h +test_opt h "" +case "$test_L,$test_h" in +-h,) test_L= ;; # we don't support either! +esac + +case "$test_L" in +"") # No, so this is about all we can do... + logs=`'ls' -ld $* | awk '{ print $NF }'` + ;; +*) # it does + logs="$*" + ;; +esac + +read_link() { + case "$test_L" in + "") 'ls' -ld $1 | awk '{ print $NF }'; return;; + esac + if test $test_L $1; then + 'ls' -ld $1 | sed 's,.*> ,,' + else + echo $1 + fi +} + +# create the new log +new_log() { + log=$1 + mode=$2 + if test "x$opt_M" != x; then + $ECHO chmod $opt_M $log.0 2> /dev/null + fi + # someone may have managed to write to it already + # so don't truncate it. + case "$opt_d" in + -d) $ECHO mkdir -p $log;; + *) $ECHO touch $log;; + esac + # the order here matters + test "x$opt_o" = x || $ECHO chown $opt_o $log + test "x$opt_g" = x || $ECHO chgrp $opt_g $log + test "x$mode" = x || $ECHO chmod $mode $log +} + +rotate_log() { + log=$1 + n=${2:-$opt_n} + + # make sure excess generations are trimmed + $ECHO rm $rm_f `echo $log.$n | sed 's/\([0-9]\)$/[\1-9]*/'` + + mode=${opt_m:-`get_mode $log`} + while test $n -gt 0 + do + p=`expr $n - 1` + if test -s $log.$p; then + $ECHO rm $rm_f $log.$p.* + $ECHO $opt_C $log.$p + if test "x$opt_M" != x; then + $ECHO chmod $opt_M $log.$p.* 2> /dev/null + fi + fi + for ext in $opt_E .gz .Z "" + do + test $opt_d $log.$p$ext || continue + $ECHO mv $log.$p$ext $log.$n$ext + done + n=$p + done + # leave $log.0 uncompressed incase some one still has it open. + $ECHO mv $log $log.0 + new_log $log $mode +} + +# unlike rotate_log we do not rotate files, +# but give each log a unique (but stable name). +# This avoids churn for folk who rsync things. +# We make log.0 a symlink to the most recent log +# so it can be found and compressed next time around. +save_log() { + log=$1 + n=${2:-$opt_n} + fmt=$3 + + last=`read_link $log.0` + case "$last" in + $log.0) # should never happen + test -s $last && $ECHO mv $last $log.$$;; + $log.*) + $ECHO $opt_C $last + ;; + *.*) $ECHO $opt_C `dirname $log`/$last + ;; + esac + $ECHO rm -f $log.0 + # remove excess logs - we rely on mtime! + $ECHO rm $rm_f `'ls' -1td $log.* 2> /dev/null | sed "1,${n}d"` + + mode=${opt_m:-`get_mode $log`} + # this is our default suffix + opt_S=${opt_S:-`get_mtime_suffix $log $fmt`} + case "$fmt" in + ""|$opt_f) suffix=$opt_S;; + *) suffix=`get_mtime_suffix $log $fmt`;; + esac + + # find a unique name to save current log as + for nlog in $log.$suffix $log.$suffix.$$ + do + for f in $nlog* + do + break + done + test $opt_d $f || break + done + # leave $log.0 uncompressed incase some one still has it open. + $ECHO mv $log $nlog + test "x$opt_M" = x || $ECHO chmod $opt_M $nlog 2> /dev/null + $ECHO ln -s `basename $nlog` $log.0 + new_log $log $mode +} + +for f in $logs +do + n=$opt_n + save= + case "$f" in + *:[1-9]*) + set -- `IFS=:; echo $f`; f=$1; n=$2;; + *:n=*|*:save=*) + eval `echo "f=$f" | tr ':' ' '`;; + esac + # try and pick the right function to use + rfunc=$rotate_func # default + if test $opt_d $f.0; then + case `read_link $f.0` in + $f.0) rfunc=rotate_log;; + *) rfunc=save_log;; + esac + fi + case "$test_L" in + -?) + while test $test_L $f # it is [still] a symlink + do + f=`read_link $f` + done + ;; + esac + case ",${opt_G}," in + *,${f}:n=*|,${f}:save=*) + eval `echo ",${opt_G}," | sed "s!.*,${f}:\([^,]*\),.*!\1!;s,:, ,g"` + ;; + *,${f}:*) + # opt_G is a , separated list of log:n pairs + n=`echo ,$opt_G, | sed -e "s,.*${f}:\([0-9][0-9]*\).*,\1,"` + ;; + esac + + if empty $f; then + test "$force" || continue + fi + + test "$save" && rfunc=save_log + + $rfunc $f $n $save +done diff --git a/mk/sys.dependfile.mk b/mk/sys.dependfile.mk index 7c1fd94d3eb8..49232646d569 100644 --- a/mk/sys.dependfile.mk +++ b/mk/sys.dependfile.mk @@ -1,59 +1,64 @@ -# $Id: sys.dependfile.mk,v 1.9 2020/08/19 17:51:53 sjg Exp $ +# $Id: sys.dependfile.mk,v 1.10 2023/05/10 19:23:26 sjg Exp $ # -# @(#) Copyright (c) 2012, Simon J. Gerraty +# @(#) Copyright (c) 2012-2023, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. # Permission to copy, redistribute or otherwise # use this file is hereby granted provided that # the above copyright notice and this notice are # left intact. # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # -# This only makes sense in meta mode. +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: .NOTMAIN + +# This only makes sense for DIRDEPS_BUILD. # This allows a mixture of auto generated as well as manually edited # dependency files, which can be differentiated by their names. # As per dirdeps.mk we only require: # 1. a common prefix # 2. that machine specific files end in .${MACHINE} # # The .MAKE.DEPENDFILE_PREFERENCE below is an example. # All depend file names should start with this .MAKE.DEPENDFILE_PREFIX ?= Makefile.depend .if !empty(.MAKE.DEPENDFILE) && \ ${.MAKE.DEPENDFILE:M${.MAKE.DEPENDFILE_PREFIX}*} == "" # let us do our thing below... .undef .MAKE.DEPENDFILE .endif # The order of preference: we will use the first one of these we find. # It usually makes sense to order from most specific to least. .MAKE.DEPENDFILE_PREFERENCE ?= \ ${.CURDIR}/${.MAKE.DEPENDFILE_PREFIX}.${MACHINE} \ ${.CURDIR}/${.MAKE.DEPENDFILE_PREFIX} # Normally the 1st entry is our default choice # Another useful default is ${.MAKE.DEPENDFILE_PREFIX} .MAKE.DEPENDFILE_DEFAULT ?= ${.MAKE.DEPENDFILE_PREFERENCE:[1]} _e := ${.MAKE.DEPENDFILE_PREFERENCE:@m@${exists($m):?$m:}@} .if !empty(_e) .MAKE.DEPENDFILE := ${_e:[1]} .elif ${.MAKE.DEPENDFILE_PREFERENCE:M*${MACHINE}} != "" && ${.MAKE.DEPENDFILE_DEFAULT:E} != ${MACHINE} # MACHINE specific depend files are supported, but *not* default. # If any already exist, we should follow suit. _aml = ${ALL_MACHINE_LIST:Uarm amd64 i386 powerpc:N${MACHINE}} ${MACHINE} # make sure we restore MACHINE _m := ${MACHINE} _e := ${_aml:@MACHINE@${.MAKE.DEPENDFILE_PREFERENCE:@m@${exists($m):?$m:}@}@} MACHINE := ${_m} .if !empty(_e) .MAKE.DEPENDFILE ?= ${.MAKE.DEPENDFILE_PREFERENCE:M*${MACHINE}:[1]} .endif .endif .MAKE.DEPENDFILE ?= ${.MAKE.DEPENDFILE_DEFAULT} + +.endif diff --git a/mk/sys.dirdeps.mk b/mk/sys.dirdeps.mk new file mode 100644 index 000000000000..845eda181b90 --- /dev/null +++ b/mk/sys.dirdeps.mk @@ -0,0 +1,183 @@ +# $Id: sys.dirdeps.mk,v 1.9 2023/05/11 20:05:42 sjg Exp $ +# +# @(#) Copyright (c) 2012-2023, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +# Originally DIRDEPS_BUILD and META_MODE were the same thing. +# So, much of this was done in *meta.sys.mk and local*mk +# but properly belongs here. + +# Include from [local.]sys.mk - if doing DIRDEPS_BUILD +# we should not be here otherwise +MK_DIRDEPS_BUILD ?= yes +# these are all implied +MK_AUTO_OBJ ?= yes +MK_META_MODE ?= yes +MK_STAGING ?= yes + +_PARSEDIR ?= ${.PARSEDIR:tA} + +.-include + +.if ${.MAKE.LEVEL} == 0 +# make sure dirdeps target exists and do it first +dirdeps: +# first .MAIN is what counts +.MAIN: dirdeps +.NOPATH: dirdeps +all: dirdeps .WAIT +.endif + +.if empty(SRCTOP) +# fallback assumes share/mk! +SRCTOP := ${SB_SRC:U${.PARSEDIR:tA:H:H}} +.export SRCTOP +.endif + +# fake SB if not using mk wrapper +.if !defined(SB) +SB := ${SRCTOP:H} +.export SB +.endif + +.if empty(OBJROOT) +OBJROOT := ${SB_OBJROOT:U${MAKEOBJDIRPREFIX:U${SB}/obj}/} +.export OBJROOT +.endif + +.if empty(STAGE_ROOT) +STAGE_ROOT ?= ${OBJROOT}stage +.export STAGE_ROOT +.endif + +# We should be included before meta.sys.mk +# If TARGET_SPEC_VARS is other than just MACHINE +# it should be set by now. +# TARGET_SPEC must not contain any '.'s. +TARGET_SPEC_VARS ?= MACHINE + +.if !target(_tspec_env_done_) +_tspec_env_done_: .NOTMAIN + +.if ${TARGET_SPEC:Uno:M*,*} != "" +# deal with TARGET_SPEC from env +_tspec := ${TARGET_SPEC:S/,/ /g} +.for i in ${TARGET_SPEC_VARS:${M_RANGE:Urange}} +${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]} +.endfor +# We need to stop that TARGET_SPEC affecting any submakes +TARGET_SPEC= +# so export but do not track +.export-env TARGET_SPEC +.export ${TARGET_SPEC_VARS} +.for v in ${TARGET_SPEC_VARS:O:u} +.if empty($v) +.undef $v +.endif +.endfor +.endif +.endif + +# Now make sure we know what TARGET_SPEC is +# as we may need it to find Makefile.depend* +.if ${MACHINE:Mhost*} != "" +# host is special +TARGET_SPEC = ${MACHINE} +.else +TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} +.endif + +.if ${TARGET_SPEC_VARS:[#]} > 1 +TARGET_OBJ_SPEC ?= ${TARGET_SPEC_VARS:@v@${$v:U}@:ts.} +.else +TARGET_OBJ_SPEC ?= ${MACHINE} +.endif + +MAKE_PRINT_VAR_ON_ERROR += ${TARGET_SPEC_VARS} + +.if !defined(MACHINE0) +# it can be handy to know which MACHINE kicked off the build +# for example, if using Makefild.depend for multiple machines, +# allowing only MACHINE0 to update can keep things simple. +MACHINE0 := ${MACHINE} +.export MACHINE0 +.endif + +.if ${MACHINE} == "host" +OBJTOP = ${HOST_OBJTOP} +.elif ${MACHINE} == "host32" +OBJTOP = ${HOST_OBJTOP32} +.endif + +MACHINE_OBJ.host = ${HOST_TARGET} +MACHINE_OBJ.host32 = ${HOST_TARGET32} +MACHINE_OBJ.${MACHINE} ?= ${TARGET_OBJ_SPEC} +MACHINE_OBJDIR = ${MACHINE_OBJ.${MACHINE}} +OBJTOP = ${OBJROOT}/${MACHINE_OBJDIR} + +# we do not use MAKEOBJDIRPREFIX +.undef MAKEOBJDIRPREFIX +# we use this +MAKEOBJDIR ?= ${.CURDIR:S,${SRCTOP},${OBJTOP},} + +STAGE_MACHINE ?= ${MACHINE_OBJDIR} +STAGE_OBJTOP ?= ${STAGE_ROOT}/${STAGE_MACHINE} +STAGE_COMMON_OBJTOP ?= ${STAGE_ROOT}/common +STAGE_HOST_OBJTOP ?= ${STAGE_ROOT}/${HOST_TARGET} +STAGE_HOST_OBJTOP32 ?= ${STAGE_ROOT}/${HOST_TARGET32} + +STAGE_INCLUDEDIR ?= ${STAGE_OBJTOP}${INCLUDEDIR:U/usr/include} +STAGE_LIBDIR ?= ${STAGE_OBJTOP}${LIBDIR:U/lib} + +TIME_STAMP_FMT ?= @ %s [%Y-%m-%d %T] ${:U} +DATE_TIME_STAMP ?= `date '+${TIME_STAMP_FMT}'` +TIME_STAMP ?= ${TIME_STAMP_FMT:localtime} + +.if ${MK_TIME_STAMPS:Uyes} == "yes" +TRACER = ${TIME_STAMP} +ECHO_DIR = echo ${TIME_STAMP} +ECHO_TRACE = echo ${TIME_STAMP} +.endif + +.if ${.CURDIR} == ${SRCTOP} +RELDIR= . +RELTOP= . +.elif ${.CURDIR:M${SRCTOP}/*} +RELDIR:= ${.CURDIR:S,${SRCTOP}/,,} +.else +RELDIR:= ${.OBJDIR:S,${OBJTOP}/,,} +.endif +RELTOP?= ${RELDIR:C,[^/]+,..,g} +RELOBJTOP?= ${RELTOP} +RELSRCTOP?= ${RELTOP} + +# this does all the smarts of setting .MAKE.DEPENDFILE +.-include + +.-include + +# check if we got anything sane +.if ${.MAKE.DEPENDFILE} == ".depend" +.undef .MAKE.DEPENDFILE +.endif +# just in case +.MAKE.DEPENDFILE ?= Makefile.depend + +.if ${.MAKE.LEVEL} > 0 +# Makefile.depend* also get read at level 1+ +# and often refer to DEP_MACHINE etc, +# so ensure DEP_* (for TARGET_SPEC_VARS anyway) are set +.for V in ${TARGET_SPEC_VARS} +DEP_$V = ${$V} +.endfor +.endif diff --git a/mk/sys.mk b/mk/sys.mk index 966409870cc5..b08f6010746d 100644 --- a/mk/sys.mk +++ b/mk/sys.mk @@ -1,158 +1,161 @@ -# $Id: sys.mk,v 1.54 2022/09/09 17:44:29 sjg Exp $ +# $Id: sys.mk,v 1.55 2023/05/10 19:23:26 sjg Exp $ # # @(#) Copyright (c) 2003-2009, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. # Permission to copy, redistribute or otherwise # use this file is hereby granted provided that # the above copyright notice and this notice are # left intact. # # Please send copies of changes and bug-fixes to: # sjg@crufty.net # # Avoid putting anything platform specific in here. # _DEBUG_MAKE_FLAGS etc. .include .if !empty(_DEBUG_MAKE_FLAGS) .if ${_DEBUG_MAKE_SYS_DIRS:Uno:@x@${.CURDIR:M$x}@} != "" .MAKEFLAGS: ${_DEBUG_MAKE_FLAGS} .endif .endif # useful modifiers .include # we expect a recent bmake .if !defined(_TARGETS) # some things we do only once _TARGETS := ${.TARGETS} .-include .endif # we need HOST_TARGET etc below. .include # early customizations .-include # Popular suffixes for C++ CXX_SUFFIXES += .cc .cpp .cxx .C CXX_SUFFIXES := ${CXX_SUFFIXES:O:u} # find the OS specifics .if defined(SYS_OS_MK) .include <${SYS_OS_MK}> .else _sys_mk = .for x in ${HOST_OSTYPE} ${HOST_TARGET} ${HOST_OS} ${MACHINE} Generic .if empty(_sys_mk) .-include _sys_mk := ${.MAKE.MAKEFILES:M*/$x.mk} .if !empty(_sys_mk) _sys_mk := sys/${_sys_mk:T} .endif .endif .if empty(_sys_mk) # might be an old style .-include <$x.sys.mk> _sys_mk := ${.MAKE.MAKEFILES:M*/$x.sys.mk:T} .endif .endfor SYS_OS_MK := ${_sys_mk} .export SYS_OS_MK .endif # some sys/ may have set this to grep -E EGREP ?= egrep # some options we need to know early OPTIONS_DEFAULT_NO += \ DIRDEPS_BUILD \ DIRDEPS_CACHE OPTIONS_DEFAULT_DEPENDENT += \ AUTO_OBJ/DIRDEPS_BUILD \ META_MODE/DIRDEPS_BUILD \ STAGING/DIRDEPS_BUILD \ STATIC_DIRDEPS_CACHE/DIRDEPS_CACHE \ .-include # :Uno incase options.mk not installed +.if ${MK_DIRDEPS_BUILD:Uno} == "yes" +.-include +.endif .if ${MK_META_MODE:Uno} == "yes" .-include .MAKE.MODE ?= meta verbose {META_MODE} .endif # make sure we have a harmless value .MAKE.MODE ?= normal # if you want objdirs make them automatic # and do it early before we compute .PATH .if ${MK_AUTO_OBJ:Uno} == "yes" || ${MKOBJDIRS:Uno} == "auto" .include .endif .if !empty(SRCTOP) .if ${.CURDIR} == ${SRCTOP} RELDIR = . .elif ${.CURDIR:M${SRCTOP}/*} RELDIR := ${.CURDIR:S,${SRCTOP}/,,} .endif .endif MACHINE_ARCH.host ?= ${_HOST_ARCH} MACHINE_ARCH.${MACHINE} ?= ${MACHINE} .if empty(MACHINE_ARCH) MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}} .endif .ifndef ROOT_GROUP ROOT_GROUP != sed -n /:0:/s/:.*//p /etc/group .export ROOT_GROUP .endif unix ?= We run ${_HOST_OSNAME}. # We need a Bourne/POSIX shell MAKE_SHELL ?= ${.SHELL:Ush} SHELL := ${MAKE_SHELL} # A race condition in mkdir, means that it can bail if another # process made a dir that mkdir expected to. # We repeat the mkdir -p a number of times to try and work around this. # We stop looping as soon as the dir exists. # If we get to the end of the loop, a plain mkdir will issue an error. Mkdirs= Mkdirs() { \ for d in $$*; do \ for i in 1 2 3 4 5 6; do \ mkdir -p $$d; \ test -d $$d && return 0; \ done; \ mkdir $$d || exit $$?; \ done; } # this often helps with debugging .SUFFIXES: .cpp-out .c.cpp-out: @${COMPILE.c:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$' ${CXX_SUFFIXES:%=%.cpp-out}: @${COMPILE.cc:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$' # late customizations .-include # if .CURDIR is matched by any entry in DEBUG_MAKE_DIRS we # will apply DEBUG_MAKE_FLAGS, now. .if !empty(_DEBUG_MAKE_FLAGS) .if ${_DEBUG_MAKE_DIRS:Uno:@x@${.CURDIR:M$x}@} != "" .MAKEFLAGS: ${_DEBUG_MAKE_FLAGS} .endif .endif diff --git a/parse.c b/parse.c index 9d8b840c4418..f0644ea67a14 100644 --- a/parse.c +++ b/parse.c @@ -1,3028 +1,3025 @@ -/* $NetBSD: parse.c,v 1.696 2023/02/15 06:52:58 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.698 2023/05/10 16:10:02 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Adam de Boor. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * Copyright (c) 1989 by Berkeley Softworks * All rights reserved. * * This code is derived from software contributed to Berkeley by * Adam de Boor. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * Parsing of makefiles. * * Parse_File is the main entry point and controls most of the other * functions in this module. * * Interface: * Parse_Init Initialize the module * * Parse_End Clean up the module * * Parse_File Parse a top-level makefile. Included files are * handled by IncludeFile instead. * * Parse_VarAssign * Try to parse the given line as a variable assignment. * Used by MainParseArgs to determine if an argument is * a target or a variable assignment. Used internally * for pretty much the same thing. * * Parse_Error Report a parse error, a warning or an informational * message. * - * Parse_MainName Returns a list of the single main target to create. + * Parse_MainName Populate the list of targets to create. */ #include #include #include #include #include "make.h" #ifdef HAVE_STDINT_H #include #endif #ifdef HAVE_MMAP #include #ifndef MAP_COPY #define MAP_COPY MAP_PRIVATE #endif #ifndef MAP_FILE #define MAP_FILE 0 #endif #endif #include "dir.h" #include "job.h" #include "pathnames.h" /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: parse.c,v 1.696 2023/02/15 06:52:58 rillig Exp $"); +MAKE_RCSID("$NetBSD: parse.c,v 1.698 2023/05/10 16:10:02 rillig Exp $"); /* * A file being read. */ typedef struct IncludedFile { FStr name; /* absolute or relative to the cwd */ unsigned lineno; /* 1-based */ unsigned readLines; /* the number of physical lines that have * been read from the file */ unsigned forHeadLineno; /* 1-based */ unsigned forBodyReadLines; /* the number of physical lines that have * been read from the file above the body of * the .for loop */ unsigned int condMinDepth; /* depth of nested 'if' directives, at the * beginning of the file */ bool depending; /* state of doing_depend on EOF */ Buffer buf; /* the file's content or the body of the .for * loop; either empty or ends with '\n' */ char *buf_ptr; /* next char to be read */ char *buf_end; /* buf_end[-1] == '\n' */ struct ForLoop *forLoop; } IncludedFile; /* Special attributes for target nodes. */ typedef enum ParseSpecial { SP_ATTRIBUTE, /* Generic attribute */ SP_BEGIN, /* .BEGIN */ SP_DEFAULT, /* .DEFAULT */ SP_DELETE_ON_ERROR, /* .DELETE_ON_ERROR */ SP_END, /* .END */ SP_ERROR, /* .ERROR */ SP_IGNORE, /* .IGNORE */ SP_INCLUDES, /* .INCLUDES; not mentioned in the manual page */ SP_INTERRUPT, /* .INTERRUPT */ SP_LIBS, /* .LIBS; not mentioned in the manual page */ SP_MAIN, /* .MAIN and no user-specified targets to make */ SP_META, /* .META */ SP_MFLAGS, /* .MFLAGS or .MAKEFLAGS */ SP_NOMETA, /* .NOMETA */ SP_NOMETA_CMP, /* .NOMETA_CMP */ SP_NOPATH, /* .NOPATH */ SP_NOREADONLY, /* .NOREADONLY */ SP_NOT, /* Not special */ SP_NOTPARALLEL, /* .NOTPARALLEL or .NO_PARALLEL */ SP_NULL, /* .NULL; not mentioned in the manual page */ SP_OBJDIR, /* .OBJDIR */ SP_ORDER, /* .ORDER */ SP_PARALLEL, /* .PARALLEL; not mentioned in the manual page */ SP_PATH, /* .PATH or .PATH.suffix */ SP_PHONY, /* .PHONY */ #ifdef POSIX SP_POSIX, /* .POSIX; not mentioned in the manual page */ #endif SP_PRECIOUS, /* .PRECIOUS */ SP_READONLY, /* .READONLY */ SP_SHELL, /* .SHELL */ SP_SILENT, /* .SILENT */ SP_SINGLESHELL, /* .SINGLESHELL; not mentioned in the manual page */ SP_STALE, /* .STALE */ SP_SUFFIXES, /* .SUFFIXES */ SP_SYSPATH, /* .SYSPATH */ SP_WAIT /* .WAIT */ } ParseSpecial; typedef List SearchPathList; typedef ListNode SearchPathListNode; typedef enum VarAssignOp { VAR_NORMAL, /* = */ VAR_APPEND, /* += */ VAR_DEFAULT, /* ?= */ VAR_SUBST, /* := */ VAR_SHELL /* != or :sh= */ } VarAssignOp; typedef struct VarAssign { char *varname; /* unexpanded */ VarAssignOp op; const char *value; /* unexpanded */ } VarAssign; static bool Parse_IsVar(const char *, VarAssign *); static void Parse_Var(VarAssign *, GNode *); /* * The target to be made if no targets are specified in the command line. * This is the first target defined in any of the makefiles. */ GNode *mainNode; /* * During parsing, the targets from the left-hand side of the currently * active dependency line, or NULL if the current line does not belong to a * dependency line, for example because it is a variable assignment. * * See unit-tests/deptgt.mk, keyword "parse.c:targets". */ static GNodeList *targets; #ifdef CLEANUP /* * All shell commands for all targets, in no particular order and possibly * with duplicates. Kept in a separate list since the commands from .USE or * .USEBEFORE nodes are shared with other GNodes, thereby giving up the * easily understandable ownership over the allocated strings. */ static StringList targCmds = LST_INIT; #endif /* * Predecessor node for handling .ORDER. Initialized to NULL when .ORDER * is seen, then set to each successive source on the line. */ static GNode *order_pred; static int parseErrors = 0; /* * The include chain of makefiles. At index 0 is the top-level makefile from * the command line, followed by the included files or .for loops, up to and * including the current file. * * See PrintStackTrace for how to interpret the data. */ static Vector /* of IncludedFile */ includes; SearchPath *parseIncPath; /* directories for "..." includes */ SearchPath *sysIncPath; /* directories for <...> includes */ SearchPath *defSysIncPath; /* default for sysIncPath */ /* * The parseKeywords table is searched using binary search when deciding - * if a target or source is special. The 'spec' field is the ParseSpecial - * type of the keyword (SP_NOT if the keyword isn't special as a target) while - * the 'op' field is the operator to apply to the list of targets if the - * keyword is used as a source ("0" if the keyword isn't special as a source) + * if a target or source is special. */ static const struct { const char name[17]; ParseSpecial special; /* when used as a target */ GNodeType targetAttr; /* when used as a source */ } parseKeywords[] = { { ".BEGIN", SP_BEGIN, OP_NONE }, { ".DEFAULT", SP_DEFAULT, OP_NONE }, { ".DELETE_ON_ERROR", SP_DELETE_ON_ERROR, OP_NONE }, { ".END", SP_END, OP_NONE }, { ".ERROR", SP_ERROR, OP_NONE }, { ".EXEC", SP_ATTRIBUTE, OP_EXEC }, { ".IGNORE", SP_IGNORE, OP_IGNORE }, { ".INCLUDES", SP_INCLUDES, OP_NONE }, { ".INTERRUPT", SP_INTERRUPT, OP_NONE }, { ".INVISIBLE", SP_ATTRIBUTE, OP_INVISIBLE }, { ".JOIN", SP_ATTRIBUTE, OP_JOIN }, { ".LIBS", SP_LIBS, OP_NONE }, { ".MADE", SP_ATTRIBUTE, OP_MADE }, { ".MAIN", SP_MAIN, OP_NONE }, { ".MAKE", SP_ATTRIBUTE, OP_MAKE }, { ".MAKEFLAGS", SP_MFLAGS, OP_NONE }, { ".META", SP_META, OP_META }, { ".MFLAGS", SP_MFLAGS, OP_NONE }, { ".NOMETA", SP_NOMETA, OP_NOMETA }, { ".NOMETA_CMP", SP_NOMETA_CMP, OP_NOMETA_CMP }, { ".NOPATH", SP_NOPATH, OP_NOPATH }, { ".NOREADONLY", SP_NOREADONLY, OP_NONE }, { ".NOTMAIN", SP_ATTRIBUTE, OP_NOTMAIN }, { ".NOTPARALLEL", SP_NOTPARALLEL, OP_NONE }, { ".NO_PARALLEL", SP_NOTPARALLEL, OP_NONE }, { ".NULL", SP_NULL, OP_NONE }, { ".OBJDIR", SP_OBJDIR, OP_NONE }, { ".OPTIONAL", SP_ATTRIBUTE, OP_OPTIONAL }, { ".ORDER", SP_ORDER, OP_NONE }, { ".PARALLEL", SP_PARALLEL, OP_NONE }, { ".PATH", SP_PATH, OP_NONE }, { ".PHONY", SP_PHONY, OP_PHONY }, #ifdef POSIX { ".POSIX", SP_POSIX, OP_NONE }, #endif { ".PRECIOUS", SP_PRECIOUS, OP_PRECIOUS }, { ".READONLY", SP_READONLY, OP_NONE }, { ".RECURSIVE", SP_ATTRIBUTE, OP_MAKE }, { ".SHELL", SP_SHELL, OP_NONE }, { ".SILENT", SP_SILENT, OP_SILENT }, { ".SINGLESHELL", SP_SINGLESHELL, OP_NONE }, { ".STALE", SP_STALE, OP_NONE }, { ".SUFFIXES", SP_SUFFIXES, OP_NONE }, { ".SYSPATH", SP_SYSPATH, OP_NONE }, { ".USE", SP_ATTRIBUTE, OP_USE }, { ".USEBEFORE", SP_ATTRIBUTE, OP_USEBEFORE }, { ".WAIT", SP_WAIT, OP_NONE }, }; enum PosixState posix_state = PS_NOT_YET; static IncludedFile * GetInclude(size_t i) { assert(i < includes.len); return Vector_Get(&includes, i); } -/* The file that is currently being read. */ +/* The makefile that is currently being read. */ static IncludedFile * CurFile(void) { return GetInclude(includes.len - 1); } unsigned int CurFile_CondMinDepth(void) { return CurFile()->condMinDepth; } static Buffer LoadFile(const char *path, int fd) { ssize_t n; Buffer buf; size_t bufSize; struct stat st; bufSize = fstat(fd, &st) == 0 && S_ISREG(st.st_mode) && st.st_size > 0 && st.st_size < 1024 * 1024 * 1024 ? (size_t)st.st_size : 1024; Buf_InitSize(&buf, bufSize); for (;;) { if (buf.len == buf.cap) { if (buf.cap >= 512 * 1024 * 1024) { Error("%s: file too large", path); exit(2); /* Not 1 so -q can distinguish error */ } Buf_Expand(&buf); } assert(buf.len < buf.cap); n = read(fd, buf.data + buf.len, buf.cap - buf.len); if (n < 0) { Error("%s: read error: %s", path, strerror(errno)); exit(2); /* Not 1 so -q can distinguish error */ } if (n == 0) break; buf.len += (size_t)n; } assert(buf.len <= buf.cap); if (!Buf_EndsWith(&buf, '\n')) Buf_AddByte(&buf, '\n'); return buf; /* may not be null-terminated */ } /* * Print the current chain of .include and .for directives. In Parse_Fatal * or other functions that already print the location, includingInnermost * would be redundant, but in other cases like Error or Fatal it needs to be * included. */ void PrintStackTrace(bool includingInnermost) { const IncludedFile *entries; size_t i, n; n = includes.len; if (n == 0) return; entries = GetInclude(0); if (!includingInnermost && entries[n - 1].forLoop == NULL) n--; /* already in the diagnostic */ for (i = n; i-- > 0;) { const IncludedFile *entry = entries + i; const char *fname = entry->name.str; char dirbuf[MAXPATHLEN + 1]; - if (fname[0] != '/' && strcmp(fname, "(stdin)") != 0) - fname = realpath(fname, dirbuf); + if (fname[0] != '/' && strcmp(fname, "(stdin)") != 0) { + const char *realPath = realpath(fname, dirbuf); + if (realPath != NULL) + fname = realPath; + } if (entry->forLoop != NULL) { char *details = ForLoop_Details(entry->forLoop); debug_printf("\tin .for loop from %s:%u with %s\n", fname, entry->forHeadLineno, details); free(details); } else if (i + 1 < n && entries[i + 1].forLoop != NULL) { /* entry->lineno is not a useful line number */ } else debug_printf("\tin %s:%u\n", fname, entry->lineno); } } /* Check if the current character is escaped on the current line. */ static bool IsEscaped(const char *line, const char *p) { bool escaped = false; while (p > line && *--p == '\\') escaped = !escaped; return escaped; } /* * Add the filename and lineno to the GNode so that we remember where it * was first defined. */ static void RememberLocation(GNode *gn) { IncludedFile *curFile = CurFile(); gn->fname = Str_Intern(curFile->name.str); gn->lineno = curFile->lineno; } /* * Look in the table of keywords for one matching the given string. * Return the index of the keyword, or -1 if it isn't there. */ static int FindKeyword(const char *str) { int start = 0; int end = sizeof parseKeywords / sizeof parseKeywords[0] - 1; while (start <= end) { int curr = start + (end - start) / 2; int diff = strcmp(str, parseKeywords[curr].name); if (diff == 0) return curr; if (diff < 0) end = curr - 1; else start = curr + 1; } return -1; } void PrintLocation(FILE *f, bool useVars, const GNode *gn) { char dirbuf[MAXPATHLEN + 1]; FStr dir, base; const char *fname; unsigned lineno; if (gn != NULL) { fname = gn->fname; lineno = gn->lineno; } else if (includes.len > 0) { IncludedFile *curFile = CurFile(); fname = curFile->name.str; lineno = curFile->lineno; } else return; if (!useVars || fname[0] == '/' || strcmp(fname, "(stdin)") == 0) { (void)fprintf(f, "\"%s\" line %u: ", fname, lineno); return; } dir = Var_Value(SCOPE_GLOBAL, ".PARSEDIR"); if (dir.str == NULL) dir.str = "."; if (dir.str[0] != '/') dir.str = realpath(dir.str, dirbuf); base = Var_Value(SCOPE_GLOBAL, ".PARSEFILE"); if (base.str == NULL) base.str = str_basename(fname); (void)fprintf(f, "\"%s/%s\" line %u: ", dir.str, base.str, lineno); FStr_Done(&base); FStr_Done(&dir); } static void MAKE_ATTR_PRINTFLIKE(5, 0) ParseVErrorInternal(FILE *f, bool useVars, const GNode *gn, ParseErrorLevel level, const char *fmt, va_list ap) { static bool fatal_warning_error_printed = false; (void)fprintf(f, "%s: ", progname); PrintLocation(f, useVars, gn); if (level == PARSE_WARNING) (void)fprintf(f, "warning: "); (void)vfprintf(f, fmt, ap); (void)fprintf(f, "\n"); (void)fflush(f); if (level == PARSE_FATAL) parseErrors++; if (level == PARSE_WARNING && opts.parseWarnFatal) { if (!fatal_warning_error_printed) { Error("parsing warnings being treated as errors"); fatal_warning_error_printed = true; } parseErrors++; } if (DEBUG(PARSE)) PrintStackTrace(false); } static void MAKE_ATTR_PRINTFLIKE(3, 4) ParseErrorInternal(const GNode *gn, ParseErrorLevel level, const char *fmt, ...) { va_list ap; (void)fflush(stdout); va_start(ap, fmt); ParseVErrorInternal(stderr, false, gn, level, fmt, ap); va_end(ap); if (opts.debug_file != stdout && opts.debug_file != stderr) { va_start(ap, fmt); ParseVErrorInternal(opts.debug_file, false, gn, level, fmt, ap); va_end(ap); } } /* * Print a parse error message, including location information. * * If the level is PARSE_FATAL, continue parsing until the end of the * current top-level makefile, then exit (see Parse_File). * * Fmt is given without a trailing newline. */ void Parse_Error(ParseErrorLevel level, const char *fmt, ...) { va_list ap; (void)fflush(stdout); va_start(ap, fmt); ParseVErrorInternal(stderr, true, NULL, level, fmt, ap); va_end(ap); if (opts.debug_file != stdout && opts.debug_file != stderr) { va_start(ap, fmt); ParseVErrorInternal(opts.debug_file, true, NULL, level, fmt, ap); va_end(ap); } } /* * Handle an .info, .warning or .error directive. For an .error directive, * exit immediately. */ static void HandleMessage(ParseErrorLevel level, const char *levelName, const char *umsg) { char *xmsg; if (umsg[0] == '\0') { Parse_Error(PARSE_FATAL, "Missing argument for \".%s\"", levelName); return; } xmsg = Var_Subst(umsg, SCOPE_CMDLINE, VARE_WANTRES); /* TODO: handle errors */ Parse_Error(level, "%s", xmsg); free(xmsg); if (level == PARSE_FATAL) { PrintOnError(NULL, "\n"); exit(1); } } /* * Add the child to the parent's children, and for non-special targets, vice * versa. Special targets such as .END do not need to be informed once the * child target has been made. */ static void LinkSource(GNode *pgn, GNode *cgn, bool isSpecial) { if ((pgn->type & OP_DOUBLEDEP) && !Lst_IsEmpty(&pgn->cohorts)) pgn = pgn->cohorts.last->datum; Lst_Append(&pgn->children, cgn); pgn->unmade++; /* Special targets like .END don't need any children. */ if (!isSpecial) Lst_Append(&cgn->parents, pgn); if (DEBUG(PARSE)) { debug_printf("# LinkSource: added child %s - %s\n", pgn->name, cgn->name); Targ_PrintNode(pgn, 0); Targ_PrintNode(cgn, 0); } } /* Add the node to each target from the current dependency group. */ static void LinkToTargets(GNode *gn, bool isSpecial) { GNodeListNode *ln; for (ln = targets->first; ln != NULL; ln = ln->next) LinkSource(ln->datum, gn, isSpecial); } static bool TryApplyDependencyOperator(GNode *gn, GNodeType op) { /* * If the node occurred on the left-hand side of a dependency and the * operator also defines a dependency, they must match. */ if ((op & OP_OPMASK) && (gn->type & OP_OPMASK) && ((op & OP_OPMASK) != (gn->type & OP_OPMASK))) { Parse_Error(PARSE_FATAL, "Inconsistent operator for %s", gn->name); return false; } if (op == OP_DOUBLEDEP && (gn->type & OP_OPMASK) == OP_DOUBLEDEP) { /* - * If the node was of the left-hand side of a '::' operator, + * If the node was on the left-hand side of a '::' operator, * we need to create a new instance of it for the children * and commands on this dependency line since each of these * dependency groups has its own attributes and commands, * separate from the others. * * The new instance is placed on the 'cohorts' list of the * initial one (note the initial one is not on its own * cohorts list) and the new instance is linked to all * parents of the initial instance. */ GNode *cohort; /* * Propagate copied bits to the initial node. They'll be * propagated back to the rest of the cohorts later. */ gn->type |= op & (unsigned)~OP_OPMASK; cohort = Targ_NewInternalNode(gn->name); if (doing_depend) RememberLocation(cohort); /* * Make the cohort invisible as well to avoid duplicating it * into other variables. True, parents of this target won't * tend to do anything with their local variables, but better * safe than sorry. * * (I think this is pointless now, since the relevant list * traversals will no longer see this node anyway. -mycroft) */ cohort->type = op | OP_INVISIBLE; Lst_Append(&gn->cohorts, cohort); cohort->centurion = gn; gn->unmade_cohorts++; snprintf(cohort->cohort_num, sizeof cohort->cohort_num, "#%d", (unsigned int)gn->unmade_cohorts % 1000000); } else { /* * We don't want to nuke any previous flags (whatever they * were) so we just OR the new operator into the old. */ gn->type |= op; } return true; } static void ApplyDependencyOperator(GNodeType op) { GNodeListNode *ln; for (ln = targets->first; ln != NULL; ln = ln->next) if (!TryApplyDependencyOperator(ln->datum, op)) break; } /* * We add a .WAIT node in the dependency list. After any dynamic dependencies * (and filename globbing) have happened, it is given a dependency on each * previous child, back until the previous .WAIT node. The next child won't * be scheduled until the .WAIT node is built. * * We give each .WAIT node a unique name (mainly for diagnostics). */ static void ApplyDependencySourceWait(bool isSpecial) { static unsigned wait_number = 0; char name[6 + 10 + 1]; GNode *gn; snprintf(name, sizeof name, ".WAIT_%u", ++wait_number); gn = Targ_NewInternalNode(name); if (doing_depend) RememberLocation(gn); gn->type = OP_WAIT | OP_PHONY | OP_DEPENDS | OP_NOTMAIN; LinkToTargets(gn, isSpecial); } static bool ApplyDependencySourceKeyword(const char *src, ParseSpecial special) { int keywd; GNodeType targetAttr; if (*src != '.' || !ch_isupper(src[1])) return false; keywd = FindKeyword(src); if (keywd == -1) return false; targetAttr = parseKeywords[keywd].targetAttr; if (targetAttr != OP_NONE) { ApplyDependencyOperator(targetAttr); return true; } if (parseKeywords[keywd].special == SP_WAIT) { ApplyDependencySourceWait(special != SP_NOT); return true; } return false; } /* * In a line like ".MAIN: source1 source2", add all sources to the list of * things to create, but only if the user didn't specify a target on the * command line and .MAIN occurs for the first time. * * See HandleDependencyTargetSpecial, branch SP_MAIN. * See unit-tests/cond-func-make-main.mk. */ static void ApplyDependencySourceMain(const char *src) { Lst_Append(&opts.create, bmake_strdup(src)); /* * Add the name to the .TARGETS variable as well, so the user can * employ that, if desired. */ Global_Append(".TARGETS", src); } /* * For the sources of a .ORDER target, create predecessor/successor links * between the previous source and the current one. */ static void ApplyDependencySourceOrder(const char *src) { GNode *gn; gn = Targ_GetNode(src); if (doing_depend) RememberLocation(gn); if (order_pred != NULL) { Lst_Append(&order_pred->order_succ, gn); Lst_Append(&gn->order_pred, order_pred); if (DEBUG(PARSE)) { debug_printf( "# .ORDER forces '%s' to be made before '%s'\n", order_pred->name, gn->name); Targ_PrintNode(order_pred, 0); Targ_PrintNode(gn, 0); } } /* * The current source now becomes the predecessor for the next one. */ order_pred = gn; } /* The source is not an attribute, so find/create a node for it. */ static void ApplyDependencySourceOther(const char *src, GNodeType targetAttr, ParseSpecial special) { GNode *gn; gn = Targ_GetNode(src); if (doing_depend) RememberLocation(gn); if (targetAttr != OP_NONE) gn->type |= targetAttr; else LinkToTargets(gn, special != SP_NOT); } /* * Given the name of a source in a dependency line, figure out if it is an * attribute (such as .SILENT) and if so, apply it to all targets. Otherwise * decide if there is some attribute which should be applied *to* the source * because of some special target (such as .PHONY) and apply it if so. * Otherwise, make the source a child of the targets. */ static void ApplyDependencySource(GNodeType targetAttr, const char *src, ParseSpecial special) { if (ApplyDependencySourceKeyword(src, special)) return; if (special == SP_MAIN) ApplyDependencySourceMain(src); else if (special == SP_ORDER) ApplyDependencySourceOrder(src); else ApplyDependencySourceOther(src, targetAttr, special); } /* * If we have yet to decide on a main target to make, in the absence of any * user input, we want the first target on the first dependency line that is * actually a real target (i.e. isn't a .USE or .EXEC rule) to be made. */ static void MaybeUpdateMainTarget(void) { GNodeListNode *ln; if (mainNode != NULL) return; for (ln = targets->first; ln != NULL; ln = ln->next) { GNode *gn = ln->datum; if (GNode_IsMainCandidate(gn)) { DEBUG1(MAKE, "Setting main node to \"%s\"\n", gn->name); mainNode = gn; return; } } } static void InvalidLineType(const char *line) { if (strncmp(line, "<<<<<<", 6) == 0 || strncmp(line, ">>>>>>", 6) == 0) Parse_Error(PARSE_FATAL, "Makefile appears to contain unresolved CVS/RCS/??? merge conflicts"); else if (line[0] == '.') { const char *dirstart = line + 1; const char *dirend; cpp_skip_whitespace(&dirstart); dirend = dirstart; while (ch_isalnum(*dirend) || *dirend == '-') dirend++; Parse_Error(PARSE_FATAL, "Unknown directive \"%.*s\"", (int)(dirend - dirstart), dirstart); } else Parse_Error(PARSE_FATAL, "Invalid line type"); } static void ParseDependencyTargetWord(char **pp, const char *lstart) { const char *cp = *pp; while (*cp != '\0') { if ((ch_isspace(*cp) || *cp == '!' || *cp == ':' || *cp == '(') && !IsEscaped(lstart, cp)) break; if (*cp == '$') { /* * Must be a dynamic source (would have been expanded * otherwise). * * There should be no errors in this, as they would * have been discovered in the initial Var_Subst and * we wouldn't be here. */ FStr val = Var_Parse(&cp, SCOPE_CMDLINE, VARE_PARSE_ONLY); FStr_Done(&val); } else cp++; } *pp += cp - *pp; } /* * Handle special targets like .PATH, .DEFAULT, .BEGIN, .ORDER. * * See the tests deptgt-*.mk. */ static void HandleDependencyTargetSpecial(const char *targetName, ParseSpecial *inout_special, SearchPathList **inout_paths) { switch (*inout_special) { case SP_PATH: if (*inout_paths == NULL) *inout_paths = Lst_New(); Lst_Append(*inout_paths, &dirSearchPath); break; case SP_SYSPATH: if (*inout_paths == NULL) *inout_paths = Lst_New(); Lst_Append(*inout_paths, sysIncPath); break; case SP_MAIN: /* * Allow targets from the command line to override the * .MAIN node. */ if (!Lst_IsEmpty(&opts.create)) *inout_special = SP_NOT; break; case SP_BEGIN: case SP_END: case SP_STALE: case SP_ERROR: case SP_INTERRUPT: { GNode *gn = Targ_GetNode(targetName); if (doing_depend) RememberLocation(gn); gn->type |= OP_NOTMAIN | OP_SPECIAL; Lst_Append(targets, gn); break; } case SP_DEFAULT: { /* * Need to create a node to hang commands on, but we don't * want it in the graph, nor do we want it to be the Main * Target. We claim the node is a transformation rule to make * life easier later, when we'll use Make_HandleUse to * actually apply the .DEFAULT commands. */ GNode *gn = GNode_New(".DEFAULT"); gn->type |= OP_NOTMAIN | OP_TRANSFORM; Lst_Append(targets, gn); defaultNode = gn; break; } case SP_DELETE_ON_ERROR: deleteOnError = true; break; case SP_NOTPARALLEL: opts.maxJobs = 1; break; case SP_SINGLESHELL: opts.compatMake = true; break; case SP_ORDER: order_pred = NULL; break; default: break; } } static bool HandleDependencyTargetPath(const char *suffixName, SearchPathList **inout_paths) { SearchPath *path; path = Suff_GetPath(suffixName); if (path == NULL) { Parse_Error(PARSE_FATAL, "Suffix '%s' not defined (yet)", suffixName); return false; } if (*inout_paths == NULL) *inout_paths = Lst_New(); Lst_Append(*inout_paths, path); return true; } /* See if it's a special target and if so set inout_special to match it. */ static bool HandleDependencyTarget(const char *targetName, ParseSpecial *inout_special, GNodeType *inout_targetAttr, SearchPathList **inout_paths) { int keywd; if (!(targetName[0] == '.' && ch_isupper(targetName[1]))) return true; /* * See if the target is a special target that must have it * or its sources handled specially. */ keywd = FindKeyword(targetName); if (keywd != -1) { if (*inout_special == SP_PATH && parseKeywords[keywd].special != SP_PATH) { Parse_Error(PARSE_FATAL, "Mismatched special targets"); return false; } *inout_special = parseKeywords[keywd].special; *inout_targetAttr = parseKeywords[keywd].targetAttr; HandleDependencyTargetSpecial(targetName, inout_special, inout_paths); } else if (strncmp(targetName, ".PATH", 5) == 0) { *inout_special = SP_PATH; if (!HandleDependencyTargetPath(targetName + 5, inout_paths)) return false; } return true; } static void HandleSingleDependencyTargetMundane(const char *name) { GNode *gn = Suff_IsTransform(name) ? Suff_AddTransform(name) : Targ_GetNode(name); if (doing_depend) RememberLocation(gn); Lst_Append(targets, gn); } static void HandleDependencyTargetMundane(const char *targetName) { if (Dir_HasWildcards(targetName)) { StringList targetNames = LST_INIT; SearchPath *emptyPath = SearchPath_New(); SearchPath_Expand(emptyPath, targetName, &targetNames); SearchPath_Free(emptyPath); while (!Lst_IsEmpty(&targetNames)) { char *targName = Lst_Dequeue(&targetNames); HandleSingleDependencyTargetMundane(targName); free(targName); } } else HandleSingleDependencyTargetMundane(targetName); } static void SkipExtraTargets(char **pp, const char *lstart) { bool warning = false; const char *p = *pp; while (*p != '\0') { if (!IsEscaped(lstart, p) && (*p == '!' || *p == ':')) break; if (IsEscaped(lstart, p) || (*p != ' ' && *p != '\t')) warning = true; p++; } if (warning) { const char *start = *pp; cpp_skip_whitespace(&start); Parse_Error(PARSE_WARNING, "Extra target '%.*s' ignored", (int)(p - start), start); } *pp += p - *pp; } static void CheckSpecialMundaneMixture(ParseSpecial special) { switch (special) { case SP_DEFAULT: case SP_STALE: case SP_BEGIN: case SP_END: case SP_ERROR: case SP_INTERRUPT: /* * These create nodes on which to hang commands, so targets * shouldn't be empty. */ case SP_NOT: /* Nothing special here -- targets may be empty. */ break; default: Parse_Error(PARSE_WARNING, "Special and mundane targets don't mix. " "Mundane ones ignored"); break; } } /* * In a dependency line like 'targets: sources' or 'targets! sources', parse * the operator ':', '::' or '!' from between the targets and the sources. */ static GNodeType ParseDependencyOp(char **pp) { if (**pp == '!') return (*pp)++, OP_FORCE; if (**pp == ':' && (*pp)[1] == ':') return *pp += 2, OP_DOUBLEDEP; else if (**pp == ':') return (*pp)++, OP_DEPENDS; else return OP_NONE; } static void ClearPaths(ParseSpecial special, SearchPathList *paths) { if (paths != NULL) { SearchPathListNode *ln; for (ln = paths->first; ln != NULL; ln = ln->next) SearchPath_Clear(ln->datum); } if (special == SP_SYSPATH) Dir_SetSYSPATH(); else Dir_SetPATH(); } static char * FindInDirOfIncludingFile(const char *file) { char *fullname, *incdir, *slash, *newName; int i; fullname = NULL; incdir = bmake_strdup(CurFile()->name.str); slash = strrchr(incdir, '/'); if (slash != NULL) { *slash = '\0'; /* * Now do lexical processing of leading "../" on the * filename. */ for (i = 0; strncmp(file + i, "../", 3) == 0; i += 3) { slash = strrchr(incdir + 1, '/'); if (slash == NULL || strcmp(slash, "/..") == 0) break; *slash = '\0'; } newName = str_concat3(incdir, "/", file + i); fullname = Dir_FindFile(newName, parseIncPath); if (fullname == NULL) fullname = Dir_FindFile(newName, &dirSearchPath); free(newName); } free(incdir); return fullname; } static char * FindInQuotPath(const char *file) { const char *suff; SearchPath *suffPath; char *fullname; fullname = FindInDirOfIncludingFile(file); if (fullname == NULL && (suff = strrchr(file, '.')) != NULL && (suffPath = Suff_GetPath(suff)) != NULL) fullname = Dir_FindFile(file, suffPath); if (fullname == NULL) fullname = Dir_FindFile(file, parseIncPath); if (fullname == NULL) fullname = Dir_FindFile(file, &dirSearchPath); return fullname; } /* * Handle one of the .[-ds]include directives by remembering the current file * and pushing the included file on the stack. After the included file has * finished, parsing continues with the including file; see Parse_PushInput * and ParseEOF. * * System includes are looked up in sysIncPath, any other includes are looked * up in the parsedir and then in the directories specified by the -I command * line options. */ static void IncludeFile(const char *file, bool isSystem, bool depinc, bool silent) { Buffer buf; char *fullname; /* full pathname of file */ int fd; fullname = file[0] == '/' ? bmake_strdup(file) : NULL; if (fullname == NULL && !isSystem) fullname = FindInQuotPath(file); if (fullname == NULL) { SearchPath *path = Lst_IsEmpty(&sysIncPath->dirs) ? defSysIncPath : sysIncPath; fullname = Dir_FindFile(file, path); } if (fullname == NULL) { if (!silent) Parse_Error(PARSE_FATAL, "Could not find %s", file); return; } if ((fd = open(fullname, O_RDONLY)) == -1) { if (!silent) Parse_Error(PARSE_FATAL, "Cannot open %s", fullname); free(fullname); return; } buf = LoadFile(fullname, fd); (void)close(fd); Parse_PushInput(fullname, 1, 0, buf, NULL); if (depinc) doing_depend = depinc; /* only turn it on */ free(fullname); } /* Handle a "dependency" line like '.SPECIAL:' without any sources. */ static void HandleDependencySourcesEmpty(ParseSpecial special, SearchPathList *paths) { switch (special) { case SP_SUFFIXES: Suff_ClearSuffixes(); break; case SP_PRECIOUS: allPrecious = true; break; case SP_IGNORE: opts.ignoreErrors = true; break; case SP_SILENT: opts.silent = true; break; case SP_PATH: case SP_SYSPATH: ClearPaths(special, paths); break; #ifdef POSIX case SP_POSIX: if (posix_state == PS_NOW_OR_NEVER) { /* * With '-r', 'posix.mk' (if it exists) * can effectively substitute for 'sys.mk', * otherwise it is an extension. */ Global_Set("%POSIX", "1003.2"); IncludeFile("posix.mk", true, false, true); } break; #endif default: break; } } static void AddToPaths(const char *dir, SearchPathList *paths) { if (paths != NULL) { SearchPathListNode *ln; for (ln = paths->first; ln != NULL; ln = ln->next) (void)SearchPath_Add(ln->datum, dir); } } /* * If the target was one that doesn't take files as its sources but takes * something like suffixes, we take each space-separated word on the line as * a something and deal with it accordingly. */ static void ParseDependencySourceSpecial(ParseSpecial special, const char *word, SearchPathList *paths) { switch (special) { case SP_SUFFIXES: Suff_AddSuffix(word); break; case SP_PATH: AddToPaths(word, paths); break; case SP_INCLUDES: Suff_AddInclude(word); break; case SP_LIBS: Suff_AddLib(word); break; case SP_NOREADONLY: Var_ReadOnly(word, false); break; case SP_NULL: Suff_SetNull(word); break; case SP_OBJDIR: Main_SetObjdir(false, "%s", word); break; case SP_READONLY: Var_ReadOnly(word, true); break; case SP_SYSPATH: AddToPaths(word, paths); break; default: break; } } static bool ApplyDependencyTarget(char *name, char *nameEnd, ParseSpecial *inout_special, GNodeType *inout_targetAttr, SearchPathList **inout_paths) { char savec = *nameEnd; *nameEnd = '\0'; if (!HandleDependencyTarget(name, inout_special, inout_targetAttr, inout_paths)) return false; if (*inout_special == SP_NOT && *name != '\0') HandleDependencyTargetMundane(name); else if (*inout_special == SP_PATH && *name != '.' && *name != '\0') Parse_Error(PARSE_WARNING, "Extra target (%s) ignored", name); *nameEnd = savec; return true; } static bool ParseDependencyTargets(char **pp, const char *lstart, ParseSpecial *inout_special, GNodeType *inout_targetAttr, SearchPathList **inout_paths) { char *p = *pp; for (;;) { char *tgt = p; ParseDependencyTargetWord(&p, lstart); /* * If the word is followed by a left parenthesis, it's the * name of one or more files inside an archive. */ if (!IsEscaped(lstart, p) && *p == '(') { p = tgt; if (!Arch_ParseArchive(&p, targets, SCOPE_CMDLINE)) { Parse_Error(PARSE_FATAL, "Error in archive specification: \"%s\"", tgt); return false; } continue; } if (*p == '\0') { InvalidLineType(lstart); return false; } if (!ApplyDependencyTarget(tgt, p, inout_special, inout_targetAttr, inout_paths)) return false; if (*inout_special != SP_NOT && *inout_special != SP_PATH) SkipExtraTargets(&p, lstart); else pp_skip_whitespace(&p); if (*p == '\0') break; if ((*p == '!' || *p == ':') && !IsEscaped(lstart, p)) break; } *pp = p; return true; } static void ParseDependencySourcesSpecial(char *start, ParseSpecial special, SearchPathList *paths) { char savec; while (*start != '\0') { char *end = start; while (*end != '\0' && !ch_isspace(*end)) end++; savec = *end; *end = '\0'; ParseDependencySourceSpecial(special, start, paths); *end = savec; if (savec != '\0') end++; pp_skip_whitespace(&end); start = end; } } static void LinkVarToTargets(VarAssign *var) { GNodeListNode *ln; for (ln = targets->first; ln != NULL; ln = ln->next) Parse_Var(var, ln->datum); } static bool ParseDependencySourcesMundane(char *start, ParseSpecial special, GNodeType targetAttr) { while (*start != '\0') { char *end = start; VarAssign var; /* * Check for local variable assignment, * rest of the line is the value. */ if (Parse_IsVar(start, &var)) { /* * Check if this makefile has disabled * setting local variables. */ bool target_vars = GetBooleanExpr( "${.MAKE.TARGET_LOCAL_VARIABLES}", true); if (target_vars) LinkVarToTargets(&var); free(var.varname); if (target_vars) return true; } /* * The targets take real sources, so we must beware of archive * specifications (i.e. things with left parentheses in them) * and handle them accordingly. */ for (; *end != '\0' && !ch_isspace(*end); end++) { if (*end == '(' && end > start && end[-1] != '$') { /* * Only stop for a left parenthesis if it * isn't at the start of a word (that'll be * for variable changes later) and isn't * preceded by a dollar sign (a dynamic * source). */ break; } } if (*end == '(') { GNodeList sources = LST_INIT; if (!Arch_ParseArchive(&start, &sources, SCOPE_CMDLINE)) { Parse_Error(PARSE_FATAL, "Error in source archive spec \"%s\"", start); return false; } while (!Lst_IsEmpty(&sources)) { GNode *gn = Lst_Dequeue(&sources); ApplyDependencySource(targetAttr, gn->name, special); } Lst_Done(&sources); end = start; } else { if (*end != '\0') { *end = '\0'; end++; } ApplyDependencySource(targetAttr, start, special); } pp_skip_whitespace(&end); start = end; } return true; } /* * From a dependency line like 'targets: sources', parse the sources. * * See the tests depsrc-*.mk. */ static void ParseDependencySources(char *p, GNodeType targetAttr, ParseSpecial special, SearchPathList **inout_paths) { if (*p == '\0') { HandleDependencySourcesEmpty(special, *inout_paths); } else if (special == SP_MFLAGS) { Main_ParseArgLine(p); return; } else if (special == SP_SHELL) { if (!Job_ParseShell(p)) { Parse_Error(PARSE_FATAL, "improper shell specification"); return; } return; } else if (special == SP_NOTPARALLEL || special == SP_SINGLESHELL || special == SP_DELETE_ON_ERROR) { return; } /* Now go for the sources. */ switch (special) { case SP_INCLUDES: case SP_LIBS: case SP_NOREADONLY: case SP_NULL: case SP_OBJDIR: case SP_PATH: case SP_READONLY: case SP_SUFFIXES: case SP_SYSPATH: ParseDependencySourcesSpecial(p, special, *inout_paths); if (*inout_paths != NULL) { Lst_Free(*inout_paths); *inout_paths = NULL; } if (special == SP_PATH) Dir_SetPATH(); if (special == SP_SYSPATH) Dir_SetSYSPATH(); break; default: assert(*inout_paths == NULL); if (!ParseDependencySourcesMundane(p, special, targetAttr)) return; break; } MaybeUpdateMainTarget(); } /* * Parse a dependency line consisting of targets, followed by a dependency * operator, optionally followed by sources. * * The nodes of the sources are linked as children to the nodes of the * targets. Nodes are created as necessary. * * The operator is applied to each node in the global 'targets' list, * which is where the nodes found for the targets are kept. * * The sources are parsed in much the same way as the targets, except * that they are expanded using the wildcarding scheme of the C-Shell, * and a target is created for each expanded word. Each of the resulting * nodes is then linked to each of the targets as one of its children. * * Certain targets and sources such as .PHONY or .PRECIOUS are handled * specially, see ParseSpecial. * * Transformation rules such as '.c.o' are also handled here, see * Suff_AddTransform. * * Upon return, the value of the line is unspecified. */ static void ParseDependency(char *line) { char *p; SearchPathList *paths; /* search paths to alter when parsing a list * of .PATH targets */ GNodeType targetAttr; /* from special sources */ ParseSpecial special; /* in special targets, the children are * linked as children of the parent but not * vice versa */ GNodeType op; DEBUG1(PARSE, "ParseDependency(%s)\n", line); p = line; paths = NULL; targetAttr = OP_NONE; special = SP_NOT; if (!ParseDependencyTargets(&p, line, &special, &targetAttr, &paths)) goto out; if (!Lst_IsEmpty(targets)) CheckSpecialMundaneMixture(special); op = ParseDependencyOp(&p); if (op == OP_NONE) { InvalidLineType(line); goto out; } ApplyDependencyOperator(op); pp_skip_whitespace(&p); ParseDependencySources(p, targetAttr, special, &paths); out: if (paths != NULL) Lst_Free(paths); } /* * Determine the assignment operator and adjust the end of the variable * name accordingly. */ static VarAssign AdjustVarassignOp(const char *name, const char *nameEnd, const char *op, const char *value) { VarAssignOp type; VarAssign va; if (op > name && op[-1] == '+') { op--; type = VAR_APPEND; } else if (op > name && op[-1] == '?') { op--; type = VAR_DEFAULT; } else if (op > name && op[-1] == ':') { op--; type = VAR_SUBST; } else if (op > name && op[-1] == '!') { op--; type = VAR_SHELL; } else { type = VAR_NORMAL; #ifdef SUNSHCMD while (op > name && ch_isspace(op[-1])) op--; if (op - name >= 3 && memcmp(op - 3, ":sh", 3) == 0) { op -= 3; type = VAR_SHELL; } #endif } va.varname = bmake_strsedup(name, nameEnd < op ? nameEnd : op); va.op = type; va.value = value; return va; } /* * Parse a variable assignment, consisting of a single-word variable name, * optional whitespace, an assignment operator, optional whitespace and the * variable value. * * Note: There is a lexical ambiguity with assignment modifier characters * in variable names. This routine interprets the character before the = * as a modifier. Therefore, an assignment like * C++=/usr/bin/CC * is interpreted as "C+ +=" instead of "C++ =". * * Used for both lines in a file and command line arguments. */ static bool Parse_IsVar(const char *p, VarAssign *out_var) { const char *nameStart, *nameEnd, *firstSpace, *eq; int level = 0; cpp_skip_hspace(&p); /* Skip to variable name */ /* * During parsing, the '+' of the operator '+=' is initially parsed * as part of the variable name. It is later corrected, as is the * ':sh' modifier. Of these two (nameEnd and eq), the earlier one * determines the actual end of the variable name. */ nameStart = p; firstSpace = NULL; /* * Scan for one of the assignment operators outside a variable * expansion. */ while (*p != '\0') { char ch = *p++; if (ch == '(' || ch == '{') { level++; continue; } if (ch == ')' || ch == '}') { level--; continue; } if (level != 0) continue; if ((ch == ' ' || ch == '\t') && firstSpace == NULL) firstSpace = p - 1; while (ch == ' ' || ch == '\t') ch = *p++; if (ch == '\0') return false; #ifdef SUNSHCMD if (ch == ':' && p[0] == 's' && p[1] == 'h') { p += 2; continue; } #endif if (ch == '=') eq = p - 1; else if (*p == '=' && (ch == '+' || ch == ':' || ch == '?' || ch == '!')) eq = p; else if (firstSpace != NULL) return false; else continue; nameEnd = firstSpace != NULL ? firstSpace : eq; p = eq + 1; cpp_skip_whitespace(&p); *out_var = AdjustVarassignOp(nameStart, nameEnd, eq, p); return true; } return false; } /* * Check for syntax errors such as unclosed expressions or unknown modifiers. */ static void VarCheckSyntax(VarAssignOp type, const char *uvalue, GNode *scope) { if (opts.strict) { if (type != VAR_SUBST && strchr(uvalue, '$') != NULL) { char *expandedValue = Var_Subst(uvalue, scope, VARE_PARSE_ONLY); /* TODO: handle errors */ free(expandedValue); } } } /* Perform a variable assignment that uses the operator ':='. */ static void VarAssign_EvalSubst(GNode *scope, const char *name, const char *uvalue, FStr *out_avalue) { char *evalue; /* * make sure that we set the variable the first time to nothing * so that it gets substituted. * * TODO: Add a test that demonstrates why this code is needed, * apart from making the debug log longer. * * XXX: The variable name is expanded up to 3 times. */ if (!Var_ExistsExpand(scope, name)) Var_SetExpand(scope, name, ""); evalue = Var_Subst(uvalue, scope, VARE_KEEP_DOLLAR_UNDEF); /* TODO: handle errors */ Var_SetExpand(scope, name, evalue); *out_avalue = FStr_InitOwn(evalue); } /* Perform a variable assignment that uses the operator '!='. */ static void VarAssign_EvalShell(const char *name, const char *uvalue, GNode *scope, FStr *out_avalue) { FStr cmd; char *output, *error; cmd = FStr_InitRefer(uvalue); Var_Expand(&cmd, SCOPE_CMDLINE, VARE_UNDEFERR); output = Cmd_Exec(cmd.str, &error); Var_SetExpand(scope, name, output); *out_avalue = FStr_InitOwn(output); if (error != NULL) { Parse_Error(PARSE_WARNING, "%s", error); free(error); } FStr_Done(&cmd); } /* * Perform a variable assignment. * * The actual value of the variable is returned in *out_true_avalue. * Especially for VAR_SUBST and VAR_SHELL this can differ from the literal * value. * * Return whether the assignment was actually performed, which is usually * the case. It is only skipped if the operator is '?=' and the variable * already exists. */ static bool VarAssign_Eval(const char *name, VarAssignOp op, const char *uvalue, GNode *scope, FStr *out_true_avalue) { FStr avalue = FStr_InitRefer(uvalue); if (op == VAR_APPEND) Var_AppendExpand(scope, name, uvalue); else if (op == VAR_SUBST) VarAssign_EvalSubst(scope, name, uvalue, &avalue); else if (op == VAR_SHELL) VarAssign_EvalShell(name, uvalue, scope, &avalue); else { /* XXX: The variable name is expanded up to 2 times. */ if (op == VAR_DEFAULT && Var_ExistsExpand(scope, name)) return false; /* Normal assignment -- just do it. */ Var_SetExpand(scope, name, uvalue); } *out_true_avalue = avalue; return true; } static void VarAssignSpecial(const char *name, const char *avalue) { if (strcmp(name, ".MAKEOVERRIDES") == 0) Main_ExportMAKEFLAGS(false); /* re-export MAKEFLAGS */ else if (strcmp(name, ".CURDIR") == 0) { /* * Someone is being (too?) clever... * Let's pretend they know what they are doing and * re-initialize the 'cur' CachedDir. */ Dir_InitCur(avalue); Dir_SetPATH(); } else if (strcmp(name, ".MAKE.JOB.PREFIX") == 0) Job_SetPrefix(); else if (strcmp(name, ".MAKE.EXPORTED") == 0) Var_ExportVars(avalue); } /* Perform the variable assignment in the given scope. */ static void Parse_Var(VarAssign *var, GNode *scope) { FStr avalue; /* actual value (maybe expanded) */ VarCheckSyntax(var->op, var->value, scope); if (VarAssign_Eval(var->varname, var->op, var->value, scope, &avalue)) { VarAssignSpecial(var->varname, avalue.str); FStr_Done(&avalue); } } /* * See if the command possibly calls a sub-make by using the variable * expressions ${.MAKE}, ${MAKE} or the plain word "make". */ static bool MaybeSubMake(const char *cmd) { const char *start; for (start = cmd; *start != '\0'; start++) { const char *p = start; char endc; /* XXX: What if progname != "make"? */ if (strncmp(p, "make", 4) == 0) if (start == cmd || !ch_isalnum(p[-1])) if (!ch_isalnum(p[4])) return true; if (*p != '$') continue; p++; if (*p == '{') endc = '}'; else if (*p == '(') endc = ')'; else continue; p++; if (*p == '.') /* Accept either ${.MAKE} or ${MAKE}. */ p++; if (strncmp(p, "MAKE", 4) == 0 && p[4] == endc) return true; } return false; } /* * Append the command to the target node. * * The node may be marked as a submake node if the command is determined to * be that. */ static void GNode_AddCommand(GNode *gn, char *cmd) { /* Add to last (ie current) cohort for :: targets */ if ((gn->type & OP_DOUBLEDEP) && gn->cohorts.last != NULL) gn = gn->cohorts.last->datum; /* if target already supplied, ignore commands */ if (!(gn->type & OP_HAS_COMMANDS)) { Lst_Append(&gn->commands, cmd); if (MaybeSubMake(cmd)) gn->type |= OP_SUBMAKE; RememberLocation(gn); } else { #if 0 /* XXX: We cannot do this until we fix the tree */ Lst_Append(&gn->commands, cmd); Parse_Error(PARSE_WARNING, "overriding commands for target \"%s\"; " "previous commands defined at %s: %u ignored", gn->name, gn->fname, gn->lineno); #else Parse_Error(PARSE_WARNING, "duplicate script for target \"%s\" ignored", gn->name); ParseErrorInternal(gn, PARSE_WARNING, "using previous script for \"%s\" defined here", gn->name); #endif } } /* * Add a directory to the path searched for included makefiles bracketed * by double-quotes. */ void Parse_AddIncludeDir(const char *dir) { (void)SearchPath_Add(parseIncPath, dir); } /* * Parse a directive like '.include' or '.-include'. * * .include "user-makefile.mk" * .include */ static void ParseInclude(char *directive) { char endc; /* '>' or '"' */ char *p; bool silent = directive[0] != 'i'; FStr file; p = directive + (silent ? 8 : 7); pp_skip_hspace(&p); if (*p != '"' && *p != '<') { Parse_Error(PARSE_FATAL, ".include filename must be delimited by '\"' or '<'"); return; } if (*p++ == '<') endc = '>'; else endc = '"'; file = FStr_InitRefer(p); /* Skip to matching delimiter */ while (*p != '\0' && *p != endc) p++; if (*p != endc) { Parse_Error(PARSE_FATAL, "Unclosed .include filename. '%c' expected", endc); return; } *p = '\0'; Var_Expand(&file, SCOPE_CMDLINE, VARE_WANTRES); IncludeFile(file.str, endc == '>', directive[0] == 'd', silent); FStr_Done(&file); } /* * Split filename into dirname + basename, then assign these to the * given variables. */ static void SetFilenameVars(const char *filename, const char *dirvar, const char *filevar) { const char *slash, *basename; FStr dirname; slash = strrchr(filename, '/'); if (slash == NULL) { dirname = FStr_InitRefer(curdir); basename = filename; } else { dirname = FStr_InitOwn(bmake_strsedup(filename, slash)); basename = slash + 1; } Global_Set(dirvar, dirname.str); Global_Set(filevar, basename); DEBUG4(PARSE, "SetFilenameVars: ${%s} = `%s' ${%s} = `%s'\n", dirvar, dirname.str, filevar, basename); FStr_Done(&dirname); } /* * Return the immediately including file. * * This is made complicated since the .for loop is implemented as a special * kind of .include; see For_Run. */ static const char * GetActuallyIncludingFile(void) { size_t i; const IncludedFile *incs = GetInclude(0); for (i = includes.len; i >= 2; i--) if (incs[i - 1].forLoop == NULL) return incs[i - 2].name.str; return NULL; } /* Set .PARSEDIR, .PARSEFILE, .INCLUDEDFROMDIR and .INCLUDEDFROMFILE. */ static void SetParseFile(const char *filename) { const char *including; SetFilenameVars(filename, ".PARSEDIR", ".PARSEFILE"); including = GetActuallyIncludingFile(); if (including != NULL) { SetFilenameVars(including, ".INCLUDEDFROMDIR", ".INCLUDEDFROMFILE"); } else { Global_Delete(".INCLUDEDFROMDIR"); Global_Delete(".INCLUDEDFROMFILE"); } } static bool StrContainsWord(const char *str, const char *word) { size_t strLen = strlen(str); size_t wordLen = strlen(word); const char *p; if (strLen < wordLen) return false; for (p = str; p != NULL; p = strchr(p, ' ')) { if (*p == ' ') p++; if (p > str + strLen - wordLen) return false; if (memcmp(p, word, wordLen) == 0 && (p[wordLen] == '\0' || p[wordLen] == ' ')) return true; } return false; } /* * XXX: Searching through a set of words with this linear search is * inefficient for variables that contain thousands of words. * * XXX: The paths in this list don't seem to be normalized in any way. */ static bool VarContainsWord(const char *varname, const char *word) { FStr val = Var_Value(SCOPE_GLOBAL, varname); bool found = val.str != NULL && StrContainsWord(val.str, word); FStr_Done(&val); return found; } /* * Track the makefiles we read - so makefiles can set dependencies on them. * Avoid adding anything more than once. * * Time complexity: O(n) per call, in total O(n^2), where n is the number * of makefiles that have been loaded. */ static void TrackInput(const char *name) { if (!VarContainsWord(".MAKE.MAKEFILES", name)) Global_Append(".MAKE.MAKEFILES", name); } /* Parse from the given buffer, later return to the current file. */ void Parse_PushInput(const char *name, unsigned lineno, unsigned readLines, Buffer buf, struct ForLoop *forLoop) { IncludedFile *curFile; if (forLoop != NULL) name = CurFile()->name.str; else TrackInput(name); DEBUG3(PARSE, "Parse_PushInput: %s %s, line %u\n", forLoop != NULL ? ".for loop in": "file", name, lineno); curFile = Vector_Push(&includes); curFile->name = FStr_InitOwn(bmake_strdup(name)); curFile->lineno = lineno; curFile->readLines = readLines; curFile->forHeadLineno = lineno; curFile->forBodyReadLines = readLines; curFile->buf = buf; curFile->depending = doing_depend; /* restore this on EOF */ curFile->forLoop = forLoop; if (forLoop != NULL && !For_NextIteration(forLoop, &curFile->buf)) abort(); /* see For_Run */ curFile->buf_ptr = curFile->buf.data; curFile->buf_end = curFile->buf.data + curFile->buf.len; curFile->condMinDepth = cond_depth; SetParseFile(name); } /* Check if the directive is an include directive. */ static bool IsInclude(const char *dir, bool sysv) { if (dir[0] == 's' || dir[0] == '-' || (dir[0] == 'd' && !sysv)) dir++; if (strncmp(dir, "include", 7) != 0) return false; /* Space is not mandatory for BSD .include */ return !sysv || ch_isspace(dir[7]); } #ifdef SYSVINCLUDE /* Check if the line is a SYSV include directive. */ static bool IsSysVInclude(const char *line) { const char *p; if (!IsInclude(line, true)) return false; /* Avoid interpreting a dependency line as an include */ for (p = line; (p = strchr(p, ':')) != NULL;) { /* end of line -> it's a dependency */ if (*++p == '\0') return false; /* '::' operator or ': ' -> it's a dependency */ if (*p == ':' || ch_isspace(*p)) return false; } return true; } /* Push to another file. The line points to the word "include". */ static void ParseTraditionalInclude(char *line) { char *cp; /* current position in file spec */ bool done = false; bool silent = line[0] != 'i'; char *file = line + (silent ? 8 : 7); char *all_files; DEBUG1(PARSE, "ParseTraditionalInclude: %s\n", file); pp_skip_whitespace(&file); all_files = Var_Subst(file, SCOPE_CMDLINE, VARE_WANTRES); /* TODO: handle errors */ for (file = all_files; !done; file = cp + 1) { /* Skip to end of line or next whitespace */ for (cp = file; *cp != '\0' && !ch_isspace(*cp); cp++) continue; if (*cp != '\0') *cp = '\0'; else done = true; IncludeFile(file, false, false, silent); } free(all_files); } #endif #ifdef GMAKEEXPORT /* Parse "export =", and actually export it. */ static void ParseGmakeExport(char *line) { char *variable = line + 6; char *value; DEBUG1(PARSE, "ParseGmakeExport: %s\n", variable); pp_skip_whitespace(&variable); for (value = variable; *value != '\0' && *value != '='; value++) continue; if (*value != '=') { Parse_Error(PARSE_FATAL, "Variable/Value missing from \"export\""); return; } *value++ = '\0'; /* terminate variable */ /* * Expand the value before putting it in the environment. */ value = Var_Subst(value, SCOPE_CMDLINE, VARE_WANTRES); /* TODO: handle errors */ setenv(variable, value, 1); free(value); } #endif /* * Called when EOF is reached in the current file. If we were reading an * include file or a .for loop, the includes stack is popped and things set * up to go back to reading the previous file at the previous location. * * Results: * true to continue parsing, i.e. it had only reached the end of an * included file, false if the main file has been parsed completely. */ static bool ParseEOF(void) { IncludedFile *curFile = CurFile(); doing_depend = curFile->depending; if (curFile->forLoop != NULL && For_NextIteration(curFile->forLoop, &curFile->buf)) { curFile->buf_ptr = curFile->buf.data; curFile->buf_end = curFile->buf.data + curFile->buf.len; curFile->readLines = curFile->forBodyReadLines; return true; } Cond_EndFile(); FStr_Done(&curFile->name); Buf_Done(&curFile->buf); if (curFile->forLoop != NULL) ForLoop_Free(curFile->forLoop); Vector_Pop(&includes); if (includes.len == 0) { /* We've run out of input */ Global_Delete(".PARSEDIR"); Global_Delete(".PARSEFILE"); Global_Delete(".INCLUDEDFROMDIR"); Global_Delete(".INCLUDEDFROMFILE"); return false; } curFile = CurFile(); DEBUG2(PARSE, "ParseEOF: returning to file %s, line %u\n", curFile->name.str, curFile->readLines + 1); SetParseFile(curFile->name.str); return true; } typedef enum ParseRawLineResult { PRLR_LINE, PRLR_EOF, PRLR_ERROR } ParseRawLineResult; /* * Parse until the end of a line, taking into account lines that end with * backslash-newline. The resulting line goes from out_line to out_line_end; * the line is not null-terminated. */ static ParseRawLineResult ParseRawLine(IncludedFile *curFile, char **out_line, char **out_line_end, char **out_firstBackslash, char **out_commentLineEnd) { char *line = curFile->buf_ptr; char *buf_end = curFile->buf_end; char *p = line; char *line_end = line; char *firstBackslash = NULL; char *commentLineEnd = NULL; ParseRawLineResult res = PRLR_LINE; curFile->readLines++; for (;;) { char ch; if (p == buf_end) { res = PRLR_EOF; break; } ch = *p; if (ch == '\0' || (ch == '\\' && p[1] == '\0')) { Parse_Error(PARSE_FATAL, "Zero byte read from file"); return PRLR_ERROR; } /* Treat next character after '\' as literal. */ if (ch == '\\') { if (firstBackslash == NULL) firstBackslash = p; if (p[1] == '\n') { curFile->readLines++; if (p + 2 == buf_end) { line_end = p; *line_end = '\n'; p += 2; continue; } } p += 2; line_end = p; assert(p <= buf_end); continue; } /* * Remember the first '#' for comment stripping, unless * the previous char was '[', as in the modifier ':[#]'. */ if (ch == '#' && commentLineEnd == NULL && !(p > line && p[-1] == '[')) commentLineEnd = line_end; p++; if (ch == '\n') break; /* We are not interested in trailing whitespace. */ if (!ch_isspace(ch)) line_end = p; } curFile->buf_ptr = p; *out_line = line; *out_line_end = line_end; *out_firstBackslash = firstBackslash; *out_commentLineEnd = commentLineEnd; return res; } /* * Beginning at start, unescape '\#' to '#' and replace backslash-newline * with a single space. */ static void UnescapeBackslash(char *line, char *start) { const char *src = start; char *dst = start; char *spaceStart = line; for (;;) { char ch = *src++; if (ch != '\\') { if (ch == '\0') break; *dst++ = ch; continue; } ch = *src++; if (ch == '\0') { /* Delete '\\' at the end of the buffer. */ dst--; break; } /* Delete '\\' from before '#' on non-command lines. */ if (ch == '#' && line[0] != '\t') *dst++ = ch; else if (ch == '\n') { cpp_skip_hspace(&src); *dst++ = ' '; } else { /* Leave '\\' in the buffer for later. */ *dst++ = '\\'; *dst++ = ch; /* Keep an escaped ' ' at the line end. */ spaceStart = dst; } } /* Delete any trailing spaces - eg from empty continuations */ while (dst > spaceStart && ch_isspace(dst[-1])) dst--; *dst = '\0'; } typedef enum LineKind { /* * Return the next line that is neither empty nor a comment. * Backslash line continuations are folded into a single space. * A trailing comment, if any, is discarded. */ LK_NONEMPTY, /* * Return the next line, even if it is empty or a comment. * Preserve backslash-newline to keep the line numbers correct. * * Used in .for loops to collect the body of the loop while waiting * for the corresponding .endfor. */ LK_FOR_BODY, /* * Return the next line that starts with a dot. * Backslash line continuations are folded into a single space. * A trailing comment, if any, is discarded. * * Used in .if directives to skip over irrelevant branches while * waiting for the corresponding .endif. */ LK_DOT } LineKind; /* * Return the next "interesting" logical line from the current file. The * returned string will be freed at the end of including the file. */ static char * ReadLowLevelLine(LineKind kind) { IncludedFile *curFile = CurFile(); ParseRawLineResult res; char *line; char *line_end; char *firstBackslash; char *commentLineEnd; for (;;) { curFile->lineno = curFile->readLines + 1; res = ParseRawLine(curFile, &line, &line_end, &firstBackslash, &commentLineEnd); if (res == PRLR_ERROR) return NULL; if (line == line_end || line == commentLineEnd) { if (res == PRLR_EOF) return NULL; if (kind != LK_FOR_BODY) continue; } /* We now have a line of data */ assert(ch_isspace(*line_end)); *line_end = '\0'; if (kind == LK_FOR_BODY) return line; /* Don't join the physical lines. */ if (kind == LK_DOT && line[0] != '.') continue; break; } if (commentLineEnd != NULL && line[0] != '\t') *commentLineEnd = '\0'; if (firstBackslash != NULL) UnescapeBackslash(line, firstBackslash); return line; } static bool SkipIrrelevantBranches(void) { const char *line; while ((line = ReadLowLevelLine(LK_DOT)) != NULL) { if (Cond_EvalLine(line) == CR_TRUE) return true; /* * TODO: Check for typos in .elif directives such as .elsif * or .elseif. * * This check will probably duplicate some of the code in * ParseLine. Most of the code there cannot apply, only * ParseVarassign and ParseDependencyLine can, and to prevent * code duplication, these would need to be called with a * flag called onlyCheckSyntax. * * See directive-elif.mk for details. */ } return false; } static bool ParseForLoop(const char *line) { int rval; unsigned forHeadLineno; unsigned bodyReadLines; int forLevel; rval = For_Eval(line); if (rval == 0) return false; /* Not a .for line */ if (rval < 0) return true; /* Syntax error - error printed, ignore line */ forHeadLineno = CurFile()->lineno; bodyReadLines = CurFile()->readLines; /* Accumulate the loop body until the matching '.endfor'. */ forLevel = 1; do { line = ReadLowLevelLine(LK_FOR_BODY); if (line == NULL) { Parse_Error(PARSE_FATAL, "Unexpected end of file in .for loop"); break; } } while (For_Accum(line, &forLevel)); For_Run(forHeadLineno, bodyReadLines); return true; } /* * Read an entire line from the input file. * * Empty lines, .if and .for are completely handled by this function, * leaving only variable assignments, other directives, dependency lines * and shell commands to the caller. * * Return a line without trailing whitespace, or NULL for EOF. The returned * string will be freed at the end of including the file. */ static char * ReadHighLevelLine(void) { char *line; for (;;) { line = ReadLowLevelLine(LK_NONEMPTY); if (posix_state == PS_MAYBE_NEXT_LINE) posix_state = PS_NOW_OR_NEVER; else posix_state = PS_TOO_LATE; if (line == NULL) return NULL; if (line[0] != '.') return line; switch (Cond_EvalLine(line)) { case CR_FALSE: /* May also mean a syntax error. */ if (!SkipIrrelevantBranches()) return NULL; continue; case CR_TRUE: continue; case CR_ERROR: /* Not a conditional line */ if (ParseForLoop(line)) continue; break; } return line; } } static void FinishDependencyGroup(void) { GNodeListNode *ln; if (targets == NULL) return; for (ln = targets->first; ln != NULL; ln = ln->next) { GNode *gn = ln->datum; Suff_EndTransform(gn); /* * Mark the target as already having commands if it does, to * keep from having shell commands on multiple dependency * lines. */ if (!Lst_IsEmpty(&gn->commands)) gn->type |= OP_HAS_COMMANDS; } Lst_Free(targets); targets = NULL; } /* Add the command to each target from the current dependency spec. */ static void ParseLine_ShellCommand(const char *p) { cpp_skip_whitespace(&p); if (*p == '\0') return; /* skip empty commands */ if (targets == NULL) { Parse_Error(PARSE_FATAL, "Unassociated shell command \"%s\"", p); return; } { char *cmd = bmake_strdup(p); GNodeListNode *ln; for (ln = targets->first; ln != NULL; ln = ln->next) { GNode *gn = ln->datum; GNode_AddCommand(gn, cmd); } #ifdef CLEANUP Lst_Append(&targCmds, cmd); #endif } } static void HandleBreak(void) { IncludedFile *curFile = CurFile(); if (curFile->forLoop != NULL) { /* pretend we reached EOF */ For_Break(curFile->forLoop); cond_depth = CurFile_CondMinDepth(); ParseEOF(); } else Parse_Error(PARSE_FATAL, "break outside of for loop"); } /* * See if the line starts with one of the known directives, and if so, handle * the directive. */ static bool ParseDirective(char *line) { char *cp = line + 1; const char *arg; Substring dir; pp_skip_whitespace(&cp); if (IsInclude(cp, false)) { ParseInclude(cp); return true; } dir.start = cp; while (ch_islower(*cp) || *cp == '-') cp++; dir.end = cp; if (*cp != '\0' && !ch_isspace(*cp)) return false; pp_skip_whitespace(&cp); arg = cp; if (Substring_Equals(dir, "break")) HandleBreak(); else if (Substring_Equals(dir, "undef")) Var_Undef(arg); else if (Substring_Equals(dir, "export")) Var_Export(VEM_PLAIN, arg); else if (Substring_Equals(dir, "export-env")) Var_Export(VEM_ENV, arg); else if (Substring_Equals(dir, "export-literal")) Var_Export(VEM_LITERAL, arg); else if (Substring_Equals(dir, "unexport")) Var_UnExport(false, arg); else if (Substring_Equals(dir, "unexport-env")) Var_UnExport(true, arg); else if (Substring_Equals(dir, "info")) HandleMessage(PARSE_INFO, "info", arg); else if (Substring_Equals(dir, "warning")) HandleMessage(PARSE_WARNING, "warning", arg); else if (Substring_Equals(dir, "error")) HandleMessage(PARSE_FATAL, "error", arg); else return false; return true; } bool Parse_VarAssign(const char *line, bool finishDependencyGroup, GNode *scope) { VarAssign var; if (!Parse_IsVar(line, &var)) return false; if (finishDependencyGroup) FinishDependencyGroup(); Parse_Var(&var, scope); free(var.varname); return true; } static char * FindSemicolon(char *p) { int level = 0; for (; *p != '\0'; p++) { if (*p == '\\' && p[1] != '\0') { p++; continue; } if (*p == '$' && (p[1] == '(' || p[1] == '{')) level++; else if (level > 0 && (*p == ')' || *p == '}')) level--; else if (level == 0 && *p == ';') break; } return p; } /* * dependency -> [target...] op [source...] [';' command] * op -> ':' | '::' | '!' */ static void ParseDependencyLine(char *line) { VarEvalMode emode; char *expanded_line; const char *shellcmd = NULL; /* * For some reason - probably to make the parser impossible - * a ';' can be used to separate commands from dependencies. * Attempt to skip over ';' inside substitution patterns. */ { char *semicolon = FindSemicolon(line); if (*semicolon != '\0') { /* Terminate the dependency list at the ';' */ *semicolon = '\0'; shellcmd = semicolon + 1; } } /* * We now know it's a dependency line so it needs to have all * variables expanded before being parsed. * * XXX: Ideally the dependency line would first be split into * its left-hand side, dependency operator and right-hand side, * and then each side would be expanded on its own. This would * allow for the left-hand side to allow only defined variables * and to allow variables on the right-hand side to be undefined * as well. * * Parsing the line first would also prevent that targets * generated from variable expressions are interpreted as the * dependency operator, such as in "target${:U\:} middle: source", * in which the middle is interpreted as a source, not a target. */ /* * In lint mode, allow undefined variables to appear in dependency * lines. * * Ideally, only the right-hand side would allow undefined variables * since it is common to have optional dependencies. Having undefined * variables on the left-hand side is more unusual though. Since * both sides are expanded in a single pass, there is not much choice * what to do here. * * In normal mode, it does not matter whether undefined variables are * allowed or not since as of 2020-09-14, Var_Parse does not print * any parse errors in such a case. It simply returns the special * empty string var_Error, which cannot be detected in the result of * Var_Subst. */ emode = opts.strict ? VARE_WANTRES : VARE_UNDEFERR; expanded_line = Var_Subst(line, SCOPE_CMDLINE, emode); /* TODO: handle errors */ /* Need a fresh list for the target nodes */ if (targets != NULL) Lst_Free(targets); targets = Lst_New(); ParseDependency(expanded_line); free(expanded_line); if (shellcmd != NULL) ParseLine_ShellCommand(shellcmd); } static void ParseLine(char *line) { /* * Lines that begin with '.' can be pretty much anything: * - directives like '.include' or '.if', * - suffix rules like '.c.o:', * - dependencies for filenames that start with '.', * - variable assignments like '.tmp=value'. */ if (line[0] == '.' && ParseDirective(line)) return; if (line[0] == '\t') { ParseLine_ShellCommand(line + 1); return; } #ifdef SYSVINCLUDE if (IsSysVInclude(line)) { /* * It's an S3/S5-style "include". */ ParseTraditionalInclude(line); return; } #endif #ifdef GMAKEEXPORT if (strncmp(line, "export", 6) == 0 && ch_isspace(line[6]) && strchr(line, ':') == NULL) { /* * It's a Gmake "export". */ ParseGmakeExport(line); return; } #endif if (Parse_VarAssign(line, true, SCOPE_GLOBAL)) return; FinishDependencyGroup(); ParseDependencyLine(line); } /* * Parse a top-level makefile, incorporating its content into the global * dependency graph. */ void Parse_File(const char *name, int fd) { char *line; Buffer buf; buf = LoadFile(name, fd != -1 ? fd : STDIN_FILENO); if (fd != -1) (void)close(fd); assert(targets == NULL); Parse_PushInput(name, 1, 0, buf, NULL); do { while ((line = ReadHighLevelLine()) != NULL) { DEBUG2(PARSE, "Parsing line %u: %s\n", CurFile()->lineno, line); ParseLine(line); } /* Reached EOF, but it may be just EOF of an include file. */ } while (ParseEOF()); FinishDependencyGroup(); if (parseErrors != 0) { (void)fflush(stdout); (void)fprintf(stderr, "%s: Fatal errors encountered -- cannot continue\n", progname); PrintOnError(NULL, ""); exit(1); } } /* Initialize the parsing module. */ void Parse_Init(void) { mainNode = NULL; parseIncPath = SearchPath_New(); sysIncPath = SearchPath_New(); defSysIncPath = SearchPath_New(); Vector_Init(&includes, sizeof(IncludedFile)); } /* Clean up the parsing module. */ void Parse_End(void) { #ifdef CLEANUP Lst_DoneCall(&targCmds, free); assert(targets == NULL); SearchPath_Free(defSysIncPath); SearchPath_Free(sysIncPath); SearchPath_Free(parseIncPath); assert(includes.len == 0); Vector_Done(&includes); #endif } -/* - * Return a list containing the single main target to create. - * If no such target exists, we Punt with an obnoxious error message. - */ +/* Populate the list with the single main target to create, or error out. */ void Parse_MainName(GNodeList *mainList) { if (mainNode == NULL) Punt("no target to make."); Lst_Append(mainList, mainNode); if (mainNode->type & OP_DOUBLEDEP) Lst_AppendAll(mainList, &mainNode->cohorts); Global_Append(".TARGETS", mainNode->name); } int Parse_NumErrors(void) { return parseErrors; } diff --git a/unit-tests/Makefile b/unit-tests/Makefile index bcfe853642a5..a3f069133739 100644 --- a/unit-tests/Makefile +++ b/unit-tests/Makefile @@ -1,855 +1,855 @@ -# $Id: Makefile,v 1.193 2023/02/25 20:03:25 sjg Exp $ +# $Id: Makefile,v 1.195 2023/05/10 18:26:24 sjg Exp $ # -# $NetBSD: Makefile,v 1.333 2023/02/25 19:30:32 sjg Exp $ +# $NetBSD: Makefile,v 1.335 2023/05/10 13:03:06 rillig Exp $ # # Unit tests for make(1) # # The main targets are: # # all: # run all the tests # test: # run 'all', and compare to expected results # accept: # move generated output to expected results # # Settable variables # # TEST_MAKE # The make program to be tested. # # # Adding a test case # # Each feature should get its own set of tests in its own suitably # named makefile (*.mk), with its own set of expected results (*.exp), # and it should be added to the TESTS list. # .MAIN: all # we use these below but we might be an older make .MAKE.OS?= ${uname -s:L:sh} .MAKE.UID?= ${id -u:L:sh} # for many tests we need a TMPDIR that will not collide # with other users. .if ${.OBJDIR} != ${.CURDIR} # easy TMPDIR:= ${.OBJDIR}/tmp .elif defined(TMPDIR) TMPDIR:= ${TMPDIR}/uid${.MAKE.UID} .else TMPDIR:= /tmp/uid${.MAKE.UID} .endif # make sure it exists .if !exist(${TMPDIR}) _!= mkdir -p ${TMPDIR} .endif # Each test is in a sub-makefile. # Keep the list sorted. # Any test that is commented out must be ignored in # src/tests/usr.bin/make/t_make.sh as well. #TESTS+= archive #TESTS+= archive-suffix TESTS+= cmd-errors TESTS+= cmd-errors-jobs TESTS+= cmd-errors-lint TESTS+= cmd-interrupt TESTS+= cmdline TESTS+= cmdline-redirect-stdin TESTS+= cmdline-undefined TESTS+= comment TESTS+= compat-error TESTS+= cond-cmp-numeric TESTS+= cond-cmp-numeric-eq TESTS+= cond-cmp-numeric-ge TESTS+= cond-cmp-numeric-gt TESTS+= cond-cmp-numeric-le TESTS+= cond-cmp-numeric-lt TESTS+= cond-cmp-numeric-ne TESTS+= cond-cmp-string TESTS+= cond-cmp-unary TESTS+= cond-eof TESTS+= cond-func TESTS+= cond-func-commands TESTS+= cond-func-defined TESTS+= cond-func-empty TESTS+= cond-func-exists TESTS+= cond-func-make TESTS+= cond-func-make-main TESTS+= cond-func-target TESTS+= cond-late TESTS+= cond-op TESTS+= cond-op-and TESTS+= cond-op-and-lint TESTS+= cond-op-not TESTS+= cond-op-or TESTS+= cond-op-or-lint TESTS+= cond-op-parentheses TESTS+= cond-short TESTS+= cond-token-number TESTS+= cond-token-plain TESTS+= cond-token-string TESTS+= cond-token-var TESTS+= cond-undef-lint TESTS+= counter TESTS+= counter-append TESTS+= dep TESTS+= dep-colon TESTS+= dep-colon-bug-cross-file TESTS+= dep-double-colon TESTS+= dep-double-colon-indep TESTS+= dep-duplicate TESTS+= dep-exclam TESTS+= dep-none TESTS+= dep-op-missing TESTS+= dep-percent TESTS+= dep-var TESTS+= dep-wildcards TESTS+= depsrc TESTS+= depsrc-end TESTS+= depsrc-exec TESTS+= depsrc-ignore TESTS+= depsrc-made TESTS+= depsrc-make TESTS+= depsrc-meta TESTS+= depsrc-nometa TESTS+= depsrc-nometa_cmp TESTS+= depsrc-nopath TESTS+= depsrc-notmain TESTS+= depsrc-optional TESTS+= depsrc-phony TESTS+= depsrc-precious TESTS+= depsrc-recursive TESTS+= depsrc-silent TESTS+= depsrc-use TESTS+= depsrc-usebefore TESTS+= depsrc-usebefore-double-colon TESTS+= depsrc-wait TESTS+= deptgt TESTS+= deptgt-begin TESTS+= deptgt-begin-fail TESTS+= deptgt-begin-fail-indirect TESTS+= deptgt-default TESTS+= deptgt-delete_on_error TESTS+= deptgt-end TESTS+= deptgt-end-fail TESTS+= deptgt-end-fail-all TESTS+= deptgt-end-fail-indirect TESTS+= deptgt-end-jobs TESTS+= deptgt-error TESTS+= deptgt-ignore TESTS+= deptgt-interrupt TESTS+= deptgt-main TESTS+= deptgt-makeflags TESTS+= deptgt-no_parallel TESTS+= deptgt-nopath TESTS+= deptgt-notparallel TESTS+= deptgt-objdir TESTS+= deptgt-order TESTS+= deptgt-path TESTS+= deptgt-path-suffix TESTS+= deptgt-phony TESTS+= deptgt-posix TESTS+= deptgt-precious TESTS+= deptgt-shell TESTS+= deptgt-silent TESTS+= deptgt-silent-jobs TESTS+= deptgt-stale TESTS+= deptgt-suffixes TESTS+= dir TESTS+= dir-expand-path TESTS+= directive TESTS+= directive-dinclude TESTS+= directive-elif TESTS+= directive-elifdef TESTS+= directive-elifmake TESTS+= directive-elifndef TESTS+= directive-elifnmake TESTS+= directive-else TESTS+= directive-endfor TESTS+= directive-endif TESTS+= directive-error TESTS+= directive-export TESTS+= directive-export-env TESTS+= directive-export-impl TESTS+= directive-export-gmake TESTS+= directive-export-literal TESTS+= directive-for TESTS+= directive-for-break TESTS+= directive-for-empty TESTS+= directive-for-errors TESTS+= directive-for-escape TESTS+= directive-for-generating-endif TESTS+= directive-for-if TESTS+= directive-for-lines TESTS+= directive-for-null TESTS+= directive-hyphen-include TESTS+= directive-if TESTS+= directive-if-nested TESTS+= directive-ifdef TESTS+= directive-ifmake TESTS+= directive-ifndef TESTS+= directive-ifnmake TESTS+= directive-include TESTS+= directive-include-fatal TESTS+= directive-info TESTS+= directive-misspellings TESTS+= directive-sinclude TESTS+= directive-undef TESTS+= directive-unexport TESTS+= directive-unexport-env TESTS+= directive-warning TESTS+= dollar TESTS+= doterror TESTS+= dotwait TESTS+= error TESTS+= # escape # broken by reverting POSIX changes TESTS+= export TESTS+= export-all TESTS+= export-env TESTS+= export-variants -TESTS+= forloop TESTS+= forsubst TESTS+= gnode-submake TESTS+= hanoi-include TESTS+= impsrc TESTS+= include-main TESTS+= job-flags #TESTS+= job-output-long-lines TESTS+= job-output-null TESTS+= jobs-empty-commands TESTS+= jobs-empty-commands-error TESTS+= jobs-error-indirect TESTS+= jobs-error-nested TESTS+= jobs-error-nested-make TESTS+= lint TESTS+= make-exported TESTS+= meta-cmd-cmp TESTS+= moderrs TESTS+= modmatch TESTS+= modmisc .if ${.MAKE.UID} > 0 TESTS+= objdir-writable .endif TESTS+= opt TESTS+= opt-backwards TESTS+= opt-chdir TESTS+= opt-debug TESTS+= opt-debug-all TESTS+= opt-debug-archive TESTS+= opt-debug-curdir TESTS+= opt-debug-cond TESTS+= opt-debug-dir TESTS+= opt-debug-errors TESTS+= opt-debug-errors-jobs TESTS+= opt-debug-file TESTS+= opt-debug-for TESTS+= opt-debug-graph1 TESTS+= opt-debug-graph2 TESTS+= opt-debug-graph3 TESTS+= opt-debug-hash #TESTS+= opt-debug-jobs TESTS+= opt-debug-lint TESTS+= opt-debug-loud TESTS+= opt-debug-meta TESTS+= opt-debug-making TESTS+= opt-debug-no-rm TESTS+= opt-debug-parse TESTS+= opt-debug-suff TESTS+= opt-debug-targets TESTS+= opt-debug-varraw TESTS+= opt-debug-var TESTS+= opt-debug-x-trace TESTS+= opt-define TESTS+= opt-env TESTS+= opt-file TESTS+= opt-ignore TESTS+= opt-include-dir TESTS+= opt-jobs TESTS+= opt-jobs-internal TESTS+= opt-jobs-no-action TESTS+= opt-keep-going TESTS+= opt-keep-going-indirect TESTS+= opt-keep-going-multiple TESTS+= opt-m-include-dir TESTS+= opt-no-action TESTS+= opt-no-action-at-all TESTS+= opt-no-action-runflags TESTS+= opt-no-action-touch TESTS+= opt-query TESTS+= opt-raw TESTS+= opt-silent TESTS+= opt-touch TESTS+= opt-touch-jobs TESTS+= opt-tracefile TESTS+= opt-var-expanded TESTS+= opt-var-literal TESTS+= opt-version TESTS+= opt-warnings-as-errors TESTS+= opt-where-am-i TESTS+= opt-x-reduce-exported TESTS+= order TESTS+= parse TESTS+= parse-var TESTS+= phony-end TESTS+= posix TESTS+= # posix1 # broken by reverting POSIX changes TESTS+= recursive TESTS+= sh TESTS+= sh-dots TESTS+= sh-errctl TESTS+= sh-flags TESTS+= sh-jobs TESTS+= sh-jobs-error TESTS+= sh-leading-at TESTS+= sh-leading-hyphen TESTS+= sh-leading-plus TESTS+= sh-meta-chars TESTS+= sh-multi-line TESTS+= sh-single-line TESTS+= shell-csh TESTS+= shell-custom .if exists(/bin/ksh) TESTS+= shell-ksh .endif TESTS+= shell-sh TESTS+= suff-add-later TESTS+= suff-clear-regular TESTS+= suff-clear-single TESTS+= suff-incomplete TESTS+= suff-lookup TESTS+= suff-main TESTS+= suff-main-several TESTS+= suff-phony TESTS+= suff-rebuild TESTS+= suff-self TESTS+= suff-transform-debug TESTS+= suff-transform-endless TESTS+= suff-transform-expand TESTS+= suff-transform-select TESTS+= suff-use TESTS+= sunshcmd TESTS+= ternary TESTS+= unexport TESTS+= unexport-env TESTS+= use-inference TESTS+= var-readonly TESTS+= var-scope TESTS+= var-scope-cmdline TESTS+= var-scope-env TESTS+= var-scope-global TESTS+= var-scope-local TESTS+= var-scope-local-legacy TESTS+= var-eval-short TESTS+= var-op TESTS+= var-op-append TESTS+= var-op-assign TESTS+= var-op-default TESTS+= var-op-expand TESTS+= var-op-shell TESTS+= var-op-sunsh TESTS+= var-recursive TESTS+= varcmd TESTS+= vardebug TESTS+= varfind TESTS+= varmisc TESTS+= varmod TESTS+= varmod-assign TESTS+= varmod-assign-shell TESTS+= varmod-defined TESTS+= varmod-edge TESTS+= varmod-exclam-shell TESTS+= varmod-extension TESTS+= varmod-gmtime TESTS+= varmod-hash TESTS+= varmod-head TESTS+= varmod-ifelse TESTS+= varmod-indirect TESTS+= varmod-l-name-to-value TESTS+= varmod-localtime TESTS+= varmod-loop TESTS+= varmod-loop-delete TESTS+= varmod-loop-varname TESTS+= varmod-match TESTS+= varmod-match-escape +TESTS+= varmod-mtime TESTS+= varmod-no-match TESTS+= varmod-order TESTS+= varmod-order-numeric TESTS+= varmod-order-reverse TESTS+= varmod-order-shuffle TESTS+= varmod-order-string TESTS+= varmod-path TESTS+= varmod-quote TESTS+= varmod-quote-dollar TESTS+= varmod-range TESTS+= varmod-remember TESTS+= varmod-root TESTS+= varmod-select-words TESTS+= varmod-shell TESTS+= varmod-subst TESTS+= varmod-subst-regex TESTS+= varmod-sun-shell TESTS+= varmod-sysv TESTS+= varmod-tail TESTS+= varmod-to-abs TESTS+= varmod-to-lower TESTS+= varmod-to-many-words TESTS+= varmod-to-one-word TESTS+= varmod-to-separator TESTS+= varmod-to-upper TESTS+= varmod-undefined TESTS+= varmod-unique TESTS+= varname TESTS+= varname-dollar TESTS+= varname-dot-alltargets TESTS+= varname-dot-curdir TESTS+= varname-dot-includes TESTS+= varname-dot-includedfromdir TESTS+= varname-dot-includedfromfile TESTS+= varname-dot-libs TESTS+= varname-dot-make-dependfile TESTS+= varname-dot-make-expand_variables TESTS+= varname-dot-make-exported TESTS+= varname-dot-make-jobs TESTS+= varname-dot-make-jobs-prefix TESTS+= varname-dot-make-level TESTS+= varname-dot-make-makefile_preference TESTS+= varname-dot-make-makefiles TESTS+= varname-dot-make-meta-bailiwick TESTS+= varname-dot-make-meta-created TESTS+= varname-dot-make-meta-files .if ${.MAKE.PATH_FILEMON:Uno:Nktrace:N/dev*} == "" && ${TMPDIR:N/tmp*:N/var/tmp*} != "" # these tests will not work if TMPDIR is or is a subdir of # /tmp or /var/tmp TESTS+= varname-dot-make-meta-ignore_filter TESTS+= varname-dot-make-meta-ignore_paths TESTS+= varname-dot-make-meta-ignore_patterns TESTS+= varname-dot-make-path_filemon .endif TESTS+= varname-dot-make-meta-prefix TESTS+= varname-dot-make-mode TESTS+= varname-dot-make-pid TESTS+= varname-dot-make-ppid TESTS+= varname-dot-make-save_dollars TESTS+= varname-dot-makeflags TESTS+= varname-dot-makeoverrides TESTS+= varname-dot-newline TESTS+= varname-dot-objdir TESTS+= varname-dot-parsedir TESTS+= varname-dot-parsefile TESTS+= varname-dot-path TESTS+= varname-dot-shell TESTS+= varname-dot-suffixes TESTS+= varname-dot-targets TESTS+= varname-empty TESTS+= varname-make TESTS+= varname-make_print_var_on_error TESTS+= varname-make_print_var_on_error-jobs TESTS+= varname-makefile TESTS+= varname-makeflags TESTS+= varname-pwd TESTS+= varname-vpath TESTS+= varparse-dynamic TESTS+= varparse-errors TESTS+= varparse-mod TESTS+= varparse-undef-partial # some shells have quirks _shell := ${.SHELL:tA:T} .if ${_shell} == "dash" # dash fails -x output BROKEN_TESTS+= opt-debug-x-trace .elif ${_shell} == "ksh" BROKEN_TESTS+= sh-flags .endif .if ${.MAKE.OS:NDarwin} == "" BROKEN_TESTS+= shell-ksh .endif .if ${.MAKE.OS} == "SCO_SV" BROKEN_TESTS+= \ opt-debug-graph[23] \ varmod-localtime \ varmod-to-separator \ .if ${_shell} == "bash" BROKEN_TESTS+= job-output-null .else BROKEN_TESTS+= \ cmd-interrupt \ job-flags \ .endif .endif # Some tests just do not work on some platforms or environments # so allow for some filtering. .if !empty(BROKEN_TESTS) .warning Skipping broken tests: ${BROKEN_TESTS:O:u} TESTS:= ${TESTS:${BROKEN_TESTS:S,^,N,:ts:}} .endif # Ideas for more tests: # char-0020-space.mk # char-005C-backslash.mk # escape-cond-str.mk # escape-cond-func-arg.mk # escape-varmod.mk # escape-varmod-define.mk # escape-varmod-match.mk # escape-varname.mk # escape-varassign-varname.mk # escape-varassign-varname-cmdline.mk # escape-varassign-value.mk # escape-varassign-value-cmdline.mk # escape-dependency-source.mk # escape-dependency-target.mk # escape-for-varname.mk # escape-for-item.mk # posix-*.mk (see posix.mk and posix1.mk) # Additional environment variables for some of the tests. # The base environment is -i PATH="$PATH". ENV.depsrc-optional+= TZ=UTC ENV.deptgt-phony+= MAKESYSPATH=. ENV.directive-undef= ENV_VAR=env-value ENV.opt-env= FROM_ENV=value-from-env ENV.opt-m-include-dir= ${MAKEOBJDIR:DMAKEOBJDIR=${MAKEOBJDIR}} ENV.varmisc= FROM_ENV=env ENV.varmisc+= FROM_ENV_BEFORE=env ENV.varmisc+= FROM_ENV_AFTER=env ENV.varmod-localtime+= TZ=${UTC_1:UEurope/Berlin} ENV.varname-vpath+= VPATH=varname-vpath.dir:varname-vpath.dir2 # Override make flags for some of the tests; default is -k. # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of # settings FLAGS.test=-dv here, since that is closer to the test code. FLAGS.cond-func-make= via-cmdline FLAGS.doterror= # none, especially not -k FLAGS.jobs-error-indirect= # none, especially not -k FLAGS.jobs-error-nested= # none, especially not -k FLAGS.jobs-error-nested-make= # none, especially not -k FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmdline-plain' # Some tests need extra postprocessing. SED_CMDS.deptgt-phony= ${STD_SED_CMDS.dd} SED_CMDS.dir= ${STD_SED_CMDS.dd} SED_CMDS.export= -e '/^[^=_A-Za-z0-9]*=/d' SED_CMDS.export-all= ${SED_CMDS.export} SED_CMDS.export-env= ${SED_CMDS.export} SED_CMDS.cmdline= -e 's,uid${.MAKE.UID}/,,' SED_CMDS.job-output-long-lines= \ ${:D Job separators on their own line are ok. } \ -e '/^--- job-[ab] ---$$/d' \ ${:D Plain output lines are ok as well. } \ ${:D They may come in multiples of 1024 or as 10000. } \ -e '/^aa*$$/d' \ -e '/^bb*$$/d' \ ${:D The following lines should rather not occur since the job } \ ${:D marker should always be at the beginning of the line. } \ -e '/^aa*--- job-b ---$$/d' \ -e '/^bb*--- job-a ---$$/d' SED_CMDS.opt-chdir= -e 's,\(nonexistent\).[1-9][0-9]*,\1,' \ -e '/name/s,file,File,' \ -e 's,no such,No such,' \ -e 's,Filename,File name,' # meta line numbers can vary based on filemon implementation SED_CMDS.meta-ignore= -e 's,\(\.meta:\) [1-9][0-9]*:,\1 :,' SED_CMDS.opt-debug-graph1= ${STD_SED_CMDS.dg1} SED_CMDS.opt-debug-graph2= ${STD_SED_CMDS.dg2} SED_CMDS.opt-debug-graph3= ${STD_SED_CMDS.dg3} SED_CMDS.opt-debug-hash= -e 's,\(numEntries\)=[1-9][0-9],\1=,' SED_CMDS.opt-debug-jobs= -e 's,([0-9][0-9]*),(),' SED_CMDS.opt-debug-jobs+= -e 's,pid [0-9][0-9]*,pid ,' SED_CMDS.opt-debug-jobs+= -e 's,Process [0-9][0-9]*,Process ,' SED_CMDS.opt-debug-jobs+= -e 's,JobFinish: [0-9][0-9]*,JobFinish: ,' SED_CMDS.opt-debug-jobs+= -e 's,Command: ${.SHELL:T},Command: ,' # The "-q" may be there or not, see jobs.c, variable shells. SED_CMDS.opt-debug-jobs+= -e 's,^\(.Command: \) -q,\1,' SED_CMDS.opt-debug-lint+= ${STD_SED_CMDS.regex} SED_CMDS.opt-jobs-no-action= ${STD_SED_CMDS.hide-from-output} SED_CMDS.opt-no-action-runflags= ${STD_SED_CMDS.hide-from-output} SED_CMDS.opt-where-am-i= -e '/usr.obj/d' # For Compat_RunCommand, useShell == false. SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,,' # For Compat_RunCommand, useShell == true. SED_CMDS.sh-dots+= -e 's,^make: exec(\(.*\)) failed (.*)$$,,' SED_CMDS.sh-dots+= -e 's,^\(\*\*\* Error code \)[1-9][0-9]*,\1,' SED_CMDS.sh-errctl= ${STD_SED_CMDS.dj} SED_CMDS.sh-flags= ${STD_SED_CMDS.hide-from-output} SED_CMDS.shell-csh= ${STD_SED_CMDS.white-space} SED_CMDS.sh-leading-hyphen= ${STD_SED_CMDS.shell} SED_CMDS.suff-main+= ${STD_SED_CMDS.dg1} SED_CMDS.suff-main-several+= ${STD_SED_CMDS.dg1} SED_CMDS.suff-transform-debug+= ${STD_SED_CMDS.dg1} SED_CMDS.var-op-shell+= ${STD_SED_CMDS.shell} SED_CMDS.var-op-shell+= -e '/command/s,No such.*,not found,' SED_CMDS.var-op-shell+= ${STD_SED_CMDS.white-space} SED_CMDS.vardebug+= -e 's,${.SHELL},,' SED_CMDS.varmod-subst-regex+= ${STD_SED_CMDS.regex} SED_CMDS.varparse-errors+= ${STD_SED_CMDS.timestamp} SED_CMDS.varname-dot-make-meta-ignore_filter+= ${SED_CMDS.meta-ignore} SED_CMDS.varname-dot-make-meta-ignore_paths+= ${SED_CMDS.meta-ignore} SED_CMDS.varname-dot-make-meta-ignore_patterns+= ${SED_CMDS.meta-ignore} SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: "[^"]*,make: ",' SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: "[^"]*,make: ",' SED_CMDS.varname-dot-shell= -e 's, = /[^ ]*, = (details omitted),g' SED_CMDS.varname-dot-shell+= -e 's,"/[^" ]*","(details omitted)",g' SED_CMDS.varname-dot-shell+= -e 's,\[/[^] ]*\],[(details omitted)],g' SED_CMDS.varname-empty= ${.OBJDIR .PARSEDIR .PATH .SHELL .SYSPATH:L:@v@-e '/\\$v/d'@} # Some tests need an additional round of postprocessing. POSTPROC.depsrc-wait= sed -e '/^---/d' -e 's,^\(: Making 3[abc]\)[123]$$,\1,' POSTPROC.deptgt-suffixes= awk '/^\#\*\*\* Suffixes/,/^never-stop/' POSTPROC.gnode-submake= awk '/Input graph/, /^$$/' POSTPROC.varname-dot-make-mode= sed 's,^\(: Making [abc]\)[123]$$,\1,' # Some tests reuse other tests, which makes them unnecessarily fragile. export-all.rawout: export.mk unexport.rawout: export.mk unexport-env.rawout: export.mk # End of the configuration section. # Some standard sed commands, to be used in the SED_CMDS above. # In tests that use the debugging option -dd, ignore debugging output that is # only logged in -DCLEANUP mode. STD_SED_CMDS.dd= -e '/^OpenDirs_Done:/d' STD_SED_CMDS.dd+= -e '/^CachedDir /d' # Omit details such as process IDs from the output of the -dg1 option. STD_SED_CMDS.dg1= -e '/\#.* \.$$/d' STD_SED_CMDS.dg1+= -e '/\.MAKE.PATH_FILEMON/d' STD_SED_CMDS.dg1+= -e '/^\#.*\/mk/d' STD_SED_CMDS.dg1+= -e 's, ${DEFSYSPATH:U/usr/share/mk}$$, ,' STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE *=\) .*,\1
,' STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.[A-Z_]* *=\) .*,\1
,' STD_SED_CMDS.dg1+= -e 's,^\(MACHINE[_ARCH]* *=\) .*,\1
,' STD_SED_CMDS.dg1+= -e 's,^\(MAKE *=\) .*,\1
,' STD_SED_CMDS.dg1+= -e 's,^\(\.SHELL *=\) .*,\1
,' STD_SED_CMDS.dg1+= -e '/\.SYSPATH/d' STD_SED_CMDS.dg2= ${STD_SED_CMDS.dg1} STD_SED_CMDS.dg2+= -e 's,\(last modified\) ..:..:.. ... ..\, ....,\1 ,' STD_SED_CMDS.dg3= ${STD_SED_CMDS.dg2} # Omit details such as process IDs from the output of the -dj option. STD_SED_CMDS.dj= \ -e '/Process/d;/JobFinish:/d' \ -e 's,^\(Job_TokenWithdraw\)([0-9]*),\1(),' \ -e 's,^([0-9][0-9]*) \(withdrew token\),() \1,' \ -e 's, \(pid\) [0-9][0-9]*, \1 ,' \ -e 's,^\( Command:\) .*,\1 ,' # Reduce the noise for tests running with the -n option, since there is no # other way to suppress the echoing of the commands. STD_SED_CMDS.hide-from-output= \ -e '/^echo hide-from-output/d' \ -e 's,hide-from-output ,,' \ -e 's,hide-from-output,,' # Normalize the output for error messages from the shell. # # $shell -c '...' # NetBSD sh ...: not found # NetBSD ksh ksh: ...: not found # bash 5.0.18 bash: ...: command not found # bash 5.1.0 bash: line 1: ...: command not found # dash dash: 1: ...: not found # # $shell -c '< /nonexistent' # NetBSD sh sh: cannot open /nonexistent: no such file # NetBSD ksh ksh: cannot open /nonexistent: No such file or directory # bash 5.0.18 bash: /nonexistent: No such file or directory # bash 5.1.0 bash: line 1: /nonexistent: No such file or directory # dash dash: 1: cannot open /nonexistent: No such file # # echo '< /nonexistent' | $shell # NetBSD sh sh: cannot open /nonexistent: no such file # NetBSD ksh ksh: [1]: cannot open /nonexistent: No such file or directory # bash 5.0.18 bash: line 1: /nonexistent: No such file or directory # bash 5.1.0 bash: line 1: /nonexistent: No such file or directory # dash dash: 1: cannot open /nonexistent: No such file # STD_SED_CMDS.shell+= -e 's,^${.SHELL},${.SHELL:T},' STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: line [0-9][0-9]*: ,,' STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: [0-9][0-9]*: ,,' STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: ,,' STD_SED_CMDS.shell+= -e 's,: command not found,: not found,' STD_SED_CMDS.white-space= -e 's, *, ,g' -e 's, *$$,,' # The actual error messages for a failed regcomp or regexec differ between the # implementations. STD_SED_CMDS.regex= \ -e 's,\(Regex compilation error:\).*,\1 (details omitted),' # Normalize timestamps from ':gmtime' or ':localtime' to ''. # See STD_SED_CMDS.dg2 for timestamps from the debug log. STD_SED_CMDS.timestamp= \ -e 's,[A-Z][a-z][a-z] [A-Z][a-z][a-z] [ 0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [12][0-9][0-9][0-9],,' # End of the configuration helpers section. .-include "Makefile.inc" .-include "Makefile.config" UNIT_TESTS:= ${.PARSEDIR} .PATH: ${UNIT_TESTS} .if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes OUTFILES= ${TESTS:@test@${.CURDIR:tA}/${test}.out@} .else OUTFILES= ${TESTS:=.out} .endif all: ${OUTFILES} CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp CLEANFILES+= obj*.[och] lib*.a # posix1.mk CLEANFILES+= issue* .[ab]* # suffixes.mk CLEANDIRS= dir dummy # posix1.mk clean: rm -f ${CLEANFILES} rm -rf ${CLEANDIRS} TEST_MAKE?= ${.MAKE} TOOL_SED?= sed TOOL_TR?= tr TOOL_DIFF?= diff DIFF_FLAGS?= -u .if defined(.PARSEDIR) # ensure consistent results from sort(1) LC_ALL= C LANG= C .export LANG LC_ALL .endif .if ${.MAKE.MODE:Unormal:Mmeta} != "" # we don't need the noise _MKMSG_TEST= : .endif # Some Linux systems such as Fedora have deprecated egrep in favor of grep -E. .if ${.MAKE.OS:NLinux} == "" EGREP= grep -E .endif # Keep the classical definition for all other systems. Just as the bmake code # is kept compatible with C90, the tests are kept compatible with systems that # are several decades old and don't follow modern POSIX standards. EGREP?= egrep MAKE_TEST_ENV= EGREP="${EGREP}" MAKE_TEST_ENV+= MALLOC_OPTIONS="JA" # for jemalloc 100 MAKE_TEST_ENV+= MALLOC_CONF="junk:true" # for jemalloc 510 MAKE_TEST_ENV+= TMPDIR=${TMPDIR} .if ${.MAKE.OS} == "NetBSD" LIMIT_RESOURCES?= ulimit -v 300000 .endif LIMIT_RESOURCES?= : # Each test is run in a sub-make, to keep the tests from interfering with # each other, and because they use different environment variables and # command line options. .SUFFIXES: .mk .rawout .out .mk.rawout: @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX} @set -eu; \ ${LIMIT_RESOURCES}; \ cd ${.OBJDIR}; \ env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \ ${TEST_MAKE} \ -r -C ${.CURDIR} -f ${.IMPSRC} \ ${FLAGS.${.PREFIX:T}:U-k} \ > ${.TARGET}.tmp 2>&1 \ && status=$$? || status=$$?; \ echo $$status > ${.TARGET:R}.status @mv ${.TARGET}.tmp ${.TARGET} # Postprocess the test output to make the output platform-independent. # # Replace anything after 'stopped in' with unit-tests _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' # Allow the test files to be placed anywhere. _SED_CMDS+= -e 's,\(\.PARSEDIR}\) = `'"/[^']*'"',\1 = ,' _SED_CMDS+= -e 's,\(\.INCLUDEDFROMDIR}\) = `'"/[^']*'"',\1 = ,' _SED_CMDS+= -e 's,${TMPDIR},,g' -e 's,${TMPDIR:tA},,g' # canonicalize ${.OBJDIR} and ${.CURDIR} _SED_CMDS+= -e 's,${.CURDIR},,g' .if ${.OBJDIR} != ${.CURDIR} # yes this is inaccurate but none of the tests expect anywhere # which we get depending on how MAKEOBJDIR is set. _SED_CMDS+= -e 's,${.OBJDIR},,g' -e 's,${.OBJDIR:tA},,g' .endif # always pretend .MAKE was called 'make' _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' _SED_CMDS+= -e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,' _SED_CMDS+= -e 's,/,,g' _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' _SED_CMDS+= -e '/MAKE_VERSION/d' _SED_CMDS+= -e '/EGREP=/d' # on AT&T derived systems: false exits 255 not 1 .if ${.MAKE.OS:N*BSD} != "" _SED_CMDS+= -e 's,\(Error code\) 255,\1 1,' .endif .if ${.SHELL:T} == "ksh" _SED_CMDS+= -e '/^set [+-]v/d' .endif .rawout.out: @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \ < ${.IMPSRC} > ${.TARGET}.tmp1 @${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 @rm ${.TARGET}.tmp1 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 @mv ${.TARGET}.tmp2 ${.TARGET} .if empty(DIFF_FLAGS) DIFF_ECHO= echo .else DIFF_ECHO= : .endif # Compare all output files test: ${OUTFILES} .PHONY @failed= ; \ for test in ${TESTS}; do \ cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out && continue || \ ${DIFF_ECHO} diff ${UNIT_TESTS}/$${test}.exp $${test}.out; \ ${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/$${test}.exp $${test}.out \ || failed="$${failed}$${failed:+ }$${test}" ; \ done ; \ if [ -n "$${failed}" ]; then \ echo "Failed tests: $${failed}" ; false ; \ else \ echo "All tests passed" ; \ fi accept: @for test in ${TESTS}; do \ cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ || { echo "Replacing $${test}.exp" ; \ cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ done .if exists(${TEST_MAKE}) ${TESTS:=.rawout}: ${TEST_MAKE} # in meta mode, we *know* if a target script is impacted # by a makefile change. .if ${.MAKE.MODE:Unormal:Mmeta} == "" ${TESTS:=.rawout}: ${.PARSEDIR}/Makefile .endif .endif .-include diff --git a/unit-tests/cond-func.mk b/unit-tests/cond-func.mk index 959367f5c6ab..e09b363edb64 100644 --- a/unit-tests/cond-func.mk +++ b/unit-tests/cond-func.mk @@ -1,135 +1,135 @@ -# $NetBSD: cond-func.mk,v 1.11 2022/01/07 19:30:17 rillig Exp $ +# $NetBSD: cond-func.mk,v 1.12 2023/05/10 15:53:32 rillig Exp $ # # Tests for those parts of the functions in .if conditions that are common # among several functions. # -# The below test uses the function defined(...) since it has no side-effects, -# the other functions (except empty(...)) would work equally well. The -# function empty is special because it uses a different parsing algorithm for -# its argument. +# The below test uses the 'defined' function since it has no side-effects. +# The other functions would work equally well, except for 'empty', which +# parses its argument differently from the other functions. +# DEF= defined ${:UA B}= variable name with spaces ${:UVAR(value)}= variable name with parentheses ${:UVAR{value}}= variable name with balanced braces # Really strange variable names must be given indirectly via another variable, # so that no unbalanced braces appear in the top-level expression. VARNAME_UNBALANCED_BRACES= VAR{{{value ${VARNAME_UNBALANCED_BRACES}= variable name with unbalanced braces .if !defined(DEF) . error .endif # Horizontal whitespace (space tab) after the opening parenthesis is ignored. .if !defined( DEF) . error .endif # Horizontal whitespace (space tab) before the closing parenthesis is ignored. .if !defined(DEF ) . error .endif # The argument of a function must not directly contain whitespace. .if !defined(A B) . error .endif # If necessary, the whitespace can be generated by a variable expression. .if !defined(${:UA B}) . error .endif # Characters that could be mistaken for operators must not appear directly # in a function argument. As with whitespace, these can be generated # indirectly. # # It's not entirely clear why these characters are forbidden. # The most plausible reason seems to be typo detection. .if !defined(A&B) . error .endif .if !defined(A|B) . error .endif # Even parentheses may appear in variable names. # They must be balanced though. .if !defined(VAR(value)) . error .endif # Braces do not have any special meaning when parsing arguments. .if !defined(VAR{value}) . error .endif # Braces do not have any special meaning when parsing arguments. # They don't need to be balanced. .if !defined(VAR{{{value) . error .endif # There may be spaces around the operators and parentheses, and even # inside the parentheses. The spaces inside the parentheses are not -# allowed for the empty() function (see cond-func-empty.mk), therefore +# allowed for the 'empty' function (see cond-func-empty.mk), therefore # they are typically omitted for the other functions as well. .if ! defined ( DEF ) . error .endif # The following condition is interpreted as defined(A) && defined(B). # In lack of a function call expression, each kind of .if directive has a # default function that is called when a bare word is parsed. For the plain # .if directive, this function is defined(); see "struct If ifs" in cond.c. .if A&B . error .endif .if defined() . error .else . info The empty variable is never defined. .endif # The plain word 'defined' is interpreted as 'defined(defined)', see # CondParser_ComparisonOrLeaf. # That variable is not defined (yet). .if defined . error .else . info A plain function name is parsed as defined(...). .endif # If a variable named 'defined' is actually defined, the bare word 'defined' # is interpreted as 'defined(defined)', and the condition evaluates to true. defined= # defined but empty .if defined . info A plain function name is parsed as defined(...). .else . error .endif # A plain symbol name may start with one of the function names, in this case # 'defined'. .if defined-var . error .else . info Symbols may start with a function name. .endif defined-var= # defined but empty .if defined-var . info Symbols may start with a function name. .else . error .endif # Missing closing parenthesis when parsing the function argument. .if defined( . error .else . error .endif diff --git a/unit-tests/cond-late.mk b/unit-tests/cond-late.mk index 4df3df2cf1d4..1cfaaa2ee4e9 100644 --- a/unit-tests/cond-late.mk +++ b/unit-tests/cond-late.mk @@ -1,31 +1,36 @@ -# $NetBSD: cond-late.mk,v 1.3 2020/11/15 14:07:53 rillig Exp $ +# $NetBSD: cond-late.mk,v 1.4 2023/05/10 15:53:32 rillig Exp $ # # Using the :? modifier, variable expressions can contain conditional # expressions that are evaluated late, at expansion time. # -# Any variables appearing in these -# conditions are expanded before parsing the condition. This is -# different from many other places. +# Any expressions appearing in these conditions are expanded before parsing +# the condition. This is different from conditions in .if directives, where +# expressions are evaluated individually and only as far as necessary, see +# cond-short.mk. # # Because of this, variables that are used in these lazy conditions # should not contain double-quotes, or the parser will probably fail. # # They should also not contain operators like == or <, since these are # actually interpreted as these operators. This is demonstrated below. # all: cond-literal COND.true= "yes" == "yes" COND.false= "yes" != "yes" # If the order of evaluation were to change to first parse the condition # and then expand the variables, the output would change from the # current "yes no" to "yes yes", since both variables are non-empty. +# expect: yes +# expect: no cond-literal: @echo ${ ${COND.true} :?yes:no} @echo ${ ${COND.false} :?yes:no} -VAR+= ${${UNDEF} != "no":?:} +VAR= ${${UNDEF} != "no":?:} +# expect-reset +# expect: make: Bad conditional expression ' != "no"' in ' != "no"?:' .if empty(VAR:Mpattern) .endif diff --git a/unit-tests/dep-var.mk b/unit-tests/dep-var.mk index f4a724f0ce7c..16f7498fd5cc 100755 --- a/unit-tests/dep-var.mk +++ b/unit-tests/dep-var.mk @@ -1,95 +1,96 @@ -# $NetBSD: dep-var.mk,v 1.7 2023/02/13 21:01:46 rillig Exp $ +# $NetBSD: dep-var.mk,v 1.8 2023/05/10 15:53:32 rillig Exp $ # # Tests for variable references in dependency declarations. # # Uh oh, this feels so strange that probably nobody uses it. But it seems to # be the only way to reach the lower half of SuffExpandChildren. .MAKEFLAGS: -dv # expect: Var_Parse: ${UNDEF1} (eval-defined) # Even though undefined expressions should lead to errors, no error message is # generated for this line. The variable expression ${UNDEF1} simply expands # to an empty string. all: ${UNDEF1} # Using a double dollar in order to circumvent immediate variable expansion # feels like unintended behavior. At least the manual page says nothing at # all about defined or undefined variables in dependency lines. # # At the point where the expression ${DEF2} is expanded, the variable DEF2 # is defined, so everything's fine. all: $${DEF2} a-$${DEF2}-b # This variable is not defined at all. # XXX: The -dv log says later when expanding the sources of 'all': # Var_Parse: ${UNDEF3} (eval-defined) # but no error message is generated for this line, just like for UNDEF1. # The variable expression ${UNDEF3} simply expands to an empty string. all: $${UNDEF3} # Try out how many levels of indirection are really expanded in dependency # lines. # # The first level of indirection is the $$ in the dependency line. # When the dependency line is parsed, it is resolved to the string # "${INDIRECT_1}". At this point, the dollar is just an ordinary character, # waiting to be expanded at some later point. # # Later, in SuffExpandChildren, that expression is expanded again by calling # Var_Parse, and this time, the result is the string "1-2-${INDIRECT_2}-2-1". # # This string is not expanded anymore by Var_Parse. But there is another # effect. Now DirExpandCurly comes into play and expands the curly braces # in this filename pattern, resulting in the string "1-2-$INDIRECT_2-2-1". # As of 2020-09-03, the test dir.mk contains further details on this topic. # # Finally, this string is assigned to the local ${.TARGET} variable. This # variable is expanded when the shell command is generated. At that point, # the $I is expanded. Since the variable I is not defined, it expands to # the empty string. This way, the final output is the string # "1-2-NDIRECT_2-2-1", which differs from the actual name of the target. # For exactly this reason, it is not recommended to use dollar signs in # target names. # # The number of actual expansions is way more than one might expect, # therefore this feature is probably not widely used. # all: 1-$${INDIRECT_1}-1 INDIRECT_1= 2-$${INDIRECT_2}-2 INDIRECT_2= 3-$${INDIRECT_3}-3 INDIRECT_3= indirect UNDEF1= undef1 DEF2= def2 # Cover the code in SuffExpandChildren that deals with malformed variable # expressions. # # This seems to be an edge case that never happens in practice, and it would # probably be appropriate to just error out in such a case. # # To trigger this piece of code, the variable name must contain "$)" or "$:" # or "$)" or "$$". Using "$:" does not work since the dependency line is # fully expanded before parsing, therefore any ':' in a target or source name # would be interpreted as a dependency operator instead. all: $$$$) # The $$INDIRECT in the following line is treated like the dependency of the # "all" target, that is, the "$$I" is first expanded to "$I", and in a second # round of expansion, the "$I" expands to nothing since the variable "I" is # undefined. # # Since 2020-09-13, this generates a parse error in lint mode (-dL), but not # in normal mode since ParseDependency does not handle any errors after # calling Var_Parse. # expect: Var_Parse: ${:U\$)}: (eval-defined) # expect: Var_Parse: $INDIRECT_2-2-1 $): (parse-only) # expect: Var_Parse: $): (parse-only) undef1 def2 a-def2-b 1-2-$$INDIRECT_2-2-1 ${:U\$)}: @echo ${.TARGET:Q} .MAKEFLAGS: -d0 -# XXX: Why is the exit status still 0, even though Parse_Error is called -# with PARSE_FATAL in SuffExpandChildren? +# XXX: The exit status is still 0, even though Parse_Error is called with +# PARSE_FATAL in SuffExpandChildren. The exit status is only affected by +# parse errors when they occur in the parsing phase, see Parse_File. diff --git a/unit-tests/directive-for-errors.exp b/unit-tests/directive-for-errors.exp index da5eee473ec2..36ed569c7932 100644 --- a/unit-tests/directive-for-errors.exp +++ b/unit-tests/directive-for-errors.exp @@ -1,22 +1,17 @@ -make: "directive-for-errors.mk" line 7: Unknown directive "fori" -make: "directive-for-errors.mk" line 8: warning: -make: "directive-for-errors.mk" line 9: for-less endfor -make: "directive-for-errors.mk" line 19: Unknown directive "for" -make: "directive-for-errors.mk" line 20: warning: -make: "directive-for-errors.mk" line 21: for-less endfor -make: "directive-for-errors.mk" line 37: Dollar $ 1 1 and backslash 2 2 2. -make: "directive-for-errors.mk" line 37: Dollar $ 3 3 and backslash 4 4 4. -make: "directive-for-errors.mk" line 43: no iteration variables in for -make: "directive-for-errors.mk" line 47: warning: Should not be reached. -make: "directive-for-errors.mk" line 48: for-less endfor -make: "directive-for-errors.mk" line 53: Wrong number of words (5) in .for substitution list with 3 variables -make: "directive-for-errors.mk" line 64: missing `in' in for -make: "directive-for-errors.mk" line 66: warning: Should not be reached. -make: "directive-for-errors.mk" line 67: for-less endfor -make: "directive-for-errors.mk" line 73: Unknown modifier "Z" -make: "directive-for-errors.mk" line 74: warning: Should not be reached. -make: "directive-for-errors.mk" line 74: warning: Should not be reached. -make: "directive-for-errors.mk" line 74: warning: Should not be reached. +make: "directive-for-errors.mk" line 11: Unknown directive "fori" +make: "directive-for-errors.mk" line 12: warning: <> +make: "directive-for-errors.mk" line 13: for-less endfor +make: "directive-for-errors.mk" line 27: Unknown directive "for" +make: "directive-for-errors.mk" line 28: warning: <> +make: "directive-for-errors.mk" line 29: for-less endfor +make: "directive-for-errors.mk" line 46: invalid character '$' in .for loop variable name +make: "directive-for-errors.mk" line 54: no iteration variables in for +make: "directive-for-errors.mk" line 66: Wrong number of words (5) in .for substitution list with 3 variables +make: "directive-for-errors.mk" line 80: missing `in' in for +make: "directive-for-errors.mk" line 91: Unknown modifier "Z" +make: "directive-for-errors.mk" line 92: warning: Should not be reached. +make: "directive-for-errors.mk" line 92: warning: Should not be reached. +make: "directive-for-errors.mk" line 92: warning: Should not be reached. make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/unit-tests/directive-for-errors.mk b/unit-tests/directive-for-errors.mk index 602ecbf32e4e..24df5e131839 100644 --- a/unit-tests/directive-for-errors.mk +++ b/unit-tests/directive-for-errors.mk @@ -1,75 +1,96 @@ -# $NetBSD: directive-for-errors.mk,v 1.3 2021/04/04 10:13:09 rillig Exp $ +# $NetBSD: directive-for-errors.mk,v 1.5 2023/05/09 19:43:12 rillig Exp $ # # Tests for error handling in .for loops. +# expect-all + + # A .for directive must be followed by whitespace, everything else results # in a parse error. +# expect+1: Unknown directive "fori" .fori in 1 2 3 -. warning ${i} +. warning <${i}> .endfor +# expect-2: <> +# expect-2: for-less endfor + # A slash is not whitespace, therefore this is not parsed as a .for loop. # # XXX: The error message is misleading though. As of 2020-12-31, it says -# "Unknown directive "for"", but that directive is actually known. This is +# 'Unknown directive "for"', but that directive is actually known. This is # because ForEval does not detect the .for loop as such, so parsing # continues in ParseLine > ParseDependencyLine > ParseDependency > # ParseDependencyTargets > ParseErrorNoDependency, and there the directive # name is parsed a bit differently. +# expect+1: Unknown directive "for" .for/i in 1 2 3 -. warning ${i} +. warning <${i}> .endfor +# expect-2: warning: <> +# expect-2: for-less endfor -# As of 2020-12-31, the variable name can be an arbitrary word, it just needs -# to be separated by whitespace. Even '$' and '\' are valid variable names, -# which is not useful in practice. -# -# The '$$' is not replaced with the values '1' or '3' from the .for loop, -# instead it is kept as-is, and when the .info directive expands its argument, -# each '$$' gets replaced with a single '$'. The "long variable expression" -# ${$} gets replaced though, even though this would be a parse error everywhere -# outside a .for loop. + +# Before for.c 1.173 from 2023-05-08, the variable name could be an arbitrary +# word, it only needed to be separated by whitespace. Even '$' and '\' were +# valid variable names, which was not useful in practice. # -# The '\' on the other hand is treated as a normal variable name. +# The '$$' was not replaced with the values '1' or '3' from the .for loop, +# instead it was kept as-is, and when the .info directive expanded its +# argument, each '$$' got replaced with a single '$'. The "long variable +# expression" ${$} got replaced though, even though this would be a parse +# error everywhere outside a .for loop. ${:U\$}= dollar # see whether the "variable" '$' is local ${:U\\}= backslash # see whether the "variable" '\' is local +# expect+1: invalid character '$' in .for loop variable name .for $ \ in 1 2 3 4 . info Dollar $$ ${$} $($) and backslash $\ ${\} $(\). .endfor # If there are no variables, there is no point in expanding the .for loop -# since this would end up in an endless loop, each time consuming 0 of the -# 3 values. +# since this would end up in an endless loop, consuming 0 of the 3 values in +# each iteration. +# expect+1: no iteration variables in for .for in 1 2 3 # XXX: This should not be reached. It should be skipped, as already done # when the number of values is not a multiple of the number of variables, # see below. . warning Should not be reached. .endfor + # There are 3 variables and 5 values. These 5 values cannot be split evenly # among the variables, therefore the loop is not expanded at all, it is -# rather skipped. +# skipped instead. +# expect+1: Wrong number of words (5) in .for substitution list with 3 variables .for a b c in 1 2 3 4 5 . warning Should not be reached. .endfor + # The list of values after the 'in' may be empty, no matter if this emptiness # comes from an empty expansion or even from a syntactically empty line. .for i in . info Would be reached if there were items to loop over. .endfor + # A missing 'in' should parse the .for loop but skip the body. -.for i : k +# expect+1: missing `in' in for +.for i over k # XXX: As of 2020-12-31, this line is reached once. . warning Should not be reached. .endfor + # A malformed modifier should be detected and skip the body of the loop. # # XXX: As of 2020-12-31, Var_Subst doesn't report any errors, therefore # the loop body is expanded as if no error had happened. +# expect+1: Unknown modifier "Z" .for i in 1 2 ${:U3:Z} 4 . warning Should not be reached. .endfor +# expect-2: Should not be reached. +# expect-3: Should not be reached. +# expect-4: Should not be reached. diff --git a/unit-tests/directive-for-escape.exp b/unit-tests/directive-for-escape.exp index d679e0756e33..0326b62377f3 100644 --- a/unit-tests/directive-for-escape.exp +++ b/unit-tests/directive-for-escape.exp @@ -1,153 +1,145 @@ For: end for 1 For: loop body: . info ${:U!"#$%&'()*+,-./0-9\:;<=>?@A-Z[\\]_^a-z{|\}~} make: Unclosed variable expression, expecting '}' for modifier "U!"" of variable "" with value "!"" -make: "directive-for-escape.mk" line 19: !" +make: "directive-for-escape.mk" line 21: !" For: end for 1 For: loop body: . info ${:U!"\\\\#$%&'()*+,-./0-9\:;<=>?@A-Z[\\]_^a-z{|\}~} make: Unclosed variable expression, expecting '}' for modifier "U!"\\\\" of variable "" with value "!"\\" -make: "directive-for-escape.mk" line 29: !"\\ +make: "directive-for-escape.mk" line 32: !"\\ For: end for 1 For: loop body: . info ${:U\$} -make: "directive-for-escape.mk" line 43: $ +make: "directive-for-escape.mk" line 47: $ For: loop body: . info ${:U${V}} -make: "directive-for-escape.mk" line 43: value +make: "directive-for-escape.mk" line 47: value For: loop body: . info ${:U${V:=-with-modifier}} -make: "directive-for-escape.mk" line 43: value-with-modifier +make: "directive-for-escape.mk" line 47: value-with-modifier For: loop body: . info ${:U$(V)} -make: "directive-for-escape.mk" line 43: value +make: "directive-for-escape.mk" line 47: value For: loop body: . info ${:U$(V:=-with-modifier)} -make: "directive-for-escape.mk" line 43: value-with-modifier +make: "directive-for-escape.mk" line 47: value-with-modifier For: end for 1 For: loop body: # ${:U\${UNDEF\:U\\$\\$} For: loop body: # ${:U{{\}\}} For: loop body: # ${:Uend\}} For: end for 1 For: loop body: . info ${:U\${UNDEF\:U\\$\\$} -make: "directive-for-escape.mk" line 92: ${UNDEF:U\backslash$ +make: "directive-for-escape.mk" line 101: ${UNDEF:U\backslash$ For: loop body: . info ${:U{{\}\}} -make: "directive-for-escape.mk" line 92: {{}} +make: "directive-for-escape.mk" line 101: {{}} For: loop body: . info ${:Uend\}} -make: "directive-for-escape.mk" line 92: end} +make: "directive-for-escape.mk" line 101: end} For: end for 1 For: loop body: . info ${:Ubegin<${UNDEF:Ufallback:N{{{}}}}>end} -make: "directive-for-escape.mk" line 113: beginend +make: "directive-for-escape.mk" line 122: beginend For: end for 1 For: loop body: . info ${:U\$} -make: "directive-for-escape.mk" line 121: $ +make: "directive-for-escape.mk" line 131: $ +make: "directive-for-escape.mk" line 140: invalid character ':' in .for loop variable name For: end for 1 -For: loop body: -. info ${NUMBERS} ${:Ureplaced} -make: "directive-for-escape.mk" line 129: one two three replaced +make: "directive-for-escape.mk" line 150: invalid character '}' in .for loop variable name For: end for 1 -For: loop body: -. info ${:Ureplaced} -make: "directive-for-escape.mk" line 139: replaced For: end for 1 For: loop body: . info . $$i: ${:Uinner} . info . $${i}: ${:Uinner} . info . $${i:M*}: ${:Uinner:M*} . info . $$(i): $(:Uinner) . info . $$(i:M*): $(:Uinner:M*) . info . $${i$${:U}}: ${i${:U}} . info . $${i\}}: ${:Uinner\}} # XXX: unclear why ForLoop_SubstVarLong needs this . info . $${i2}: ${i2} . info . $${i,}: ${i,} . info . adjacent: ${:Uinner}${:Uinner}${:Uinner:M*}${:Uinner} -make: "directive-for-escape.mk" line 147: . $i: inner -make: "directive-for-escape.mk" line 148: . ${i}: inner -make: "directive-for-escape.mk" line 149: . ${i:M*}: inner -make: "directive-for-escape.mk" line 150: . $(i): inner -make: "directive-for-escape.mk" line 151: . $(i:M*): inner -make: "directive-for-escape.mk" line 152: . ${i${:U}}: outer -make: "directive-for-escape.mk" line 153: . ${i\}}: inner} -make: "directive-for-escape.mk" line 154: . ${i2}: two -make: "directive-for-escape.mk" line 155: . ${i,}: comma -make: "directive-for-escape.mk" line 156: . adjacent: innerinnerinnerinner -For: end for 1 -For: loop body: -. info eight $$$$$$$$ and no cents. -. info eight ${:Udollar}${:Udollar}${:Udollar}${:Udollar} and no cents. -make: "directive-for-escape.mk" line 164: eight $$$$ and no cents. -make: "directive-for-escape.mk" line 165: eight dollardollardollardollar and no cents. -make: "directive-for-escape.mk" line 174: eight and no cents. -For: end for 1 -make: "directive-for-escape.mk" line 181: newline in .for value -make: "directive-for-escape.mk" line 181: newline in .for value +make: "directive-for-escape.mk" line 159: . $i: inner +make: "directive-for-escape.mk" line 160: . ${i}: inner +make: "directive-for-escape.mk" line 161: . ${i:M*}: inner +make: "directive-for-escape.mk" line 162: . $(i): inner +make: "directive-for-escape.mk" line 163: . $(i:M*): inner +make: "directive-for-escape.mk" line 164: . ${i${:U}}: outer +make: "directive-for-escape.mk" line 165: . ${i\}}: inner} +make: "directive-for-escape.mk" line 166: . ${i2}: two +make: "directive-for-escape.mk" line 167: . ${i,}: comma +make: "directive-for-escape.mk" line 168: . adjacent: innerinnerinnerinner +make: "directive-for-escape.mk" line 187: invalid character '$' in .for loop variable name +For: end for 1 +make: "directive-for-escape.mk" line 199: eight and no cents. +For: end for 1 +make: "directive-for-escape.mk" line 212: newline in .for value +make: "directive-for-escape.mk" line 212: newline in .for value For: loop body: . info short: ${:U" "} . info long: ${:U" "} -make: "directive-for-escape.mk" line 182: short: " " -make: "directive-for-escape.mk" line 183: long: " " +make: "directive-for-escape.mk" line 213: short: " " +make: "directive-for-escape.mk" line 214: long: " " For: end for 1 For: loop body: For: end for 1 -Parse_PushInput: .for loop in directive-for-escape.mk, line 196 -make: "directive-for-escape.mk" line 196: newline in .for value - in .for loop from directive-for-escape.mk:196 with i = " +Parse_PushInput: .for loop in directive-for-escape.mk, line 230 +make: "directive-for-escape.mk" line 230: newline in .for value + in .for loop from directive-for-escape.mk:230 with i = " " For: loop body: : ${:U" "} SetFilenameVars: ${.PARSEDIR} = ${.PARSEFILE} = `directive-for-escape.mk' -Parsing line 197: : ${:U" "} +Parsing line 231: : ${:U" "} ParseDependency(: " ") -ParseEOF: returning to file directive-for-escape.mk, line 199 +ParseEOF: returning to file directive-for-escape.mk, line 233 SetFilenameVars: ${.PARSEDIR} = ${.PARSEFILE} = `directive-for-escape.mk' -Parsing line 199: .MAKEFLAGS: -d0 +Parsing line 233: .MAKEFLAGS: -d0 ParseDependency(.MAKEFLAGS: -d0) For: end for 1 For: loop body: # ${:U#} For: loop body: # ${:U\\\\#} For: end for 1 For: loop body: # ${:U\$} For: loop body: # ${:U$i} For: loop body: # ${:U$(i)} For: loop body: # ${:U${i}} For: loop body: # ${:U$$} For: loop body: # ${:U$$$$} For: loop body: # ${:U${:U\$\$}} For: end for 1 For: loop body: # ${:U${.TARGET}} For: loop body: # ${:U${.TARGET}} For: loop body: # ${:U$${.TARGET\}} For: loop body: # ${:U$${.TARGET\}} For: end for 1 For: loop body: # ${:U(((} For: loop body: # ${:U{{{} For: loop body: # ${:U)))} For: loop body: # ${:U\}\}\}} make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/unit-tests/directive-for-escape.mk b/unit-tests/directive-for-escape.mk index fe704c453046..7fbd09131d2c 100644 --- a/unit-tests/directive-for-escape.mk +++ b/unit-tests/directive-for-escape.mk @@ -1,229 +1,263 @@ -# $NetBSD: directive-for-escape.mk,v 1.16 2022/06/12 16:09:21 rillig Exp $ +# $NetBSD: directive-for-escape.mk,v 1.18 2023/05/09 19:43:12 rillig Exp $ # # Test escaping of special characters in the iteration values of a .for loop. # These values get expanded later using the :U variable modifier, and this -# escaping and unescaping must pass all characters and strings effectively -# unmodified. +# escaping and unescaping must pass all characters and strings unmodified. + +# expect-all .MAKEFLAGS: -df # Even though the .for loops take quotes into account when splitting the # string into words, the quotes don't need to be balanced, as of 2020-12-31. # This could be considered a bug. ASCII= !"\#$$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~ + # XXX: As of 2020-12-31, the '#' is not preserved in the expanded body of # the loop. Not only would it need the escaping for the variable modifier # ':U' but also the escaping for the line-end comment. .for chars in ${ASCII} . info ${chars} .endfor +# expect-2: !" # As of 2020-12-31, using 2 backslashes before be '#' would treat the '#' # as comment character. Using 3 backslashes doesn't help either since # then the situation is essentially the same as with 1 backslash. # This means that a '#' sign cannot be passed in the value of a .for loop # at all. ASCII.2020-12-31= !"\\\#$$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~ .for chars in ${ASCII.2020-12-31} . info ${chars} .endfor +# expect-2: !"\\ # Cover the code in ExprLen. # # XXX: It is unexpected that the variable V gets expanded in the loop body. # The double '$$' should intuitively prevent exactly this. Probably nobody # was adventurous enough to use literal dollar signs in the values of a .for # loop, allowing this edge case to go unnoticed for years. # # See for.c, function ExprLen. V= value VALUES= $$ $${V} $${V:=-with-modifier} $$(V) $$(V:=-with-modifier) .for i in ${VALUES} . info $i .endfor +# expect-2: $ +# expect-3: value +# expect-4: value-with-modifier +# expect-5: value +# expect-6: value-with-modifier # Try to cover the code for nested '{}' in ExprLen, without success. # # The value of the variable VALUES is not meant to be a variable expression. # Instead, it is meant to represent literal text, the only escaping mechanism # being that each '$' is written as '$$'. VALUES= $${UNDEF:U\$$\$$ {{}} end} # # The .for loop splits ${VALUES} into 3 words, at the space characters, since # the '$$' is an ordinary character and the spaces are not escaped. # Word 1 is '${UNDEF:U\$\$' # Word 2 is '{{}}' # Word 3 is 'end}' # # Each of these words is now inserted in the body of the .for loop. .for i in ${VALUES} # $i .endfor # # When these words are injected into the body of the .for loop, each inside a # '${:U...}' expression, the result is: # # expect: For: loop body: # expect: # ${:U\${UNDEF\:U\\$\\$} # expect: For: loop body: # expect: # ${:U{{\}\}} # expect: For: loop body: # expect: # ${:Uend\}} # expect: For: end for 1 # # The first of these expressions is the most interesting one, due to its many # special characters. This expression is properly balanced: # # Text Meaning Explanation # \$ $ escaped # { { ordinary text # UNDEF UNDEF ordinary text # \: : escaped # U U ordinary text # \\ \ escaped # $\ (expr) an expression, the variable name is '\' # \$ $ escaped # # To make the expression '$\' visible, define it to an actual word: ${:U\\}= backslash .for i in ${VALUES} . info $i .endfor # # expect-3: ${UNDEF:U\backslash$ # expect-4: {{}} # expect-5: end} # # FIXME: There was no expression '$\' in the original text of the variable # 'VALUES', that's a surprise in the parser. # Second try to cover the code for nested '{}' in ExprLen. # # XXX: It is not the job of ExprLen to parse an expression, it is naive to # expect ExprLen to get all the details right in just a few lines of code. # Each variable modifier has its own inconsistent way of parsing nested # variable expressions, braces and parentheses. (Compare ':M', ':S', and # ':D' for details.) The only sensible thing to do is therefore to let # Var_Parse do all the parsing work. VALUES= begin<$${UNDEF:Ufallback:N{{{}}}}>end .for i in ${VALUES} . info $i .endfor +# expect-2: beginend # A single trailing dollar doesn't happen in practice. # The dollar sign is correctly passed through to the body of the .for loop. # There, it is expanded by the .info directive, but even there a trailing # dollar sign is kept as-is. .for i in ${:U\$} . info ${i} .endfor +# expect-2: $ -# As of 2020-12-31, the name of the iteration variable can even contain -# colons, which then affects variable expressions having this exact modifier. -# This is clearly an unintended side effect of the implementation. +# Before for.c 1.173 from 2023-05-08, the name of the iteration variable +# could contain colons, which affected variable expressions having this exact +# modifier. This possibility was neither intended nor documented. NUMBERS= one two three +# expect+1: invalid character ':' in .for loop variable name .for NUMBERS:M*e in replaced . info ${NUMBERS} ${NUMBERS:M*e} .endfor -# As of 2020-12-31, the name of the iteration variable can contain braces, -# which gets even more surprising than colons, since it allows to replace -# sequences of variable expressions. There is no practical use case for -# this, though. +# Before for.c 1.173 from 2023-05-08, the name of the iteration variable +# could contain braces, which allowed to replace sequences of variable +# expressions. This possibility was neither intended nor documented. BASENAME= one EXT= .c +# expect+1: invalid character '}' in .for loop variable name .for BASENAME}${EXT in replaced . info ${BASENAME}${EXT} .endfor # Demonstrate the various ways to refer to the iteration variable. i= outer i2= two i,= comma .for i in inner . info . $$i: $i . info . $${i}: ${i} . info . $${i:M*}: ${i:M*} . info . $$(i): $(i) . info . $$(i:M*): $(i:M*) . info . $${i$${:U}}: ${i${:U}} . info . $${i\}}: ${i\}} # XXX: unclear why ForLoop_SubstVarLong needs this . info . $${i2}: ${i2} . info . $${i,}: ${i,} . info . adjacent: $i${i}${i:M*}$i .endfor +# expect-11: . $i: inner +# expect-11: . ${i}: inner +# expect-11: . ${i:M*}: inner +# expect-11: . $(i): inner +# expect-11: . $(i:M*): inner +# expect-11: . ${i${:U}}: outer +# expect-11: . ${i\}}: inner} +# expect-11: . ${i2}: two +# expect-11: . ${i,}: comma +# expect-11: . adjacent: innerinnerinnerinner -# The variable name can be a single '$' since there is no check on valid -# variable names. ForLoop_SubstVarShort skips "stupid" variable names though, -# but ForLoop_SubstVarLong naively parses the body of the loop, substituting -# each '${$}' with an actual 'dollar'. +# Before for.c 1.173 from 2023-05-08, the variable name could be a single '$' +# since there was no check on valid variable names. ForLoop_SubstVarShort +# skipped "stupid" variable names though, but ForLoop_SubstVarLong naively +# parsed the body of the loop, substituting each '${$}' with an actual +# '${:Udollar}'. +# expect+1: invalid character '$' in .for loop variable name .for $ in dollar . info eight $$$$$$$$ and no cents. . info eight ${$}${$}${$}${$} and no cents. .endfor # Outside a .for loop, '${$}' is interpreted differently. The outer '$' starts # a variable expression. The inner '$' is followed by a '}' and is thus a # silent syntax error, the '$' is skipped. The variable name is thus '', and # since since there is never a variable named '', the whole expression '${$}' # evaluates to an empty string. closing-brace= } # guard against an ${closing-brace}= # alternative interpretation +# expect+1: eight and no cents. .info eight ${$}${$}${$}${$} and no cents. # What happens if the values from the .for loop contain a literal newline? # Before for.c 1.144 from 2021-06-25, the newline was passed verbatim to the # body of the .for loop, where it was then interpreted as a literal newline, # leading to syntax errors such as "Unclosed variable expression" in the upper # line and "Invalid line type" in the lower line. +# +# The error message occurs in the line of the .for loop since that's the place +# where the body of the .for loop is constructed, and at this point the +# newline character gets replaced with a plain space. +# expect+2: newline in .for value +# expect+1: newline in .for value .for i in "${.newline}" . info short: $i . info long: ${i} .endfor +# expect-3: short: " " +# expect-3: long: " " # No error since the newline character is not actually used. .for i in "${.newline}" .endfor # Between for.c 1.161 from 2022-01-08 and before for.c 1.163 from 2022-01-09, # a newline character in a .for loop led to a crash since at the point where # the error message including the stack trace is printed, the body of the .for # loop is assembled, and at that point, ForLoop.nextItem had already been # advanced. .MAKEFLAGS: -dp +# expect+1: newline in .for value .for i in "${.newline}" : $i .endfor .MAKEFLAGS: -d0 .MAKEFLAGS: -df .for i in \# \\\# # $i .endfor .for i in $$ $$i $$(i) $${i} $$$$ $$$$$$$$ $${:U\$$\$$} # $i .endfor # The expression '${.TARGET}' must be preserved as it is one of the 7 built-in # target-local variables. See for.c 1.45 from 2009-01-14. .for i in ${.TARGET} $${.TARGET} $$${.TARGET} $$$${.TARGET} # $i .endfor # expect: # ${:U${.TARGET}} # XXX: Why does '$' result in the same text as '$$'? # expect: # ${:U${.TARGET}} # XXX: Why does the '$$' before the '${.TARGET}' lead to an escaped '}'? # expect: # ${:U$${.TARGET\}} # XXX: Why does '$' result in the same text as '$$'? # XXX: Why does the '$$' before the '${.TARGET}' lead to an escaped '}'? # expect: # ${:U$${.TARGET\}} .for i in ((( {{{ ))) }}} # $i .endfor .MAKEFLAGS: -d0 all: diff --git a/unit-tests/directive-for.exp b/unit-tests/directive-for.exp index dda487917e68..97878ee49f44 100755 --- a/unit-tests/directive-for.exp +++ b/unit-tests/directive-for.exp @@ -1,42 +1,41 @@ -make: "directive-for.mk" line 108: outer -make: "directive-for.mk" line 133: a:\ a:\file.txt -make: "directive-for.mk" line 133: d:\\ -make: "directive-for.mk" line 133: d:\\file.txt -make: "directive-for.mk" line 140: ( ( ( -make: "directive-for.mk" line 140: [ [ [ -make: "directive-for.mk" line 140: { { { -make: "directive-for.mk" line 140: ) ) ) -make: "directive-for.mk" line 140: ] ] ] -make: "directive-for.mk" line 140: } } } -make: "directive-for.mk" line 140: (()) (()) (()) -make: "directive-for.mk" line 140: [[]] [[]] [[]] -make: "directive-for.mk" line 140: {{}} {{}} {{}} -make: "directive-for.mk" line 140: )( )( )( -make: "directive-for.mk" line 140: ][ ][ ][ -make: "directive-for.mk" line 140: }{ }{ }{ -make: "directive-for.mk" line 148: outer value value -make: "directive-for.mk" line 148: outer "quoted" \"quoted\" -make: "directive-for.mk" line 154: Unknown modifier "Z" -make: "directive-for.mk" line 155: XXX: Not reached word1 -make: "directive-for.mk" line 155: XXX: Not reached word3 -make: "directive-for.mk" line 160: no iteration variables in for -make: "directive-for.mk" line 162: Missing argument for ".error" -make: "directive-for.mk" line 163: for-less endfor -make: "directive-for.mk" line 187: 1 open conditional -make: "directive-for.mk" line 203: for-less endfor -make: "directive-for.mk" line 204: if-less endif -make: "directive-for.mk" line 212: if-less endif +make: "directive-for.mk" line 119: outer +make: "directive-for.mk" line 137: a:\ a:\file.txt +make: "directive-for.mk" line 137: d:\\ +make: "directive-for.mk" line 137: d:\\file.txt +make: "directive-for.mk" line 148: ( ( ( +make: "directive-for.mk" line 148: [ [ [ +make: "directive-for.mk" line 148: { { { +make: "directive-for.mk" line 148: ) ) ) +make: "directive-for.mk" line 148: ] ] ] +make: "directive-for.mk" line 148: } } } +make: "directive-for.mk" line 148: (()) (()) (()) +make: "directive-for.mk" line 148: [[]] [[]] [[]] +make: "directive-for.mk" line 148: {{}} {{}} {{}} +make: "directive-for.mk" line 148: )( )( )( +make: "directive-for.mk" line 148: ][ ][ ][ +make: "directive-for.mk" line 148: }{ }{ }{ +make: "directive-for.mk" line 168: invalid character ':' in .for loop variable name +make: "directive-for.mk" line 175: invalid character '$' in .for loop variable name +make: "directive-for.mk" line 187: invalid character '$' in .for loop variable name +make: "directive-for.mk" line 198: Unknown modifier "Z" +make: "directive-for.mk" line 199: XXX: Not reached word1 +make: "directive-for.mk" line 199: XXX: Not reached word3 +make: "directive-for.mk" line 206: no iteration variables in for +make: "directive-for.mk" line 232: 1 open conditional +make: "directive-for.mk" line 248: for-less endfor +make: "directive-for.mk" line 249: if-less endif +make: "directive-for.mk" line 257: if-less endif +For: new loop 2 +For: end for 2 For: end for 1 For: loop body: .\ for inner in i .\ endfor -make: "directive-for.mk" line 229: Unexpected end of file in .for loop +For: end for 1 For: loop body: -.\ - endfor -make: "directive-for.mk" line 227: for-less endfor +make: "directive-for.mk" line 305: newline-item=(a) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/unit-tests/directive-for.mk b/unit-tests/directive-for.mk index 95171c68031f..224a466a7709 100755 --- a/unit-tests/directive-for.mk +++ b/unit-tests/directive-for.mk @@ -1,246 +1,307 @@ -# $NetBSD: directive-for.mk,v 1.15 2022/10/01 09:23:04 rillig Exp $ +# $NetBSD: directive-for.mk,v 1.20 2023/05/10 13:03:06 rillig Exp $ # # Tests for the .for directive. # # TODO: Describe naming conventions for the loop variables. # .for f in values # .for file in values # .for _FILE_ in values # .for .FILE. in values # .for _f_ in values - -# Using the .for loop, lists of values can be produced. -# In simple cases, the :@var@${var}@ variable modifier can be used to -# achieve the same effects. # +# See also: +# varmod-loop.mk The ':@var@...@' modifier + +# expect-all + +# A typical use case for a .for loop is to populate a variable with a list of +# values depending on other variables. In simple cases, the same effect can +# be achieved using the ':@var@${var}@' modifier. .undef NUMBERS .for num in 1 2 3 NUMBERS+= ${num} .endfor .if ${NUMBERS} != "1 2 3" . error .endif + # The .for loop also works for multiple iteration variables. -# This is something that the variable modifier :@ cannot do. +# This is something that the modifier :@ cannot do. .for name value in VARNAME value NAME2 value2 ${name}= ${value} .endfor .if ${VARNAME} != "value" || ${NAME2} != "value2" . error .endif + # The .for loop splits the items at whitespace, taking quotes into account, -# just like the :M or :S variable modifiers. -# -# Until 2012-06-03, it had split the items exactly at whitespace, without -# taking the quotes into account. This had resulted in 10 words. +# just like the :M or :S modifiers. # +# Until 2012-06-03, the .for loop had split the items exactly at whitespace, +# without taking the quotes into account. This had resulted in 10 words. .undef WORDS .for var in one t\ w\ o "three three" 'four four' `five six` WORDS+= counted .endfor .if ${WORDS:[#]} != 6 . error .endif + # In the body of the .for loop, the iteration variables can be accessed # like normal variables, even though they are not really variables. # -# Instead, the expression ${var} is transformed into ${:U1}, ${:U2} and so -# on, before the loop body is evaluated. +# Instead, before interpreting the body of the .for loop, the body is +# generated by replacing each expression ${var} with ${:U1}, ${:U2} and so +# on. # -# A notable effect of this implementation technique is that the .for +# A noticeable effect of this implementation technique is that the .for # iteration variables and the normal global variables live in separate -# namespaces and do not influence each other. -# +# namespaces and do not influence each other. The "scope" of the .for loop +# variables is restricted to the current makefile, it does not reach over to +# any included makefiles. var= value before var2= value before .for var var2 in 1 2 3 4 .endfor .if ${var} != "value before" . warning After the .for loop, var must still have its original value. .endif .if ${var2} != "value before" . warning After the .for loop, var2 must still have its original value. .endif # Everything from the paragraph above also applies if the loop body is -# empty, even if there is no actual iteration since the loop items are -# also empty. -# +# empty. In this particular example, the items to be iterated are empty as +# well. var= value before var2= value before .for var var2 in ${:U} .endfor .if ${var} != "value before" . warning After the .for loop, var must still have its original value. .endif .if ${var2} != "value before" . warning After the .for loop, var2 must still have its original value. .endif # Until 2008-12-21, the values of the iteration variables were simply # inserted as plain text and then parsed as usual, which made it possible -# to achieve all kinds of strange effects. +# to achieve all kinds of strange effects, such as generating '.if' +# directives or inserting '$' characters in random places, thereby changing +# how following '$' are interpreted. # -# Before that date, the .for loop expanded to: +# Before that date, the .for loop below expanded to: # EXPANSION+= value -# Since that date, the .for loop expands to: +# Since that date, the .for loop below expands to: # EXPANSION${:U+}= value # EXPANSION= before EXPANSION+ = before .for plus in + EXPANSION${plus}= value .endfor .if ${EXPANSION} != "before" . error This must be a make from before 2009. .endif .if ${EXPANSION+} != "value" . error This must be a make from before 2009. .endif # When the outer .for loop is expanded, it sees the expression ${i} and -# expands it. The inner loop then has nothing more to expand. +# expands it. The inner loop then only sees the expression ${:Uouter} and +# has nothing more to expand. .for i in outer . for i in inner +# expect+1: outer . info ${i} . endfor .endfor + # From https://gnats.netbsd.org/29985. # # Until 2008-12-21, the .for loop was expanded by replacing the variable # value literally in the body. This could lead to situations where the # characters from the variable value were interpreted as markup rather than # plain text. # # Until 2012-06-03, the .for loop had split the words at whitespace, without # taking quotes into account. This made it possible to have variable values # like "a:\ a:\file.txt" that ended in a single backslash. Since then, the # variable values have been replaced with expressions of the form ${:U...}, # which are not interpreted as code anymore. -# -# As of 2020-09-22, a comment in for.c says that it may be possible to -# produce an "unwanted substitution", but there is no demonstration code yet. -# -# The above changes prevent a backslash at the end of a word from being -# interpreted as part of the code. Because of this, the trailingBackslash -# hack in Var_Subst is no longer needed and as of 2020-09-22, has been -# removed. .for path in a:\ a:\file.txt d:\\ d:\\file.txt . info ${path} .endfor +# expect-2: a:\ a:\file.txt +# expect-3: d:\\ +# expect-4: d:\\file.txt + # Ensure that braces and parentheses are properly escaped by the .for loop. # Each line must print the same word 3 times. # See ForLoop_SubstBody. .for v in ( [ { ) ] } (()) [[]] {{}} )( ][ }{ . info $v ${v} $(v) .endfor +# expect-02: ( ( ( +# expect-03: [ [ [ +# expect-04: { { { +# expect-05: ) ) ) +# expect-06: ] ] ] +# expect-07: } } } +# expect-08: (()) (()) (()) +# expect-09: [[]] [[]] [[]] +# expect-10: {{}} {{}} {{}} +# expect-11: )( )( )( +# expect-12: ][ ][ ][ +# expect-13: }{ }{ }{ -# As of 2020-10-25, the variable names may contain arbitrary characters, -# except for whitespace. This allows for creative side effects. Hopefully -# nobody is misusing this "feature". +# Before 2023-05-09, the variable names could contain arbitrary characters, +# except for whitespace, allowing for creative side effects, as usual for +# arbitrary code injection. var= outer +# expect+1: invalid character ':' in .for loop variable name .for var:Q in value "quoted" -. info ${var} ${var:Q} ${var:Q:Q} +. info <${var}> <${var:Q}> <${var:Q:Q}> +.endfor + +# Before 2023-05-09, when variable names could contain '$', the short +# expression '$$' was preserved, the long expressions were substituted. +# expect+1: invalid character '$' in .for loop variable name +.for $ in value +. info <$$> <${$}> <$($)> +.endfor + + +# https://gnats.netbsd.org/53146 mentions the idea of using a dynamic +# variable name in .for loops, based on some other variable. The .for loops +# are already tricky enough to understand in detail, even without this +# possibility, therefore the variable names are restricted to using harmless +# characters only. +INDIRECT= direct +# expect+1: invalid character '$' in .for loop variable name +.for $(INDIRECT) in value +# If the variable name could be chosen dynamically, the iteration variable +# might have been 'direct', thereby expanding the expression '${direct}'. +. info <$(INDIRECT)> <$(direct)> <$($(INDIRECT))> .endfor # XXX: A parse error or evaluation error in the items of the .for loop -# should skip the whole loop. As of 2020-12-27, the loop is expanded twice. +# should skip the whole loop. As of 2023-05-09, the loop is expanded as +# usual. +# expect+1: Unknown modifier "Z" .for var in word1 ${:Uword2:Z} word3 . info XXX: Not reached ${var} .endfor +# expect-2: XXX: Not reached word1 +# expect-3: XXX: Not reached word3 # An empty list of variables to the left of the 'in' is a parse error. .for in value # expect+0: no iteration variables in for -# XXX: The loop body is evaluated once, even with the parse error above. -. error # expect+0: Missing argument for ".error" -.endfor # expect+0: for-less endfor +. error +.endfor # An empty list of iteration values to the right of the 'in' is accepted. # Unlike in the shell, it is not a parse error. .for var in . error .endfor # If the iteration values become empty after expanding the expressions, the # body of the loop is not evaluated. It is not a parse error. .for var in ${:U} . error .endfor # The loop body can be empty. .for var in 1 2 3 .endfor # A mismatched .if inside a .for loop is detected each time when the loop body # is processed. .for var in value . if 0 .endfor # expect+0: 1 open conditional # If there are no iteration values, the loop body is not processed, and the # check for mismatched conditionals is not performed. .for var in ${:U} . if 0 .endfor # When a .for without the corresponding .endfor occurs in an inactive branch # of an .if, the .for directive is just skipped, it does not even need a # corresponding .endfor. In other words, the behavior of the parser depends # on the actual values of the conditions in the .if clauses. .if 0 . for var in value # does not need a corresponding .endfor .endif .endfor # expect+0: for-less endfor .endif # expect+0: if-less endif # When a .for without the corresponding .endfor occurs in an active branch of # an .if, the parser just counts the number of .for and .endfor directives, # without looking at any other directives. .if 1 . for var in value . endif # expect+0: if-less endif . endfor # no 'for-less endfor' .endif # no 'if-less endif' -# When make parses a .for loop, it assumes that there is no line break between -# the '.' and the 'for' or 'endfor', as there is no practical reason to break -# the line at this point. When make scans the outer .for loop, it does not -# recognize the inner directives as such. When make scans the inner .for -# loop, it recognizes the '.\n for' but does not recognize the '.\n endfor', -# as LK_FOR_BODY preserves the backslash-newline sequences. +# Before for.c 1.172 from 2023-05-08, when make parsed a .for loop, it +# assumed that there was no line continuation between the '.' and the 'for' +# or 'endfor', as there is no practical reason to break the line at this +# point. +# +# When make scanned the outer .for loop, it did not recognize the inner .for +# loop as such and instead treated it as an unknown directive. The body of +# the outer .for loop thus ended above the '.endfor'. +# +# When make scanned the inner .for loop, it did not recognize the inner +# .endfor as such, which led to a parse error 'Unexpected end of file in .for +# loop' from the '.endfor' line, followed by a second parse error 'for-less +# .endfor' from the '.\\n endfor' line. .MAKEFLAGS: -df .for outer in o .\ for inner in i .\ endfor .endfor .MAKEFLAGS: -d0 # When there is a variable definition 'scope=cmdline' from the command line # (which has higher precedence than global variables) and a .for loop iterates # over a variable of the same name, the expression '${scope}' expands to the # value from the .for loop. This is because when the body of the .for loop is # expanded, the expression '${scope}' is textually replaced with ${:Uloop}', # without resolving any other variable names (ForLoop_SubstBody). Later, when # the body of the .for loop is actually interpreted, the body text doesn't # contain the word 'scope' anymore. .MAKEFLAGS: scope=cmdline .for scope in loop . if ${scope} != "loop" . error . endif .endfor + + +# Since at least 1993, iteration stops at the first newline. +# Back then, the .newline variable didn't exist, therefore it was unlikely +# that a newline ever occurred. +.for var in a${.newline}b${.newline}c +. info newline-item=(${var}) +.endfor +# expect-2: newline-item=(a) diff --git a/unit-tests/forloop.exp b/unit-tests/forloop.exp deleted file mode 100644 index 422711b41247..000000000000 --- a/unit-tests/forloop.exp +++ /dev/null @@ -1,20 +0,0 @@ -make: "forloop.mk" line 14: x=one -make: "forloop.mk" line 14: x="two and three" -make: "forloop.mk" line 14: x=four -make: "forloop.mk" line 14: x="five" -make: "forloop.mk" line 20: x=-I/this -make: "forloop.mk" line 20: x=-I"This or that" -make: "forloop.mk" line 20: x=-Ithat -make: "forloop.mk" line 20: x="-DTHIS=\"this and that\"" -make: "forloop.mk" line 27: cfl=-I/this -I"This or that" -Ithat "-DTHIS=\"this and that\"" -make: "forloop.mk" line 41: newline-item=(a) -make: "forloop.mk" line 47: a=one b="two and three" -make: "forloop.mk" line 47: a=four b="five" -make: "forloop.mk" line 47: a=ONE b="TWO AND THREE" -make: "forloop.mk" line 47: a=FOUR b="FIVE" -We expect an error next: -make: "forloop.mk" line 46: Wrong number of words (9) in .for substitution list with 2 variables -make: Fatal errors encountered -- cannot continue -make: stopped in unit-tests -OK -exit status 0 diff --git a/unit-tests/forloop.mk b/unit-tests/forloop.mk deleted file mode 100644 index cef05cbe4c61..000000000000 --- a/unit-tests/forloop.mk +++ /dev/null @@ -1,53 +0,0 @@ -# $NetBSD: forloop.mk,v 1.7 2020/11/03 17:37:57 rillig Exp $ - -all: for-loop - -LIST= one "two and three" four "five" - -.if make(for-fail) -for-fail: - -XTRA_LIST= xtra -.else - -. for x in ${LIST} -. info x=$x -. endfor - -CFL= -I/this -I"This or that" -Ithat "-DTHIS=\"this and that\"" -cfl= -. for x in ${CFL} -. info x=$x -. if empty(cfl) -cfl= $x -. else -cfl+= $x -. endif -. endfor -. info cfl=${cfl} - -. if ${cfl} != ${CFL} -. error ${.newline}${cfl} != ${.newline}${CFL} -. endif - -. for a b in ${EMPTY} -. info a=$a b=$b -. endfor - -# Since at least 1993, iteration stops at the first newline. -# Back then, the .newline variable didn't exist, therefore it was unlikely -# that a newline ever occurred. -. for var in a${.newline}b${.newline}c -. info newline-item=(${var}) -. endfor - -.endif # for-fail - -.for a b in ${LIST} ${LIST:tu} ${XTRA_LIST} -. info a=$a b=$b -.endfor - -for-loop: - @echo We expect an error next: - @(cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} for-fail) && \ - { echo "Oops that should have failed!"; exit 1; } || echo OK diff --git a/unit-tests/parse.mk b/unit-tests/parse.mk index 986c303083bf..551dc98aaf24 100644 --- a/unit-tests/parse.mk +++ b/unit-tests/parse.mk @@ -1,24 +1,54 @@ -# $NetBSD: parse.mk,v 1.3 2022/07/24 20:25:23 rillig Exp $ +# $NetBSD: parse.mk,v 1.4 2023/04/28 13:09:48 rillig Exp $ # # Test those parts of the parsing that do not belong in any of the other # categories. # expect+1: Makefile appears to contain unresolved CVS/RCS/??? merge conflicts <<<<<< old # No diagnostic since the following line is parsed as a variable assignment, # even though the variable name is empty. See also varname-empty.mk. ====== middle # expect+1: Makefile appears to contain unresolved CVS/RCS/??? merge conflicts >>>>>> new # Since parse.c 1.578 from 2021-12-14 and before parse.c 1.681 from # 2022-07-24, if a line of a makefile could only be a dependency specification # but didn't contain any of the dependency operators ':', '!', '::' and its # expansion ended with a space, make read a single byte from the memory beyond # the expanded line's terminating '\0'. # # https://bugs.freebsd.org/265119 one-target ${:U } + + +# Since parse.c 1.656 from 2022-01-27 and before parse.c 1.662 from +# 2022-02-05, there was an out-of-bounds read in Parse_IsVar when looking for +# a variable assignment in a dependency line with trailing whitespace. Lines +# without trailing whitespace were not affected. Global variable assignments +# were guaranteed to have no trailing whitespace and were thus not affected. +# +# Try to reproduce some variants that may lead to a crash, depending on the +# memory allocator. To get a crash, the terminating '\0' of the line must be +# the last byte of a memory page. The expression '${:U}' forces this trailing +# whitespace. + +# On FreeBSD x86_64, a crash could in some cases be forced using the following +# line, which has length 47, and if the memory for the expanded line starts at +# 0xXXXX_XXd0, the terminating '\0' may end up at 0xXXXX_Xfff: +Try_to_crash_FreeBSD.xxxxxxxxxxxxxxxxxx: 12345 ${:U} + +# The following line has length 4095 after being expanded, so line[4095] == +# '\0'. If the line is +# allocated on a page boundary and the following page is not mapped, this line +# leads to a segmentation fault. +${:U:range=511:@_@1234567@:ts.}: 12345 ${:U} + +# The following line has length 8191, so line[8191] == '\0'. If the line is +# allocated on a page boundary and the following page is not mapped, this line +# leads to a segmentation fault. +${:U:range=1023:@_@1234567@:ts.}: 12345 ${:U} + +12345: diff --git a/unit-tests/var-eval-short.exp b/unit-tests/var-eval-short.exp index 34380ec61c41..ea6e0d7485f9 100644 --- a/unit-tests/var-eval-short.exp +++ b/unit-tests/var-eval-short.exp @@ -1,33 +1,29 @@ make: "var-eval-short.mk" line 44: In the :@ modifier of "", the variable name "${FAIL}" must not contain a dollar make: "var-eval-short.mk" line 44: Malformed conditional (0 && ${:Uword:@${FAIL}@expr@}) -make: "var-eval-short.mk" line 84: Invalid time value at "${FAIL}}" -make: "var-eval-short.mk" line 84: Malformed conditional (0 && ${:Uword:gmtime=${FAIL}}) -make: "var-eval-short.mk" line 98: Invalid time value at "${FAIL}}" -make: "var-eval-short.mk" line 98: Malformed conditional (0 && ${:Uword:localtime=${FAIL}}) CondParser_Eval: 0 && ${0:?${FAIL}then:${FAIL}else} Var_Parse: ${0:?${FAIL}then:${FAIL}else} (parse-only) Parsing modifier ${0:?...} Var_Parse: ${FAIL}then:${FAIL}else} (parse-only) Modifier part: "${FAIL}then" Var_Parse: ${FAIL}else} (parse-only) Modifier part: "${FAIL}else" Result of ${0:?${FAIL}then:${FAIL}else} is "" (parse-only, defined) -Parsing line 163: DEFINED= defined +Parsing line 165: DEFINED= defined Global: DEFINED = defined CondParser_Eval: 0 && ${DEFINED:L:?${FAIL}then:${FAIL}else} Var_Parse: ${DEFINED:L:?${FAIL}then:${FAIL}else} (parse-only) Parsing modifier ${DEFINED:L} Result of ${DEFINED:L} is "defined" (parse-only, regular) Parsing modifier ${DEFINED:?...} Var_Parse: ${FAIL}then:${FAIL}else} (parse-only) Modifier part: "${FAIL}then" Var_Parse: ${FAIL}else} (parse-only) Modifier part: "${FAIL}else" Result of ${DEFINED:?${FAIL}then:${FAIL}else} is "defined" (parse-only, regular) -Parsing line 166: .MAKEFLAGS: -d0 +Parsing line 168: .MAKEFLAGS: -d0 ParseDependency(.MAKEFLAGS: -d0) Global: .MAKEFLAGS = -r -k -d cpv -d Global: .MAKEFLAGS = -r -k -d cpv -d 0 make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/unit-tests/var-eval-short.mk b/unit-tests/var-eval-short.mk index a099b6871d1e..7faf1cc5d154 100644 --- a/unit-tests/var-eval-short.mk +++ b/unit-tests/var-eval-short.mk @@ -1,168 +1,170 @@ -# $NetBSD: var-eval-short.mk,v 1.8 2021/12/27 18:54:19 rillig Exp $ +# $NetBSD: var-eval-short.mk,v 1.9 2023/05/09 16:27:00 rillig Exp $ # # Tests for each variable modifier to ensure that they only do the minimum # necessary computations. If the result of the expression is irrelevant, # the modifier should only be parsed. The modifier should not be evaluated, # but if it is evaluated for simplicity of the code (such as ':ts'), it must # not have any observable side effects. # # See also: # var.c, the comment starting with 'The ApplyModifier functions' # ParseModifierPart, for evaluating nested expressions # cond-short.mk FAIL= ${:!echo unexpected 1>&2!} # The following tests only ensure that nested expressions are not evaluated. # They cannot ensure that any unexpanded text returned from ParseModifierPart # is ignored as well. To do that, it is necessary to step through the code of # each modifier. # TODO: Test the modifiers in the same order as they appear in ApplyModifier. .if 0 && ${FAIL} .endif .if 0 && ${VAR::=${FAIL}} .elif defined(VAR) . error .endif .if 0 && ${${FAIL}:?then:else} .endif .if 0 && ${1:?${FAIL}:${FAIL}} .endif .if 0 && ${0:?${FAIL}:${FAIL}} .endif # Before var.c 1.870 from 2021-03-14, the expression ${FAIL} was evaluated # after the loop, when undefining the temporary global loop variable. # Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the # variable name. .if 0 && ${:Uword:@${FAIL}@expr@} .endif .if 0 && ${:Uword:@var@${FAIL}@} .endif # Before var.c 1.877 from 2021-03-14, the modifier ':[...]' did not expand # the nested expression ${FAIL} and then tried to parse the unexpanded text, # which failed since '$' is not a valid range character. .if 0 && ${:Uword:[${FAIL}]} .endif # Before var.c 1.867 from 2021-03-14, the modifier ':_' defined the variable # even though the whole expression should have only been parsed, not # evaluated. .if 0 && ${:Uword:_=VAR} .elif defined(VAR) . error .endif # Before var.c 1.856 from 2021-03-14, the modifier ':C' did not expand the # nested expression ${FAIL}, which is correct, and then tried to compile the # unexpanded text as a regular expression, which is unnecessary since the # right-hand side of the '&&' cannot influence the outcome of the condition. # Compiling the regular expression then failed both because of the '{FAIL}', # which is not a valid repetition of the form '{1,5}', and because of the # '****', which are repeated repetitions as well. # '${FAIL}' .if 0 && ${:Uword:C,${FAIL}****,,} .endif DEFINED= # defined .if 0 && ${DEFINED:D${FAIL}} .endif .if 0 && ${:Uword:E} .endif -# As of 2021-03-14, the error 'Invalid time value: ${FAIL}}' is ok since -# ':gmtime' does not expand its argument. +# Before var.c 1.1050 from 2023-05-09, the ':gmtime' modifier produced the +# error message 'Invalid time value: ${FAIL}}' since it did not expand its +# argument. .if 0 && ${:Uword:gmtime=${FAIL}} .endif .if 0 && ${:Uword:H} .endif .if 0 && ${:Uword:hash} .endif .if 0 && ${value:L} .endif -# As of 2021-03-14, the error 'Invalid time value: ${FAIL}}' is ok since -# ':localtime' does not expand its argument. +# Before var.c 1.1050 from 2023-05-09, the ':localtime' modifier produced the +# error message 'Invalid time value: ${FAIL}}' since it did not expand its +# argument. .if 0 && ${:Uword:localtime=${FAIL}} .endif .if 0 && ${:Uword:M${FAIL}} .endif .if 0 && ${:Uword:N${FAIL}} .endif .if 0 && ${:Uword:O} .endif .if 0 && ${:Uword:Ox} .endif .if 0 && ${:Uword:P} .endif .if 0 && ${:Uword:Q} .endif .if 0 && ${:Uword:q} .endif .if 0 && ${:Uword:R} .endif .if 0 && ${:Uword:range} .endif .if 0 && ${:Uword:S,${FAIL},${FAIL},} .endif .if 0 && ${:Uword:sh} .endif .if 0 && ${:Uword:T} .endif .if 0 && ${:Uword:ts/} .endif .if 0 && ${:U${FAIL}} .endif .if 0 && ${:Uword:u} .endif .if 0 && ${:Uword:word=replacement} .endif # Before var.c 1.875 from 2021-03-14, Var_Parse returned "${FAIL}else" for the # irrelevant right-hand side of the condition, even though this was not # necessary. Since the return value from Var_Parse is supposed to be ignored # anyway, and since it is actually ignored in an overly complicated way, # an empty string suffices. .MAKEFLAGS: -dcpv .if 0 && ${0:?${FAIL}then:${FAIL}else} .endif # The ':L' is applied before the ':?' modifier, giving the expression a name # and a value, just to see whether this value gets passed through or whether # the parse-only mode results in an empty string (only visible in the debug # log). As of var.c 1.875 from 2021-03-14, the value of the variable gets # through, even though an empty string would suffice. DEFINED= defined .if 0 && ${DEFINED:L:?${FAIL}then:${FAIL}else} .endif .MAKEFLAGS: -d0 all: diff --git a/unit-tests/var-scope-local.exp b/unit-tests/var-scope-local.exp index 403bf83884f7..a9a947a620c7 100644 --- a/unit-tests/var-scope-local.exp +++ b/unit-tests/var-scope-local.exp @@ -1,21 +1,71 @@ -Global: .ALLTARGETS = one -Global: .ALLTARGETS = one two +Global: .ALLTARGETS = all target-rule.ext dir/subdir/target-rule.ext target-rule.ir-gen-from dir/subdir/target-rule-dir.ir-gen-from inference-rule.ir-to dir/subdir/inference-rule.ir-to inference-rule.ir-from dir/subdir/inference-rule.ir-from inference-rule-chain.ir-to dir/subdir/inference-rule-chain.ir-to inference-rule-chain.ir-gen-from dir/subdir/inference-rule-chain.ir-gen-from one +Global: .ALLTARGETS = all target-rule.ext dir/subdir/target-rule.ext target-rule.ir-gen-from dir/subdir/target-rule-dir.ir-gen-from inference-rule.ir-to dir/subdir/inference-rule.ir-to inference-rule.ir-from dir/subdir/inference-rule.ir-from inference-rule-chain.ir-to dir/subdir/inference-rule-chain.ir-to inference-rule-chain.ir-gen-from dir/subdir/inference-rule-chain.ir-gen-from one two Var_Parse: ${.MAKE.TARGET_LOCAL_VARIABLES} (eval) Var_SetExpand: variable name "" expands to empty string, with value "three" - ignored Var_SetExpand: variable name "" expands to empty string, with value "three" - ignored Global: one two = # (empty) Global: one two = three Global: .MAKEFLAGS = -r -k -d v -d Global: .MAKEFLAGS = -r -k -d v -d 0 +target-rule.ext: @ = +target-rule.ext: % = +target-rule.ext: ? = <> +target-rule.ext: < = +target-rule.ext: * = +dir/subdir/target-rule.ext: @ = +dir/subdir/target-rule.ext: % = +dir/subdir/target-rule.ext: ? = <> +dir/subdir/target-rule.ext: < = +dir/subdir/target-rule.ext: * = +target-rule.ir-gen-from: @ = +target-rule.ir-gen-from: % = +target-rule.ir-gen-from: ? = <> +target-rule.ir-gen-from: < = +target-rule.ir-gen-from: * = +dir/subdir/target-rule-dir.ir-gen-from: @ = +dir/subdir/target-rule-dir.ir-gen-from: % = +dir/subdir/target-rule-dir.ir-gen-from: ? = <> +dir/subdir/target-rule-dir.ir-gen-from: < = +dir/subdir/target-rule-dir.ir-gen-from: * = +inference-rule.ir-to: @ = +inference-rule.ir-to: % = +inference-rule.ir-to: ? = +inference-rule.ir-to: < = +inference-rule.ir-to: * = +dir/subdir/inference-rule.ir-to: @ = +dir/subdir/inference-rule.ir-to: % = +dir/subdir/inference-rule.ir-to: ? = +dir/subdir/inference-rule.ir-to: < = +dir/subdir/inference-rule.ir-to: * = +inference-rule-chain.ir-from: @ = +inference-rule-chain.ir-from: % = +inference-rule-chain.ir-from: ? = +inference-rule-chain.ir-from: < = +inference-rule-chain.ir-from: * = +inference-rule-chain.ir-to: @ = +inference-rule-chain.ir-to: % = +inference-rule-chain.ir-to: ? = +inference-rule-chain.ir-to: < = +inference-rule-chain.ir-to: * = +dir/subdir/inference-rule-chain.ir-from: @ = +dir/subdir/inference-rule-chain.ir-from: % = +dir/subdir/inference-rule-chain.ir-from: ? = +dir/subdir/inference-rule-chain.ir-from: < = +dir/subdir/inference-rule-chain.ir-from: * = +dir/subdir/inference-rule-chain.ir-to: @ = +dir/subdir/inference-rule-chain.ir-to: % = +dir/subdir/inference-rule-chain.ir-to: ? = +dir/subdir/inference-rule-chain.ir-to: < = +dir/subdir/inference-rule-chain.ir-to: * = : Making var-scope-local.c out of nothing. : Making var-scope-local.o from var-scope-local.c. : Making basename "var-scope-local.o" in "." from "var-scope-local.c" in ".". : Making var-scope-local-assign.o with VAR="local". : Making var-scope-local-append.o with VAR="local to var-scope-local-append.o". : Making var-scope-local-append-global.o with VAR="global+local". : Making var-scope-local-default.o with VAR="global". : Making var-scope-local-subst.o with VAR="global+local". : Making var-scope-local-shell.o with VAR="output". : var-scope-local-use.o uses .USE VAR="global" : all overwritten exit status 0 diff --git a/unit-tests/var-scope-local.mk b/unit-tests/var-scope-local.mk index ed1362444504..2cfeda044c40 100644 --- a/unit-tests/var-scope-local.mk +++ b/unit-tests/var-scope-local.mk @@ -1,236 +1,269 @@ -# $NetBSD: var-scope-local.mk,v 1.5 2022/02/09 21:09:24 rillig Exp $ +# $NetBSD: var-scope-local.mk,v 1.7 2023/04/29 10:16:24 rillig Exp $ # # Tests for target-local variables, such as ${.TARGET} or $@. These variables # are relatively short-lived as they are created just before making the # target. In contrast, global variables are typically created when the # makefiles are read in. # # The 7 built-in target-local variables are listed in the manual page. They # are defined just before the target is actually made. Additional # target-local variables can be defined in dependency lines like # 'target: VAR=value', one at a time. .MAIN: all +# Target-local variables in a target rule +# +# In target rules, '$*' only strips the extension off the pathname if the +# extension is listed in '.SUFFIXES'. +# +# expect: target-rule.ext: * = +all: target-rule.ext dir/subdir/target-rule.ext +target-rule.ext dir/subdir/target-rule.ext: .PHONY + @echo '$@: @ = <${@:Uundefined}>' + @echo '$@: % = <${%:Uundefined}>' + @echo '$@: ? = <${?:Uundefined}>' + @echo '$@: < = <${<:Uundefined}>' + @echo '$@: * = <${*:Uundefined}>' + +.SUFFIXES: .ir-gen-from .ir-from .ir-to + +# In target rules, '$*' strips the extension off the pathname of the target +# if the extension is listed in '.SUFFIXES'. +# +# expect: target-rule.ir-gen-from: * = +all: target-rule.ir-gen-from dir/subdir/target-rule-dir.ir-gen-from +target-rule.ir-gen-from dir/subdir/target-rule-dir.ir-gen-from: + @echo '$@: @ = <${@:Uundefined}>' + @echo '$@: % = <${%:Uundefined}>' + @echo '$@: ? = <${?:Uundefined}>' + @echo '$@: < = <${<:Uundefined}>' + @echo '$@: * = <${*:Uundefined}>' + +.ir-from.ir-to: + @echo '$@: @ = <${@:Uundefined}>' + @echo '$@: % = <${%:Uundefined}>' + @echo '$@: ? = <${?:Uundefined}>' + @echo '$@: < = <${<:Uundefined}>' + @echo '$@: * = <${*:Uundefined}>' +.ir-gen-from.ir-from: + @echo '$@: @ = <${@:Uundefined}>' + @echo '$@: % = <${%:Uundefined}>' + @echo '$@: ? = <${?:Uundefined}>' + @echo '$@: < = <${<:Uundefined}>' + @echo '$@: * = <${*:Uundefined}>' + +# Target-local variables in an inference rule +all: inference-rule.ir-to dir/subdir/inference-rule.ir-to +inference-rule.ir-from: .PHONY +dir/subdir/inference-rule.ir-from: .PHONY + +# Target-local variables in a chain of inference rules +all: inference-rule-chain.ir-to dir/subdir/inference-rule-chain.ir-to +inference-rule-chain.ir-gen-from: .PHONY +dir/subdir/inference-rule-chain.ir-gen-from: .PHONY + +# The run-time 'check' directives from above happen after the parse-time +# 'check' directives from below. +# +# expect-reset + +# Deferred evaluation during parsing +# # The target-local variables can be used in expressions, just like other # variables. When these expressions are evaluated outside of a target, these # expressions are not yet expanded, instead their text is preserved, to allow # these expressions to expand right in time when the target-local variables # are actually set. # # Conditions from .if directives are evaluated in the scope of the command # line, which means that variables from the command line, from the global -# scope and from the environment are resolved, in this order (but see the -# command line option '-e'). In that phase, expressions involving +# scope and from the environment are resolved, in this precedence order (but +# see the command line option '-e'). In that phase, expressions involving # target-local variables need to be preserved, including the exact names of # the variables. # # Each of the built-in target-local variables has two equivalent names, for # example '@' is equivalent to '.TARGET'. The implementation might # canonicalize these aliases at some point, and that might be surprising. # This aliasing happens for single-character variable names like $@ or $< # (see VarFind, CanonicalVarname), but not for braced or parenthesized # expressions like ${@}, ${.TARGET} ${VAR:Mpattern} (see Var_Parse, # ParseVarname). # # In the following condition, make expands '$@' to the long-format alias # '$(.TARGET)'; note that the alias is not written with braces, as would be # common in BSD makefiles, but with parentheses. This alternative spelling # behaves the same though. .if $@ != "\$\(.TARGET)" . error .endif # In the long form of writing a target-local variable, the text of the # expression is preserved exactly as written, no matter whether it is written # with '{' or '('. .if ${@} != "\$\{@}" . error .endif .if $(@) != "\$\(@)" . error .endif # If the variable expression contains modifiers, the behavior depends on the # actual modifiers. The modifier ':M' keeps the expression in the state # 'undefined'. Since the expression is still undefined after evaluating all # the modifiers, the value of the expression is discarded and the expression # text is used instead. This preserves the expressions based on target-local # variables as long as possible. .if ${@:M*} != "\$\{@:M*}" . error .endif # In the following examples, the expressions are based on target-local # variables but use the modifier ':L', which turns an undefined expression # into a defined one. At the end of evaluating the expression, the state of # the expression is not 'undefined' anymore. The value of the expression # is the name of the variable, since that's what the modifier ':L' does. .if ${@:L} != "@" . error .endif .if ${.TARGET:L} != ".TARGET" . error .endif .if ${@F:L} != "@F" . error .endif .if ${@D:L} != "@D" . error .endif +# Custom local variables +# # Additional target-local variables may be defined in dependency lines. .MAKEFLAGS: -dv # In the following line, the ':=' may either be interpreted as an assignment # operator or as the dependency operator ':', followed by an empty variable # name and the assignment operator '='. It is the latter since in an -# assignment, the left-hand side must be at most a single word. The empty -# variable name is expanded twice, once for 'one' and once for 'two'. +# assignment, the left-hand side must be a single word or empty. +# +# The empty variable name is expanded twice, once for 'one' and once for +# 'two'. # expect: Var_SetExpand: variable name "" expands to empty string, with value "three" - ignored # expect: Var_SetExpand: variable name "" expands to empty string, with value "three" - ignored one two:=three # If the two targets to the left are generated by a variable expression, the # line is parsed as a variable assignment since its left-hand side is a single # word. # expect: Global: one two = three ${:Uone two}:=three .MAKEFLAGS: -d0 .SUFFIXES: .c .o # One of the dynamic target-local variables is '.TARGET'. Since this is not # a suffix transformation rule, the variable '.IMPSRC' is not defined. # expect: : Making var-scope-local.c out of nothing. var-scope-local.c: : Making ${.TARGET} ${.IMPSRC:Dfrom ${.IMPSRC}:Uout of nothing}. # This is a suffix transformation rule, so both '.TARGET' and '.IMPSRC' are # defined. # expect: : Making var-scope-local.o from var-scope-local.c. # expect: : Making basename "var-scope-local.o" in "." from "var-scope-local.c" in ".". .c.o: : Making ${.TARGET} from ${.IMPSRC}. # The local variables @F, @D, varmod-path.subdir/varmod-path.phony _!= > varmod-path.subdir/varmod-path.real -# To have an effect, this .PATH declaration must be after the directory is created. +# To have an effect, this .PATH declaration must be processed after the +# directory has been created. .PATH: varmod-path.subdir varmod-path.phony: .PHONY varmod-path.real: all: varmod-path.phony varmod-path.real @echo ${varmod-path.phony:P} @echo ${varmod-path.real:P} @echo ${varmod-path.enoent:P} .END: @rm -rf varmod-path.subdir diff --git a/var.c b/var.c index 965080bbcddd..074a96639bdb 100644 --- a/var.c +++ b/var.c @@ -1,4773 +1,4858 @@ -/* $NetBSD: var.c,v 1.1049 2023/03/28 14:39:31 rillig Exp $ */ +/* $NetBSD: var.c,v 1.1054 2023/05/10 18:22:33 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Adam de Boor. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * Copyright (c) 1989 by Berkeley Softworks * All rights reserved. * * This code is derived from software contributed to Berkeley by * Adam de Boor. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * Handling of variables and the expressions formed from them. * * Variables are set using lines of the form VAR=value. Both the variable * name and the value can contain references to other variables, by using * expressions like ${VAR}, ${VAR:Modifiers}, ${${VARNAME}} or ${VAR:${MODS}}. * * Interface: * Var_Init Initialize this module. * * Var_End Clean up the module. * * Var_Set * Var_SetExpand * Set the value of the variable, creating it if * necessary. * * Var_Append * Var_AppendExpand * Append more characters to the variable, creating it if * necessary. A space is placed between the old value and * the new one. * * Var_Exists * Var_ExistsExpand * See if a variable exists. * * Var_Value Return the unexpanded value of a variable, or NULL if * the variable is undefined. * * Var_Subst Substitute all variable expressions in a string. * * Var_Parse Parse a variable expression such as ${VAR:Mpattern}. * * Var_Delete * Delete a variable. * * Var_ReexportVars * Export some or even all variables to the environment * of this process and its child processes. * * Var_Export Export the variable to the environment of this process * and its child processes. * * Var_UnExport Don't export the variable anymore. * * Debugging: * Var_Stats Print out hashing statistics if in -dh mode. * * Var_Dump Print out all variables defined in the given scope. * * XXX: There's a lot of almost duplicate code in these functions that only * differs in subtle details that are not mentioned in the manual page. */ #include #include #ifndef NO_REGEX #include #endif #include "make.h" #include #ifdef HAVE_INTTYPES_H #include #elif defined(HAVE_STDINT_H) #include #endif #ifdef HAVE_LIMITS_H #include #endif #include #include "dir.h" #include "job.h" #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.1049 2023/03/28 14:39:31 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.1054 2023/05/10 18:22:33 sjg Exp $"); /* * Variables are defined using one of the VAR=value assignments. Their * value can be queried by expressions such as $V, ${VAR}, or with modifiers * such as ${VAR:S,from,to,g:Q}. * * There are 3 kinds of variables: scope variables, environment variables, * undefined variables. * * Scope variables are stored in a GNode.scope. The only way to undefine * a scope variable is using the .undef directive. In particular, it must * not be possible to undefine a variable during the evaluation of an * expression, or Var.name might point nowhere. (There is another, * unintended way to undefine a scope variable, see varmod-loop-delete.mk.) * * Environment variables are short-lived. They are returned by VarFind, and * after using them, they must be freed using VarFreeShortLived. * * Undefined variables occur during evaluation of variable expressions such * as ${UNDEF:Ufallback} in Var_Parse and ApplyModifiers. */ typedef struct Var { /* * The name of the variable, once set, doesn't change anymore. * For scope variables, it aliases the corresponding HashEntry name. * For environment and undefined variables, it is allocated. */ FStr name; /* The unexpanded value of the variable. */ Buffer val; /* The variable came from the command line. */ bool fromCmd:1; /* * The variable is short-lived. * These variables are not registered in any GNode, therefore they * must be freed after use. */ bool shortLived:1; /* * The variable comes from the environment. * Appending to its value moves the variable to the global scope. */ bool fromEnvironment:1; /* * The variable value cannot be changed anymore, and the variable * cannot be deleted. Any attempts to do so are silently ignored, * they are logged with -dv though. * Use .[NO]READONLY: to adjust. * * See VAR_SET_READONLY. */ bool readOnly:1; /* * The variable is currently being accessed by Var_Parse or Var_Subst. * This temporary marker is used to avoid endless recursion. */ bool inUse:1; /* * The variable is exported to the environment, to be used by child * processes. */ bool exported:1; /* * At the point where this variable was exported, it contained an * unresolved reference to another variable. Before any child * process is started, it needs to be exported again, in the hope * that the referenced variable can then be resolved. */ bool reexport:1; } Var; /* * Exporting variables is expensive and may leak memory, so skip it if we * can. * * To avoid this, it might be worth encapsulating the environment variables * in a separate data structure called EnvVars. */ typedef enum VarExportedMode { VAR_EXPORTED_NONE, VAR_EXPORTED_SOME, VAR_EXPORTED_ALL } VarExportedMode; typedef enum UnexportWhat { /* Unexport the variables given by name. */ UNEXPORT_NAMED, /* * Unexport all globals previously exported, but keep the environment * inherited from the parent. */ UNEXPORT_ALL, /* * Unexport all globals previously exported and clear the environment * inherited from the parent. */ UNEXPORT_ENV } UnexportWhat; /* Flags for pattern matching in the :S and :C modifiers */ typedef struct PatternFlags { bool subGlobal:1; /* 'g': replace as often as possible */ bool subOnce:1; /* '1': replace only once */ bool anchorStart:1; /* '^': match only at start of word */ bool anchorEnd:1; /* '$': match only at end of word */ } PatternFlags; /* SepBuf builds a string from words interleaved with separators. */ typedef struct SepBuf { Buffer buf; bool needSep; /* Usually ' ', but see the ':ts' modifier. */ char sep; } SepBuf; /* * This lets us tell if we have replaced the original environ * (which we cannot free). */ char **savedEnv = NULL; /* * Special return value for Var_Parse, indicating a parse error. It may be * caused by an undefined variable, a syntax error in a modifier or * something entirely different. */ char var_Error[] = ""; /* * Special return value for Var_Parse, indicating an undefined variable in * a case where VARE_UNDEFERR is not set. This undefined variable is * typically a dynamic variable such as ${.TARGET}, whose expansion needs to * be deferred until it is defined in an actual target. * * See VARE_EVAL_KEEP_UNDEF. */ static char varUndefined[] = ""; /* * Traditionally this make consumed $$ during := like any other expansion. * Other make's do not, and this make follows straight since 2016-01-09. * * This knob allows controlling the behavior: * false to consume $$ during := assignment. * true to preserve $$ during := assignment. */ #define MAKE_SAVE_DOLLARS ".MAKE.SAVE_DOLLARS" static bool save_dollars = false; /* * A scope collects variable names and their values. * * The main scope is SCOPE_GLOBAL, which contains the variables that are set * in the makefiles. SCOPE_INTERNAL acts as a fallback for SCOPE_GLOBAL and * contains some internal make variables. These internal variables can thus * be overridden, they can also be restored by undefining the overriding * variable. * * SCOPE_CMDLINE contains variables from the command line arguments. These * override variables from SCOPE_GLOBAL. * * There is no scope for environment variables, these are generated on-the-fly * whenever they are referenced. If there were such a scope, each change to * environment variables would have to be reflected in that scope, which may * be simpler or more complex than the current implementation. * * Each target has its own scope, containing the 7 target-local variables * .TARGET, .ALLSRC, etc. Variables set on dependency lines also go in * this scope. */ GNode *SCOPE_CMDLINE; GNode *SCOPE_GLOBAL; GNode *SCOPE_INTERNAL; static VarExportedMode var_exportedVars = VAR_EXPORTED_NONE; static const char VarEvalMode_Name[][32] = { "parse-only", "parse-balanced", "eval", "eval-defined", "eval-keep-dollar", "eval-keep-undefined", "eval-keep-dollar-and-undefined", }; static Var * VarNew(FStr name, const char *value, bool shortLived, bool fromEnvironment, bool readOnly) { size_t value_len = strlen(value); Var *var = bmake_malloc(sizeof *var); var->name = name; Buf_InitSize(&var->val, value_len + 1); Buf_AddBytes(&var->val, value, value_len); var->fromCmd = false; var->shortLived = shortLived; var->fromEnvironment = fromEnvironment; var->readOnly = readOnly; var->inUse = false; var->exported = false; var->reexport = false; return var; } static Substring CanonicalVarname(Substring name) { if (!(Substring_Length(name) > 0 && name.start[0] == '.')) return name; if (Substring_Equals(name, ".ALLSRC")) return Substring_InitStr(ALLSRC); if (Substring_Equals(name, ".ARCHIVE")) return Substring_InitStr(ARCHIVE); if (Substring_Equals(name, ".IMPSRC")) return Substring_InitStr(IMPSRC); if (Substring_Equals(name, ".MEMBER")) return Substring_InitStr(MEMBER); if (Substring_Equals(name, ".OODATE")) return Substring_InitStr(OODATE); if (Substring_Equals(name, ".PREFIX")) return Substring_InitStr(PREFIX); if (Substring_Equals(name, ".TARGET")) return Substring_InitStr(TARGET); if (Substring_Equals(name, ".SHELL") && shellPath == NULL) Shell_Init(); /* GNU make has an additional alias $^ == ${.ALLSRC}. */ return name; } static Var * GNode_FindVar(GNode *scope, Substring varname, unsigned int hash) { return HashTable_FindValueBySubstringHash(&scope->vars, varname, hash); } /* * Find the variable in the scope, and maybe in other scopes as well. * * Input: * name name to find, is not expanded any further * scope scope in which to look first * elsewhere true to look in other scopes as well * * Results: * The found variable, or NULL if the variable does not exist. * If the variable is short-lived (such as environment variables), it * must be freed using VarFreeShortLived after use. */ static Var * VarFindSubstring(Substring name, GNode *scope, bool elsewhere) { Var *var; unsigned int nameHash; /* Replace '.TARGET' with '@', likewise for other local variables. */ name = CanonicalVarname(name); nameHash = Hash_Substring(name); var = GNode_FindVar(scope, name, nameHash); if (!elsewhere) return var; if (var == NULL && scope != SCOPE_CMDLINE) var = GNode_FindVar(SCOPE_CMDLINE, name, nameHash); if (!opts.checkEnvFirst && var == NULL && scope != SCOPE_GLOBAL) { var = GNode_FindVar(SCOPE_GLOBAL, name, nameHash); if (var == NULL && scope != SCOPE_INTERNAL) { /* SCOPE_INTERNAL is subordinate to SCOPE_GLOBAL */ var = GNode_FindVar(SCOPE_INTERNAL, name, nameHash); } } if (var == NULL) { FStr envName; const char *envValue; envName = Substring_Str(name); envValue = getenv(envName.str); if (envValue != NULL) return VarNew(envName, envValue, true, true, false); FStr_Done(&envName); if (opts.checkEnvFirst && scope != SCOPE_GLOBAL) { var = GNode_FindVar(SCOPE_GLOBAL, name, nameHash); if (var == NULL && scope != SCOPE_INTERNAL) var = GNode_FindVar(SCOPE_INTERNAL, name, nameHash); return var; } return NULL; } return var; } static Var * VarFind(const char *name, GNode *scope, bool elsewhere) { return VarFindSubstring(Substring_InitStr(name), scope, elsewhere); } /* If the variable is short-lived, free it, including its value. */ static void VarFreeShortLived(Var *v) { if (!v->shortLived) return; FStr_Done(&v->name); Buf_Done(&v->val); free(v); } static const char * ValueDescription(const char *value) { if (value[0] == '\0') return "# (empty)"; if (ch_isspace(value[strlen(value) - 1])) return "# (ends with space)"; return ""; } /* Add a new variable of the given name and value to the given scope. */ static Var * VarAdd(const char *name, const char *value, GNode *scope, VarSetFlags flags) { HashEntry *he = HashTable_CreateEntry(&scope->vars, name, NULL); Var *v = VarNew(FStr_InitRefer(/* aliased to */ he->key), value, false, false, (flags & VAR_SET_READONLY) != 0); HashEntry_Set(he, v); DEBUG4(VAR, "%s: %s = %s%s\n", scope->name, name, value, ValueDescription(value)); return v; } /* * Remove a variable from a scope, freeing all related memory as well. * The variable name is kept as-is, it is not expanded. */ void Var_Delete(GNode *scope, const char *varname) { HashEntry *he = HashTable_FindEntry(&scope->vars, varname); Var *v; if (he == NULL) { DEBUG2(VAR, "%s: delete %s (not found)\n", scope->name, varname); return; } DEBUG2(VAR, "%s: delete %s\n", scope->name, varname); v = he->value; if (v->inUse) { Parse_Error(PARSE_FATAL, "Cannot delete variable \"%s\" while it is used", v->name.str); return; } if (v->exported) unsetenv(v->name.str); if (strcmp(v->name.str, ".MAKE.EXPORTED") == 0) var_exportedVars = VAR_EXPORTED_NONE; assert(v->name.freeIt == NULL); HashTable_DeleteEntry(&scope->vars, he); Buf_Done(&v->val); free(v); } /* * Undefine one or more variables from the global scope. * The argument is expanded exactly once and then split into words. */ void Var_Undef(const char *arg) { char *expanded; Words varnames; size_t i; if (arg[0] == '\0') { Parse_Error(PARSE_FATAL, "The .undef directive requires an argument"); return; } expanded = Var_Subst(arg, SCOPE_GLOBAL, VARE_WANTRES); if (expanded == var_Error) { /* TODO: Make this part of the code reachable. */ Parse_Error(PARSE_FATAL, "Error in variable names to be undefined"); return; } varnames = Str_Words(expanded, false); if (varnames.len == 1 && varnames.words[0][0] == '\0') varnames.len = 0; for (i = 0; i < varnames.len; i++) { const char *varname = varnames.words[i]; Global_Delete(varname); } Words_Free(varnames); free(expanded); } static bool MayExport(const char *name) { if (name[0] == '.') return false; /* skip internals */ if (name[0] == '-') return false; /* skip misnamed variables */ if (name[1] == '\0') { /* * A single char. * If it is one of the variables that should only appear in * local scope, skip it, else we can get Var_Subst * into a loop. */ switch (name[0]) { case '@': case '%': case '*': case '!': return false; } } return true; } static bool ExportVarEnv(Var *v) { const char *name = v->name.str; char *val = v->val.data; char *expr; if (v->exported && !v->reexport) return false; /* nothing to do */ if (strchr(val, '$') == NULL) { if (!v->exported) setenv(name, val, 1); return true; } if (v->inUse) { /* * We recursed while exporting in a child. * This isn't going to end well, just skip it. */ return false; } /* XXX: name is injected without escaping it */ expr = str_concat3("${", name, "}"); val = Var_Subst(expr, SCOPE_GLOBAL, VARE_WANTRES); /* TODO: handle errors */ setenv(name, val, 1); free(val); free(expr); return true; } static bool ExportVarPlain(Var *v) { if (strchr(v->val.data, '$') == NULL) { setenv(v->name.str, v->val.data, 1); v->exported = true; v->reexport = false; return true; } /* * Flag the variable as something we need to re-export. * No point actually exporting it now though, * the child process can do it at the last minute. * Avoid calling setenv more often than necessary since it can leak. */ v->exported = true; v->reexport = true; return true; } static bool ExportVarLiteral(Var *v) { if (v->exported && !v->reexport) return false; if (!v->exported) setenv(v->name.str, v->val.data, 1); return true; } /* * Mark a single variable to be exported later for subprocesses. * * Internal variables (those starting with '.') are not exported. */ static bool ExportVar(const char *name, VarExportMode mode) { Var *v; if (!MayExport(name)) return false; v = VarFind(name, SCOPE_GLOBAL, false); if (v == NULL) return false; if (mode == VEM_ENV) return ExportVarEnv(v); else if (mode == VEM_PLAIN) return ExportVarPlain(v); else return ExportVarLiteral(v); } /* * Actually export the variables that have been marked as needing to be * re-exported. */ void Var_ReexportVars(void) { char *xvarnames; /* * Several make implementations support this sort of mechanism for * tracking recursion - but each uses a different name. * We allow the makefiles to update MAKELEVEL and ensure * children see a correctly incremented value. */ char tmp[21]; snprintf(tmp, sizeof tmp, "%d", makelevel + 1); setenv(MAKE_LEVEL_ENV, tmp, 1); if (var_exportedVars == VAR_EXPORTED_NONE) return; if (var_exportedVars == VAR_EXPORTED_ALL) { HashIter hi; /* Ouch! Exporting all variables at once is crazy. */ HashIter_Init(&hi, &SCOPE_GLOBAL->vars); while (HashIter_Next(&hi) != NULL) { Var *var = hi.entry->value; ExportVar(var->name.str, VEM_ENV); } return; } xvarnames = Var_Subst("${.MAKE.EXPORTED:O:u}", SCOPE_GLOBAL, VARE_WANTRES); /* TODO: handle errors */ if (xvarnames[0] != '\0') { Words varnames = Str_Words(xvarnames, false); size_t i; for (i = 0; i < varnames.len; i++) ExportVar(varnames.words[i], VEM_ENV); Words_Free(varnames); } free(xvarnames); } static void ExportVars(const char *varnames, bool isExport, VarExportMode mode) /* TODO: try to combine the parameters 'isExport' and 'mode'. */ { Words words = Str_Words(varnames, false); size_t i; if (words.len == 1 && words.words[0][0] == '\0') words.len = 0; for (i = 0; i < words.len; i++) { const char *varname = words.words[i]; if (!ExportVar(varname, mode)) continue; if (var_exportedVars == VAR_EXPORTED_NONE) var_exportedVars = VAR_EXPORTED_SOME; if (isExport && mode == VEM_PLAIN) Global_Append(".MAKE.EXPORTED", varname); } Words_Free(words); } static void ExportVarsExpand(const char *uvarnames, bool isExport, VarExportMode mode) { char *xvarnames = Var_Subst(uvarnames, SCOPE_GLOBAL, VARE_WANTRES); /* TODO: handle errors */ ExportVars(xvarnames, isExport, mode); free(xvarnames); } /* Export the named variables, or all variables. */ void Var_Export(VarExportMode mode, const char *varnames) { if (mode == VEM_PLAIN && varnames[0] == '\0') { var_exportedVars = VAR_EXPORTED_ALL; /* use with caution! */ return; } ExportVarsExpand(varnames, true, mode); } void Var_ExportVars(const char *varnames) { ExportVarsExpand(varnames, false, VEM_PLAIN); } static void ClearEnv(void) { const char *cp; char **newenv; cp = getenv(MAKE_LEVEL_ENV); /* we should preserve this */ if (environ == savedEnv) { /* we have been here before! */ newenv = bmake_realloc(environ, 2 * sizeof(char *)); } else { if (savedEnv != NULL) { free(savedEnv); savedEnv = NULL; } newenv = bmake_malloc(2 * sizeof(char *)); } /* Note: we cannot safely free() the original environ. */ environ = savedEnv = newenv; newenv[0] = NULL; newenv[1] = NULL; if (cp != NULL && *cp != '\0') setenv(MAKE_LEVEL_ENV, cp, 1); } static void GetVarnamesToUnexport(bool isEnv, const char *arg, FStr *out_varnames, UnexportWhat *out_what) { UnexportWhat what; FStr varnames = FStr_InitRefer(""); if (isEnv) { if (arg[0] != '\0') { Parse_Error(PARSE_FATAL, "The directive .unexport-env does not take " "arguments"); /* continue anyway */ } what = UNEXPORT_ENV; } else { what = arg[0] != '\0' ? UNEXPORT_NAMED : UNEXPORT_ALL; if (what == UNEXPORT_NAMED) varnames = FStr_InitRefer(arg); } if (what != UNEXPORT_NAMED) { char *expanded = Var_Subst("${.MAKE.EXPORTED:O:u}", SCOPE_GLOBAL, VARE_WANTRES); /* TODO: handle errors */ varnames = FStr_InitOwn(expanded); } *out_varnames = varnames; *out_what = what; } static void UnexportVar(Substring varname, UnexportWhat what) { Var *v = VarFindSubstring(varname, SCOPE_GLOBAL, false); if (v == NULL) { DEBUG2(VAR, "Not unexporting \"%.*s\" (not found)\n", (int)Substring_Length(varname), varname.start); return; } DEBUG2(VAR, "Unexporting \"%.*s\"\n", (int)Substring_Length(varname), varname.start); if (what != UNEXPORT_ENV && v->exported && !v->reexport) unsetenv(v->name.str); v->exported = false; v->reexport = false; if (what == UNEXPORT_NAMED) { /* Remove the variable names from .MAKE.EXPORTED. */ /* XXX: v->name is injected without escaping it */ char *expr = str_concat3("${.MAKE.EXPORTED:N", v->name.str, "}"); char *cp = Var_Subst(expr, SCOPE_GLOBAL, VARE_WANTRES); /* TODO: handle errors */ Global_Set(".MAKE.EXPORTED", cp); free(cp); free(expr); } } static void UnexportVars(FStr *varnames, UnexportWhat what) { size_t i; SubstringWords words; if (what == UNEXPORT_ENV) ClearEnv(); words = Substring_Words(varnames->str, false); for (i = 0; i < words.len; i++) UnexportVar(words.words[i], what); SubstringWords_Free(words); if (what != UNEXPORT_NAMED) Global_Delete(".MAKE.EXPORTED"); } /* * This is called when .unexport[-env] is seen. * * str must have the form "unexport[-env] varname...". */ void Var_UnExport(bool isEnv, const char *arg) { UnexportWhat what; FStr varnames; GetVarnamesToUnexport(isEnv, arg, &varnames, &what); UnexportVars(&varnames, what); FStr_Done(&varnames); } /* * When there is a variable of the same name in the command line scope, the * global variable would not be visible anywhere. Therefore there is no * point in setting it at all. * * See 'scope == SCOPE_CMDLINE' in Var_SetWithFlags. */ static bool ExistsInCmdline(const char *name, const char *val) { Var *v; v = VarFind(name, SCOPE_CMDLINE, false); if (v == NULL) return false; if (v->fromCmd) { DEBUG3(VAR, "%s: %s = %s ignored!\n", SCOPE_GLOBAL->name, name, val); return true; } VarFreeShortLived(v); return false; } /* Set the variable to the value; the name is not expanded. */ void Var_SetWithFlags(GNode *scope, const char *name, const char *val, VarSetFlags flags) { Var *v; assert(val != NULL); if (name[0] == '\0') { DEBUG0(VAR, "SetVar: variable name is empty - ignored\n"); return; } if (scope == SCOPE_GLOBAL && ExistsInCmdline(name, val)) return; /* * Only look for a variable in the given scope since anything set * here will override anything in a lower scope, so there's not much * point in searching them all. */ v = VarFind(name, scope, false); if (v == NULL) { if (scope == SCOPE_CMDLINE && !(flags & VAR_SET_NO_EXPORT)) { /* * This var would normally prevent the same name being * added to SCOPE_GLOBAL, so delete it from there if * needed. Otherwise -V name may show the wrong value. * * See ExistsInCmdline. */ Var_Delete(SCOPE_GLOBAL, name); } if (strcmp(name, ".SUFFIXES") == 0) { /* special: treat as readOnly */ DEBUG3(VAR, "%s: %s = %s ignored (read-only)\n", scope->name, name, val); return; } v = VarAdd(name, val, scope, flags); } else { if (v->readOnly && !(flags & VAR_SET_READONLY)) { DEBUG3(VAR, "%s: %s = %s ignored (read-only)\n", scope->name, name, val); return; } Buf_Clear(&v->val); Buf_AddStr(&v->val, val); DEBUG4(VAR, "%s: %s = %s%s\n", scope->name, name, val, ValueDescription(val)); if (v->exported) ExportVar(name, VEM_PLAIN); } /* * Any variables given on the command line are automatically exported * to the environment (as per POSIX standard), except for internals. */ if (scope == SCOPE_CMDLINE && !(flags & VAR_SET_NO_EXPORT) && name[0] != '.') { v->fromCmd = true; /* * If requested, don't export these in the environment * individually. We still put them in .MAKEOVERRIDES so * that the command-line settings continue to override * Makefile settings. */ if (!opts.varNoExportEnv) setenv(name, val, 1); /* XXX: What about .MAKE.EXPORTED? */ /* * XXX: Why not just mark the variable for needing export, as * in ExportVarPlain? */ Global_Append(".MAKEOVERRIDES", name); } if (name[0] == '.' && strcmp(name, MAKE_SAVE_DOLLARS) == 0) save_dollars = ParseBoolean(val, save_dollars); if (v != NULL) VarFreeShortLived(v); } void Var_Set(GNode *scope, const char *name, const char *val) { Var_SetWithFlags(scope, name, val, VAR_SET_NONE); } /* * Set the variable name to the value val in the given scope. * * If the variable doesn't yet exist, it is created. * Otherwise the new value overwrites and replaces the old value. * * Input: * scope scope in which to set it * name name of the variable to set, is expanded once * val value to give to the variable */ void Var_SetExpand(GNode *scope, const char *name, const char *val) { const char *unexpanded_name = name; FStr varname = FStr_InitRefer(name); assert(val != NULL); Var_Expand(&varname, scope, VARE_WANTRES); if (varname.str[0] == '\0') { DEBUG2(VAR, "Var_SetExpand: variable name \"%s\" expands " "to empty string, with value \"%s\" - ignored\n", unexpanded_name, val); } else Var_SetWithFlags(scope, varname.str, val, VAR_SET_NONE); FStr_Done(&varname); } void Global_Set(const char *name, const char *value) { Var_Set(SCOPE_GLOBAL, name, value); } void Global_Delete(const char *name) { Var_Delete(SCOPE_GLOBAL, name); } void Global_Set_ReadOnly(const char *name, const char *value) { Var_SetWithFlags(SCOPE_GLOBAL, name, value, VAR_SET_READONLY); } /* * Append the value to the named variable. * * If the variable doesn't exist, it is created. Otherwise a single space * and the given value are appended. */ void Var_Append(GNode *scope, const char *name, const char *val) { Var *v; v = VarFind(name, scope, scope == SCOPE_GLOBAL); if (v == NULL) { Var_SetWithFlags(scope, name, val, VAR_SET_NONE); } else if (v->readOnly) { DEBUG1(VAR, "Ignoring append to %s since it is read-only\n", name); } else if (scope == SCOPE_CMDLINE || !v->fromCmd) { Buf_AddByte(&v->val, ' '); Buf_AddStr(&v->val, val); DEBUG3(VAR, "%s: %s = %s\n", scope->name, name, v->val.data); if (v->fromEnvironment) { /* See VarAdd. */ HashEntry *he = HashTable_CreateEntry(&scope->vars, name, NULL); HashEntry_Set(he, v); FStr_Done(&v->name); v->name = FStr_InitRefer(/* aliased to */ he->key); v->shortLived = false; v->fromEnvironment = false; } } } /* * The variable of the given name has the given value appended to it in the * given scope. * * If the variable doesn't exist, it is created. Otherwise the strings are * concatenated, with a space in between. * * Input: * scope scope in which this should occur * name name of the variable to modify, is expanded once * val string to append to it * * Notes: * Only if the variable is being sought in the global scope is the * environment searched. * XXX: Knows its calling circumstances in that if called with scope * an actual target, it will only search that scope since only * a local variable could be being appended to. This is actually * a big win and must be tolerated. */ void Var_AppendExpand(GNode *scope, const char *name, const char *val) { FStr xname = FStr_InitRefer(name); assert(val != NULL); Var_Expand(&xname, scope, VARE_WANTRES); if (xname.str != name && xname.str[0] == '\0') DEBUG2(VAR, "Var_AppendExpand: variable name \"%s\" expands " "to empty string, with value \"%s\" - ignored\n", name, val); else Var_Append(scope, xname.str, val); FStr_Done(&xname); } void Global_Append(const char *name, const char *value) { Var_Append(SCOPE_GLOBAL, name, value); } bool Var_Exists(GNode *scope, const char *name) { Var *v = VarFind(name, scope, true); if (v == NULL) return false; VarFreeShortLived(v); return true; } /* * See if the given variable exists, in the given scope or in other * fallback scopes. * * Input: * scope scope in which to start search * name name of the variable to find, is expanded once */ bool Var_ExistsExpand(GNode *scope, const char *name) { FStr varname = FStr_InitRefer(name); bool exists; Var_Expand(&varname, scope, VARE_WANTRES); exists = Var_Exists(scope, varname.str); FStr_Done(&varname); return exists; } /* * Return the unexpanded value of the given variable in the given scope, * or the usual scopes. * * Input: * scope scope in which to search for it * name name to find, is not expanded any further * * Results: * The value if the variable exists, NULL if it doesn't. * The value is valid until the next modification to any variable. */ FStr Var_Value(GNode *scope, const char *name) { Var *v = VarFind(name, scope, true); char *value; if (v == NULL) return FStr_InitRefer(NULL); if (!v->shortLived) return FStr_InitRefer(v->val.data); value = v->val.data; v->val.data = NULL; VarFreeShortLived(v); return FStr_InitOwn(value); } /* * set readOnly attribute of specified var if it exists */ void Var_ReadOnly(const char *name, bool bf) { Var *v; v = VarFind(name, SCOPE_GLOBAL, false); if (v == NULL) { DEBUG1(VAR, "Var_ReadOnly: %s not found\n", name); return; } v->readOnly = bf; DEBUG2(VAR, "Var_ReadOnly: %s %s\n", name, bf ? "true" : "false"); } /* * Return the unexpanded variable value from this node, without trying to look * up the variable in any other scope. */ const char * GNode_ValueDirect(GNode *gn, const char *name) { Var *v = VarFind(name, gn, false); return v != NULL ? v->val.data : NULL; } static VarEvalMode VarEvalMode_WithoutKeepDollar(VarEvalMode emode) { if (emode == VARE_KEEP_DOLLAR_UNDEF) return VARE_EVAL_KEEP_UNDEF; if (emode == VARE_EVAL_KEEP_DOLLAR) return VARE_WANTRES; return emode; } static VarEvalMode VarEvalMode_UndefOk(VarEvalMode emode) { return emode == VARE_UNDEFERR ? VARE_WANTRES : emode; } static bool VarEvalMode_ShouldEval(VarEvalMode emode) { return emode != VARE_PARSE_ONLY; } static bool VarEvalMode_ShouldKeepUndef(VarEvalMode emode) { return emode == VARE_EVAL_KEEP_UNDEF || emode == VARE_KEEP_DOLLAR_UNDEF; } static bool VarEvalMode_ShouldKeepDollar(VarEvalMode emode) { return emode == VARE_EVAL_KEEP_DOLLAR || emode == VARE_KEEP_DOLLAR_UNDEF; } static void SepBuf_Init(SepBuf *buf, char sep) { Buf_InitSize(&buf->buf, 32); buf->needSep = false; buf->sep = sep; } static void SepBuf_Sep(SepBuf *buf) { buf->needSep = true; } static void SepBuf_AddBytes(SepBuf *buf, const char *mem, size_t mem_size) { if (mem_size == 0) return; if (buf->needSep && buf->sep != '\0') { Buf_AddByte(&buf->buf, buf->sep); buf->needSep = false; } Buf_AddBytes(&buf->buf, mem, mem_size); } static void SepBuf_AddBytesBetween(SepBuf *buf, const char *start, const char *end) { SepBuf_AddBytes(buf, start, (size_t)(end - start)); } static void SepBuf_AddStr(SepBuf *buf, const char *str) { SepBuf_AddBytes(buf, str, strlen(str)); } static void SepBuf_AddSubstring(SepBuf *buf, Substring sub) { SepBuf_AddBytesBetween(buf, sub.start, sub.end); } static char * SepBuf_DoneData(SepBuf *buf) { return Buf_DoneData(&buf->buf); } /* * This callback for ModifyWords gets a single word from a variable expression * and typically adds a modification of this word to the buffer. It may also * do nothing or add several words. * * For example, when evaluating the modifier ':M*b' in ${:Ua b c:M*b}, the * callback is called 3 times, once for "a", "b" and "c". * * Some ModifyWord functions assume that they are always passed a * null-terminated substring, which is currently guaranteed but may change in * the future. */ typedef void (*ModifyWordProc)(Substring word, SepBuf *buf, void *data); /* * Callback for ModifyWords to implement the :H modifier. * Add the dirname of the given word to the buffer. */ /*ARGSUSED*/ static void ModifyWord_Head(Substring word, SepBuf *buf, void *dummy MAKE_ATTR_UNUSED) { SepBuf_AddSubstring(buf, Substring_Dirname(word)); } /* * Callback for ModifyWords to implement the :T modifier. * Add the basename of the given word to the buffer. */ /*ARGSUSED*/ static void ModifyWord_Tail(Substring word, SepBuf *buf, void *dummy MAKE_ATTR_UNUSED) { SepBuf_AddSubstring(buf, Substring_Basename(word)); } /* * Callback for ModifyWords to implement the :E modifier. * Add the filename suffix of the given word to the buffer, if it exists. */ /*ARGSUSED*/ static void ModifyWord_Suffix(Substring word, SepBuf *buf, void *dummy MAKE_ATTR_UNUSED) { const char *lastDot = Substring_LastIndex(word, '.'); if (lastDot != NULL) SepBuf_AddBytesBetween(buf, lastDot + 1, word.end); } /* * Callback for ModifyWords to implement the :R modifier. * Add the filename without extension of the given word to the buffer. */ /*ARGSUSED*/ static void ModifyWord_Root(Substring word, SepBuf *buf, void *dummy MAKE_ATTR_UNUSED) { const char *lastDot, *end; lastDot = Substring_LastIndex(word, '.'); end = lastDot != NULL ? lastDot : word.end; SepBuf_AddBytesBetween(buf, word.start, end); } /* * Callback for ModifyWords to implement the :M modifier. * Place the word in the buffer if it matches the given pattern. */ static void ModifyWord_Match(Substring word, SepBuf *buf, void *data) { const char *pattern = data; assert(word.end[0] == '\0'); /* assume null-terminated word */ if (Str_Match(word.start, pattern)) SepBuf_AddSubstring(buf, word); } /* * Callback for ModifyWords to implement the :N modifier. * Place the word in the buffer if it doesn't match the given pattern. */ static void ModifyWord_NoMatch(Substring word, SepBuf *buf, void *data) { const char *pattern = data; assert(word.end[0] == '\0'); /* assume null-terminated word */ if (!Str_Match(word.start, pattern)) SepBuf_AddSubstring(buf, word); } #ifdef SYSVVARSUB struct ModifyWord_SysVSubstArgs { GNode *scope; Substring lhsPrefix; bool lhsPercent; Substring lhsSuffix; const char *rhs; }; /* Callback for ModifyWords to implement the :%.from=%.to modifier. */ static void ModifyWord_SysVSubst(Substring word, SepBuf *buf, void *data) { const struct ModifyWord_SysVSubstArgs *args = data; FStr rhs; const char *percent; if (Substring_IsEmpty(word)) return; if (!Substring_HasPrefix(word, args->lhsPrefix) || !Substring_HasSuffix(word, args->lhsSuffix)) { SepBuf_AddSubstring(buf, word); return; } rhs = FStr_InitRefer(args->rhs); Var_Expand(&rhs, args->scope, VARE_WANTRES); percent = args->lhsPercent ? strchr(rhs.str, '%') : NULL; if (percent != NULL) SepBuf_AddBytesBetween(buf, rhs.str, percent); if (percent != NULL || !args->lhsPercent) SepBuf_AddBytesBetween(buf, word.start + Substring_Length(args->lhsPrefix), word.end - Substring_Length(args->lhsSuffix)); SepBuf_AddStr(buf, percent != NULL ? percent + 1 : rhs.str); FStr_Done(&rhs); } #endif struct ModifyWord_SubstArgs { Substring lhs; Substring rhs; PatternFlags pflags; bool matched; }; static const char * Substring_Find(Substring haystack, Substring needle) { size_t len, needleLen, i; len = Substring_Length(haystack); needleLen = Substring_Length(needle); for (i = 0; i + needleLen <= len; i++) if (memcmp(haystack.start + i, needle.start, needleLen) == 0) return haystack.start + i; return NULL; } /* * Callback for ModifyWords to implement the :S,from,to, modifier. * Perform a string substitution on the given word. */ static void ModifyWord_Subst(Substring word, SepBuf *buf, void *data) { struct ModifyWord_SubstArgs *args = data; size_t wordLen, lhsLen; const char *wordEnd, *match; wordLen = Substring_Length(word); wordEnd = word.end; if (args->pflags.subOnce && args->matched) goto nosub; lhsLen = Substring_Length(args->lhs); if (args->pflags.anchorStart) { if (wordLen < lhsLen || memcmp(word.start, args->lhs.start, lhsLen) != 0) goto nosub; if (args->pflags.anchorEnd && wordLen != lhsLen) goto nosub; /* :S,^prefix,replacement, or :S,^whole$,replacement, */ SepBuf_AddSubstring(buf, args->rhs); SepBuf_AddBytesBetween(buf, word.start + lhsLen, wordEnd); args->matched = true; return; } if (args->pflags.anchorEnd) { if (wordLen < lhsLen) goto nosub; if (memcmp(wordEnd - lhsLen, args->lhs.start, lhsLen) != 0) goto nosub; /* :S,suffix$,replacement, */ SepBuf_AddBytesBetween(buf, word.start, wordEnd - lhsLen); SepBuf_AddSubstring(buf, args->rhs); args->matched = true; return; } if (Substring_IsEmpty(args->lhs)) goto nosub; /* unanchored case, may match more than once */ while ((match = Substring_Find(word, args->lhs)) != NULL) { SepBuf_AddBytesBetween(buf, word.start, match); SepBuf_AddSubstring(buf, args->rhs); args->matched = true; word.start = match + lhsLen; if (Substring_IsEmpty(word) || !args->pflags.subGlobal) break; } nosub: SepBuf_AddSubstring(buf, word); } #ifndef NO_REGEX /* Print the error caused by a regcomp or regexec call. */ static void VarREError(int reerr, const regex_t *pat, const char *str) { size_t errlen = regerror(reerr, pat, NULL, 0); char *errbuf = bmake_malloc(errlen); regerror(reerr, pat, errbuf, errlen); Error("%s: %s", str, errbuf); free(errbuf); } /* In the modifier ':C', replace a backreference from \0 to \9. */ static void RegexReplaceBackref(char ref, SepBuf *buf, const char *wp, const regmatch_t *m, size_t nsub) { unsigned int n = (unsigned)ref - '0'; if (n >= nsub) Error("No subexpression \\%u", n); else if (m[n].rm_so == -1) { if (opts.strict) Error("No match for subexpression \\%u", n); } else { SepBuf_AddBytesBetween(buf, wp + (size_t)m[n].rm_so, wp + (size_t)m[n].rm_eo); } } /* * The regular expression matches the word; now add the replacement to the * buffer, taking back-references from 'wp'. */ static void RegexReplace(Substring replace, SepBuf *buf, const char *wp, const regmatch_t *m, size_t nsub) { const char *rp; for (rp = replace.start; rp != replace.end; rp++) { if (*rp == '\\' && rp + 1 != replace.end && (rp[1] == '&' || rp[1] == '\\')) SepBuf_AddBytes(buf, ++rp, 1); else if (*rp == '\\' && rp + 1 != replace.end && ch_isdigit(rp[1])) RegexReplaceBackref(*++rp, buf, wp, m, nsub); else if (*rp == '&') { SepBuf_AddBytesBetween(buf, wp + (size_t)m[0].rm_so, wp + (size_t)m[0].rm_eo); } else SepBuf_AddBytes(buf, rp, 1); } } struct ModifyWord_SubstRegexArgs { regex_t re; size_t nsub; Substring replace; PatternFlags pflags; bool matched; }; /* * Callback for ModifyWords to implement the :C/from/to/ modifier. * Perform a regex substitution on the given word. */ static void ModifyWord_SubstRegex(Substring word, SepBuf *buf, void *data) { struct ModifyWord_SubstRegexArgs *args = data; int xrv; const char *wp; int flags = 0; regmatch_t m[10]; assert(word.end[0] == '\0'); /* assume null-terminated word */ wp = word.start; if (args->pflags.subOnce && args->matched) goto no_match; again: xrv = regexec(&args->re, wp, args->nsub, m, flags); if (xrv == 0) goto ok; if (xrv != REG_NOMATCH) VarREError(xrv, &args->re, "Unexpected regex error"); no_match: SepBuf_AddBytesBetween(buf, wp, word.end); return; ok: args->matched = true; SepBuf_AddBytes(buf, wp, (size_t)m[0].rm_so); RegexReplace(args->replace, buf, wp, m, args->nsub); wp += (size_t)m[0].rm_eo; if (args->pflags.subGlobal) { flags |= REG_NOTBOL; if (m[0].rm_so == 0 && m[0].rm_eo == 0) { SepBuf_AddBytes(buf, wp, 1); wp++; } if (*wp != '\0') goto again; } if (*wp != '\0') SepBuf_AddStr(buf, wp); } #endif struct ModifyWord_LoopArgs { GNode *scope; const char *var; /* name of the temporary variable */ const char *body; /* string to expand */ VarEvalMode emode; }; /* Callback for ModifyWords to implement the :@var@...@ modifier of ODE make. */ static void ModifyWord_Loop(Substring word, SepBuf *buf, void *data) { const struct ModifyWord_LoopArgs *args; char *s; if (Substring_IsEmpty(word)) return; args = data; assert(word.end[0] == '\0'); /* assume null-terminated word */ Var_SetWithFlags(args->scope, args->var, word.start, VAR_SET_NO_EXPORT); s = Var_Subst(args->body, args->scope, args->emode); /* TODO: handle errors */ assert(word.end[0] == '\0'); /* assume null-terminated word */ DEBUG4(VAR, "ModifyWord_Loop: " "in \"%s\", replace \"%s\" with \"%s\" to \"%s\"\n", word.start, args->var, args->body, s); if (s[0] == '\n' || Buf_EndsWith(&buf->buf, '\n')) buf->needSep = false; SepBuf_AddStr(buf, s); free(s); } /* * The :[first..last] modifier selects words from the expression. * It can also reverse the words. */ static char * VarSelectWords(const char *str, int first, int last, char sep, bool oneBigWord) { SubstringWords words; int len, start, end, step; int i; SepBuf buf; SepBuf_Init(&buf, sep); if (oneBigWord) { /* fake what Substring_Words() would do */ words.len = 1; words.words = bmake_malloc(sizeof(words.words[0])); words.freeIt = NULL; words.words[0] = Substring_InitStr(str); /* no need to copy */ } else { words = Substring_Words(str, false); } /* * Now sanitize the given range. If first or last are negative, * convert them to the positive equivalents (-1 gets converted to len, * -2 gets converted to (len - 1), etc.). */ len = (int)words.len; if (first < 0) first += len + 1; if (last < 0) last += len + 1; /* We avoid scanning more of the list than we need to. */ if (first > last) { start = (first > len ? len : first) - 1; end = last < 1 ? 0 : last - 1; step = -1; } else { start = first < 1 ? 0 : first - 1; end = last > len ? len : last; step = 1; } for (i = start; (step < 0) == (i >= end); i += step) { SepBuf_AddSubstring(&buf, words.words[i]); SepBuf_Sep(&buf); } SubstringWords_Free(words); return SepBuf_DoneData(&buf); } /* * Callback for ModifyWords to implement the :tA modifier. * Replace each word with the result of realpath() if successful. */ /*ARGSUSED*/ static void ModifyWord_Realpath(Substring word, SepBuf *buf, void *data MAKE_ATTR_UNUSED) { struct stat st; char rbuf[MAXPATHLEN]; const char *rp; assert(word.end[0] == '\0'); /* assume null-terminated word */ rp = cached_realpath(word.start, rbuf); if (rp != NULL && *rp == '/' && stat(rp, &st) == 0) SepBuf_AddStr(buf, rp); else SepBuf_AddSubstring(buf, word); } static char * SubstringWords_JoinFree(SubstringWords words) { Buffer buf; size_t i; Buf_Init(&buf); for (i = 0; i < words.len; i++) { if (i != 0) { /* * XXX: Use ch->sep instead of ' ', for consistency. */ Buf_AddByte(&buf, ' '); } Buf_AddBytesBetween(&buf, words.words[i].start, words.words[i].end); } SubstringWords_Free(words); return Buf_DoneData(&buf); } /* * Quote shell meta-characters and space characters in the string. * If quoteDollar is set, also quote and double any '$' characters. */ static void VarQuote(const char *str, bool quoteDollar, LazyBuf *buf) { const char *p; LazyBuf_Init(buf, str); for (p = str; *p != '\0'; p++) { if (*p == '\n') { const char *newline = Shell_GetNewline(); if (newline == NULL) newline = "\\\n"; LazyBuf_AddStr(buf, newline); continue; } if (ch_isspace(*p) || ch_is_shell_meta(*p)) LazyBuf_Add(buf, '\\'); LazyBuf_Add(buf, *p); if (quoteDollar && *p == '$') LazyBuf_AddStr(buf, "\\$"); } } /* * Compute the 32-bit hash of the given string, using the MurmurHash3 * algorithm. Output is encoded as 8 hex digits, in Little Endian order. */ static char * VarHash(const char *str) { static const char hexdigits[16] = "0123456789abcdef"; const unsigned char *ustr = (const unsigned char *)str; uint32_t h = 0x971e137bU; uint32_t c1 = 0x95543787U; uint32_t c2 = 0x2ad7eb25U; size_t len2 = strlen(str); char *buf; size_t i; size_t len; for (len = len2; len != 0;) { uint32_t k = 0; switch (len) { default: k = ((uint32_t)ustr[3] << 24) | ((uint32_t)ustr[2] << 16) | ((uint32_t)ustr[1] << 8) | (uint32_t)ustr[0]; len -= 4; ustr += 4; break; case 3: k |= (uint32_t)ustr[2] << 16; /* FALLTHROUGH */ case 2: k |= (uint32_t)ustr[1] << 8; /* FALLTHROUGH */ case 1: k |= (uint32_t)ustr[0]; len = 0; } c1 = c1 * 5 + 0x7b7d159cU; c2 = c2 * 5 + 0x6bce6396U; k *= c1; k = (k << 11) ^ (k >> 21); k *= c2; h = (h << 13) ^ (h >> 19); h = h * 5 + 0x52dce729U; h ^= k; } h ^= (uint32_t)len2; h *= 0x85ebca6b; h ^= h >> 13; h *= 0xc2b2ae35; h ^= h >> 16; buf = bmake_malloc(9); for (i = 0; i < 8; i++) { buf[i] = hexdigits[h & 0x0f]; h >>= 4; } buf[8] = '\0'; return buf; } static char * VarStrftime(const char *fmt, time_t t, bool gmt) { char buf[BUFSIZ]; if (t == 0) time(&t); if (*fmt == '\0') fmt = "%c"; strftime(buf, sizeof buf, fmt, gmt ? gmtime(&t) : localtime(&t)); buf[sizeof buf - 1] = '\0'; return bmake_strdup(buf); } /* * The ApplyModifier functions take an expression that is being evaluated. * Their task is to apply a single modifier to the expression. This involves * parsing the modifier, evaluating it and finally updating the value of the * expression. * * Parsing the modifier * * If parsing succeeds, the parsing position *pp is updated to point to the * first character following the modifier, which typically is either ':' or * ch->endc. The modifier doesn't have to check for this delimiter character, * this is done by ApplyModifiers. * * XXX: As of 2020-11-15, some modifiers such as :S, :C, :P, :L do not * need to be followed by a ':' or endc; this was an unintended mistake. * * If parsing fails because of a missing delimiter (as in the :S, :C or :@ * modifiers), return AMR_CLEANUP. * * If parsing fails because the modifier is unknown, return AMR_UNKNOWN to * try the SysV modifier ${VAR:from=to} as fallback. This should only be * done as long as there have been no side effects from evaluating nested * variables, to avoid evaluating them more than once. In this case, the * parsing position may or may not be updated. (XXX: Why not? The original * parsing position is well-known in ApplyModifiers.) * * If parsing fails and the SysV modifier ${VAR:from=to} should not be used * as a fallback, either issue an error message using Error or Parse_Error * and then return AMR_CLEANUP, or return AMR_BAD for the default error * message. Both of these return values will stop processing the variable * expression. (XXX: As of 2020-08-23, evaluation of the whole string * continues nevertheless after skipping a few bytes, which essentially is * undefined behavior. Not in the sense of C, but still the resulting string * is garbage.) * * Evaluating the modifier * * After parsing, the modifier is evaluated. The side effects from evaluating * nested variable expressions in the modifier text often already happen * during parsing though. For most modifiers this doesn't matter since their * only noticeable effect is that they update the value of the expression. * Some modifiers such as ':sh' or '::=' have noticeable side effects though. * * Evaluating the modifier usually takes the current value of the variable * expression from ch->expr->value, or the variable name from ch->var->name * and stores the result back in expr->value via Expr_SetValueOwn or * Expr_SetValueRefer. * * If evaluating fails (as of 2020-08-23), an error message is printed using * Error. This function has no side-effects, it really just prints the error * message. Processing the expression continues as if everything were ok. * XXX: This should be fixed by adding proper error handling to Var_Subst, * Var_Parse, ApplyModifiers and ModifyWords. * * Housekeeping * * Some modifiers such as :D and :U turn undefined expressions into defined * expressions (see Expr_Define). * * Some modifiers need to free some memory. */ typedef enum ExprDefined { /* The variable expression is based on a regular, defined variable. */ DEF_REGULAR, /* The variable expression is based on an undefined variable. */ DEF_UNDEF, /* * The variable expression started as an undefined expression, but one * of the modifiers (such as ':D' or ':U') has turned the expression * from undefined to defined. */ DEF_DEFINED } ExprDefined; static const char ExprDefined_Name[][10] = { "regular", "undefined", "defined" }; #if __STDC_VERSION__ >= 199901L #define const_member const #else #define const_member /* no const possible */ #endif /* An expression based on a variable, such as $@ or ${VAR:Mpattern:Q}. */ typedef struct Expr { const char *name; FStr value; VarEvalMode const_member emode; GNode *const_member scope; ExprDefined defined; } Expr; /* * The status of applying a chain of modifiers to an expression. * * The modifiers of an expression are broken into chains of modifiers, * starting a new nested chain whenever an indirect modifier starts. There * are at most 2 nesting levels: the outer one for the direct modifiers, and * the inner one for the indirect modifiers. * * For example, the expression ${VAR:M*:${IND1}:${IND2}:O:u} has 3 chains of * modifiers: * * Chain 1 starts with the single modifier ':M*'. * Chain 2 starts with all modifiers from ${IND1}. * Chain 2 ends at the ':' between ${IND1} and ${IND2}. * Chain 3 starts with all modifiers from ${IND2}. * Chain 3 ends at the ':' after ${IND2}. * Chain 1 continues with the 2 modifiers ':O' and ':u'. * Chain 1 ends at the final '}' of the expression. * * After such a chain ends, its properties no longer have any effect. * * It may or may not have been intended that 'defined' has scope Expr while * 'sep' and 'oneBigWord' have smaller scope. * * See varmod-indirect.mk. */ typedef struct ModChain { Expr *expr; /* '\0' or '{' or '(' */ char const_member startc; /* '\0' or '}' or ')' */ char const_member endc; /* Word separator in expansions (see the :ts modifier). */ char sep; /* * True if some modifiers that otherwise split the variable value * into words, like :S and :C, treat the variable value as a single * big word, possibly containing spaces. */ bool oneBigWord; } ModChain; static void Expr_Define(Expr *expr) { if (expr->defined == DEF_UNDEF) expr->defined = DEF_DEFINED; } static const char * Expr_Str(const Expr *expr) { return expr->value.str; } static SubstringWords Expr_Words(const Expr *expr) { return Substring_Words(Expr_Str(expr), false); } static void Expr_SetValue(Expr *expr, FStr value) { FStr_Done(&expr->value); expr->value = value; } static void Expr_SetValueOwn(Expr *expr, char *value) { Expr_SetValue(expr, FStr_InitOwn(value)); } static void Expr_SetValueRefer(Expr *expr, const char *value) { Expr_SetValue(expr, FStr_InitRefer(value)); } static bool Expr_ShouldEval(const Expr *expr) { return VarEvalMode_ShouldEval(expr->emode); } static bool ModChain_ShouldEval(const ModChain *ch) { return Expr_ShouldEval(ch->expr); } typedef enum ApplyModifierResult { /* Continue parsing */ AMR_OK, /* Not a match, try other modifiers as well. */ AMR_UNKNOWN, /* Error out with "Bad modifier" message. */ AMR_BAD, /* Error out without the standard error message. */ AMR_CLEANUP } ApplyModifierResult; /* * Allow backslashes to escape the delimiter, $, and \, but don't touch other * backslashes. */ static bool IsEscapedModifierPart(const char *p, char delim, struct ModifyWord_SubstArgs *subst) { if (p[0] != '\\') return false; if (p[1] == delim || p[1] == '\\' || p[1] == '$') return true; return p[1] == '&' && subst != NULL; } /* * In a part of a modifier, parse a subexpression and evaluate it. */ static void ParseModifierPartExpr(const char **pp, LazyBuf *part, const ModChain *ch, VarEvalMode emode) { const char *p = *pp; FStr nested_val = Var_Parse(&p, ch->expr->scope, VarEvalMode_WithoutKeepDollar(emode)); /* TODO: handle errors */ if (VarEvalMode_ShouldEval(emode)) LazyBuf_AddStr(part, nested_val.str); else LazyBuf_AddSubstring(part, Substring_Init(*pp, p)); FStr_Done(&nested_val); *pp = p; } /* * In a part of a modifier, parse some text that looks like a subexpression. * If the text starts with '$(', any '(' and ')' must be balanced. * If the text starts with '${', any '{' and '}' must be balanced. * If the text starts with '$', that '$' is copied, it is not parsed as a * short-name variable expression. */ static void ParseModifierPartBalanced(const char **pp, LazyBuf *part) { const char *p = *pp; const char *start = *pp; if (p[1] == '(' || p[1] == '{') { char startc = p[1]; int endc = startc == '(' ? ')' : '}'; int depth = 1; for (p += 2; *p != '\0' && depth > 0; p++) { if (p[-1] != '\\') { if (*p == startc) depth++; if (*p == endc) depth--; } } LazyBuf_AddSubstring(part, Substring_Init(start, p)); *pp = p; } else { LazyBuf_Add(part, *start); *pp = p + 1; } } /* See ParseModifierPart for the documentation. */ static bool ParseModifierPartSubst( const char **pp, + /* If true, parse up to but excluding the next ':' or ch->endc. */ + bool whole, char delim, VarEvalMode emode, ModChain *ch, LazyBuf *part, /* * For the first part of the modifier ':S', set anchorEnd if the last * character of the pattern is a $. */ PatternFlags *out_pflags, /* * For the second part of the :S modifier, allow ampersands to be escaped * and replace unescaped ampersands with subst->lhs. */ struct ModifyWord_SubstArgs *subst ) { const char *p; + char end1, end2; p = *pp; LazyBuf_Init(part, p); - while (*p != '\0' && *p != delim) { + end1 = whole ? ':' : delim; + end2 = whole ? ch->endc : delim; + while (*p != '\0' && *p != end1 && *p != end2) { if (IsEscapedModifierPart(p, delim, subst)) { LazyBuf_Add(part, p[1]); p += 2; } else if (*p != '$') { /* Unescaped, simple text */ if (subst != NULL && *p == '&') LazyBuf_AddSubstring(part, subst->lhs); else LazyBuf_Add(part, *p); p++; } else if (p[1] == delim) { /* Unescaped '$' at end */ if (out_pflags != NULL) out_pflags->anchorEnd = true; else LazyBuf_Add(part, *p); p++; } else if (emode == VARE_PARSE_BALANCED) ParseModifierPartBalanced(&p, part); else ParseModifierPartExpr(&p, part, ch, emode); } - if (*p != delim) { - *pp = p; + *pp = p; + if (*p != end1 && *p != end2) { Error("Unfinished modifier for \"%s\" ('%c' missing)", - ch->expr->name, delim); + ch->expr->name, end2); LazyBuf_Done(part); return false; } - - *pp = p + 1; + if (!whole) + (*pp)++; { Substring sub = LazyBuf_Get(part); DEBUG2(VAR, "Modifier part: \"%.*s\"\n", (int)Substring_Length(sub), sub.start); } return true; } /* * Parse a part of a modifier such as the "from" and "to" in :S/from/to/ or * the "var" or "replacement ${var}" in :@var@replacement ${var}@, up to and * including the next unescaped delimiter. The delimiter, as well as the * backslash or the dollar, can be escaped with a backslash. * * Return true if parsing succeeded, together with the parsed (and possibly * expanded) part. In that case, pp points right after the delimiter. The * delimiter is not included in the part though. */ static bool ParseModifierPart( /* The parsing position, updated upon return */ const char **pp, /* Parsing stops at this delimiter */ char delim, /* Mode for evaluating nested variables. */ VarEvalMode emode, ModChain *ch, LazyBuf *part ) { - return ParseModifierPartSubst(pp, delim, emode, ch, part, NULL, NULL); + return ParseModifierPartSubst(pp, false, delim, emode, ch, part, + NULL, NULL); } MAKE_INLINE bool IsDelimiter(char c, const ModChain *ch) { return c == ':' || c == ch->endc || c == '\0'; } /* Test whether mod starts with modname, followed by a delimiter. */ MAKE_INLINE bool ModMatch(const char *mod, const char *modname, const ModChain *ch) { size_t n = strlen(modname); return strncmp(mod, modname, n) == 0 && IsDelimiter(mod[n], ch); } /* Test whether mod starts with modname, followed by a delimiter or '='. */ MAKE_INLINE bool ModMatchEq(const char *mod, const char *modname, const ModChain *ch) { size_t n = strlen(modname); return strncmp(mod, modname, n) == 0 && (IsDelimiter(mod[n], ch) || mod[n] == '='); } static bool TryParseIntBase0(const char **pp, int *out_num) { char *end; long n; errno = 0; n = strtol(*pp, &end, 0); if (end == *pp) return false; if ((n == LONG_MIN || n == LONG_MAX) && errno == ERANGE) return false; if (n < INT_MIN || n > INT_MAX) return false; *pp = end; *out_num = (int)n; return true; } static bool TryParseSize(const char **pp, size_t *out_num) { char *end; unsigned long n; if (!ch_isdigit(**pp)) return false; errno = 0; n = strtoul(*pp, &end, 10); if (n == ULONG_MAX && errno == ERANGE) return false; if (n > SIZE_MAX) return false; *pp = end; *out_num = (size_t)n; return true; } static bool TryParseChar(const char **pp, int base, char *out_ch) { char *end; unsigned long n; if (!ch_isalnum(**pp)) return false; errno = 0; n = strtoul(*pp, &end, base); if (n == ULONG_MAX && errno == ERANGE) return false; if (n > UCHAR_MAX) return false; *pp = end; *out_ch = (char)n; return true; } /* * Modify each word of the expression using the given function and place the * result back in the expression. */ static void ModifyWords(ModChain *ch, ModifyWordProc modifyWord, void *modifyWord_args, bool oneBigWord) { Expr *expr = ch->expr; const char *val = Expr_Str(expr); SepBuf result; SubstringWords words; size_t i; Substring word; if (oneBigWord) { SepBuf_Init(&result, ch->sep); /* XXX: performance: Substring_InitStr calls strlen */ word = Substring_InitStr(val); modifyWord(word, &result, modifyWord_args); goto done; } words = Substring_Words(val, false); DEBUG3(VAR, "ModifyWords: split \"%s\" into %u %s\n", val, (unsigned)words.len, words.len != 1 ? "words" : "word"); SepBuf_Init(&result, ch->sep); for (i = 0; i < words.len; i++) { modifyWord(words.words[i], &result, modifyWord_args); if (result.buf.len > 0) SepBuf_Sep(&result); } SubstringWords_Free(words); done: Expr_SetValueOwn(expr, SepBuf_DoneData(&result)); } /* :@var@...${var}...@ */ static ApplyModifierResult ApplyModifier_Loop(const char **pp, ModChain *ch) { Expr *expr = ch->expr; struct ModifyWord_LoopArgs args; char prev_sep; LazyBuf tvarBuf, strBuf; FStr tvar, str; args.scope = expr->scope; (*pp)++; /* Skip the first '@' */ if (!ParseModifierPart(pp, '@', VARE_PARSE_ONLY, ch, &tvarBuf)) return AMR_CLEANUP; tvar = LazyBuf_DoneGet(&tvarBuf); args.var = tvar.str; if (strchr(args.var, '$') != NULL) { Parse_Error(PARSE_FATAL, "In the :@ modifier of \"%s\", the variable name \"%s\" " "must not contain a dollar", expr->name, args.var); return AMR_CLEANUP; } if (!ParseModifierPart(pp, '@', VARE_PARSE_BALANCED, ch, &strBuf)) return AMR_CLEANUP; str = LazyBuf_DoneGet(&strBuf); args.body = str.str; if (!Expr_ShouldEval(expr)) goto done; args.emode = VarEvalMode_WithoutKeepDollar(expr->emode); prev_sep = ch->sep; ch->sep = ' '; /* XXX: should be ch->sep for consistency */ ModifyWords(ch, ModifyWord_Loop, &args, ch->oneBigWord); ch->sep = prev_sep; /* XXX: Consider restoring the previous value instead of deleting. */ Var_Delete(expr->scope, args.var); done: FStr_Done(&tvar); FStr_Done(&str); return AMR_OK; } static void ParseModifier_Defined(const char **pp, ModChain *ch, bool shouldEval, LazyBuf *buf) { const char *p; p = *pp + 1; LazyBuf_Init(buf, p); while (!IsDelimiter(*p, ch)) { /* * XXX: This code is similar to the one in Var_Parse. See if * the code can be merged. See also ApplyModifier_Match and * ParseModifierPart. */ /* Escaped delimiter or other special character */ /* See Buf_AddEscaped in for.c. */ if (*p == '\\') { char c = p[1]; if ((IsDelimiter(c, ch) && c != '\0') || c == '$' || c == '\\') { if (shouldEval) LazyBuf_Add(buf, c); p += 2; continue; } } /* Nested variable expression */ if (*p == '$') { FStr val = Var_Parse(&p, ch->expr->scope, shouldEval ? ch->expr->emode : VARE_PARSE_ONLY); /* TODO: handle errors */ if (shouldEval) LazyBuf_AddStr(buf, val.str); FStr_Done(&val); continue; } /* Ordinary text */ if (shouldEval) LazyBuf_Add(buf, *p); p++; } *pp = p; } /* :Ddefined or :Uundefined */ static ApplyModifierResult ApplyModifier_Defined(const char **pp, ModChain *ch) { Expr *expr = ch->expr; LazyBuf buf; bool shouldEval = Expr_ShouldEval(expr) && (**pp == 'D') == (expr->defined == DEF_REGULAR); ParseModifier_Defined(pp, ch, shouldEval, &buf); Expr_Define(expr); if (shouldEval) Expr_SetValue(expr, Substring_Str(LazyBuf_Get(&buf))); return AMR_OK; } /* :L */ static ApplyModifierResult ApplyModifier_Literal(const char **pp, ModChain *ch) { Expr *expr = ch->expr; (*pp)++; if (Expr_ShouldEval(expr)) { Expr_Define(expr); Expr_SetValueOwn(expr, bmake_strdup(expr->name)); } return AMR_OK; } static bool TryParseTime(const char **pp, time_t *out_time) { char *end; unsigned long n; if (!ch_isdigit(**pp)) return false; errno = 0; n = strtoul(*pp, &end, 10); if (n == ULONG_MAX && errno == ERANGE) return false; *pp = end; *out_time = (time_t)n; /* ignore possible truncation for now */ return true; } /* :gmtime and :localtime */ static ApplyModifierResult ApplyModifier_Time(const char **pp, ModChain *ch) { Expr *expr; time_t t; const char *args; const char *mod = *pp; bool gmt = mod[0] == 'g'; if (!ModMatchEq(mod, gmt ? "gmtime" : "localtime", ch)) return AMR_UNKNOWN; args = mod + (gmt ? 6 : 9); if (args[0] == '=') { const char *p = args + 1; - if (!TryParseTime(&p, &t)) { - Parse_Error(PARSE_FATAL, - "Invalid time value at \"%s\"", p); + LazyBuf buf; + if (!ParseModifierPartSubst(&p, true, '\0', ch->expr->emode, + ch, &buf, NULL, NULL)) return AMR_CLEANUP; - } + if (ModChain_ShouldEval(ch)) { + Substring arg = LazyBuf_Get(&buf); + const char *arg_p = arg.start; + if (!TryParseTime(&arg_p, &t) || arg_p != arg.end) { + Parse_Error(PARSE_FATAL, + "Invalid time value \"%.*s\"", + (int)Substring_Length(arg), arg.start); + LazyBuf_Done(&buf); + return AMR_CLEANUP; + } + } else + t = 0; + LazyBuf_Done(&buf); *pp = p; } else { t = 0; *pp = args; } expr = ch->expr; if (Expr_ShouldEval(expr)) Expr_SetValueOwn(expr, VarStrftime(Expr_Str(expr), t, gmt)); return AMR_OK; } /* :hash */ static ApplyModifierResult ApplyModifier_Hash(const char **pp, ModChain *ch) { if (!ModMatch(*pp, "hash", ch)) return AMR_UNKNOWN; *pp += 4; if (ModChain_ShouldEval(ch)) Expr_SetValueOwn(ch->expr, VarHash(Expr_Str(ch->expr))); return AMR_OK; } /* :P */ static ApplyModifierResult ApplyModifier_Path(const char **pp, ModChain *ch) { Expr *expr = ch->expr; GNode *gn; char *path; (*pp)++; if (!Expr_ShouldEval(expr)) return AMR_OK; Expr_Define(expr); gn = Targ_FindNode(expr->name); if (gn == NULL || gn->type & OP_NOPATH) { path = NULL; } else if (gn->path != NULL) { path = bmake_strdup(gn->path); } else { SearchPath *searchPath = Suff_FindPath(gn); path = Dir_FindFile(expr->name, searchPath); } if (path == NULL) path = bmake_strdup(expr->name); Expr_SetValueOwn(expr, path); return AMR_OK; } /* :!cmd! */ static ApplyModifierResult ApplyModifier_ShellCommand(const char **pp, ModChain *ch) { Expr *expr = ch->expr; LazyBuf cmdBuf; FStr cmd; (*pp)++; if (!ParseModifierPart(pp, '!', expr->emode, ch, &cmdBuf)) return AMR_CLEANUP; cmd = LazyBuf_DoneGet(&cmdBuf); if (Expr_ShouldEval(expr)) { char *output, *error; output = Cmd_Exec(cmd.str, &error); Expr_SetValueOwn(expr, output); if (error != NULL) { /* XXX: why still return AMR_OK? */ Error("%s", error); free(error); } } else Expr_SetValueRefer(expr, ""); FStr_Done(&cmd); Expr_Define(expr); return AMR_OK; } /* * The :range modifier generates an integer sequence as long as the words. * The :range=7 modifier generates an integer sequence from 1 to 7. */ static ApplyModifierResult ApplyModifier_Range(const char **pp, ModChain *ch) { size_t n; Buffer buf; size_t i; const char *mod = *pp; if (!ModMatchEq(mod, "range", ch)) return AMR_UNKNOWN; if (mod[5] == '=') { const char *p = mod + 6; if (!TryParseSize(&p, &n)) { Parse_Error(PARSE_FATAL, "Invalid number \"%s\" for ':range' modifier", mod + 6); return AMR_CLEANUP; } *pp = p; } else { n = 0; *pp = mod + 5; } if (!ModChain_ShouldEval(ch)) return AMR_OK; if (n == 0) { SubstringWords words = Expr_Words(ch->expr); n = words.len; SubstringWords_Free(words); } Buf_Init(&buf); for (i = 0; i < n; i++) { if (i != 0) { /* * XXX: Use ch->sep instead of ' ', for consistency. */ Buf_AddByte(&buf, ' '); } Buf_AddInt(&buf, 1 + (int)i); } Expr_SetValueOwn(ch->expr, Buf_DoneData(&buf)); return AMR_OK; } /* Parse a ':M' or ':N' modifier. */ static char * ParseModifier_Match(const char **pp, const ModChain *ch) { const char *mod = *pp; Expr *expr = ch->expr; bool copy = false; /* pattern should be, or has been, copied */ bool needSubst = false; const char *endpat; char *pattern; /* * In the loop below, ignore ':' unless we are at (or back to) the * original brace level. * XXX: This will likely not work right if $() and ${} are intermixed. */ /* * XXX: This code is similar to the one in Var_Parse. * See if the code can be merged. * See also ApplyModifier_Defined. */ int nest = 0; const char *p; for (p = mod + 1; *p != '\0' && !(*p == ':' && nest == 0); p++) { if (*p == '\\' && p[1] != '\0' && (IsDelimiter(p[1], ch) || p[1] == ch->startc)) { if (!needSubst) copy = true; p++; continue; } if (*p == '$') needSubst = true; if (*p == '(' || *p == '{') nest++; if (*p == ')' || *p == '}') { nest--; if (nest < 0) break; } } *pp = p; endpat = p; if (copy) { char *dst; const char *src; /* Compress the \:'s out of the pattern. */ pattern = bmake_malloc((size_t)(endpat - (mod + 1)) + 1); dst = pattern; src = mod + 1; for (; src < endpat; src++, dst++) { if (src[0] == '\\' && src + 1 < endpat && /* XXX: ch->startc is missing here; see above */ IsDelimiter(src[1], ch)) src++; *dst = *src; } *dst = '\0'; } else { pattern = bmake_strsedup(mod + 1, endpat); } if (needSubst) { char *old_pattern = pattern; /* * XXX: Contrary to ParseModifierPart, a dollar in a ':M' or * ':N' modifier must be escaped as '$$', not as '\$'. */ pattern = Var_Subst(pattern, expr->scope, expr->emode); /* TODO: handle errors */ free(old_pattern); } DEBUG2(VAR, "Pattern for ':%c' is \"%s\"\n", mod[0], pattern); return pattern; } /* :Mpattern or :Npattern */ static ApplyModifierResult ApplyModifier_Match(const char **pp, ModChain *ch) { char mod = **pp; char *pattern; pattern = ParseModifier_Match(pp, ch); if (ModChain_ShouldEval(ch)) { ModifyWordProc modifyWord = mod == 'M' ? ModifyWord_Match : ModifyWord_NoMatch; ModifyWords(ch, modifyWord, pattern, ch->oneBigWord); } free(pattern); return AMR_OK; } +struct ModifyWord_MtimeArgs { + bool error; + bool fallback; + ApplyModifierResult rc; + time_t t; +}; + +static void +ModifyWord_Mtime(Substring word, SepBuf *buf, void *data) +{ + char tbuf[BUFSIZ]; + struct stat st; + struct ModifyWord_MtimeArgs *args = data; + + if (Substring_IsEmpty(word)) + return; + assert(word.end[0] == '\0'); /* assume null-terminated word */ + if (stat(word.start, &st) < 0) { + if (args->error) { + Parse_Error(PARSE_FATAL, + "Cannot determine mtime for '%s': %s", + word.start, strerror(errno)); + args->rc = AMR_CLEANUP; + return; + } + if (args->fallback) + st.st_mtime = args->t; + else + time(&st.st_mtime); + } + snprintf(tbuf, sizeof(tbuf), "%u", (unsigned)st.st_mtime); + SepBuf_AddStr(buf, tbuf); +} + +/* :mtime */ +static ApplyModifierResult +ApplyModifier_Mtime(const char **pp, ModChain *ch) +{ + const char *p, *mod = *pp; + struct ModifyWord_MtimeArgs args; + + if (!ModMatchEq(mod, "mtime", ch)) + return AMR_UNKNOWN; + *pp += 5; + p = *pp; + args.error = args.fallback = false; + args.rc = AMR_OK; + if (p[0] == '=') { + p++; + args.fallback = true; + if (!TryParseTime(&p, &args.t)) { + if (strncmp(p, "error", 5) == 0) { + args.error = true; + p += 5; + } else + return AMR_BAD; + } + *pp = p; + } + if (!ModChain_ShouldEval(ch)) + return AMR_OK; + ModifyWords(ch, ModifyWord_Mtime, &args, ch->oneBigWord); + return args.rc; +} + static void ParsePatternFlags(const char **pp, PatternFlags *pflags, bool *oneBigWord) { for (;; (*pp)++) { if (**pp == 'g') pflags->subGlobal = true; else if (**pp == '1') pflags->subOnce = true; else if (**pp == 'W') *oneBigWord = true; else break; } } MAKE_INLINE PatternFlags PatternFlags_None(void) { PatternFlags pflags = { false, false, false, false }; return pflags; } /* :S,from,to, */ static ApplyModifierResult ApplyModifier_Subst(const char **pp, ModChain *ch) { struct ModifyWord_SubstArgs args; bool oneBigWord; LazyBuf lhsBuf, rhsBuf; char delim = (*pp)[1]; if (delim == '\0') { Error("Missing delimiter for modifier ':S'"); (*pp)++; return AMR_CLEANUP; } *pp += 2; args.pflags = PatternFlags_None(); args.matched = false; if (**pp == '^') { args.pflags.anchorStart = true; (*pp)++; } - if (!ParseModifierPartSubst(pp, delim, ch->expr->emode, ch, &lhsBuf, - &args.pflags, NULL)) + if (!ParseModifierPartSubst(pp, + false, delim, ch->expr->emode, ch, &lhsBuf, &args.pflags, NULL)) return AMR_CLEANUP; args.lhs = LazyBuf_Get(&lhsBuf); - if (!ParseModifierPartSubst(pp, delim, ch->expr->emode, ch, &rhsBuf, - NULL, &args)) { + if (!ParseModifierPartSubst(pp, + false, delim, ch->expr->emode, ch, &rhsBuf, NULL, &args)) { LazyBuf_Done(&lhsBuf); return AMR_CLEANUP; } args.rhs = LazyBuf_Get(&rhsBuf); oneBigWord = ch->oneBigWord; ParsePatternFlags(pp, &args.pflags, &oneBigWord); ModifyWords(ch, ModifyWord_Subst, &args, oneBigWord); LazyBuf_Done(&lhsBuf); LazyBuf_Done(&rhsBuf); return AMR_OK; } #ifndef NO_REGEX /* :C,from,to, */ static ApplyModifierResult ApplyModifier_Regex(const char **pp, ModChain *ch) { struct ModifyWord_SubstRegexArgs args; bool oneBigWord; int error; LazyBuf reBuf, replaceBuf; FStr re; char delim = (*pp)[1]; if (delim == '\0') { Error("Missing delimiter for :C modifier"); (*pp)++; return AMR_CLEANUP; } *pp += 2; if (!ParseModifierPart(pp, delim, ch->expr->emode, ch, &reBuf)) return AMR_CLEANUP; re = LazyBuf_DoneGet(&reBuf); if (!ParseModifierPart(pp, delim, ch->expr->emode, ch, &replaceBuf)) { FStr_Done(&re); return AMR_CLEANUP; } args.replace = LazyBuf_Get(&replaceBuf); args.pflags = PatternFlags_None(); args.matched = false; oneBigWord = ch->oneBigWord; ParsePatternFlags(pp, &args.pflags, &oneBigWord); if (!ModChain_ShouldEval(ch)) goto done; error = regcomp(&args.re, re.str, REG_EXTENDED); if (error != 0) { VarREError(error, &args.re, "Regex compilation error"); LazyBuf_Done(&replaceBuf); FStr_Done(&re); return AMR_CLEANUP; } args.nsub = args.re.re_nsub + 1; if (args.nsub > 10) args.nsub = 10; ModifyWords(ch, ModifyWord_SubstRegex, &args, oneBigWord); regfree(&args.re); done: LazyBuf_Done(&replaceBuf); FStr_Done(&re); return AMR_OK; } #endif /* :Q, :q */ static ApplyModifierResult ApplyModifier_Quote(const char **pp, ModChain *ch) { LazyBuf buf; bool quoteDollar; quoteDollar = **pp == 'q'; if (!IsDelimiter((*pp)[1], ch)) return AMR_UNKNOWN; (*pp)++; if (!ModChain_ShouldEval(ch)) return AMR_OK; VarQuote(Expr_Str(ch->expr), quoteDollar, &buf); if (buf.data != NULL) Expr_SetValue(ch->expr, LazyBuf_DoneGet(&buf)); else LazyBuf_Done(&buf); return AMR_OK; } /*ARGSUSED*/ static void ModifyWord_Copy(Substring word, SepBuf *buf, void *data MAKE_ATTR_UNUSED) { SepBuf_AddSubstring(buf, word); } /* :ts */ static ApplyModifierResult ApplyModifier_ToSep(const char **pp, ModChain *ch) { const char *sep = *pp + 2; /* * Even in parse-only mode, proceed as normal since there is * neither any observable side effect nor a performance penalty. * Checking for wantRes for every single piece of code in here * would make the code in this function too hard to read. */ /* ":ts" or ":ts:" */ if (sep[0] != ch->endc && IsDelimiter(sep[1], ch)) { *pp = sep + 1; ch->sep = sep[0]; goto ok; } /* ":ts" or ":ts:" */ if (IsDelimiter(sep[0], ch)) { *pp = sep; ch->sep = '\0'; /* no separator */ goto ok; } /* ":ts". */ if (sep[0] != '\\') { (*pp)++; /* just for backwards compatibility */ return AMR_BAD; } /* ":ts\n" */ if (sep[1] == 'n') { *pp = sep + 2; ch->sep = '\n'; goto ok; } /* ":ts\t" */ if (sep[1] == 't') { *pp = sep + 2; ch->sep = '\t'; goto ok; } /* ":ts\x40" or ":ts\100" */ { const char *p = sep + 1; int base = 8; /* assume octal */ if (sep[1] == 'x') { base = 16; p++; } else if (!ch_isdigit(sep[1])) { (*pp)++; /* just for backwards compatibility */ return AMR_BAD; /* ":ts". */ } if (!TryParseChar(&p, base, &ch->sep)) { Parse_Error(PARSE_FATAL, "Invalid character number at \"%s\"", p); return AMR_CLEANUP; } if (!IsDelimiter(*p, ch)) { (*pp)++; /* just for backwards compatibility */ return AMR_BAD; } *pp = p; } ok: ModifyWords(ch, ModifyWord_Copy, NULL, ch->oneBigWord); return AMR_OK; } static char * str_toupper(const char *str) { char *res; size_t i, len; len = strlen(str); res = bmake_malloc(len + 1); for (i = 0; i < len + 1; i++) res[i] = ch_toupper(str[i]); return res; } static char * str_tolower(const char *str) { char *res; size_t i, len; len = strlen(str); res = bmake_malloc(len + 1); for (i = 0; i < len + 1; i++) res[i] = ch_tolower(str[i]); return res; } /* :tA, :tu, :tl, :ts, etc. */ static ApplyModifierResult ApplyModifier_To(const char **pp, ModChain *ch) { Expr *expr = ch->expr; const char *mod = *pp; assert(mod[0] == 't'); if (IsDelimiter(mod[1], ch)) { *pp = mod + 1; return AMR_BAD; /* Found ":t" or ":t:". */ } if (mod[1] == 's') return ApplyModifier_ToSep(pp, ch); if (!IsDelimiter(mod[2], ch)) { /* :t */ *pp = mod + 1; return AMR_BAD; } if (mod[1] == 'A') { /* :tA */ *pp = mod + 2; ModifyWords(ch, ModifyWord_Realpath, NULL, ch->oneBigWord); return AMR_OK; } if (mod[1] == 'u') { /* :tu */ *pp = mod + 2; if (Expr_ShouldEval(expr)) Expr_SetValueOwn(expr, str_toupper(Expr_Str(expr))); return AMR_OK; } if (mod[1] == 'l') { /* :tl */ *pp = mod + 2; if (Expr_ShouldEval(expr)) Expr_SetValueOwn(expr, str_tolower(Expr_Str(expr))); return AMR_OK; } if (mod[1] == 'W' || mod[1] == 'w') { /* :tW, :tw */ *pp = mod + 2; ch->oneBigWord = mod[1] == 'W'; return AMR_OK; } /* Found ":t:" or ":t". */ *pp = mod + 1; /* XXX: unnecessary but observable */ return AMR_BAD; } /* :[#], :[1], :[-1..1], etc. */ static ApplyModifierResult ApplyModifier_Words(const char **pp, ModChain *ch) { Expr *expr = ch->expr; const char *estr; int first, last; const char *p; LazyBuf estrBuf; FStr festr; (*pp)++; /* skip the '[' */ if (!ParseModifierPart(pp, ']', expr->emode, ch, &estrBuf)) return AMR_CLEANUP; festr = LazyBuf_DoneGet(&estrBuf); estr = festr.str; if (!IsDelimiter(**pp, ch)) goto bad_modifier; /* Found junk after ']' */ if (!ModChain_ShouldEval(ch)) goto ok; if (estr[0] == '\0') goto bad_modifier; /* Found ":[]". */ if (estr[0] == '#' && estr[1] == '\0') { /* Found ":[#]" */ if (ch->oneBigWord) { Expr_SetValueRefer(expr, "1"); } else { Buffer buf; SubstringWords words = Expr_Words(expr); size_t ac = words.len; SubstringWords_Free(words); /* 3 digits + '\0' is usually enough */ Buf_InitSize(&buf, 4); Buf_AddInt(&buf, (int)ac); Expr_SetValueOwn(expr, Buf_DoneData(&buf)); } goto ok; } if (estr[0] == '*' && estr[1] == '\0') { /* Found ":[*]" */ ch->oneBigWord = true; goto ok; } if (estr[0] == '@' && estr[1] == '\0') { /* Found ":[@]" */ ch->oneBigWord = false; goto ok; } /* * We expect estr to contain a single integer for :[N], or two * integers separated by ".." for :[start..end]. */ p = estr; if (!TryParseIntBase0(&p, &first)) goto bad_modifier; /* Found junk instead of a number */ if (p[0] == '\0') { /* Found only one integer in :[N] */ last = first; } else if (p[0] == '.' && p[1] == '.' && p[2] != '\0') { /* Expecting another integer after ".." */ p += 2; if (!TryParseIntBase0(&p, &last) || *p != '\0') goto bad_modifier; /* Found junk after ".." */ } else goto bad_modifier; /* Found junk instead of ".." */ /* * Now first and last are properly filled in, but we still have to * check for 0 as a special case. */ if (first == 0 && last == 0) { /* ":[0]" or perhaps ":[0..0]" */ ch->oneBigWord = true; goto ok; } /* ":[0..N]" or ":[N..0]" */ if (first == 0 || last == 0) goto bad_modifier; /* Normal case: select the words described by first and last. */ Expr_SetValueOwn(expr, VarSelectWords(Expr_Str(expr), first, last, ch->sep, ch->oneBigWord)); ok: FStr_Done(&festr); return AMR_OK; bad_modifier: FStr_Done(&festr); return AMR_BAD; } #if __STDC__ >= 199901L || defined(HAVE_LONG_LONG_INT) # define NUM_TYPE long long # define PARSE_NUM_TYPE strtoll #else # define NUM_TYPE long # define PARSE_NUM_TYPE strtol #endif static NUM_TYPE num_val(Substring s) { NUM_TYPE val; char *ep; val = PARSE_NUM_TYPE(s.start, &ep, 0); if (ep != s.start) { switch (*ep) { case 'K': case 'k': val <<= 10; break; case 'M': case 'm': val <<= 20; break; case 'G': case 'g': val <<= 30; break; } } return val; } static int SubNumAsc(const void *sa, const void *sb) { NUM_TYPE a, b; a = num_val(*((const Substring *)sa)); b = num_val(*((const Substring *)sb)); return (a > b) ? 1 : (b > a) ? -1 : 0; } static int SubNumDesc(const void *sa, const void *sb) { return SubNumAsc(sb, sa); } static int SubStrAsc(const void *sa, const void *sb) { return strcmp( ((const Substring *)sa)->start, ((const Substring *)sb)->start); } static int SubStrDesc(const void *sa, const void *sb) { return SubStrAsc(sb, sa); } static void ShuffleSubstrings(Substring *strs, size_t n) { size_t i; for (i = n - 1; i > 0; i--) { size_t rndidx = (size_t)random() % (i + 1); Substring t = strs[i]; strs[i] = strs[rndidx]; strs[rndidx] = t; } } /* * :O order ascending * :Or order descending * :Ox shuffle * :On numeric ascending * :Onr, :Orn numeric descending */ static ApplyModifierResult ApplyModifier_Order(const char **pp, ModChain *ch) { const char *mod = *pp; SubstringWords words; int (*cmp)(const void *, const void *); if (IsDelimiter(mod[1], ch)) { cmp = SubStrAsc; (*pp)++; } else if (IsDelimiter(mod[2], ch)) { if (mod[1] == 'n') cmp = SubNumAsc; else if (mod[1] == 'r') cmp = SubStrDesc; else if (mod[1] == 'x') cmp = NULL; else goto bad; *pp += 2; } else if (IsDelimiter(mod[3], ch)) { if ((mod[1] == 'n' && mod[2] == 'r') || (mod[1] == 'r' && mod[2] == 'n')) cmp = SubNumDesc; else goto bad; *pp += 3; } else goto bad; if (!ModChain_ShouldEval(ch)) return AMR_OK; words = Expr_Words(ch->expr); if (cmp == NULL) ShuffleSubstrings(words.words, words.len); else { assert(words.words[0].end[0] == '\0'); qsort(words.words, words.len, sizeof(words.words[0]), cmp); } Expr_SetValueOwn(ch->expr, SubstringWords_JoinFree(words)); return AMR_OK; bad: (*pp)++; return AMR_BAD; } /* :? then : else */ static ApplyModifierResult ApplyModifier_IfElse(const char **pp, ModChain *ch) { Expr *expr = ch->expr; LazyBuf thenBuf; LazyBuf elseBuf; VarEvalMode then_emode = VARE_PARSE_ONLY; VarEvalMode else_emode = VARE_PARSE_ONLY; CondResult cond_rc = CR_TRUE; /* just not CR_ERROR */ if (Expr_ShouldEval(expr)) { cond_rc = Cond_EvalCondition(expr->name); if (cond_rc == CR_TRUE) then_emode = expr->emode; if (cond_rc == CR_FALSE) else_emode = expr->emode; } (*pp)++; /* skip past the '?' */ if (!ParseModifierPart(pp, ':', then_emode, ch, &thenBuf)) return AMR_CLEANUP; if (!ParseModifierPart(pp, ch->endc, else_emode, ch, &elseBuf)) { LazyBuf_Done(&thenBuf); return AMR_CLEANUP; } (*pp)--; /* Go back to the ch->endc. */ if (cond_rc == CR_ERROR) { Substring thenExpr = LazyBuf_Get(&thenBuf); Substring elseExpr = LazyBuf_Get(&elseBuf); Error("Bad conditional expression '%s' in '%s?%.*s:%.*s'", expr->name, expr->name, (int)Substring_Length(thenExpr), thenExpr.start, (int)Substring_Length(elseExpr), elseExpr.start); LazyBuf_Done(&thenBuf); LazyBuf_Done(&elseBuf); return AMR_CLEANUP; } if (!Expr_ShouldEval(expr)) { LazyBuf_Done(&thenBuf); LazyBuf_Done(&elseBuf); } else if (cond_rc == CR_TRUE) { Expr_SetValue(expr, LazyBuf_DoneGet(&thenBuf)); LazyBuf_Done(&elseBuf); } else { LazyBuf_Done(&thenBuf); Expr_SetValue(expr, LazyBuf_DoneGet(&elseBuf)); } Expr_Define(expr); return AMR_OK; } /* * The ::= modifiers are special in that they do not read the variable value * but instead assign to that variable. They always expand to an empty * string. * * Their main purpose is in supporting .for loops that generate shell commands * since an ordinary variable assignment at that point would terminate the * dependency group for these targets. For example: * * list-targets: .USE * .for i in ${.TARGET} ${.TARGET:R}.gz * @${t::=$i} * @echo 'The target is ${t:T}.' * .endfor * * ::= Assigns as the new value of variable. * ::?= Assigns as value of variable if * it was not already set. * ::+= Appends to variable. * ::!= Assigns output of as the new value of * variable. */ static ApplyModifierResult ApplyModifier_Assign(const char **pp, ModChain *ch) { Expr *expr = ch->expr; GNode *scope; FStr val; LazyBuf buf; const char *mod = *pp; const char *op = mod + 1; if (op[0] == '=') goto found_op; if ((op[0] == '+' || op[0] == '?' || op[0] == '!') && op[1] == '=') goto found_op; return AMR_UNKNOWN; /* "::" */ found_op: if (expr->name[0] == '\0') { *pp = mod + 1; return AMR_BAD; } *pp = mod + (op[0] == '+' || op[0] == '?' || op[0] == '!' ? 3 : 2); if (!ParseModifierPart(pp, ch->endc, expr->emode, ch, &buf)) return AMR_CLEANUP; val = LazyBuf_DoneGet(&buf); (*pp)--; /* Go back to the ch->endc. */ if (!Expr_ShouldEval(expr)) goto done; scope = expr->scope; /* scope where v belongs */ if (expr->defined == DEF_REGULAR && expr->scope != SCOPE_GLOBAL) { Var *v = VarFind(expr->name, expr->scope, false); if (v == NULL) scope = SCOPE_GLOBAL; else VarFreeShortLived(v); } if (op[0] == '+') Var_Append(scope, expr->name, val.str); else if (op[0] == '!') { char *output, *error; output = Cmd_Exec(val.str, &error); if (error != NULL) { Error("%s", error); free(error); } else Var_Set(scope, expr->name, output); free(output); } else if (op[0] == '?' && expr->defined == DEF_REGULAR) { /* Do nothing. */ } else Var_Set(scope, expr->name, val.str); Expr_SetValueRefer(expr, ""); done: FStr_Done(&val); return AMR_OK; } /* * :_=... * remember current value */ static ApplyModifierResult ApplyModifier_Remember(const char **pp, ModChain *ch) { Expr *expr = ch->expr; const char *mod = *pp; FStr name; if (!ModMatchEq(mod, "_", ch)) return AMR_UNKNOWN; name = FStr_InitRefer("_"); if (mod[1] == '=') { /* * XXX: This ad-hoc call to strcspn deviates from the usual * behavior defined in ParseModifierPart. This creates an * unnecessary, undocumented inconsistency in make. */ const char *arg = mod + 2; size_t argLen = strcspn(arg, ":)}"); *pp = arg + argLen; name = FStr_InitOwn(bmake_strldup(arg, argLen)); } else *pp = mod + 1; if (Expr_ShouldEval(expr)) Var_Set(SCOPE_GLOBAL, name.str, Expr_Str(expr)); FStr_Done(&name); return AMR_OK; } /* * Apply the given function to each word of the variable value, * for a single-letter modifier such as :H, :T. */ static ApplyModifierResult ApplyModifier_WordFunc(const char **pp, ModChain *ch, ModifyWordProc modifyWord) { if (!IsDelimiter((*pp)[1], ch)) return AMR_UNKNOWN; (*pp)++; if (ModChain_ShouldEval(ch)) ModifyWords(ch, modifyWord, NULL, ch->oneBigWord); return AMR_OK; } /* Remove adjacent duplicate words. */ static ApplyModifierResult ApplyModifier_Unique(const char **pp, ModChain *ch) { SubstringWords words; if (!IsDelimiter((*pp)[1], ch)) return AMR_UNKNOWN; (*pp)++; if (!ModChain_ShouldEval(ch)) return AMR_OK; words = Expr_Words(ch->expr); if (words.len > 1) { size_t si, di; di = 0; for (si = 1; si < words.len; si++) { if (!Substring_Eq(words.words[si], words.words[di])) { di++; if (di != si) words.words[di] = words.words[si]; } } words.len = di + 1; } Expr_SetValueOwn(ch->expr, SubstringWords_JoinFree(words)); return AMR_OK; } #ifdef SYSVVARSUB /* :from=to */ static ApplyModifierResult ApplyModifier_SysV(const char **pp, ModChain *ch) { Expr *expr = ch->expr; LazyBuf lhsBuf, rhsBuf; FStr rhs; struct ModifyWord_SysVSubstArgs args; Substring lhs; const char *lhsSuffix; const char *mod = *pp; bool eqFound = false; /* * First we make a pass through the string trying to verify it is a * SysV-make-style translation. It must be: = */ int depth = 1; const char *p = mod; while (*p != '\0' && depth > 0) { if (*p == '=') { /* XXX: should also test depth == 1 */ eqFound = true; /* continue looking for ch->endc */ } else if (*p == ch->endc) depth--; else if (*p == ch->startc) depth++; if (depth > 0) p++; } if (*p != ch->endc || !eqFound) return AMR_UNKNOWN; if (!ParseModifierPart(pp, '=', expr->emode, ch, &lhsBuf)) return AMR_CLEANUP; /* * The SysV modifier lasts until the end of the variable expression. */ if (!ParseModifierPart(pp, ch->endc, expr->emode, ch, &rhsBuf)) { LazyBuf_Done(&lhsBuf); return AMR_CLEANUP; } rhs = LazyBuf_DoneGet(&rhsBuf); (*pp)--; /* Go back to the ch->endc. */ /* Do not turn an empty expression into non-empty. */ if (lhsBuf.len == 0 && Expr_Str(expr)[0] == '\0') goto done; lhs = LazyBuf_Get(&lhsBuf); lhsSuffix = Substring_SkipFirst(lhs, '%'); args.scope = expr->scope; args.lhsPrefix = Substring_Init(lhs.start, lhsSuffix != lhs.start ? lhsSuffix - 1 : lhs.start); args.lhsPercent = lhsSuffix != lhs.start; args.lhsSuffix = Substring_Init(lhsSuffix, lhs.end); args.rhs = rhs.str; ModifyWords(ch, ModifyWord_SysVSubst, &args, ch->oneBigWord); done: LazyBuf_Done(&lhsBuf); FStr_Done(&rhs); return AMR_OK; } #endif #ifdef SUNSHCMD /* :sh */ static ApplyModifierResult ApplyModifier_SunShell(const char **pp, ModChain *ch) { Expr *expr = ch->expr; const char *p = *pp; if (!(p[1] == 'h' && IsDelimiter(p[2], ch))) return AMR_UNKNOWN; *pp = p + 2; if (Expr_ShouldEval(expr)) { char *output, *error; output = Cmd_Exec(Expr_Str(expr), &error); if (error != NULL) { Error("%s", error); free(error); } Expr_SetValueOwn(expr, output); } return AMR_OK; } #endif /* * In cases where the evaluation mode and the definedness are the "standard" * ones, don't log them, to keep the logs readable. */ static bool ShouldLogInSimpleFormat(const Expr *expr) { return (expr->emode == VARE_WANTRES || expr->emode == VARE_UNDEFERR) && expr->defined == DEF_REGULAR; } static void LogBeforeApply(const ModChain *ch, const char *mod) { const Expr *expr = ch->expr; bool is_single_char = mod[0] != '\0' && IsDelimiter(mod[1], ch); /* * At this point, only the first character of the modifier can * be used since the end of the modifier is not yet known. */ if (!Expr_ShouldEval(expr)) { debug_printf("Parsing modifier ${%s:%c%s}\n", expr->name, mod[0], is_single_char ? "" : "..."); return; } if (ShouldLogInSimpleFormat(expr)) { debug_printf( "Evaluating modifier ${%s:%c%s} on value \"%s\"\n", expr->name, mod[0], is_single_char ? "" : "...", Expr_Str(expr)); return; } debug_printf( "Evaluating modifier ${%s:%c%s} on value \"%s\" (%s, %s)\n", expr->name, mod[0], is_single_char ? "" : "...", Expr_Str(expr), VarEvalMode_Name[expr->emode], ExprDefined_Name[expr->defined]); } static void LogAfterApply(const ModChain *ch, const char *p, const char *mod) { const Expr *expr = ch->expr; const char *value = Expr_Str(expr); const char *quot = value == var_Error ? "" : "\""; if (ShouldLogInSimpleFormat(expr)) { debug_printf("Result of ${%s:%.*s} is %s%s%s\n", expr->name, (int)(p - mod), mod, quot, value == var_Error ? "error" : value, quot); return; } debug_printf("Result of ${%s:%.*s} is %s%s%s (%s, %s)\n", expr->name, (int)(p - mod), mod, quot, value == var_Error ? "error" : value, quot, VarEvalMode_Name[expr->emode], ExprDefined_Name[expr->defined]); } static ApplyModifierResult ApplyModifier(const char **pp, ModChain *ch) { switch (**pp) { case '!': return ApplyModifier_ShellCommand(pp, ch); case ':': return ApplyModifier_Assign(pp, ch); case '?': return ApplyModifier_IfElse(pp, ch); case '@': return ApplyModifier_Loop(pp, ch); case '[': return ApplyModifier_Words(pp, ch); case '_': return ApplyModifier_Remember(pp, ch); #ifndef NO_REGEX case 'C': return ApplyModifier_Regex(pp, ch); #endif case 'D': case 'U': return ApplyModifier_Defined(pp, ch); case 'E': return ApplyModifier_WordFunc(pp, ch, ModifyWord_Suffix); case 'g': case 'l': return ApplyModifier_Time(pp, ch); case 'H': return ApplyModifier_WordFunc(pp, ch, ModifyWord_Head); case 'h': return ApplyModifier_Hash(pp, ch); case 'L': return ApplyModifier_Literal(pp, ch); case 'M': case 'N': return ApplyModifier_Match(pp, ch); + case 'm': + return ApplyModifier_Mtime(pp, ch); case 'O': return ApplyModifier_Order(pp, ch); case 'P': return ApplyModifier_Path(pp, ch); case 'Q': case 'q': return ApplyModifier_Quote(pp, ch); case 'R': return ApplyModifier_WordFunc(pp, ch, ModifyWord_Root); case 'r': return ApplyModifier_Range(pp, ch); case 'S': return ApplyModifier_Subst(pp, ch); #ifdef SUNSHCMD case 's': return ApplyModifier_SunShell(pp, ch); #endif case 'T': return ApplyModifier_WordFunc(pp, ch, ModifyWord_Tail); case 't': return ApplyModifier_To(pp, ch); case 'u': return ApplyModifier_Unique(pp, ch); default: return AMR_UNKNOWN; } } static void ApplyModifiers(Expr *, const char **, char, char); typedef enum ApplyModifiersIndirectResult { /* The indirect modifiers have been applied successfully. */ AMIR_CONTINUE, /* Fall back to the SysV modifier. */ AMIR_SYSV, /* Error out. */ AMIR_OUT } ApplyModifiersIndirectResult; /* * While expanding a variable expression, expand and apply indirect modifiers, * such as in ${VAR:${M_indirect}}. * * All indirect modifiers of a group must come from a single variable * expression. ${VAR:${M1}} is valid but ${VAR:${M1}${M2}} is not. * * Multiple groups of indirect modifiers can be chained by separating them * with colons. ${VAR:${M1}:${M2}} contains 2 indirect modifiers. * * If the variable expression is not followed by ch->endc or ':', fall * back to trying the SysV modifier, such as in ${VAR:${FROM}=${TO}}. */ static ApplyModifiersIndirectResult ApplyModifiersIndirect(ModChain *ch, const char **pp) { Expr *expr = ch->expr; const char *p = *pp; FStr mods = Var_Parse(&p, expr->scope, expr->emode); /* TODO: handle errors */ if (mods.str[0] != '\0' && !IsDelimiter(*p, ch)) { FStr_Done(&mods); return AMIR_SYSV; } DEBUG3(VAR, "Indirect modifier \"%s\" from \"%.*s\"\n", mods.str, (int)(p - *pp), *pp); if (mods.str[0] != '\0') { const char *modsp = mods.str; ApplyModifiers(expr, &modsp, '\0', '\0'); if (Expr_Str(expr) == var_Error || *modsp != '\0') { FStr_Done(&mods); *pp = p; return AMIR_OUT; /* error already reported */ } } FStr_Done(&mods); if (*p == ':') p++; else if (*p == '\0' && ch->endc != '\0') { Error("Unclosed variable expression after indirect " "modifier, expecting '%c' for variable \"%s\"", ch->endc, expr->name); *pp = p; return AMIR_OUT; } *pp = p; return AMIR_CONTINUE; } static ApplyModifierResult ApplySingleModifier(const char **pp, ModChain *ch) { ApplyModifierResult res; const char *mod = *pp; const char *p = *pp; if (DEBUG(VAR)) LogBeforeApply(ch, mod); res = ApplyModifier(&p, ch); #ifdef SYSVVARSUB if (res == AMR_UNKNOWN) { assert(p == mod); res = ApplyModifier_SysV(&p, ch); } #endif if (res == AMR_UNKNOWN) { /* * Guess the end of the current modifier. * XXX: Skipping the rest of the modifier hides * errors and leads to wrong results. * Parsing should rather stop here. */ for (p++; !IsDelimiter(*p, ch); p++) continue; Parse_Error(PARSE_FATAL, "Unknown modifier \"%.*s\"", (int)(p - mod), mod); Expr_SetValueRefer(ch->expr, var_Error); } if (res == AMR_CLEANUP || res == AMR_BAD) { *pp = p; return res; } if (DEBUG(VAR)) LogAfterApply(ch, p, mod); if (*p == '\0' && ch->endc != '\0') { Error( "Unclosed variable expression, expecting '%c' for " "modifier \"%.*s\" of variable \"%s\" with value \"%s\"", ch->endc, (int)(p - mod), mod, ch->expr->name, Expr_Str(ch->expr)); } else if (*p == ':') { p++; } else if (opts.strict && *p != '\0' && *p != ch->endc) { Parse_Error(PARSE_FATAL, "Missing delimiter ':' after modifier \"%.*s\"", (int)(p - mod), mod); /* * TODO: propagate parse error to the enclosing * expression */ } *pp = p; return AMR_OK; } #if __STDC_VERSION__ >= 199901L #define ModChain_Literal(expr, startc, endc, sep, oneBigWord) \ (ModChain) { expr, startc, endc, sep, oneBigWord } #else MAKE_INLINE ModChain ModChain_Literal(Expr *expr, char startc, char endc, char sep, bool oneBigWord) { ModChain ch; ch.expr = expr; ch.startc = startc; ch.endc = endc; ch.sep = sep; ch.oneBigWord = oneBigWord; return ch; } #endif /* Apply any modifiers (such as :Mpattern or :@var@loop@ or :Q or ::=value). */ static void ApplyModifiers( Expr *expr, const char **pp, /* the parsing position, updated upon return */ char startc, /* '(' or '{'; or '\0' for indirect modifiers */ char endc /* ')' or '}'; or '\0' for indirect modifiers */ ) { ModChain ch = ModChain_Literal(expr, startc, endc, ' ', false); const char *p; const char *mod; assert(startc == '(' || startc == '{' || startc == '\0'); assert(endc == ')' || endc == '}' || endc == '\0'); assert(Expr_Str(expr) != NULL); p = *pp; if (*p == '\0' && endc != '\0') { Error( "Unclosed variable expression (expecting '%c') for \"%s\"", ch.endc, expr->name); goto cleanup; } while (*p != '\0' && *p != endc) { ApplyModifierResult res; if (*p == '$') { ApplyModifiersIndirectResult amir = ApplyModifiersIndirect(&ch, &p); if (amir == AMIR_CONTINUE) continue; if (amir == AMIR_OUT) break; /* * It's neither '${VAR}:' nor '${VAR}}'. Try to parse * it as a SysV modifier, as that is the only modifier * that can start with '$'. */ } mod = p; res = ApplySingleModifier(&p, &ch); if (res == AMR_CLEANUP) goto cleanup; if (res == AMR_BAD) goto bad_modifier; } *pp = p; assert(Expr_Str(expr) != NULL); /* Use var_Error or varUndefined. */ return; bad_modifier: /* XXX: The modifier end is only guessed. */ Error("Bad modifier \":%.*s\" for variable \"%s\"", (int)strcspn(mod, ":)}"), mod, expr->name); cleanup: /* * TODO: Use p + strlen(p) instead, to stop parsing immediately. * * In the unit tests, this generates a few shell commands with * unbalanced quotes. Instead of producing these incomplete strings, * commands with evaluation errors should not be run at all. * * To make that happen, Var_Subst must report the actual errors * instead of returning the resulting string unconditionally. */ *pp = p; Expr_SetValueRefer(expr, var_Error); } /* * Only 4 of the 7 built-in local variables are treated specially as they are * the only ones that will be set when dynamic sources are expanded. */ static bool VarnameIsDynamic(Substring varname) { const char *name; size_t len; name = varname.start; len = Substring_Length(varname); if (len == 1 || (len == 2 && (name[1] == 'F' || name[1] == 'D'))) { switch (name[0]) { case '@': case '%': case '*': case '!': return true; } return false; } if ((len == 7 || len == 8) && name[0] == '.' && ch_isupper(name[1])) { return Substring_Equals(varname, ".TARGET") || Substring_Equals(varname, ".ARCHIVE") || Substring_Equals(varname, ".PREFIX") || Substring_Equals(varname, ".MEMBER"); } return false; } static const char * UndefinedShortVarValue(char varname, const GNode *scope) { if (scope == SCOPE_CMDLINE || scope == SCOPE_GLOBAL) { /* * If substituting a local variable in a non-local scope, * assume it's for dynamic source stuff. We have to handle * this specially and return the longhand for the variable * with the dollar sign escaped so it makes it back to the * caller. Only four of the local variables are treated * specially as they are the only four that will be set * when dynamic sources are expanded. */ switch (varname) { case '@': return "$(.TARGET)"; case '%': return "$(.MEMBER)"; case '*': return "$(.PREFIX)"; case '!': return "$(.ARCHIVE)"; } } return NULL; } /* * Parse a variable name, until the end character or a colon, whichever * comes first. */ static void ParseVarname(const char **pp, char startc, char endc, GNode *scope, VarEvalMode emode, LazyBuf *buf) { const char *p = *pp; int depth = 0; /* Track depth so we can spot parse errors. */ LazyBuf_Init(buf, p); while (*p != '\0') { if ((*p == endc || *p == ':') && depth == 0) break; if (*p == startc) depth++; if (*p == endc) depth--; /* A variable inside a variable, expand. */ if (*p == '$') { FStr nested_val = Var_Parse(&p, scope, emode); /* TODO: handle errors */ LazyBuf_AddStr(buf, nested_val.str); FStr_Done(&nested_val); } else { LazyBuf_Add(buf, *p); p++; } } *pp = p; } static bool IsShortVarnameValid(char varname, const char *start) { if (varname != '$' && varname != ':' && varname != '}' && varname != ')' && varname != '\0') return true; if (!opts.strict) return false; /* XXX: Missing error message */ if (varname == '$') Parse_Error(PARSE_FATAL, "To escape a dollar, use \\$, not $$, at \"%s\"", start); else if (varname == '\0') Parse_Error(PARSE_FATAL, "Dollar followed by nothing"); else Parse_Error(PARSE_FATAL, "Invalid variable name '%c', at \"%s\"", varname, start); return false; } /* * Parse a single-character variable name such as in $V or $@. * Return whether to continue parsing. */ static bool ParseVarnameShort(char varname, const char **pp, GNode *scope, VarEvalMode emode, const char **out_false_val, Var **out_true_var) { char name[2]; Var *v; const char *val; if (!IsShortVarnameValid(varname, *pp)) { (*pp)++; /* only skip the '$' */ *out_false_val = var_Error; return false; } name[0] = varname; name[1] = '\0'; v = VarFind(name, scope, true); if (v != NULL) { /* No need to advance *pp, the calling code handles this. */ *out_true_var = v; return true; } *pp += 2; val = UndefinedShortVarValue(varname, scope); if (val == NULL) val = emode == VARE_UNDEFERR ? var_Error : varUndefined; if (opts.strict && val == var_Error) { Parse_Error(PARSE_FATAL, "Variable \"%s\" is undefined", name); } *out_false_val = val; return false; } /* Find variables like @F or ", varname.start[0]) == NULL) return NULL; v = VarFindSubstring(Substring_Sub(varname, 0, 1), scope, false); if (v == NULL) return NULL; *out_extraModifiers = varname.start[1] == 'D' ? "H:" : "T:"; return v; } static FStr EvalUndefined(bool dynamic, const char *start, const char *p, Substring varname, VarEvalMode emode) { if (dynamic) return FStr_InitOwn(bmake_strsedup(start, p)); if (emode == VARE_UNDEFERR && opts.strict) { Parse_Error(PARSE_FATAL, "Variable \"%.*s\" is undefined", (int)Substring_Length(varname), varname.start); return FStr_InitRefer(var_Error); } return FStr_InitRefer( emode == VARE_UNDEFERR ? var_Error : varUndefined); } /* * Parse a long variable name enclosed in braces or parentheses such as $(VAR) * or ${VAR}, up to the closing brace or parenthesis, or in the case of * ${VAR:Modifiers}, up to the ':' that starts the modifiers. * Return whether to continue parsing. */ static bool ParseVarnameLong( const char **pp, char startc, GNode *scope, VarEvalMode emode, const char **out_false_pp, FStr *out_false_val, char *out_true_endc, Var **out_true_v, bool *out_true_haveModifier, const char **out_true_extraModifiers, bool *out_true_dynamic, ExprDefined *out_true_exprDefined ) { LazyBuf varname; Substring name; Var *v; bool haveModifier; bool dynamic = false; const char *p = *pp; const char *const start = p; char endc = startc == '(' ? ')' : '}'; p += 2; /* skip "${" or "$(" or "y(" */ ParseVarname(&p, startc, endc, scope, emode, &varname); name = LazyBuf_Get(&varname); if (*p == ':') { haveModifier = true; } else if (*p == endc) { haveModifier = false; } else { Parse_Error(PARSE_FATAL, "Unclosed variable \"%.*s\"", (int)Substring_Length(name), name.start); LazyBuf_Done(&varname); *out_false_pp = p; *out_false_val = FStr_InitRefer(var_Error); return false; } v = VarFindSubstring(name, scope, true); /* * At this point, p points just after the variable name, either at * ':' or at endc. */ if (v == NULL && Substring_Equals(name, ".SUFFIXES")) { char *suffixes = Suff_NamesStr(); v = VarNew(FStr_InitRefer(".SUFFIXES"), suffixes, true, false, true); free(suffixes); } else if (v == NULL) v = FindLocalLegacyVar(name, scope, out_true_extraModifiers); if (v == NULL) { /* * Defer expansion of dynamic variables if they appear in * non-local scope since they are not defined there. */ dynamic = VarnameIsDynamic(name) && (scope == SCOPE_CMDLINE || scope == SCOPE_GLOBAL); if (!haveModifier) { p++; /* skip endc */ *out_false_pp = p; *out_false_val = EvalUndefined(dynamic, start, p, name, emode); LazyBuf_Done(&varname); return false; } /* * The variable expression is based on an undefined variable. * Nevertheless it needs a Var, for modifiers that access the * variable name, such as :L or :?. * * Most modifiers leave this expression in the "undefined" * state (VES_UNDEF), only a few modifiers like :D, :U, :L, * :P turn this undefined expression into a defined * expression (VES_DEF). * * In the end, after applying all modifiers, if the expression * is still undefined, Var_Parse will return an empty string * instead of the actually computed value. */ v = VarNew(LazyBuf_DoneGet(&varname), "", true, false, false); *out_true_exprDefined = DEF_UNDEF; } else LazyBuf_Done(&varname); *pp = p; *out_true_endc = endc; *out_true_v = v; *out_true_haveModifier = haveModifier; *out_true_dynamic = dynamic; return true; } #if __STDC_VERSION__ >= 199901L #define Expr_Literal(name, value, emode, scope, defined) \ { name, value, emode, scope, defined } #else MAKE_INLINE Expr Expr_Literal(const char *name, FStr value, VarEvalMode emode, GNode *scope, ExprDefined defined) { Expr expr; expr.name = name; expr.value = value; expr.emode = emode; expr.scope = scope; expr.defined = defined; return expr; } #endif /* * Expressions of the form ${:U...} with a trivial value are often generated * by .for loops and are boring, therefore parse and evaluate them in a fast * lane without debug logging. */ static bool Var_Parse_FastLane(const char **pp, VarEvalMode emode, FStr *out_value) { const char *p; p = *pp; if (!(p[0] == '$' && p[1] == '{' && p[2] == ':' && p[3] == 'U')) return false; p += 4; while (*p != '$' && *p != '{' && *p != ':' && *p != '\\' && *p != '}' && *p != '\0') p++; if (*p != '}') return false; if (emode == VARE_PARSE_ONLY) *out_value = FStr_InitRefer(""); else *out_value = FStr_InitOwn(bmake_strsedup(*pp + 4, p)); *pp = p + 1; return true; } /* * Given the start of a variable expression (such as $v, $(VAR), * ${VAR:Mpattern}), extract the variable name and value, and the modifiers, * if any. While doing that, apply the modifiers to the value of the * expression, forming its final value. A few of the modifiers such as :!cmd! * or ::= have side effects. * * Input: * *pp The string to parse. * When called from CondParser_FuncCallEmpty, it can * also point to the "y" of "empty(VARNAME:Modifiers)". * scope The scope for finding variables * emode Controls the exact details of parsing and evaluation * * Output: * *pp The position where to continue parsing. * TODO: After a parse error, the value of *pp is * unspecified. It may not have been updated at all, * point to some random character in the string, to the * location of the parse error, or at the end of the * string. * return The value of the variable expression, never NULL. * return var_Error if there was a parse error. * return var_Error if the base variable of the expression was * undefined, emode is VARE_UNDEFERR, and none of * the modifiers turned the undefined expression into a * defined expression. * XXX: It is not guaranteed that an error message has * been printed. * return varUndefined if the base variable of the expression * was undefined, emode was not VARE_UNDEFERR, * and none of the modifiers turned the undefined * expression into a defined expression. * XXX: It is not guaranteed that an error message has * been printed. */ FStr Var_Parse(const char **pp, GNode *scope, VarEvalMode emode) { const char *p = *pp; const char *const start = p; bool haveModifier; /* true for ${VAR:...}, false for ${VAR} */ char startc; /* the actual '{' or '(' or '\0' */ char endc; /* the expected '}' or ')' or '\0' */ /* * true if the expression is based on one of the 7 predefined * variables that are local to a target, and the expression is * expanded in a non-local scope. The result is the text of the * expression, unaltered. This is needed to support dynamic sources. */ bool dynamic; const char *extramodifiers; Var *v; Expr expr = Expr_Literal(NULL, FStr_InitRefer(NULL), emode, scope, DEF_REGULAR); FStr val; if (Var_Parse_FastLane(pp, emode, &val)) return val; /* TODO: Reduce computations in parse-only mode. */ DEBUG2(VAR, "Var_Parse: %s (%s)\n", start, VarEvalMode_Name[emode]); val = FStr_InitRefer(NULL); extramodifiers = NULL; /* extra modifiers to apply first */ dynamic = false; endc = '\0'; /* Appease GCC. */ startc = p[1]; if (startc != '(' && startc != '{') { if (!ParseVarnameShort(startc, pp, scope, emode, &val.str, &v)) return val; haveModifier = false; p++; } else { if (!ParseVarnameLong(&p, startc, scope, emode, pp, &val, &endc, &v, &haveModifier, &extramodifiers, &dynamic, &expr.defined)) return val; } expr.name = v->name.str; if (v->inUse && VarEvalMode_ShouldEval(emode)) { if (scope->fname != NULL) { fprintf(stderr, "In a command near "); PrintLocation(stderr, false, scope); } Fatal("Variable %s is recursive.", v->name.str); } /* * XXX: This assignment creates an alias to the current value of the * variable. This means that as long as the value of the expression * stays the same, the value of the variable must not change. * Using the '::=' modifier, it could be possible to trigger exactly * this situation. * * At the bottom of this function, the resulting value is compared to * the then-current value of the variable. This might also invoke * undefined behavior. */ expr.value = FStr_InitRefer(v->val.data); /* * Before applying any modifiers, expand any nested expressions from * the variable value. */ if (VarEvalMode_ShouldEval(emode) && strchr(Expr_Str(&expr), '$') != NULL) { char *expanded; VarEvalMode nested_emode = emode; if (opts.strict) nested_emode = VarEvalMode_UndefOk(nested_emode); v->inUse = true; expanded = Var_Subst(Expr_Str(&expr), scope, nested_emode); v->inUse = false; /* TODO: handle errors */ Expr_SetValueOwn(&expr, expanded); } if (extramodifiers != NULL) { const char *em = extramodifiers; ApplyModifiers(&expr, &em, '\0', '\0'); } if (haveModifier) { p++; /* Skip initial colon. */ ApplyModifiers(&expr, &p, startc, endc); } if (*p != '\0') /* Skip past endc if possible. */ p++; *pp = p; if (expr.defined == DEF_UNDEF) { if (dynamic) Expr_SetValueOwn(&expr, bmake_strsedup(start, p)); else { /* * The expression is still undefined, therefore * discard the actual value and return an error marker * instead. */ Expr_SetValueRefer(&expr, emode == VARE_UNDEFERR ? var_Error : varUndefined); } } if (v->shortLived) { if (expr.value.str == v->val.data) { /* move ownership */ expr.value.freeIt = v->val.data; v->val.data = NULL; } VarFreeShortLived(v); } return expr.value; } static void VarSubstDollarDollar(const char **pp, Buffer *res, VarEvalMode emode) { /* A dollar sign may be escaped with another dollar sign. */ if (save_dollars && VarEvalMode_ShouldKeepDollar(emode)) Buf_AddByte(res, '$'); Buf_AddByte(res, '$'); *pp += 2; } static void VarSubstExpr(const char **pp, Buffer *buf, GNode *scope, VarEvalMode emode, bool *inout_errorReported) { const char *p = *pp; const char *nested_p = p; FStr val = Var_Parse(&nested_p, scope, emode); /* TODO: handle errors */ if (val.str == var_Error || val.str == varUndefined) { if (!VarEvalMode_ShouldKeepUndef(emode)) { p = nested_p; } else if (val.str == var_Error) { /* * XXX: This condition is wrong. If val == var_Error, * this doesn't necessarily mean there was an undefined * variable. It could equally well be a parse error; * see unit-tests/varmod-order.exp. */ /* * If variable is undefined, complain and skip the * variable. The complaint will stop us from doing * anything when the file is parsed. */ if (!*inout_errorReported) { Parse_Error(PARSE_FATAL, "Undefined variable \"%.*s\"", (int)(size_t)(nested_p - p), p); } p = nested_p; *inout_errorReported = true; } else { /* * Copy the initial '$' of the undefined expression, * thereby deferring expansion of the expression, but * expand nested expressions if already possible. See * unit-tests/varparse-undef-partial.mk. */ Buf_AddByte(buf, *p); p++; } } else { p = nested_p; Buf_AddStr(buf, val.str); } FStr_Done(&val); *pp = p; } /* * Skip as many characters as possible -- either to the end of the string * or to the next dollar sign (variable expression). */ static void VarSubstPlain(const char **pp, Buffer *res) { const char *p = *pp; const char *start = p; for (p++; *p != '$' && *p != '\0'; p++) continue; Buf_AddBytesBetween(res, start, p); *pp = p; } /* * Expand all variable expressions like $V, ${VAR}, $(VAR:Modifiers) in the * given string. * * Input: * str The string in which the variable expressions are * expanded. * scope The scope in which to start searching for * variables. The other scopes are searched as well. * emode The mode for parsing or evaluating subexpressions. */ char * Var_Subst(const char *str, GNode *scope, VarEvalMode emode) { const char *p = str; Buffer res; /* * Set true if an error has already been reported, to prevent a * plethora of messages when recursing */ /* See varparse-errors.mk for why the 'static' is necessary here. */ static bool errorReported; Buf_Init(&res); errorReported = false; while (*p != '\0') { if (p[0] == '$' && p[1] == '$') VarSubstDollarDollar(&p, &res, emode); else if (p[0] == '$') VarSubstExpr(&p, &res, scope, emode, &errorReported); else VarSubstPlain(&p, &res); } return Buf_DoneDataCompact(&res); } void Var_Expand(FStr *str, GNode *scope, VarEvalMode emode) { char *expanded; if (strchr(str->str, '$') == NULL) return; expanded = Var_Subst(str->str, scope, emode); /* TODO: handle errors */ FStr_Done(str); *str = FStr_InitOwn(expanded); } /* Initialize the variables module. */ void Var_Init(void) { SCOPE_INTERNAL = GNode_New("Internal"); SCOPE_GLOBAL = GNode_New("Global"); SCOPE_CMDLINE = GNode_New("Command"); } /* Clean up the variables module. */ void Var_End(void) { Var_Stats(); } void Var_Stats(void) { HashTable_DebugStats(&SCOPE_GLOBAL->vars, "Global variables"); } static int StrAsc(const void *sa, const void *sb) { return strcmp( *((const char *const *)sa), *((const char *const *)sb)); } /* Print all variables in a scope, sorted by name. */ void Var_Dump(GNode *scope) { Vector /* of const char * */ vec; HashIter hi; size_t i; const char **varnames; Vector_Init(&vec, sizeof(const char *)); HashIter_Init(&hi, &scope->vars); while (HashIter_Next(&hi) != NULL) *(const char **)Vector_Push(&vec) = hi.entry->key; varnames = vec.items; qsort(varnames, vec.len, sizeof varnames[0], StrAsc); for (i = 0; i < vec.len; i++) { const char *varname = varnames[i]; const Var *var = HashTable_FindValue(&scope->vars, varname); debug_printf("%-16s = %s%s\n", varname, var->val.data, ValueDescription(var->val.data)); } Vector_Done(&vec); }