diff options
author | bsiegert <bsiegert@pkgsrc.org> | 2011-06-18 22:17:41 +0000 |
---|---|---|
committer | bsiegert <bsiegert@pkgsrc.org> | 2011-06-18 22:17:41 +0000 |
commit | 7cb16bb66575467ac59352068eaec344242b439a (patch) | |
tree | c8f5dd7d540977ec601c02e7d04c13e80115f641 | |
parent | 92219014db9b676e01e78bbe73c3877f94f2a471 (diff) | |
download | pkgsrc-7cb16bb66575467ac59352068eaec344242b439a.tar.gz |
Import bmake-20110606. Many changes, among them:
- unit-tests/modts now works on MirBSD
- meta mode
- ApplyModifiers: when we parse a variable which is not the entire modifier
string, or not followed by ':', do not consider it as containing modifiers.
- when long modifiers fail to match, check sysV style.
- :hash - cheap 32bit hash of value
- :localtime, :gmtime - use value as format string for strftime.
- fix for use after free() in CondDoExists().
- boot-strap (TOOL_DIFF): aparently at least on linux distro
formats the output of 'type' differently - so eat any "()"
- correct sysV substitution handling of empty lhs and variable
- correct exists() check for dir with trailing /
- correct handling of modifiers for non-existant variables during evaluation
of conditionals.
- fix for incorrect .PARSEDIR when .OBJDIR is re-computed after makefiles
have been read.
- fix example of :? modifier in man page.
- sigcompat.c: convert to ansi so we can use higher warning levels.
- parse.c: SunOS 5.8 at least does not have MAP_FILE
- use mmap(2) if available, for reading makefiles
- to ensure unit-tests results match, need to control LC_ALL as well as LANG.
- if stale dependency is an IMPSRC, search via .PATH
- machine.sh: like os.sh, allow for uname -p producing useless drivel
- boot-strap: document configure knobs for meta and filemon.
42 files changed, 4606 insertions, 338 deletions
diff --git a/devel/bmake/files/ChangeLog b/devel/bmake/files/ChangeLog index 19052c5561f..b24761aa3d3 100644 --- a/devel/bmake/files/ChangeLog +++ b/devel/bmake/files/ChangeLog @@ -1,3 +1,173 @@ +2011-06-07 Simon J. Gerraty <sjg@bad.crufty.net> + + * Merge with NetBSD make, pick up + o unit-tests/modts now works on MirBSD + +2011-06-04 Simon J. Gerraty <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> + + * parse.c: SunOS 5.8 at least does not have MAP_FILE + +2011-01-01 Simon J. Gerraty <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> + + * Makefile.in (MAKE_VERSION): bump version to 20101101 + +2010-10-16 Simon J. Gerraty <sjg@bad.crufty.net> + + * machine.sh: like os.sh, + allow for uname -p producing useless drivel + +2010-09-13 Simon J. Gerraty <sjg@bad.crufty.net> + + * 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 <sjg@bad.crufty.net> * boot-strap (TOOL_DIFF): set this to ensure tests use diff --git a/devel/bmake/files/FILES b/devel/bmake/files/FILES index ed3a3dc8836..24e1359bece 100644 --- a/devel/bmake/files/FILES +++ b/devel/bmake/files/FILES @@ -30,9 +30,14 @@ hash.h install-sh job.c job.h +meta.c +meta.h +dirname.c realpath.c +strlcpy.c strlist.c strlist.h +stresep.c trace.c trace.h lst.h @@ -96,6 +101,8 @@ unit-tests/error unit-tests/export unit-tests/export-all unit-tests/forsubst +unit-tests/hash +unit-tests/misc unit-tests/moderrs unit-tests/modmatch unit-tests/modmisc @@ -104,6 +111,7 @@ unit-tests/modts unit-tests/modword unit-tests/posix unit-tests/qequals +unit-tests/sysv unit-tests/ternary unit-tests/test.exp unit-tests/unexport diff --git a/devel/bmake/files/Makefile.in b/devel/bmake/files/Makefile.in index af0dbf2eace..9762db149a4 100644 --- a/devel/bmake/files/Makefile.in +++ b/devel/bmake/files/Makefile.in @@ -1,7 +1,7 @@ -# $NetBSD: Makefile.in,v 1.1.1.9 2010/09/07 14:11:16 joerg Exp $ +# $NetBSD: Makefile.in,v 1.1.1.10 2011/06/18 22:17:41 bsiegert Exp $ # @(#)Makefile 5.2 (Berkeley) 12/28/90 -# $Id: Makefile.in,v 1.1.1.9 2010/09/07 14:11:16 joerg Exp $ +# $Id: Makefile.in,v 1.1.1.10 2011/06/18 22:17:41 bsiegert Exp $ PROG= bmake SRCS= arch.c buf.c compat.c cond.c dir.c for.c hash.c job.c main.c \ @@ -21,7 +21,7 @@ srcdir= @srcdir@ CC?= @CC@ # Base version on src date -MAKE_VERSION= 20100808 +MAKE_VERSION= 20110606 MACHINE=@machine@ MACHINE_ARCH=@machine_arch@ DEFAULT_SYS_PATH = @default_sys_path@ @@ -38,6 +38,16 @@ LDADD= @LIBS@ SRCS+= ${LIBOBJS:T:.o=.c} .endif +USE_META ?= @use_meta@ +.if ${USE_META:tl} != "no" +SRCS+= meta.c +CPPFLAGS+= -DUSE_META +FILEMON_H ?= @filemon_h@ +.if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h" +COPTS.meta.c += -DHAVE_FILEMON_H -I${FILEMON_H:H} +.endif +.endif + .PATH: ${srcdir} .PATH: ${srcdir}/lst.lib diff --git a/devel/bmake/files/arch.c b/devel/bmake/files/arch.c index 70a8768100d..80c289a7637 100644 --- a/devel/bmake/files/arch.c +++ b/devel/bmake/files/arch.c @@ -1,4 +1,4 @@ -/* $NetBSD: arch.c,v 1.1.1.6 2010/04/20 13:32:19 joerg Exp $ */ +/* $NetBSD: arch.c,v 1.1.1.7 2011/06/18 22:17:42 bsiegert Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: arch.c,v 1.1.1.6 2010/04/20 13:32:19 joerg Exp $"; +static char rcsid[] = "$NetBSD: arch.c,v 1.1.1.7 2011/06/18 22:17:42 bsiegert Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)arch.c 8.2 (Berkeley) 1/2/94"; #else -__RCSID("$NetBSD: arch.c,v 1.1.1.6 2010/04/20 13:32:19 joerg Exp $"); +__RCSID("$NetBSD: arch.c,v 1.1.1.7 2011/06/18 22:17:42 bsiegert Exp $"); #endif #endif /* not lint */ #endif @@ -1260,7 +1260,7 @@ Arch_FindLib(GNode *gn, Lst path) * A library will be considered out-of-date for any of these reasons, * given that it is a target on a dependency line somewhere: * Its modification time is less than that of one of its - * sources (gn->mtime < gn->cmtime). + * sources (gn->mtime < gn->cmgn->mtime). * Its modification time is greater than the time at which the * make began (i.e. it's been modified in the course * of the make, probably by archiving). @@ -1293,8 +1293,9 @@ Arch_LibOODate(GNode *gn) oodate = TRUE; } else if (OP_NOP(gn->type) && Lst_IsEmpty(gn->children)) { oodate = FALSE; - } else if ((!Lst_IsEmpty(gn->children) && gn->cmtime == 0) || - (gn->mtime > now) || (gn->mtime < gn->cmtime)) { + } else if ((!Lst_IsEmpty(gn->children) && gn->cmgn == NULL) || + (gn->mtime > now) || + (gn->cmgn != NULL && gn->mtime < gn->cmgn->mtime)) { oodate = TRUE; } else { #ifdef RANLIBMAG @@ -1309,7 +1310,7 @@ Arch_LibOODate(GNode *gn) if (DEBUG(ARCH) || DEBUG(MAKE)) { fprintf(debug_file, "%s modified %s...", RANLIBMAG, Targ_FmtTime(modTimeTOC)); } - oodate = (gn->cmtime > modTimeTOC); + oodate = (gn->cmgn == NULL || gn->cmgn->mtime > modTimeTOC); } else { /* * A library w/o a table of contents is out-of-date diff --git a/devel/bmake/files/bmake.1 b/devel/bmake/files/bmake.1 index 4fe03dab4c1..124c04a41ff 100644 --- a/devel/bmake/files/bmake.1 +++ b/devel/bmake/files/bmake.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: bmake.1,v 1.1.1.3 2010/09/07 14:11:53 joerg Exp $ +.\" $NetBSD: bmake.1,v 1.1.1.4 2011/06/18 22:17:44 bsiegert Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" -.Dd June 30, 2010 +.Dd May 29, 2011 .Dt MAKE 1 .Os .Sh NAME @@ -194,6 +194,8 @@ Print commands in Makefiles regardless of whether or not they are prefixed by .Ql @ or other "quiet" flags. Also known as "loud" behavior. +.It Ar M +Print debugging information about "meta" mode decisions about targets. .It Ar m Print debugging information about making targets, including modification dates. @@ -266,6 +268,8 @@ cooperate to avoid overloading the system. Specify the maximum number of jobs that .Nm may have running at any one time. +The value is saved in +.Va .MAKE.JOBS . Turns compatibility mode off, unless the .Ar B flag is also specified. @@ -759,9 +763,65 @@ Processed after reading all makefiles. Can affect the mode that .Nm runs in. -Currently just -.Ql Pa compat -mode. +It can contain a number of keywords: +.Bl -hang -width ignore-cmd +.It Pa compat +Like +.Fl B , +puts +.Nm +into "compat" mode. +.It Pa meta +Puts +.Nm +into "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 very useful when diagnosing errors. +.It Pa curdirOk= Ar bf +Normally +.Nm +will not create .meta files in +.Ql Va .CURDIR . +This can be overridden by setting +.Va bf +to a value which represents True. +.It Pa 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 the value of: +.Va .MAKE.META.PREFIX . +.It Pa 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 +.Ic .NOMETA_CMP . +.El +.It Va .MAKE.META.BAILIWICK +In "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.CREATED +In "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 "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.PREFIX +Defines the message printed for each meta file updated in "meta verbose" mode. +The default value is: +.Dl Building ${.TARGET:H:tA}/${.TARGET:T} .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 @@ -990,6 +1050,18 @@ safely through recursive invocations of .Nm . .It Cm \&:R Replaces each word in the variable with everything but its suffix. +.It Cm \&:gmtime +The value is a format string for +.Xr strftime 3 , +using the current +.Xr gmtime 3 . +.It Cm \&:hash +Compute a 32bit hash of the value and encode it as hex digits. +.It Cm \&:localtime +The value is a format string for +.Xr strftime 3 , +using the current +.Xr localtime 3 . .It Cm \&:tA Attempt to convert variable to an absolute path using .Xr realpath 3 , @@ -1129,7 +1201,7 @@ A common error is trying to use expressions like .Dl ${NUMBERS:M42:?match:no} which actually tests defined(NUMBERS), to determine is any words match "42" you need to use something like: -.Dl ${${NUMBERS:M42} != "":?match:no} . +.Dl ${"${NUMBERS:M42}" != \&"\&":?match:no} . .It Ar :old_string=new_string This is the .At V @@ -1612,6 +1684,27 @@ or 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. +.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 will still be out of date. .It Ic .NOPATH Do not search for the target in the directories specified by .Ic .PATH . @@ -1774,7 +1867,7 @@ could be built, unless is built by another part of the dependency graph, the following is a dependency loop: .Bd -literal -\&.ORDER: a b +\&.ORDER: b a b: a .Ed .Pp @@ -1926,6 +2019,21 @@ The way that .for loop variables are substituted changed after 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 +Unlike other +.Nm +programs, this implementation by default executes all commands for a given +target using a single shell invocation. +This is done for both efficiency and to simplify error handling in remote +command invocations. +Typically this is transparent to the user, unless the target commands change +the current working directory using +.Dq cd +or +.Dq chdir . +To be compatible with Makefiles that do this, one can use +.Fl B +to disable this behavior. .Sh SEE ALSO .Xr mkdep 1 .Sh HISTORY diff --git a/devel/bmake/files/bmake.cat1 b/devel/bmake/files/bmake.cat1 index a88acfe3147..8fceef71e5b 100644 --- a/devel/bmake/files/bmake.cat1 +++ b/devel/bmake/files/bmake.cat1 @@ -96,6 +96,1299 @@ DDEESSCCRRIIPPTTIIOONN 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 _/_t_m_p if TMPDIR is unset or set to the empty + string. The temporary scripts are created by mkstemp(3), + and have names of the form _m_a_k_e_X_X_X_X_X_X. _N_O_T_E: This can + create many files in TMPDIR or _/_t_m_p, 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 Print debugging information about variable assignment. + + _x Run shell commands with --xx so the actual commands are + printed as they are executed. + + --ee Specify that environment variables override macro assignments + within makefiles. + + --ff _m_a_k_e_f_i_l_e + Specify a makefile to read instead of the default `_m_a_k_e_f_i_l_e'. If + _m_a_k_e_f_i_l_e is `--', standard input is read. Multiple makefiles may + be specified, and are read in the order specified. + + --II _d_i_r_e_c_t_o_r_y + Specify a directory in which to search for makefiles and included + makefiles. The system makefile directory (or directories, see + the --mm option) is automatically included as part of this list. + + --ii Ignore non-zero exit of shell commands in the makefile. Equiva- + lent to specifying `--' before each command line in the makefile. + + --JJ _p_r_i_v_a_t_e + This option should _n_o_t 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. + + --jj _m_a_x___j_o_b_s + Specify the maximum number of jobs that bbmmaakkee may have running at + any one time. The value is saved in _._M_A_K_E_._J_O_B_S. Turns compati- + bility mode off, unless the _B flag is also specified. When com- + patibility mode is off, all commands associated with a target are + executed in a single shell invocation as opposed to the tradi- + tional 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. + + --kk Continue processing after errors are encountered, but only on + those targets that do not depend on the target whose creation + caused the error. + + --mm _d_i_r_e_c_t_o_r_y + Specify a directory in which to search for sys.mk and makefiles + included via the <_f_i_l_e>-style include statement. The --mm option + can be used multiple times to form a search path. This path will + override the default system include path: /usr/share/mk. Fur- + thermore the system include path will be appended to the search + path used for "_f_i_l_e"-style include statements (see the --II + option). + + If a file or directory name in the --mm argument (or the + MAKESYSPATH environment variable) starts with the string ".../" + then bbmmaakkee will search for the specified file or directory named + in the remaining part of the argument string. The search starts + with the current directory of the Makefile and then works upward + towards the root of the filesystem. If the search is successful, + then the resulting directory replaces the ".../" specification in + the --mm argument. If used, this feature allows bbmmaakkee to easily + search in the current source tree for customized sys.mk files + (e.g., by using ".../mk/sys.mk" as an argument). + + --nn 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). + + --NN Display the commands which would have been executed, but do not + actually execute any of them; useful for debugging top-level + makefiles without descending into subdirectories. + + --qq Do not execute any commands, but exit 0 if the specified targets + are up-to-date and 1, otherwise. + + --rr Do not use the built-in rules specified in the system makefile. + + --ss Do not echo any commands as they are executed. Equivalent to + specifying `@@' before each command line in the makefile. + + --TT _t_r_a_c_e_f_i_l_e + When used with the --jj flag, append a trace record to _t_r_a_c_e_f_i_l_e + for each job started and completed. + + --tt 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. + + --VV _v_a_r_i_a_b_l_e + Print bbmmaakkee's idea of the value of _v_a_r_i_a_b_l_e, in the global con- + text. Do not build any targets. Multiple instances of this + option may be specified; the variables will be printed one per + line, with a blank line for each null or undefined variable. If + _v_a_r_i_a_b_l_e contains a `$' then the value will be expanded before + printing. + + --WW Treat any warnings during makefile parsing as errors. + + --XX 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 _M_A_K_E_F_L_A_G_S environment variable. This + option may be useful on systems which have a small limit on the + size of command arguments. + + _v_a_r_i_a_b_l_e_=_v_a_l_u_e + Set the value of the variable _v_a_r_i_a_b_l_e to _v_a_l_u_e. Normally, all + values passed on the command line are also exported to sub-makes + in the environment. The --XX flag disables this behavior. Vari- + able assignments should follow options for POSIX compatibility + but no ordering is enforced. + + There are seven different types of lines in a makefile: file dependency + specifications, shell commands, variable assignments, include statements, + conditional directives, for loops, and comments. + + In general, 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. + +FFIILLEE DDEEPPEENNDDEENNCCYY SSPPEECCIIFFIICCAATTIIOONNSS + 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 usually created from them. The exact relationship + between the target and the source is determined by the operator that sep- + arates them. The three operators are as follows: + + :: A target is considered out-of-date if its modification time is less + than those of any of its sources. Sources for a target accumulate + over dependency lines when this operator is used. The target is + removed if bbmmaakkee is interrupted. + + !! Targets are always re-created, but not until all sources have been + examined and re-created as necessary. Sources for a target accumu- + late over dependency lines when this operator is used. The target + is removed if bbmmaakkee is interrupted. + + :::: If no sources are specified, the target is always re-created. Oth- + erwise, a target is considered out-of-date if any of its sources + has been modified more recently than the target. Sources for a + target do not accumulate over dependency lines when this operator + is used. The target will not be removed if bbmmaakkee is interrupted. + + 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 must be used to describe + 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. + +SSHHEELLLL CCOOMMMMAANNDDSS + Each target may have associated with it a series of shell commands, nor- + mally used to create the target. Each of the commands in this script + _m_u_s_t be preceded by a tab. While any target may appear on a dependency + line, only one of these dependencies may be followed by a creation + script, unless the `::::' operator is used. + + If the first characters of the command line are any combination of `@@', + `++', or `--', the command is treated specially. A `@@' causes the command + not to be echoed before it is executed. A `++' causes the command to be + executed even when --nn 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. A `--' causes any non-zero exit status of the command + line to be ignored. + +VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS + Variables in make are much like variables in the shell, and, by tradi- + tion, consist of all upper-case letters. + + VVaarriiaabbllee aassssiiggnnmmeenntt mmooddiiffiieerrss + The five operators that can be used to assign values to variables are as + follows: + + == Assign the value to the variable. Any previous value is overrid- + den. + + ++== Append the value to the current value of the variable. + + ??== Assign the value to the variable if it is not already defined. + + ::== Assign with expansion, i.e. expand the value before assigning it + to the variable. Normally, expansion is not done until the vari- + able is referenced. _N_O_T_E: References to undefined variables are + _n_o_t expanded. This can cause problems when variable modifiers + are used. + + !!== Expand the value and pass it to the shell for execution and + assign the result to the variable. Any newlines in the result + are replaced with spaces. + + Any white-space before the assigned _v_a_l_u_e is removed; if the value is + being appended, a single space is inserted between the previous contents + of the variable and the appended value. + + Variables are expanded by surrounding the variable name with either curly + braces (`{}') or parentheses (`()') and preceding it with a dollar sign + (`$'). If the variable name contains only a single letter, the surround- + ing braces or parentheses are not required. This shorter form is not + recommended. + + If the variable name contains a dollar, then the name itself is expanded + first. This allows almost arbitrary variable names, however names con- + taining dollar, braces, parenthesis, or whitespace are really best + avoided! + + If the result of expanding a variable contains a dollar sign (`$') the + string is expanded again. + + Variable substitution occurs at three 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 shell commands are expanded when the shell command is + executed. + + 3. ``.for'' loop index variables are expanded on each loop iteration. + Note that other variables are not expanded inside loops so the fol- + lowing example code: + + + .for i in 1 2 3 + a+= ${i} + j= ${i} + b+= ${j} + .endfor + + all: + @echo ${a} + @echo ${b} + + will print: + + 1 2 3 + 3 3 3 + + Because while ${a} contains ``1 2 3'' after the loop is executed, + ${b} contains ``${j} ${j} ${j}'' which expands to ``3 3 3'' since + after the loop completes ${j} contains ``3''. + + VVaarriiaabbllee ccllaasssseess + The four different classes of variables (in order of increasing prece- + dence) are: + + Environment variables + Variables defined as part of bbmmaakkee'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. The + seven local variables are as follows: + + _._A_L_L_S_R_C The list of all sources for this target; also known as + `_>'. + + _._A_R_C_H_I_V_E The name of the archive file. + + _._I_M_P_S_R_C 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. + + _._M_E_M_B_E_R The name of the archive member. + + _._O_O_D_A_T_E The list of sources for this target that were deemed + out-of-date; also known as `_?'. + + _._P_R_E_F_I_X The file prefix of the target, containing only the file + portion, no suffix or preceding directory components; + also known as `_*'. + + _._T_A_R_G_E_T The name of the target; also known as `_@'. + + The shorter forms `_@', `_?', `_<', `_>', and `_*' are permitted for + backward compatibility with historical makefiles and are not rec- + ommended. The six variables `_@_F', `_@_D', `_<_F', `_<_D', `_*_F', and + `_*_D' are permitted for compatibility with AT&T System V UNIX + makefiles and 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 `_._T_A_R_G_E_T', `_._P_R_E_F_I_X', `_._A_R_C_H_I_V_E', + and `_._M_E_M_B_E_R'. + + AAddddiittiioonnaall bbuuiilltt--iinn vvaarriiaabblleess + In addition, bbmmaakkee sets or knows about the following variables: + + _$ A single dollar sign `$', i.e. `$$' expands to a single + dollar sign. + + _._A_L_L_T_A_R_G_E_T_S The list of all targets encountered in the Makefile. If + evaluated during Makefile parsing, lists only those tar- + gets encountered thus far. + + _._C_U_R_D_I_R A path to the directory where bbmmaakkee was executed. Refer + to the description of `PWD' for more details. + + MAKE The name that bbmmaakkee was executed with (_a_r_g_v_[_0_]). For + compatibility bbmmaakkee also sets _._M_A_K_E with the same value. + The preferred variable to use is the environment variable + MAKE because it is more compatible with other versions of + bbmmaakkee and cannot be confused with the special target with + the same name. + + _._M_A_K_E_._D_E_P_E_N_D_F_I_L_E + Names the makefile (default `_._d_e_p_e_n_d') from which gener- + ated dependencies are read. + + _._M_A_K_E_._E_X_P_O_R_T_E_D The list of variables exported by bbmmaakkee. + + _._M_A_K_E_._J_O_B_S The argument to the --jj option. + + _._M_A_K_E_._J_O_B_._P_R_E_F_I_X + If bbmmaakkee is run with _j then output for each target is + prefixed with a token `--- target ---' the first part of + which can be controlled via _._M_A_K_E_._J_O_B_._P_R_E_F_I_X. + For example: + .MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}] + would produce tokens like `---make[1234] target ---' mak- + ing it easier to track the degree of parallelism being + achieved. + + MAKEFLAGS The environment variable `MAKEFLAGS' may contain anything + that may be specified on bbmmaakkee's command line. Anything + specified on bbmmaakkee's command line is appended to the + `MAKEFLAGS' variable which is then entered into the envi- + ronment for all programs which bbmmaakkee executes. + + _._M_A_K_E_._L_E_V_E_L The recursion depth of bbmmaakkee. The initial instance of + bbmmaakkee will be 0, and an incremented value is put into the + environment to be seen by the next generation. This + allows tests like: .if ${.MAKE.LEVEL} == 0 to protect + things which should only be evaluated in the initial + instance of bbmmaakkee. + + _._M_A_K_E_._M_A_K_E_F_I_L_E___P_R_E_F_E_R_E_N_C_E + The ordered list of makefile names (default `_m_a_k_e_f_i_l_e', + `_M_a_k_e_f_i_l_e') that bbmmaakkee will look for. + + _._M_A_K_E_._M_A_K_E_F_I_L_E_S + The list of makefiles read by bbmmaakkee, which is useful for + tracking dependencies. Each makefile is recorded only + once, regardless of the number of times read. + + _._M_A_K_E_._M_O_D_E Processed after reading all makefiles. Can affect the + mode that bbmmaakkee runs in. It can contain a number of key- + words: + + _c_o_m_p_a_t Like --BB, puts bbmmaakkee into "compat" mode. + + _m_e_t_a Puts bbmmaakkee 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 bbmmaakkee. The captured + output can be very useful when diagnosing + errors. + + _c_u_r_d_i_r_O_k_= _b_f Normally bbmmaakkee will not create .meta files + in `_._C_U_R_D_I_R'. This can be overridden by set- + ting _b_f to a value which represents True. + + _v_e_r_b_o_s_e 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 the value of: + _._M_A_K_E_._M_E_T_A_._P_R_E_F_I_X. + + _i_g_n_o_r_e_-_c_m_d 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 + ..NNOOMMEETTAA__CCMMPP. + + _._M_A_K_E_._M_E_T_A_._B_A_I_L_I_W_I_C_K + In "meta" mode, provides a list of prefixes which match + the directories controlled by bbmmaakkee. If a file that was + generated outside of _._O_B_J_D_I_R but within said bailiwick is + missing, the current target is considered out-of-date. + + _._M_A_K_E_._M_E_T_A_._C_R_E_A_T_E_D + In "meta" mode, this variable contains a list of all the + meta files updated. If not empty, it can be used to + trigger processing of _._M_A_K_E_._M_E_T_A_._F_I_L_E_S. + + _._M_A_K_E_._M_E_T_A_._F_I_L_E_S + 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 informa- + tion. + + _._M_A_K_E_._M_E_T_A_._P_R_E_F_I_X + Defines the message printed for each meta file updated in + "meta verbose" mode. The default value is: + Building ${.TARGET:H:tA}/${.TARGET:T} + + _._M_A_K_E_O_V_E_R_R_I_D_E_S 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 behaviour can be + disabled by assigning an empty value to `_._M_A_K_E_O_V_E_R_R_I_D_E_S' + within a makefile. Extra variables can be exported from + a makefile by appending their names to `_._M_A_K_E_O_V_E_R_R_I_D_E_S'. + `MAKEFLAGS' is re-exported whenever `_._M_A_K_E_O_V_E_R_R_I_D_E_S' is + modified. + + _._M_A_K_E_._P_I_D The process-id of bbmmaakkee. + + _._M_A_K_E_._P_P_I_D The parent process-id of bbmmaakkee. + + _M_A_K_E___P_R_I_N_T___V_A_R___O_N___E_R_R_O_R + When bbmmaakkee stops due to an error, it prints its name and + the value of `_._C_U_R_D_I_R' as well as the value of any vari- + ables named in `_M_A_K_E___P_R_I_N_T___V_A_R___O_N___E_R_R_O_R'. + + _._n_e_w_l_i_n_e This variable is simply assigned a newline character as + its value. This allows expansions using the ::@@ modifier + to put a newline between iterations of the loop rather + than a space. For example, the printing of + `_M_A_K_E___P_R_I_N_T___V_A_R___O_N___E_R_R_O_R' could be done as + ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}. + + _._O_B_J_D_I_R A path to the directory where the targets are built. Its + value is determined by trying to chdir(2) to the follow- + ing directories in order and using the first match: + + 1. ${MAKEOBJDIRPREFIX}${.CURDIR} + + (Only if `MAKEOBJDIRPREFIX' is set in the environ- + ment or on the command line.) + + 2. ${MAKEOBJDIR} + + (Only if `MAKEOBJDIR' is set in the environment or + on the command line.) + + 3. ${.CURDIR}_/_o_b_j_.${MACHINE} + + 4. ${.CURDIR}_/_o_b_j + + 5. _/_u_s_r_/_o_b_j_/${.CURDIR} + + 6. ${.CURDIR} + + Variable expansion is performed on the value before it's + used, so expressions such as + ${.CURDIR:S,^/usr/src,/var/obj,} + may be used. This is especially useful with + `MAKEOBJDIR'. + + `_._O_B_J_D_I_R' may be modified in the makefile as a global + variable. In all cases, bbmmaakkee will chdir(2) to `_._O_B_J_D_I_R' + and set `PWD' to that directory before executing any tar- + gets. + + _._P_A_R_S_E_D_I_R A path to the directory of the current `_M_a_k_e_f_i_l_e' being + parsed. + + _._P_A_R_S_E_F_I_L_E The basename of the current `_M_a_k_e_f_i_l_e' being parsed. + This variable and `_._P_A_R_S_E_D_I_R' are both set only while the + `_M_a_k_e_f_i_l_e_s' are being parsed. + + _._P_A_T_H A variable that represents the list of directories that + bbmmaakkee will search for files. The search list should be + updated using the target `_._P_A_T_H' rather than the vari- + able. + + PWD Alternate path to the current directory. bbmmaakkee normally + sets `_._C_U_R_D_I_R' to the canonical path given by getcwd(3). + However, if the environment variable `PWD' is set and + gives a path to the current directory, then bbmmaakkee sets + `_._C_U_R_D_I_R' to the value of `PWD' instead. This behaviour + is disabled if `MAKEOBJDIRPREFIX' is set or `MAKEOBJDIR' + contains a variable transform. `PWD' is set to the value + of `_._O_B_J_D_I_R' for all programs which bbmmaakkee executes. + + .TARGETS The list of targets explicitly specified on the command + line, if any. + + VPATH Colon-separated (``:'') lists of directories that bbmmaakkee + will search for files. The variable is supported for + compatibility with old make programs only, use `_._P_A_T_H' + instead. + + VVaarriiaabbllee mmooddiiffiieerrss + Variable expansion may be modified to select or modify each word of the + variable (where a ``word'' is white-space delimited sequence of charac- + ters). The general format of a variable expansion is as follows: + + ${variable[:modifier[:...]]} + + Each modifier begins with a colon, which may be escaped with a backslash + (`\'). + + A set of 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 must appear in the referencing variable. If any + of the modifiers in the modifier_variable contain a dollar sign (`$'), + these must be doubled to avoid early expansion. + + The supported modifiers are: + + ::EE Replaces each word in the variable with its suffix. + + ::HH Replaces each word in the variable with everything but the last com- + ponent. + + ::MM_p_a_t_t_e_r_n + Select only those words that match _p_a_t_t_e_r_n. The standard shell + wildcard characters (`*', `?', and `[]') may be used. The wildcard + characters may be escaped with a backslash (`\'). + + ::NN_p_a_t_t_e_r_n + This is identical to `::MM', but selects all words which do not match + _p_a_t_t_e_r_n. + + ::OO Order every word in variable alphabetically. To sort words in + reverse order use the `::OO::[[--11....11]]' combination of modifiers. + + ::OOxx Randomize words in variable. The results will be different each + time you are referring to the modified variable; use the assignment + with expansion (`::==') to prevent such behaviour. 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 + + ::QQ Quotes every shell meta-character in the variable, so that it can be + passed safely through recursive invocations of bbmmaakkee. + + ::RR Replaces each word in the variable with everything but its suffix. + + ::ggmmttiimmee + The value is a format string for strftime(3), using the current + gmtime(3). + + ::hhaasshh + Compute a 32bit hash of the value and encode it as hex digits. + + ::llooccaallttiimmee + The value is a format string for strftime(3), using the current + localtime(3). + + ::ttAA Attempt to convert variable to an absolute path using realpath(3), + if that fails, the value is unchanged. + + ::ttll Converts variable to lower-case letters. + + ::ttss_c + Words in the variable are normally separated by a space on expan- + sion. This modifier sets the separator to the character _c. If _c is + omitted, then no separator is used. The common escapes (including + octal numeric codes), work as expected. + + ::ttuu Converts variable to upper-case letters. + + ::ttWW Causes the value to be treated as a single word (possibly containing + embedded white space). See also `::[[**]]'. + + ::ttww Causes the value to be treated as a sequence of words delimited by + white space. See also `::[[@@]]'. + + ::SS/_o_l_d___s_t_r_i_n_g/_n_e_w___s_t_r_i_n_g/[11ggWW] + Modify the first occurrence of _o_l_d___s_t_r_i_n_g in the variable's value, + replacing it with _n_e_w___s_t_r_i_n_g. If a `g' is appended to the last + slash of the pattern, all occurrences in each word are replaced. If + a `1' is appended to the last slash of the pattern, only the first + word is affected. If a `W' is appended to the last slash of the + pattern, then the value is treated as a single word (possibly con- + taining embedded white space). If _o_l_d___s_t_r_i_n_g begins with a caret + (`^'), _o_l_d___s_t_r_i_n_g is anchored at the beginning of each word. If + _o_l_d___s_t_r_i_n_g ends with a dollar sign (`$'), it is anchored at the end + of each word. Inside _n_e_w___s_t_r_i_n_g, an ampersand (`&') is replaced by + _o_l_d___s_t_r_i_n_g (without any `^' or `$'). Any character may be used as a + delimiter for the parts of the modifier string. The anchoring, + ampersand and delimiter characters may be escaped with a backslash + (`\'). + + Variable expansion occurs in the normal fashion inside both + _o_l_d___s_t_r_i_n_g and _n_e_w___s_t_r_i_n_g with the single exception that a backslash + is used to prevent the expansion of a dollar sign (`$'), not a pre- + ceding dollar sign as is usual. + + ::CC/_p_a_t_t_e_r_n/_r_e_p_l_a_c_e_m_e_n_t/[11ggWW] + The ::CC modifier is just like the ::SS modifier except that the old and + new strings, instead of being simple strings, are a regular expres- + sion (see regex(3)) string _p_a_t_t_e_r_n and an ed(1)-style string + _r_e_p_l_a_c_e_m_e_n_t. Normally, the first occurrence of the pattern _p_a_t_t_e_r_n + in each word of the value is substituted with _r_e_p_l_a_c_e_m_e_n_t. 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 _p_a_t_t_e_r_n 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 white space). Note that `1' + and `g' are orthogonal; the former specifies whether multiple words + are potentially affected, the latter whether multiple substitutions + can potentially occur within each affected word. + + ::TT Replaces each word in the variable with its last component. + + ::uu Remove adjacent duplicate words (like uniq(1)). + + ::??_t_r_u_e___s_t_r_i_n_g::_f_a_l_s_e___s_t_r_i_n_g + If the variable name (not its value), when parsed as a .if condi- + tional expression, evaluates to true, return as its value the + _t_r_u_e___s_t_r_i_n_g, otherwise return the _f_a_l_s_e___s_t_r_i_n_g. Since the variable + name is used as the expression, :? must be the first modifier after + the variable name itself - which will, of course, usually contain + variable expansions. A common error is trying to use expressions + like + ${NUMBERS:M42:?match:no} + which actually tests defined(NUMBERS), to determine is any words + match "42" you need to use something like: + ${"${NUMBERS:M42}" != "":?match:no}. + + _:_o_l_d___s_t_r_i_n_g_=_n_e_w___s_t_r_i_n_g + This is the AT&T System V UNIX style variable substitution. It must + be the last modifier specified. If _o_l_d___s_t_r_i_n_g or _n_e_w___s_t_r_i_n_g do not + contain the pattern matching character _% then it is assumed that + they are anchored at the end of each word, so only suffixes or + entire words may be replaced. Otherwise _% is the substring of + _o_l_d___s_t_r_i_n_g to be replaced in _n_e_w___s_t_r_i_n_g. + + Variable expansion occurs in the normal fashion inside both + _o_l_d___s_t_r_i_n_g and _n_e_w___s_t_r_i_n_g with the single exception that a backslash + is used to prevent the expansion of a dollar sign (`$'), not a pre- + ceding dollar sign as is usual. + + ::@@_t_e_m_p@@_s_t_r_i_n_g@@ + This is the loop expansion mechanism from the OSF Development Envi- + ronment (ODE) make. Unlike ..ffoorr loops expansion occurs at the time + of reference. Assign _t_e_m_p to each word in the variable and evaluate + _s_t_r_i_n_g. The ODE convention is that _t_e_m_p should start and end with a + period. For example. + ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@} + + ::UU_n_e_w_v_a_l + If the variable is undefined _n_e_w_v_a_l 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: + ${_${.TARGET:T}_CFLAGS:U${DEF_CFLAGS}} + If a value is only required if the variable is undefined, use: + ${VAR:D:Unewval} + + ::DD_n_e_w_v_a_l + If the variable is defined _n_e_w_v_a_l is the value. + + ::LL The name of the variable is the value. + + ::PP 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, then the name of + the variable is used. + + ::!!_c_m_d!! + The output of running _c_m_d is the value. + + ::sshh If the variable is non-empty it is run as a command and the output + becomes the new value. + + ::::==_s_t_r + The variable is assigned the value _s_t_r after substitution. This + modifier and its variations are useful in obscure situations such as + wanting to set a variable when shell commands are being parsed. + These assignment modifiers always expand to nothing, so if appearing + in a rule line by themselves should be preceded with something to + keep bbmmaakkee happy. + + The `::::' helps avoid false matches with the AT&T System V UNIX style + ::== modifier and since substitution always occurs the ::::== form is + vaguely appropriate. + + ::::??==_s_t_r + As for ::::== but only if the variable does not already have a value. + + ::::++==_s_t_r + Append _s_t_r to the variable. + + ::::!!==_c_m_d + Assign the output of _c_m_d to the variable. + + ::[[_r_a_n_g_e]] + Selects one or more words from the value, or performs other opera- + tions related to the way in which the value is divided into words. + + Ordinarily, a value is treated as a sequence of words delimited by + white space. Some modifiers suppress this behaviour, causing a + value to be treated as a single word (possibly containing embedded + white space). 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 integers (where index -1 represents the last word). + + The _r_a_n_g_e is subjected to variable expansion, and the expanded + result is then interpreted as follows: + + _i_n_d_e_x Selects a single word from the value. + + _s_t_a_r_t...._e_n_d + Selects all words from _s_t_a_r_t to _e_n_d, inclusive. For example, + `::[[22....--11]]' selects all words from the second word to the last + word. If _s_t_a_r_t is greater than _e_n_d, then the words are out- + put in reverse order. For example, `::[[--11....11]]' selects all + the words from last to first. + + ** Causes subsequent modifiers to treat the value as a single + word (possibly containing embedded white space). 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 white space. Analogous to the effect + of "$@" in Bourne shell. + + ## Returns the number of words in the value. + +IINNCCLLUUDDEE SSTTAATTEEMMEENNTTSS,, CCOONNDDIITTIIOONNAALLSS AANNDD FFOORR LLOOOOPPSS + Makefile inclusion, conditional structures and for loops reminiscent of + the C programming language are provided in bbmmaakkee. All such structures + are identified by a line beginning with a single dot (`.') character. + Files are included with either ..iinncclluuddee <_f_i_l_e> or ..iinncclluuddee "_f_i_l_e". 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 + expected to be in the system makefile directory. If double quotes are + used, the including makefile's directory and any directories specified + using the --II option are searched before the system makefile directory. + For compatibility with other versions of bbmmaakkee `include file ...' is also + accepted. If the include statement is written as ..--iinncclluuddee or as + ..ssiinncclluuddee then errors locating and/or opening include files are ignored. + + Conditional expressions are also preceded by a single dot as the first + character of a line. The possible conditionals are as follows: + + ..eerrrroorr _m_e_s_s_a_g_e + The message is printed along with the name of the makefile and + line number, then bbmmaakkee will exit. + + ..eexxppoorrtt _v_a_r_i_a_b_l_e _._._. + 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 --XX + flag, so should be used with caution. + + Appending a variable name to _._M_A_K_E_._E_X_P_O_R_T_E_D is equivalent to + exporting a variable. + + ..eexxppoorrtt--eennvv _v_a_r_i_a_b_l_e _._._. + The same as `.export', except that the variable is not appended + to _._M_A_K_E_._E_X_P_O_R_T_E_D. This allows exporting a value to the environ- + ment which is different from that used by bbmmaakkee internally. + + ..iinnffoo _m_e_s_s_a_g_e + The message is printed along with the name of the makefile and + line number. + + ..uunnddeeff _v_a_r_i_a_b_l_e + Un-define the specified global variable. Only global variables + may be un-defined. + + ..uunneexxppoorrtt _v_a_r_i_a_b_l_e _._._. + The opposite of `.export'. The specified global _v_a_r_i_a_b_l_e will be + removed from _._M_A_K_E_._E_X_P_O_R_T_E_D. If no variable list is provided, + all globals are unexported, and _._M_A_K_E_._E_X_P_O_R_T_E_D deleted. + + ..uunneexxppoorrtt--eennvv + Unexport all globals previously exported and clear the environ- + ment inherited from the parent. This operation will cause a mem- + ory leak of the original environment, so should be used spar- + ingly. Testing for _._M_A_K_E_._L_E_V_E_L being 0, would make sense. Also + note that any variables which originated in the parent environ- + ment 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' will also + be pushed into the new environment. + + ..wwaarrnniinngg _m_e_s_s_a_g_e + The message prefixed by `_w_a_r_n_i_n_g_:' is printed along with the name + of the makefile and line number. + + ..iiff [!]_e_x_p_r_e_s_s_i_o_n [_o_p_e_r_a_t_o_r _e_x_p_r_e_s_s_i_o_n _._._.] + Test the value of an expression. + + ..iiffddeeff [!]_v_a_r_i_a_b_l_e [_o_p_e_r_a_t_o_r _v_a_r_i_a_b_l_e _._._.] + Test the value of a variable. + + ..iiffnnddeeff [!]_v_a_r_i_a_b_l_e [_o_p_e_r_a_t_o_r _v_a_r_i_a_b_l_e _._._.] + Test the value of a variable. + + ..iiffmmaakkee [!]_t_a_r_g_e_t [_o_p_e_r_a_t_o_r _t_a_r_g_e_t _._._.] + Test the target being built. + + ..iiffnnmmaakkee [!] _t_a_r_g_e_t [_o_p_e_r_a_t_o_r _t_a_r_g_e_t _._._.] + Test the target being built. + + ..eellssee Reverse the sense of the last conditional. + + ..eelliiff [!] _e_x_p_r_e_s_s_i_o_n [_o_p_e_r_a_t_o_r _e_x_p_r_e_s_s_i_o_n _._._.] + A combination of `..eellssee' followed by `..iiff'. + + ..eelliiffddeeff [!]_v_a_r_i_a_b_l_e [_o_p_e_r_a_t_o_r _v_a_r_i_a_b_l_e _._._.] + A combination of `..eellssee' followed by `..iiffddeeff'. + + ..eelliiffnnddeeff [!]_v_a_r_i_a_b_l_e [_o_p_e_r_a_t_o_r _v_a_r_i_a_b_l_e _._._.] + A combination of `..eellssee' followed by `..iiffnnddeeff'. + + ..eelliiffmmaakkee [!]_t_a_r_g_e_t [_o_p_e_r_a_t_o_r _t_a_r_g_e_t _._._.] + A combination of `..eellssee' followed by `..iiffmmaakkee'. + + ..eelliiffnnmmaakkee [!]_t_a_r_g_e_t [_o_p_e_r_a_t_o_r _t_a_r_g_e_t _._._.] + A combination of `..eellssee' followed by `..iiffnnmmaakkee'. + + ..eennddiiff End the body of the conditional. + + The _o_p_e_r_a_t_o_r may be any one of the following: + + |||| Logical OR. + + &&&& Logical AND; of higher precedence than ``||''. + + As in C, bbmmaakkee will only evaluate a conditional as far as is necessary to + determine its value. Parentheses may be used to change the order of + evaluation. The boolean operator `!!' may be used to logically negate an + entire conditional. It is of higher precedence than `&&&&'. + + The value of _e_x_p_r_e_s_s_i_o_n may be any of the following: + + ddeeffiinneedd Takes a variable name as an argument and evaluates to true if + the variable has been defined. + + mmaakkee Takes a target name as an argument and evaluates to true if the + target was specified as part of bbmmaakkee's command line or was + declared the default target (either implicitly or explicitly, + see _._M_A_I_N) before the line containing the conditional. + + eemmppttyy Takes a variable, with possible modifiers, and evaluates to true + if the expansion of the variable would result in an empty + string. + + eexxiissttss Takes a file name as an argument and evaluates to true if the + file exists. The file is searched for on the system search path + (see _._P_A_T_H). + + ttaarrggeett Takes a target name as an argument and evaluates to true if the + target has been defined. + + ccoommmmaannddss + Takes a target name as an argument and evaluates to true if the + target has been defined and has commands associated with it. + + _E_x_p_r_e_s_s_i_o_n may also be an arithmetic or string comparison. Variable + expansion is performed on both sides of the comparison, after which the + integral values are compared. A value is interpreted as hexadecimal if + it is preceded by 0x, otherwise it is decimal; octal numbers are not sup- + ported. The standard C relational operators are all supported. If after + variable expansion, either the left or right hand side of a `====' or `!!==' + operator is not an integral value, then string comparison is performed + between the expanded variables. If no relational operator is given, it + is assumed that the expanded variable is being compared against 0 or an + empty string in the case of a string comparison. + + When bbmmaakkee is evaluating one of these conditional expressions, and it + encounters a (white-space separated) word it doesn't recognize, either + the ``make'' or ``defined'' expression is applied to it, depending on the + form of the conditional. If the form is `..iiffddeeff', `..iiffnnddeeff', or `..iiff' + the ``defined'' expression is applied. Similarly, if the form is + `..iiffmmaakkee' or `..iiffnnmmaakkee, tthhee' ``make'' expression is applied. + + If the conditional evaluates to true the parsing of the makefile contin- + ues as before. If it evaluates to false, the following lines are + skipped. In both cases this continues until a `..eellssee' or `..eennddiiff' is + found. + + For loops are typically used to apply a set of rules to a list of files. + The syntax of a for loop is: + + ..ffoorr _v_a_r_i_a_b_l_e [_v_a_r_i_a_b_l_e _._._.] iinn _e_x_p_r_e_s_s_i_o_n + <make-rules> + ..eennddffoorr + + After the for eexxpprreessssiioonn is evaluated, it is split into words. On each + iteration of the loop, one word is taken and assigned to each vvaarriiaabbllee, + in order, and these vvaarriiaabblleess are substituted into the mmaakkee--rruulleess 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. + +CCOOMMMMEENNTTSS + Comments begin with a hash (`#') character, anywhere but in a shell com- + mand line, and continue to the end of an unescaped new line. + +SSPPEECCIIAALL SSOOUURRCCEESS ((AATTTTRRIIBBUUTTEESS)) + ..EEXXEECC Target is never out of date, but always execute commands any- + way. + + ..IIGGNNOORREE Ignore any errors from the commands associated with this tar- + get, exactly as if they all were preceded by a dash (`-'). + + ..MMAADDEE Mark all sources of this target as being up-to-date. + + ..MMAAKKEE Execute the commands associated with this target even if the --nn + or --tt options were specified. Normally used to mark recursive + bbmmaakkee's. + + ..MMEETTAA Create a meta file for the target, even if it is flagged as + ..PPHHOONNYY, ..MMAAKKEE, or ..SSPPEECCIIAALL. Usage in conjunction with ..MMAAKKEE is + the most likely case. + + ..NNOOMMEETTAA Do not create a meta file for the target. Meta files are also + not created for ..PPHHOONNYY, ..MMAAKKEE, or ..SSPPEECCIIAALL targets. + + ..NNOOMMEETTAA__CCMMPP + 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 will still be out of date. + + ..NNOOPPAATTHH Do not search for the target in the directories specified by + ..PPAATTHH. + + ..NNOOTTMMAAIINN Normally bbmmaakkee 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. + + ..OOPPTTIIOONNAALL + If a target is marked with this attribute and bbmmaakkee can't fig- + ure out how to create it, it will ignore this fact and assume + the file isn't needed or already exists. + + ..PPHHOONNYY The target does not correspond to an actual file; it is always + considered to be out of date, and will not be created with the + --tt option. Suffix-transformation rules are not applied to + ..PPHHOONNYY targets. + + ..PPRREECCIIOOUUSS + When bbmmaakkee is interrupted, it normally removes any partially + made targets. This source prevents the target from being + removed. + + ..RREECCUURRSSIIVVEE + Synonym for ..MMAAKKEE. + + ..SSIILLEENNTT Do not echo any of the commands associated with this target, + exactly as if they all were preceded by an at sign (`@'). + + ..UUSSEE Turn the target into bbmmaakkee'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 + ..UUSSEE) of the source. If the target already has commands, the + ..UUSSEE target's commands are appended to them. + + ..UUSSEEBBEEFFOORREE + Exactly like ..UUSSEE, but prepend the ..UUSSEEBBEEFFOORREE target commands + to the target. + + ..WWAAIITT If ..WWAAIITT 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 depen- + dency 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 ..WWAAIITT is only relevant for parallel + makes. + +SSPPEECCIIAALL TTAARRGGEETTSS + Special targets may not be included with other targets, i.e. they must be + the only target specified. + + ..BBEEGGIINN Any command lines attached to this target are executed before + anything else is done. + + ..DDEEFFAAUULLTT + This is sort of a ..UUSSEE rule for any target (that was used only + as a source) that bbmmaakkee can't figure out any other way to cre- + ate. Only the shell script is used. The ..IIMMPPSSRRCC variable of a + target that inherits ..DDEEFFAAUULLTT's commands is set to the target's + own name. + + ..EENNDD Any command lines attached to this target are executed after + everything else is done. + + ..EERRRROORR Any command lines attached to this target are executed when + another target fails. The ..EERRRROORR__TTAARRGGEETT variable is set to the + target that failed. See also MMAAKKEE__PPRRIINNTT__VVAARR__OONN__EERRRROORR. + + ..IIGGNNOORREE Mark each of the sources with the ..IIGGNNOORREE attribute. If no + sources are specified, this is the equivalent of specifying the + --ii option. + + ..IINNTTEERRRRUUPPTT + If bbmmaakkee is interrupted, the commands for this target will be + executed. + + ..MMAAIINN If no target is specified when bbmmaakkee is invoked, this target + will be built. + + ..MMAAKKEEFFLLAAGGSS + This target provides a way to specify flags for bbmmaakkee when the + makefile is used. The flags are as if typed to the shell, + though the --ff option will have no effect. + + ..NNOOPPAATTHH Apply the ..NNOOPPAATTHH attribute to any specified sources. + + ..NNOOTTPPAARRAALLLLEELL + Disable parallel mode. + + ..NNOO__PPAARRAALLLLEELL + Synonym for ..NNOOTTPPAARRAALLLLEELL, for compatibility with other pmake + variants. + + ..OORRDDEERR The named targets are made in sequence. This ordering does not + add targets to the list of targets to be made. Since the depen- + dents of a target do not get built until the target 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 + + The ordering imposed by ..OORRDDEERR is only relevant for parallel + makes. + + ..PPAATTHH 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 deleted. If the + source is the special ..DDOOTTLLAASSTT target, then the current working + directory is searched last. + + ..PPHHOONNYY Apply the ..PPHHOONNYY attribute to any specified sources. + + ..PPRREECCIIOOUUSS + Apply the ..PPRREECCIIOOUUSS attribute to any specified sources. If no + sources are specified, the ..PPRREECCIIOOUUSS attribute is applied to + every target in the file. + + ..SSHHEELLLL Sets the shell that bbmmaakkee will use to execute commands. The + sources are a set of _f_i_e_l_d_=_v_a_l_u_e pairs. + + _n_a_m_e This is the minimal specification, used to select + one of the builtin shell specs; _s_h, _k_s_h, and _c_s_h. + + _p_a_t_h Specifies the path to the shell. + + _h_a_s_E_r_r_C_t_l Indicates whether the shell supports exit on error. + + _c_h_e_c_k The command to turn on error checking. + + _i_g_n_o_r_e The command to disable error checking. + + _e_c_h_o The command to turn on echoing of commands executed. + + _q_u_i_e_t The command to turn off echoing of commands exe- + cuted. + + _f_i_l_t_e_r The output to filter after issuing the _q_u_i_e_t com- + mand. It is typically identical to _q_u_i_e_t. + + _e_r_r_F_l_a_g The flag to pass the shell to enable error checking. + + _e_c_h_o_F_l_a_g The flag to pass the shell to enable command echo- + ing. + + _n_e_w_l_i_n_e 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'" + + ..SSIILLEENNTT Apply the ..SSIILLEENNTT attribute to any specified sources. If no + sources are specified, the ..SSIILLEENNTT attribute is applied to every + command in the file. + + ..SSUUFFFFIIXXEESS + Each source specifies a suffix to bbmmaakkee. If no sources are + specified, any previously specified suffixes are deleted. It + allows the creation of suffix-transformation rules. + + Example: + + .SUFFIXES: .o + .c.o: + cc -o ${.TARGET} -c ${.IMPSRC} + +EENNVVIIRROONNMMEENNTT + bbmmaakkee 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 bbmmaakkee and not as makefile variables; see the descrip- + tion of `_._O_B_J_D_I_R' for more details. + +FFIILLEESS + .depend list of dependencies + Makefile list of dependencies + makefile list of dependencies + sys.mk system makefile + /usr/share/mk system makefile directory + +CCOOMMPPAATTIIBBIILLIITTYY + The basic make syntax is compatible between different versions of make, + however the special variables, variable modifiers and conditionals are + not. + + The way that parallel makes are scheduled changed in NetBSD 4.0 so that + .ORDER and .WAIT apply recursively to the dependant nodes. The algo- + rithms used may change again in the future. + + 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. + + Unlike other bbmmaakkee programs, this implementation by default executes all + commands for a given target using a single shell invocation. This is + done for both efficiency and to simplify error handling in remote command + invocations. Typically this is transparent to the user, unless the tar- + get commands change the current working directory using ``cd'' or + ``chdir''. To be compatible with Makefiles that do this, one can use --BB + to disable this behavior. + +SSEEEE AALLSSOO + mkdep(1) + +HHIISSTTOORRYY + bbmmaakkee is derived from NetBSD's make(1). It uses autoconf to facilitate +MAKE(1) NetBSD General Commands Manual MAKE(1) + + portability to other platforms. + +NNAAMMEE + bbmmaakkee -- maintain program dependencies + +SSYYNNOOPPSSIISS + bbmmaakkee [--BBeeiikkNNnnqqrrssttWWXX] [--CC _d_i_r_e_c_t_o_r_y] [--DD _v_a_r_i_a_b_l_e] [--dd _f_l_a_g_s] + [--ff _m_a_k_e_f_i_l_e] [--II _d_i_r_e_c_t_o_r_y] [--JJ _p_r_i_v_a_t_e] [--jj _m_a_x___j_o_b_s] + [--mm _d_i_r_e_c_t_o_r_y] [--TT _f_i_l_e] [--VV _v_a_r_i_a_b_l_e] [_v_a_r_i_a_b_l_e_=_v_a_l_u_e] + [_t_a_r_g_e_t _._._.] + +DDEESSCCRRIIPPTTIIOONN + bbmmaakkee 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 --ff _m_a_k_e_f_i_l_e makefile option is + given, bbmmaakkee will try to open `_m_a_k_e_f_i_l_e' then `_M_a_k_e_f_i_l_e' in order to find + the specifications. If the file `_._d_e_p_e_n_d' exists, it is read (see + mkdep(1)). + + This manual page is intended as a reference document only. For a more + thorough description of bbmmaakkee and makefiles, please refer to _M_a_k_e _- _A + _T_u_t_o_r_i_a_l. + + bbmmaakkee will prepend the contents of the _M_A_K_E_F_L_A_G_S environment variable to + the command line arguments before parsing them. + + The options are as follows: + + --BB Try to be backwards compatible by executing a single shell per + command and by executing the commands to make the sources of a + dependency line in sequence. + + --CC _d_i_r_e_c_t_o_r_y + Change to _d_i_r_e_c_t_o_r_y before reading the makefiles or doing any- + thing else. If multiple --CC options are specified, each is inter- + preted relative to the previous one: --CC _/ --CC _e_t_c is equivalent to + --CC _/_e_t_c. + + --DD _v_a_r_i_a_b_l_e + Define _v_a_r_i_a_b_l_e to be 1, in the global context. + + --dd _[_-_]_f_l_a_g_s + Turn on debugging, and specify which portions of bbmmaakkee are to + print debugging information. Unless the flags are preceded by + `-' they are added to the _M_A_K_E_F_L_A_G_S environment variable and will + be processed by any child make processes. By default, debugging + information is printed to standard error, but this can be changed + using the _F debugging flag. The debugging output is always + unbuffered; in addition, if debugging is enabled but debugging + output is not directed to standard output, then the standard out- + put is line buffered. _F_l_a_g_s is one or more of the following: + + _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 current working direc- + tory. + + _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[++]_f_i_l_e_n_a_m_e + 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 `+', then the file will be opened in append mode; + otherwise the file will be overwritten. If the file name + is `stdout' or `stderr' then debugging output will be + written to the standard output or standard error output + file descriptors respectively (and the `+' option has no + effect). Otherwise, the output will be written to the + named file. If the file name ends `.%d' then the `%d' is + replaced by the pid. + + _f Print debugging information about loop evaluation. + + _g_1 Print the input graph before making anything. + + _g_2 Print the input graph after making everything, or before + exiting on error. + + _g_3 Print the input graph before exiting on error. + + _j Print debugging information about running multiple + shells. + + _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. @@ -145,14 +1438,15 @@ DDEESSCCRRIIPPTTIIOONN --jj _m_a_x___j_o_b_s Specify the maximum number of jobs that bbmmaakkee may have running at - any one time. Turns compatibility mode off, unless the _B flag is - also specified. When compatibility mode is off, all commands - associated with a target are executed in a single shell invoca- - tion 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. + any one time. The value is saved in _._M_A_K_E_._J_O_B_S. Turns compati- + bility mode off, unless the _B flag is also specified. When com- + patibility mode is off, all commands associated with a target are + executed in a single shell invocation as opposed to the tradi- + tional 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. --kk Continue processing after errors are encountered, but only on those targets that do not depend on the target whose creation @@ -463,7 +1757,56 @@ VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS once, regardless of the number of times read. _._M_A_K_E_._M_O_D_E Processed after reading all makefiles. Can affect the - mode that bbmmaakkee runs in. Currently just `_c_o_m_p_a_t' mode. + mode that bbmmaakkee runs in. It can contain a number of key- + words: + + _c_o_m_p_a_t Like --BB, puts bbmmaakkee into "compat" mode. + + _m_e_t_a Puts bbmmaakkee 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 bbmmaakkee. The captured + output can be very useful when diagnosing + errors. + + _c_u_r_d_i_r_O_k_= _b_f Normally bbmmaakkee will not create .meta files + in `_._C_U_R_D_I_R'. This can be overridden by set- + ting _b_f to a value which represents True. + + _v_e_r_b_o_s_e 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 the value of: + _._M_A_K_E_._M_E_T_A_._P_R_E_F_I_X. + + _i_g_n_o_r_e_-_c_m_d 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 + ..NNOOMMEETTAA__CCMMPP. + + _._M_A_K_E_._M_E_T_A_._B_A_I_L_I_W_I_C_K + In "meta" mode, provides a list of prefixes which match + the directories controlled by bbmmaakkee. If a file that was + generated outside of _._O_B_J_D_I_R but within said bailiwick is + missing, the current target is considered out-of-date. + + _._M_A_K_E_._M_E_T_A_._C_R_E_A_T_E_D + In "meta" mode, this variable contains a list of all the + meta files updated. If not empty, it can be used to + trigger processing of _._M_A_K_E_._M_E_T_A_._F_I_L_E_S. + + _._M_A_K_E_._M_E_T_A_._F_I_L_E_S + 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 informa- + tion. + + _._M_A_K_E_._M_E_T_A_._P_R_E_F_I_X + Defines the message printed for each meta file updated in + "meta verbose" mode. The default value is: + Building ${.TARGET:H:tA}/${.TARGET:T} _._M_A_K_E_O_V_E_R_R_I_D_E_S This variable is used to record the names of variables assigned to on the command line, so that they may be @@ -616,6 +1959,17 @@ VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS ::RR Replaces each word in the variable with everything but its suffix. + ::ggmmttiimmee + The value is a format string for strftime(3), using the current + gmtime(3). + + ::hhaasshh + Compute a 32bit hash of the value and encode it as hex digits. + + ::llooccaallttiimmee + The value is a format string for strftime(3), using the current + localtime(3). + ::ttAA Attempt to convert variable to an absolute path using realpath(3), if that fails, the value is unchanged. @@ -686,7 +2040,7 @@ VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS ${NUMBERS:M42:?match:no} which actually tests defined(NUMBERS), to determine is any words match "42" you need to use something like: - ${${NUMBERS:M42} != :?match:no}. + ${"${NUMBERS:M42}" != "":?match:no}. _:_o_l_d___s_t_r_i_n_g_=_n_e_w___s_t_r_i_n_g This is the AT&T System V UNIX style variable substitution. It must @@ -985,6 +2339,19 @@ SSPPEECCIIAALL SSOOUURRCCEESS ((AATTTTRRIIBBUUTTEESS)) or --tt options were specified. Normally used to mark recursive bbmmaakkee's. + ..MMEETTAA Create a meta file for the target, even if it is flagged as + ..PPHHOONNYY, ..MMAAKKEE, or ..SSPPEECCIIAALL. Usage in conjunction with ..MMAAKKEE is + the most likely case. + + ..NNOOMMEETTAA Do not create a meta file for the target. Meta files are also + not created for ..PPHHOONNYY, ..MMAAKKEE, or ..SSPPEECCIIAALL targets. + + ..NNOOMMEETTAA__CCMMPP + 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 will still be out of date. + ..NNOOPPAATTHH Do not search for the target in the directories specified by ..PPAATTHH. @@ -1095,7 +2462,7 @@ SSPPEECCIIAALL TTAARRGGEETTSS be built, unless `a' is built by another part of the dependency graph, the following is a dependency loop: - .ORDER: a b + .ORDER: b a b: a The ordering imposed by ..OORRDDEERR is only relevant for parallel @@ -1196,6 +2563,14 @@ CCOOMMPPAATTIIBBIILLIITTYY stops them being treated as syntax, and removes some obscure problems using them in .if statements. + Unlike other bbmmaakkee programs, this implementation by default executes all + commands for a given target using a single shell invocation. This is + done for both efficiency and to simplify error handling in remote command + invocations. Typically this is transparent to the user, unless the tar- + get commands change the current working directory using ``cd'' or + ``chdir''. To be compatible with Makefiles that do this, one can use --BB + to disable this behavior. + SSEEEE AALLSSOO mkdep(1) @@ -1203,4 +2578,4 @@ HHIISSTTOORRYY bbmmaakkee is derived from NetBSD's make(1). It uses autoconf to facilitate portability to other platforms. -NetBSD 5.0_STABLE June 30, 2010 NetBSD 5.0_STABLE +NetBSD 5.1 May 29, 2011 NetBSD 5.1 diff --git a/devel/bmake/files/boot-strap b/devel/bmake/files/boot-strap index 44d497c9883..9ecb73fd373 100755 --- a/devel/bmake/files/boot-strap +++ b/devel/bmake/files/boot-strap @@ -34,6 +34,16 @@ # # Possibly useful configure_args: # +# --without-meta +# disable use of meta mode. +# +# --without-filemon +# disable use of filemon(9) which is currently only +# available for NetBSD and FreeBSD. +# +# --with-filemon="path/to/filemon.h" +# enables use of filemon(9) by meta mode. +# # --with-machine="machine" # set "machine" to override that determined by # machine.sh @@ -53,7 +63,7 @@ # Simon J. Gerraty <sjg@crufty.net> # RCSid: -# $Id: boot-strap,v 1.1.1.9 2010/09/07 14:11:15 joerg Exp $ +# $Id: boot-strap,v 1.1.1.10 2011/06/18 22:17:47 bsiegert Exp $ # # @(#) Copyright (c) 2001 Simon J. Gerraty # @@ -263,6 +273,12 @@ ShareDir() { echo $1/share } +# make it easy to force prefix to use $HOST_TARGET +: looking at "$prefix" +case "$prefix" in +*/host?target) prefix=`echo "$prefix" | sed "s,host.target,${HOST_TARGET},"`;; +esac + share_dir="${share_dir:-`ShareDir $prefix`}" AddConfigure --prefix= "$prefix" @@ -294,7 +310,7 @@ if [ -s "${mksrc:-/dev/null}/install-mk" ]; then esac fi # make sure test below uses the same diff that configure did -TOOL_DIFF=`type diff | sed 's,^[^/][^/]*,,;q'` +TOOL_DIFF=`type diff | sed 's,[()],,g;s,^[^/][^/]*,,;q'` export MAKESYSPATH TOOL_DIFF if [ "$mksrc" ]; then $objdir/bmake test || exit 1 diff --git a/devel/bmake/files/compat.c b/devel/bmake/files/compat.c index 195328c1393..45d5686d6fe 100644 --- a/devel/bmake/files/compat.c +++ b/devel/bmake/files/compat.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat.c,v 1.1.1.7 2010/09/07 14:11:20 joerg Exp $ */ +/* $NetBSD: compat.c,v 1.1.1.8 2011/06/18 22:17:48 bsiegert Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: compat.c,v 1.1.1.7 2010/09/07 14:11:20 joerg Exp $"; +static char rcsid[] = "$NetBSD: compat.c,v 1.1.1.8 2011/06/18 22:17:48 bsiegert Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: compat.c,v 1.1.1.7 2010/09/07 14:11:20 joerg Exp $"); +__RCSID("$NetBSD: compat.c,v 1.1.1.8 2011/06/18 22:17:48 bsiegert Exp $"); #endif #endif /* not lint */ #endif @@ -355,6 +355,12 @@ again: local = TRUE; +#ifdef USE_META + if (useMeta) { + meta_compat_start(); + } +#endif + /* * Fork and execute the single command. If the fork fails, we abort. */ @@ -365,6 +371,11 @@ again: if (cpid == 0) { Check_Cwd(av); Var_ExportVars(); +#ifdef USE_META + if (useMeta) { + meta_compat_child(); + } +#endif if (local) (void)execvp(av[0], (char *const *)UNCONST(av)); else @@ -378,6 +389,12 @@ again: free(bp); Lst_Replace(cmdNode, NULL); +#ifdef USE_META + if (useMeta) { + meta_compat_parent(); + } +#endif + /* * The child is off and running. Now all we can do is wait... */ @@ -396,6 +413,11 @@ again: 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)) { fprintf(debug_file, "\n*** Failed target: %s\n*** Failed command: ", @@ -422,6 +444,11 @@ again: if (!WIFEXITED(reason) || (status != 0)) { if (errCheck) { +#ifdef USE_META + if (useMeta) { + meta_job_error(NULL, gn, 0, status); + } +#endif gn->made = ERROR; if (keepgoing) { /* @@ -503,10 +530,10 @@ Compat_Make(void *gnp, void *pgnp) } /* - * All the children were made ok. Now cmtime 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 the - * Make_OODate function. + * All the children were made ok. Now cmgn->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 the Make_OODate function. */ if (DEBUG(MAKE)) { fprintf(debug_file, "Examining %s...", gn->name); @@ -554,6 +581,11 @@ Compat_Make(void *gnp, void *pgnp) */ if (!touchFlag || (gn->type & OP_MAKE)) { curTarg = gn; +#ifdef USE_META + if (useMeta && !NoExecute(gn)) { + meta_job_start(NULL, gn); + } +#endif Lst_ForEach(gn->commands, CompatRunCommand, gn); curTarg = NULL; } else { @@ -562,6 +594,11 @@ Compat_Make(void *gnp, void *pgnp) } else { gn->made = ERROR; } +#ifdef USE_META + if (useMeta && !NoExecute(gn)) { + meta_job_finish(NULL); + } +#endif if (gn->made != ERROR) { /* diff --git a/devel/bmake/files/cond.c b/devel/bmake/files/cond.c index a2069d59447..c4345a85982 100644 --- a/devel/bmake/files/cond.c +++ b/devel/bmake/files/cond.c @@ -1,4 +1,4 @@ -/* $NetBSD: cond.c,v 1.1.1.6 2010/04/20 13:32:20 joerg Exp $ */ +/* $NetBSD: cond.c,v 1.1.1.7 2011/06/18 22:17:48 bsiegert Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: cond.c,v 1.1.1.6 2010/04/20 13:32:20 joerg Exp $"; +static char rcsid[] = "$NetBSD: cond.c,v 1.1.1.7 2011/06/18 22:17:48 bsiegert Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94"; #else -__RCSID("$NetBSD: cond.c,v 1.1.1.6 2010/04/20 13:32:20 joerg Exp $"); +__RCSID("$NetBSD: cond.c,v 1.1.1.7 2011/06/18 22:17:48 bsiegert Exp $"); #endif #endif /* not lint */ #endif @@ -327,7 +327,7 @@ CondGetArg(char **linePtr, char **argPtr, const char *func) *----------------------------------------------------------------------- */ static Boolean -CondDoDefined(int argLen, const char *arg) +CondDoDefined(int argLen __unused, const char *arg) { char *p1; Boolean result; @@ -376,7 +376,7 @@ CondStrMatch(const void *string, const void *pattern) *----------------------------------------------------------------------- */ static Boolean -CondDoMake(int argLen, const char *arg) +CondDoMake(int argLen __unused, const char *arg) { return Lst_Find(create, arg, CondStrMatch) != NULL; } @@ -395,22 +395,22 @@ CondDoMake(int argLen, const char *arg) *----------------------------------------------------------------------- */ static Boolean -CondDoExists(int argLen, const char *arg) +CondDoExists(int argLen __unused, const char *arg) { Boolean result; char *path; path = Dir_FindFile(arg, dirSearchPath); + if (DEBUG(COND)) { + fprintf(debug_file, "exists(%s) result is \"%s\"\n", + arg, path ? path : ""); + } if (path != NULL) { result = TRUE; free(path); } else { result = FALSE; } - if (DEBUG(COND)) { - fprintf(debug_file, "exists(%s) result is \"%s\"\n", - arg, path ? path : ""); - } return (result); } @@ -428,7 +428,7 @@ CondDoExists(int argLen, const char *arg) *----------------------------------------------------------------------- */ static Boolean -CondDoTarget(int argLen, const char *arg) +CondDoTarget(int argLen __unused, const char *arg) { GNode *gn; @@ -452,7 +452,7 @@ CondDoTarget(int argLen, const char *arg) *----------------------------------------------------------------------- */ static Boolean -CondDoCommands(int argLen, const char *arg) +CondDoCommands(int argLen __unused, const char *arg) { GNode *gn; @@ -790,7 +790,7 @@ done: } static int -get_mpt_arg(char **linePtr, char **argPtr, const char *func) +get_mpt_arg(char **linePtr, char **argPtr, const char *func __unused) { /* * Use Var_Parse to parse the spec in parens and return @@ -831,7 +831,7 @@ get_mpt_arg(char **linePtr, char **argPtr, const char *func) } static Boolean -CondDoEmpty(int arglen, const char *arg) +CondDoEmpty(int arglen, const char *arg __unused) { return arglen == 1; } diff --git a/devel/bmake/files/config.h.in b/devel/bmake/files/config.h.in index f0a3152c092..2c7e4eb297c 100644 --- a/devel/bmake/files/config.h.in +++ b/devel/bmake/files/config.h.in @@ -20,9 +20,21 @@ */ #undef HAVE_DIRENT_H +/* Define to 1 if you have the `dirname' function. */ +#undef HAVE_DIRNAME + /* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ #undef HAVE_DOPRNT +/* Define to 1 if you have the `err' function. */ +#undef HAVE_ERR + +/* Define to 1 if you have the `errx' function. */ +#undef HAVE_ERRX + +/* Define to 1 if you have the <err.h> header file. */ +#undef HAVE_ERR_H + /* Define to 1 if you have the <fcntl.h> header file. */ #undef HAVE_FCNTL_H @@ -50,6 +62,9 @@ /* Define to 1 if you have the <memory.h> header file. */ #undef HAVE_MEMORY_H +/* Define to 1 if you have the `mmap' function. */ +#undef HAVE_MMAP + /* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */ #undef HAVE_NDIR_H @@ -92,6 +107,9 @@ /* Define to 1 if you have the `strerror' function. */ #undef HAVE_STRERROR +/* Define to 1 if you have the `stresep' function. */ +#undef HAVE_STRESEP + /* Define to 1 if you have the `strftime' function. */ #undef HAVE_STRFTIME @@ -101,6 +119,12 @@ /* Define to 1 if you have the <string.h> header file. */ #undef HAVE_STRING_H +/* Define to 1 if you have the `strlcpy' function. */ +#undef HAVE_STRLCPY + +/* Define to 1 if you have the `strsep' function. */ +#undef HAVE_STRSEP + /* Define to 1 if you have the `strtod' function. */ #undef HAVE_STRTOD @@ -118,6 +142,9 @@ */ #undef HAVE_SYS_DIR_H +/* Define to 1 if you have the <sys/mman.h> header file. */ +#undef HAVE_SYS_MMAN_H + /* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'. */ #undef HAVE_SYS_NDIR_H @@ -173,6 +200,12 @@ /* Define to 1 if you have the `waitpid' function. */ #undef HAVE_WAITPID +/* Define to 1 if you have the `warn' function. */ +#undef HAVE_WARN + +/* Define to 1 if you have the `warnx' function. */ +#undef HAVE_WARNX + /* Define to 1 if `fork' works. */ #undef HAVE_WORKING_FORK diff --git a/devel/bmake/files/configure b/devel/bmake/files/configure index ebf085d5920..9a0d5fe4206 100755 --- a/devel/bmake/files/configure +++ b/devel/bmake/files/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.64 for bmake 20100414. +# Generated by GNU Autoconf 2.64 for bmake 2010505. # # Report bugs to <sjg@NetBSD.org>. # @@ -549,8 +549,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='bmake' PACKAGE_TARNAME='bmake' -PACKAGE_VERSION='20100414' -PACKAGE_STRING='bmake 20100414' +PACKAGE_VERSION='2010505' +PACKAGE_STRING='bmake 2010505' PACKAGE_BUGREPORT='sjg@NetBSD.org' PACKAGE_URL='' @@ -591,6 +591,8 @@ ac_includes_default="\ #endif" ac_subst_vars='LTLIBOBJS +filemon_h +use_meta diff_u GCC INSTALL @@ -656,6 +658,8 @@ ac_subst_files='' ac_user_opts=' enable_option_checking with_defshell +with_meta +with_filemon with_machine with_force_machine with_force_machine_arch @@ -1216,7 +1220,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures bmake 20100414 to adapt to many kinds of systems. +\`configure' configures bmake 2010505 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1277,7 +1281,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of bmake 20100414:";; + short | recursive ) echo "Configuration of bmake 2010505:";; esac cat <<\_ACEOF @@ -1293,6 +1297,8 @@ Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-defshell=SHELL use SHELL by default - must be sh compatible, use sh or ksh to pick the internal definitions + --without-meta dissable use of meta-mode + --with-filemon=path/filemon.h indicate path to filemon.h for meta-mode --with-machine=MACHINE explicitly set MACHINE --with-force-machine=MACHINE set FORCE_MACHINE --with-force-machine-arch=MACHINE set FORCE_MACHINE_ARCH @@ -1380,7 +1386,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -bmake configure 20100414 +bmake configure 2010505 generated by GNU Autoconf 2.64 Copyright (C) 2009 Free Software Foundation, Inc. @@ -1901,7 +1907,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by bmake $as_me 20100414, which was +It was created by bmake $as_me 2010505, which was generated by GNU Autoconf 2.64. Invocation command line was $ $0 $@ @@ -2267,6 +2273,47 @@ no) ;; esac fi +use_meta=yes + +# Check whether --with-meta was given. +if test "${with_meta+set}" = set; then : + withval=$with_meta; case "${withval}" in +yes|no) use_meta=${withval};; +*) as_fn_error "bad value ${withval} given for meta" "$LINENO" 5 ;; +esac +fi + + +# Check whether --with-filemon was given. +if test "${with_filemon+set}" = set; then : + withval=$with_filemon; case "/${withval}" in +/no|*/filemon.h) filemon_h="${withval}";; +*/filemon*) filemon_h="${withval}/filemon.h";; +*) as_fn_error "bad value ${withval} given for filemon" "$LINENO" 5 ;; +esac +else + +OS=`uname -s` +for d in "$srcdir/filemon" "$srcdir/../filemon" +do + for x in "/$OS" "" + do + filemon_h="$d$x/filemon.h" + test -s "$filemon_h" && break + done + test -s "$filemon_h" && break +done +test -s "${filemon_h:-/dev/null}" || filemon_h=no + +fi + +case "$use_meta" in +yes) + case "$filemon_h" in + *.h) echo "Using: filemon=$filemon_h" >&6;; + esac + ;; +esac ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -4508,11 +4555,13 @@ fi for ac_header in \ ar.h \ + err.h \ fcntl.h \ paths.h \ poll.h \ ranlib.h \ string.h \ + sys/mman.h \ sys/select.h \ sys/socket.h \ sys/time.h \ @@ -5360,11 +5409,14 @@ $as_echo "#define HAVE_WAIT3 1" >>confdefs.h fi for ac_func in \ + err \ + errx \ getcwd \ getenv \ getopt \ getwd \ killpg \ + mmap \ putenv \ select \ setenv \ @@ -5373,6 +5425,7 @@ for ac_func in \ snprintf \ strerror \ strftime \ + strsep \ strtod \ strtol \ unsetenv \ @@ -5380,6 +5433,8 @@ for ac_func in \ wait3 \ wait4 \ waitpid \ + warn \ + warnx \ do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` @@ -5397,6 +5452,9 @@ done for ac_func in \ getenv \ realpath \ + dirname \ + stresep \ + strlcpy \ do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` @@ -5793,6 +5851,8 @@ fi + + ac_config_files="$ac_config_files Makefile make-bootstrap.sh unit-tests/Makefile" cat >confcache <<\_ACEOF @@ -6301,7 +6361,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by bmake $as_me 20100414, which was +This file was extended by bmake $as_me 2010505, which was generated by GNU Autoconf 2.64. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -6361,7 +6421,7 @@ Report bugs to <sjg@NetBSD.org>." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_version="\\ -bmake config.status 20100414 +bmake config.status 2010505 configured by $0, generated by GNU Autoconf 2.64, with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" diff --git a/devel/bmake/files/configure.in b/devel/bmake/files/configure.in index 2855edcfc61..212e7058506 100644 --- a/devel/bmake/files/configure.in +++ b/devel/bmake/files/configure.in @@ -1,10 +1,10 @@ dnl dnl RCSid: -dnl $Id: configure.in,v 1.1.1.5 2010/04/20 13:32:23 joerg Exp $ +dnl $Id: configure.in,v 1.1.1.6 2011/06/18 22:17:53 bsiegert Exp $ dnl dnl Process this file with autoconf to produce a configure script dnl -AC_INIT([bmake], [20100414], [sjg@NetBSD.org]) +AC_INIT([bmake], [2010505], [sjg@NetBSD.org]) AC_CONFIG_HEADER(config.h) dnl @@ -22,6 +22,42 @@ no) ;; ;; esac]) dnl +use_meta=yes +AC_ARG_WITH(meta, +[ --without-meta dissable use of meta-mode], +[case "${withval}" in +yes|no) use_meta=${withval};; +*) AC_MSG_ERROR(bad value ${withval} given for meta) ;; +esac]) +dnl +AC_ARG_WITH(filemon, +[ --with-filemon=path/filemon.h indicate path to filemon.h for meta-mode], +[ case "/${withval}" in +/no|*/filemon.h) filemon_h="${withval}";; +*/filemon*) filemon_h="${withval}/filemon.h";; +*) AC_MSG_ERROR(bad value ${withval} given for filemon) ;; +esac], +[ +OS=`uname -s` +for d in "$srcdir/filemon" "$srcdir/../filemon" +do + for x in "/$OS" "" + do + filemon_h="$d$x/filemon.h" + test -s "$filemon_h" && break + done + test -s "$filemon_h" && break +done +test -s "${filemon_h:-/dev/null}" || filemon_h=no +]) +dnl echo "Note: use_meta=$use_meta filemon_h=$filemon_h" >&6 +case "$use_meta" in +yes) + case "$filemon_h" in + *.h) echo "Using: filemon=$filemon_h" >&6;; + esac + ;; +esac dnl dnl Check for OS problems dnl Solaris's signal.h only privides sigset_t etc if one of @@ -47,11 +83,13 @@ AC_HEADER_DIRENT dnl Keep this list sorted AC_CHECK_HEADERS( \ ar.h \ + err.h \ fcntl.h \ paths.h \ poll.h \ ranlib.h \ string.h \ + sys/mman.h \ sys/select.h \ sys/socket.h \ sys/time.h \ @@ -94,11 +132,14 @@ AC_FUNC_VPRINTF AC_FUNC_WAIT3 dnl Keep this list sorted AC_CHECK_FUNCS( \ + err \ + errx \ getcwd \ getenv \ getopt \ getwd \ killpg \ + mmap \ putenv \ select \ setenv \ @@ -107,6 +148,7 @@ AC_CHECK_FUNCS( \ snprintf \ strerror \ strftime \ + strsep \ strtod \ strtol \ unsetenv \ @@ -114,12 +156,17 @@ AC_CHECK_FUNCS( \ wait3 \ wait4 \ waitpid \ + warn \ + warnx \ ) dnl functions which we may need to provide AC_REPLACE_FUNCS( \ getenv \ realpath \ + dirname \ + stresep \ + strlcpy \ ) AC_CHECK_LIB([util], [emalloc], @@ -298,6 +345,8 @@ AC_SUBST(default_sys_path) AC_SUBST(INSTALL) AC_SUBST(GCC) AC_SUBST(diff_u) +AC_SUBST(use_meta) +AC_SUBST(filemon_h) AC_OUTPUT(Makefile make-bootstrap.sh unit-tests/Makefile) cat <<EOF diff --git a/devel/bmake/files/dir.c b/devel/bmake/files/dir.c index e4fe4280b92..680f7c37d2a 100644 --- a/devel/bmake/files/dir.c +++ b/devel/bmake/files/dir.c @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.1.1.5 2009/09/18 20:55:25 joerg Exp $ */ +/* $NetBSD: dir.c,v 1.1.1.6 2011/06/18 22:17:55 bsiegert Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: dir.c,v 1.1.1.5 2009/09/18 20:55:25 joerg Exp $"; +static char rcsid[] = "$NetBSD: dir.c,v 1.1.1.6 2011/06/18 22:17:55 bsiegert Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)dir.c 8.2 (Berkeley) 1/2/94"; #else -__RCSID("$NetBSD: dir.c,v 1.1.1.5 2009/09/18 20:55:25 joerg Exp $"); +__RCSID("$NetBSD: dir.c,v 1.1.1.6 2011/06/18 22:17:55 bsiegert Exp $"); #endif #endif /* not lint */ #endif @@ -1061,6 +1061,7 @@ Dir_FindFile(const char *name, Lst path) Boolean hasSlash; /* true if 'name' contains a / */ struct stat stb; /* Buffer for stat, if necessary */ Hash_Entry *entry; /* Entry for mtimes table */ + const char *trailing_dot = "."; /* * Find the final component of the name and note whether it has a @@ -1165,6 +1166,11 @@ Dir_FindFile(const char *name, Lst path) return NULL; } + if (*cp == '\0') { + /* we were given a trailing "/" */ + cp = trailing_dot; + } + if (name[0] != '/') { Boolean checkedDot = FALSE; @@ -1272,6 +1278,10 @@ Dir_FindFile(const char *name, Lst path) * b/c we added it here. This is not good... */ #ifdef notdef + if (cp == traling_dot) { + cp = strrchr(name, '/'); + cp += 1; + } cp[-1] = '\0'; (void)Dir_AddDir(path, name); cp[-1] = '/'; @@ -1434,6 +1444,31 @@ Dir_MTime(GNode *gn) fullName = NULL; else { fullName = Dir_FindFile(gn->name, Suff_FindPath(gn)); + if (fullName == NULL && gn->flags & FROM_DEPEND && + !Lst_IsEmpty(gn->iParents)) { + char *cp; + + cp = strrchr(gn->name, '/'); + if (cp) { + /* + * This is an implied source, and it may have moved, + * see if we can find it via the current .PATH + */ + cp++; + + fullName = Dir_FindFile(cp, Suff_FindPath(gn)); + if (fullName) { + /* + * Put the found file in gn->path + * so that we give that to the compiler. + */ + gn->path = bmake_strdup(fullName); + fprintf(stdout, + "%s: ignoring stale %s for %s, found %s\n", + progname, makeDependfile, gn->name, fullName); + } + } + } if (DEBUG(DIR)) fprintf(debug_file, "Found '%s' as '%s'\n", gn->name, fullName ? fullName : "(not found)" ); diff --git a/devel/bmake/files/dirname.c b/devel/bmake/files/dirname.c new file mode 100644 index 00000000000..2f4ede97a26 --- /dev/null +++ b/devel/bmake/files/dirname.c @@ -0,0 +1,95 @@ +/* $NetBSD: dirname.c,v 1.1.1.1 2011/06/18 22:17:55 bsiegert Exp $ */ + +/*- + * Copyright (c) 1997, 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein and Jason R. Thorpe. + * + * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif +#ifndef HAVE_DIRNAME + +#include <sys/cdefs.h> + +#ifdef HAVE_LIMITS_H +#include <limits.h> +#endif +#ifdef HAVE_STRING_H +#include <string.h> +#endif +#ifndef PATH_MAX +# define PATH_MAX 1024 +#endif + +char * +dirname(char *path) +{ + static char result[PATH_MAX]; + const char *lastp; + size_t len; + + /* + * If `path' is a null pointer or points to an empty string, + * return a pointer to the string ".". + */ + if ((path == NULL) || (*path == '\0')) + goto singledot; + + + /* Strip trailing slashes, if any. */ + lastp = path + strlen(path) - 1; + while (lastp != path && *lastp == '/') + lastp--; + + /* Terminate path at the last occurence of '/'. */ + do { + if (*lastp == '/') { + /* Strip trailing slashes, if any. */ + while (lastp != path && *lastp == '/') + lastp--; + + /* ...and copy the result into the result buffer. */ + len = (lastp - path) + 1 /* last char */; + if (len > (PATH_MAX - 1)) + len = PATH_MAX - 1; + + memcpy(result, path, len); + result[len] = '\0'; + + return (result); + } + } while (--lastp >= path); + + /* No /'s found, return a pointer to the string ".". */ +singledot: + result[0] = '.'; + result[1] = '\0'; + + return (result); +} +#endif diff --git a/devel/bmake/files/for.c b/devel/bmake/files/for.c index 26a34ad1da8..f98415563c4 100644 --- a/devel/bmake/files/for.c +++ b/devel/bmake/files/for.c @@ -1,4 +1,4 @@ -/* $NetBSD: for.c,v 1.1.1.6 2010/04/20 13:32:25 joerg Exp $ */ +/* $NetBSD: for.c,v 1.1.1.7 2011/06/18 22:17:55 bsiegert Exp $ */ /* * Copyright (c) 1992, The Regents of the University of California. @@ -30,14 +30,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: for.c,v 1.1.1.6 2010/04/20 13:32:25 joerg Exp $"; +static char rcsid[] = "$NetBSD: for.c,v 1.1.1.7 2011/06/18 22:17:55 bsiegert Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)for.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: for.c,v 1.1.1.6 2010/04/20 13:32:25 joerg Exp $"); +__RCSID("$NetBSD: for.c,v 1.1.1.7 2011/06/18 22:17:55 bsiegert Exp $"); #endif #endif /* not lint */ #endif @@ -366,7 +366,7 @@ for_substitute(Buffer *cmds, strlist_t *items, unsigned int item_no, char ech) } static char * -For_Iterate(void *v_arg) +For_Iterate(void *v_arg, size_t *ret_len) { For *arg = v_arg; int i, len; @@ -451,6 +451,7 @@ For_Iterate(void *v_arg) arg->sub_next += strlist_num(&arg->vars); arg->parse_buf = cp; + *ret_len = strlen(cp); return cp; } diff --git a/devel/bmake/files/job.c b/devel/bmake/files/job.c index 9c7adc9ad86..c7732eeafa0 100644 --- a/devel/bmake/files/job.c +++ b/devel/bmake/files/job.c @@ -1,4 +1,4 @@ -/* $NetBSD: job.c,v 1.1.1.8 2010/09/07 14:11:44 joerg Exp $ */ +/* $NetBSD: job.c,v 1.1.1.9 2011/06/18 22:17:58 bsiegert Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: job.c,v 1.1.1.8 2010/09/07 14:11:44 joerg Exp $"; +static char rcsid[] = "$NetBSD: job.c,v 1.1.1.9 2011/06/18 22:17:58 bsiegert Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: job.c,v 1.1.1.8 2010/09/07 14:11:44 joerg Exp $"); +__RCSID("$NetBSD: job.c,v 1.1.1.9 2011/06/18 22:17:58 bsiegert Exp $"); #endif #endif /* not lint */ #endif @@ -1030,6 +1030,11 @@ JobFinish (Job *job, WAIT_T status) MESSAGE(stdout, job->node); lastNode = job->node; } +#ifdef USE_META + if (useMeta) { + meta_job_error(job, job->node, job->flags, WEXITSTATUS(status)); + } +#endif (void)printf("*** [%s] Error code %d%s\n", job->node->name, WEXITSTATUS(status), @@ -1058,6 +1063,12 @@ JobFinish (Job *job, WAIT_T status) (void)fflush(stdout); } +#ifdef USE_META + if (useMeta) { + meta_job_finish(job); + } +#endif + return_job_token = FALSE; Trace_Log(JOBEND, job); @@ -1325,6 +1336,11 @@ JobExec(Job *job, char **argv) /* Child */ sigset_t tmask; +#ifdef USE_META + if (useMeta) { + meta_job_child(job); + } +#endif /* * Reset all signal handlers; this is necessary because we also * need to unblock signals before we exec(2). @@ -1588,6 +1604,11 @@ JobStart(GNode *gn, int flags) */ noExec = FALSE; +#ifdef USE_META + if (useMeta) { + meta_job_start(job, gn); + } +#endif /* * We can do all the commands at once. hooray for sanity */ @@ -1860,6 +1881,11 @@ end_loop: MESSAGE(stdout, job->node); lastNode = job->node; } +#ifdef USE_META + if (useMeta) { + meta_job_output(job, cp, gotNL ? "\n" : ""); + } +#endif (void)fprintf(stdout, "%s%s", cp, gotNL ? "\n" : ""); (void)fflush(stdout); } diff --git a/devel/bmake/files/job.h b/devel/bmake/files/job.h index 73dab3c2eb7..b3e7e26c58e 100644 --- a/devel/bmake/files/job.h +++ b/devel/bmake/files/job.h @@ -1,4 +1,4 @@ -/* $NetBSD: job.h,v 1.1.1.4 2009/09/18 20:55:27 joerg Exp $ */ +/* $NetBSD: job.h,v 1.1.1.5 2011/06/18 22:17:58 bsiegert Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -135,6 +135,11 @@ emul_poll(struct pollfd *fd, int nfd, int timeout); */ struct pollfd; + +#ifdef USE_META +# include "meta.h" +#endif + #define JOB_BUFSIZE 1024 typedef struct Job { int pid; /* The child's process ID */ @@ -165,6 +170,10 @@ typedef struct Job { /* Buffer for storing the output of the * job, line by line */ int curPos; /* Current position in op_outBuf */ + +#ifdef USE_META + struct BuildMon bm; +#endif } Job; #define inPipe jobPipe[0] diff --git a/devel/bmake/files/machine.sh b/devel/bmake/files/machine.sh index 2719b79d116..1f267b092ad 100755 --- a/devel/bmake/files/machine.sh +++ b/devel/bmake/files/machine.sh @@ -2,7 +2,7 @@ # derrived from /etc/rc_d/os.sh # RCSid: -# $Id: machine.sh,v 1.1.1.3 2009/09/18 20:55:27 joerg Exp $ +# $Id: machine.sh,v 1.1.1.4 2011/06/18 22:17:59 bsiegert Exp $ # # @(#) Copyright (c) 1994-2002 Simon J. Gerraty # @@ -23,8 +23,10 @@ OSMAJOR=`IFS=.; set $OSREL; echo $1` machine=`uname -p 2>/dev/null || uname -m` MACHINE= +# there is at least one case of `uname -p` outputting +# a bunch of usless drivel case "$machine" in -unknown) +unknown|*[!A-Za-z0-9_-]*) machine=`uname -m` ;; esac diff --git a/devel/bmake/files/main.c b/devel/bmake/files/main.c index c1943f684eb..0a8420f59f4 100644 --- a/devel/bmake/files/main.c +++ b/devel/bmake/files/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.1.1.9 2010/09/07 14:11:48 joerg Exp $ */ +/* $NetBSD: main.c,v 1.1.1.10 2011/06/18 22:18:00 bsiegert Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,7 +69,7 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: main.c,v 1.1.1.9 2010/09/07 14:11:48 joerg Exp $"; +static char rcsid[] = "$NetBSD: main.c,v 1.1.1.10 2011/06/18 22:18:00 bsiegert Exp $"; #else #include <sys/cdefs.h> #ifndef lint @@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\ #if 0 static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: main.c,v 1.1.1.9 2010/09/07 14:11:48 joerg Exp $"); +__RCSID("$NetBSD: main.c,v 1.1.1.10 2011/06/18 22:18:00 bsiegert Exp $"); #endif #endif /* not lint */ #endif @@ -183,8 +183,8 @@ static int ReadMakefile(const void *, const void *); static void usage(void); static Boolean ignorePWD; /* if we use -C, PWD is meaningless */ -static char curdir[MAXPATHLEN + 1]; /* startup directory */ static char objdir[MAXPATHLEN + 1]; /* where we chdir'ed to */ +char curdir[MAXPATHLEN + 1]; /* Startup directory */ char *progname; /* the program name */ char *makeDependfile; pid_t myPid; @@ -253,6 +253,9 @@ parse_debug_options(const char *argvalue) case 'l': debug |= DEBUG_LOUD; break; + case 'M': + debug |= DEBUG_META; + break; case 'm': debug |= DEBUG_MAKE; break; @@ -713,7 +716,7 @@ ReadAllMakefiles(const void *p, const void *q) return (ReadMakefile(p, q) == 0); } -static int +int str2Lst_Append(Lst lp, char *str, const char *sep) { char *cp; @@ -732,7 +735,7 @@ str2Lst_Append(Lst lp, char *str, const char *sep) #ifdef SIGINFO /*ARGSUSED*/ static void -siginfo(int signo) +siginfo(int signo __unused) { char dir[MAXPATHLEN]; char str[2 * MAXPATHLEN]; @@ -761,6 +764,10 @@ MakeMode(const char *mode) compatMake = TRUE; forceJobs = FALSE; } +#if USE_META + if (strstr(mode, "meta")) + meta_init(mode); +#endif } if (mp) free(mp); @@ -792,9 +799,9 @@ main(int argc, char **argv) char *p1, *path, *pwd; char mdpath[MAXPATHLEN]; #ifdef FORCE_MACHINE - char *machine = FORCE_MACHINE; + const char *machine = FORCE_MACHINE; #else - char *machine = getenv("MACHINE"); + const char *machine = getenv("MACHINE"); #endif const char *machine_arch = getenv("MACHINE_ARCH"); char *syspath = getenv("MAKESYSPATH"); @@ -990,7 +997,8 @@ main(int argc, char **argv) * We take care of PWD for the automounter below... */ if (getcwd(curdir, MAXPATHLEN) == NULL) { - (void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno)); + (void)fprintf(stderr, "%s: getcwd: %s.\n", + progname, strerror(errno)); exit(2); } @@ -1336,7 +1344,7 @@ ReadMakefile(const void *p, const void *q __unused) char *name, *path = bmake_malloc(len); if (!strcmp(fname, "-")) { - Parse_File("(stdin)", dup(fileno(stdin))); + Parse_File(NULL /*stdin*/, -1); Var_Set("MAKEFILE", "", VAR_GLOBAL, 0); } else { /* if we've chdir'd, rebuild the path name */ @@ -2013,20 +2021,10 @@ Main_ExportMAKEFLAGS(Boolean first) } } -/* - * Create and open a temp file using "pattern". - * If "fnamep" is provided set it to a copy of the filename created. - * Otherwise unlink the file once open. - */ -int -mkTempFile(const char *pattern, char **fnamep) +char * +getTmpdir(void) { static char *tmpdir = NULL; - char tfile[MAXPATHLEN]; - int fd; - - if (!pattern) - pattern = TMPPAT; if (!tmpdir) { struct stat st; @@ -2041,6 +2039,25 @@ mkTempFile(const char *pattern, char **fnamep) tmpdir = bmake_strdup(_PATH_TMP); } } + return tmpdir; +} + +/* + * Create and open a temp file using "pattern". + * If "fnamep" is provided set it to a copy of the filename created. + * Otherwise unlink the file once open. + */ +int +mkTempFile(const char *pattern, char **fnamep) +{ + static char *tmpdir = NULL; + char tfile[MAXPATHLEN]; + int fd; + + if (!pattern) + pattern = TMPPAT; + if (!tmpdir) + tmpdir = getTmpdir(); if (pattern[0] == '/') { snprintf(tfile, sizeof(tfile), "%s", pattern); } else { diff --git a/devel/bmake/files/make-bootstrap.sh.in b/devel/bmake/files/make-bootstrap.sh.in index 64cb9e4d308..07942d6f87e 100644 --- a/devel/bmake/files/make-bootstrap.sh.in +++ b/devel/bmake/files/make-bootstrap.sh.in @@ -6,13 +6,19 @@ srcdir=@srcdir@ DEFAULT_SYS_PATH="@default_sys_path@" +case "@use_meta@" in +yes) XDEFS="-DUSE_META ${XDEFS}";; +esac + CC="@CC@" -CFLAGS="@CFLAGS@ -I. -I${srcdir} @DEFS@ @CPPFLAGS@ -DMAKE_NATIVE ${XDEFS} \ - -D_PATH_DEFSYSPATH=\"${DEFAULT_SYS_PATH}\"" +CFLAGS="@CFLAGS@ -I. -I${srcdir} @DEFS@ @CPPFLAGS@ -DMAKE_NATIVE ${XDEFS}" MAKE_VERSION=`sed -n '/^MAKE_VERSION=/s,.*=[^0-9]*,,p' Makefile` -MDEFS="-D@force_machine@MACHINE=\"@machine@\" -DMACHINE_ARCH=\"@machine_arch@\" -DMAKE_VERSION=\"$MAKE_VERSION\"" +MDEFS="-DMAKE_VERSION=\"$MAKE_VERSION\" \ +-D@force_machine@MACHINE=\"@machine@\" -DMACHINE_ARCH=\"@machine_arch@\" \ +-D_PATH_DEFSYSPATH=\"${DEFAULT_SYS_PATH}\"" + LDFLAGS="@LDFLAGS@" LIBS="@LIBS@" @@ -35,7 +41,7 @@ do_compile() { do_compile2 "$obj" "$d/$src" "$@" || exit 1 return done - echo "Unknown object file '$1'" >&2 + echo "Unknown object file '$obj'" >&2 exit 1 } @@ -65,4 +71,14 @@ do do_compile "$o" done +case "@use_meta@" in +yes) + case "@filemon_h@" in + */filemon.h) FDEFS="-DHAVE_FILEMON_H -I`dirname @filemon_h@`";; + esac + do_compile meta.o ${FDEFS} + BASE_OBJECTS="meta.o ${BASE_OBJECTS}" + ;; +esac + do_link bmake main.o ${BASE_OBJECTS} ${LST_OBJECTS} ${LIB_OBJECTS} diff --git a/devel/bmake/files/make.1 b/devel/bmake/files/make.1 index 5eb2ce352fc..179f8e20668 100644 --- a/devel/bmake/files/make.1 +++ b/devel/bmake/files/make.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: make.1,v 1.1.1.8 2010/09/07 14:11:51 joerg Exp $ +.\" $NetBSD: make.1,v 1.1.1.9 2011/06/18 22:18:01 bsiegert Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" -.Dd June 30, 2010 +.Dd May 29, 2011 .Dt MAKE 1 .Os .Sh NAME @@ -194,6 +194,8 @@ Print commands in Makefiles regardless of whether or not they are prefixed by .Ql @ or other "quiet" flags. Also known as "loud" behavior. +.It Ar M +Print debugging information about "meta" mode decisions about targets. .It Ar m Print debugging information about making targets, including modification dates. @@ -266,6 +268,8 @@ cooperate to avoid overloading the system. Specify the maximum number of jobs that .Nm may have running at any one time. +The value is saved in +.Va .MAKE.JOBS . Turns compatibility mode off, unless the .Ar B flag is also specified. @@ -759,9 +763,65 @@ Processed after reading all makefiles. Can affect the mode that .Nm runs in. -Currently just -.Ql Pa compat -mode. +It can contain a number of keywords: +.Bl -hang -width ignore-cmd +.It Pa compat +Like +.Fl B , +puts +.Nm +into "compat" mode. +.It Pa meta +Puts +.Nm +into "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 very useful when diagnosing errors. +.It Pa curdirOk= Ar bf +Normally +.Nm +will not create .meta files in +.Ql Va .CURDIR . +This can be overridden by setting +.Va bf +to a value which represents True. +.It Pa 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 the value of: +.Va .MAKE.META.PREFIX . +.It Pa 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 +.Ic .NOMETA_CMP . +.El +.It Va .MAKE.META.BAILIWICK +In "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.CREATED +In "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 "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.PREFIX +Defines the message printed for each meta file updated in "meta verbose" mode. +The default value is: +.Dl Building ${.TARGET:H:tA}/${.TARGET:T} .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 @@ -990,6 +1050,18 @@ safely through recursive invocations of .Nm . .It Cm \&:R Replaces each word in the variable with everything but its suffix. +.It Cm \&:gmtime +The value is a format string for +.Xr strftime 3 , +using the current +.Xr gmtime 3 . +.It Cm \&:hash +Compute a 32bit hash of the value and encode it as hex digits. +.It Cm \&:localtime +The value is a format string for +.Xr strftime 3 , +using the current +.Xr localtime 3 . .It Cm \&:tA Attempt to convert variable to an absolute path using .Xr realpath 3 , @@ -1129,7 +1201,7 @@ A common error is trying to use expressions like .Dl ${NUMBERS:M42:?match:no} which actually tests defined(NUMBERS), to determine is any words match "42" you need to use something like: -.Dl ${${NUMBERS:M42} != "":?match:no} . +.Dl ${"${NUMBERS:M42}" != \&"\&":?match:no} . .It Ar :old_string=new_string This is the .At V @@ -1612,6 +1684,27 @@ or 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. +.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 will still be out of date. .It Ic .NOPATH Do not search for the target in the directories specified by .Ic .PATH . @@ -1774,7 +1867,7 @@ could be built, unless is built by another part of the dependency graph, the following is a dependency loop: .Bd -literal -\&.ORDER: a b +\&.ORDER: b a b: a .Ed .Pp @@ -1926,6 +2019,21 @@ The way that .for loop variables are substituted changed after 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 +Unlike other +.Nm +programs, this implementation by default executes all commands for a given +target using a single shell invocation. +This is done for both efficiency and to simplify error handling in remote +command invocations. +Typically this is transparent to the user, unless the target commands change +the current working directory using +.Dq cd +or +.Dq chdir . +To be compatible with Makefiles that do this, one can use +.Fl B +to disable this behavior. .Sh SEE ALSO .Xr mkdep 1 .Sh HISTORY @@ -1933,6 +2041,13 @@ A .Nm command appeared in .At v7 . +This +.Nm +implementation is based on Adam De Boor's pmake program which was written +for Sprint at Berkeley. +It was designed to be a parallel distributed make running jobs on different +machines using a daemon called +.Dq customs . .Sh BUGS The .Nm diff --git a/devel/bmake/files/make.c b/devel/bmake/files/make.c index 9c3ea58d659..1ba3c659760 100644 --- a/devel/bmake/files/make.c +++ b/devel/bmake/files/make.c @@ -1,4 +1,4 @@ -/* $NetBSD: make.c,v 1.1.1.6 2010/09/07 14:11:56 joerg Exp $ */ +/* $NetBSD: make.c,v 1.1.1.7 2011/06/18 22:18:02 bsiegert Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: make.c,v 1.1.1.6 2010/09/07 14:11:56 joerg Exp $"; +static char rcsid[] = "$NetBSD: make.c,v 1.1.1.7 2011/06/18 22:18:02 bsiegert Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)make.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: make.c,v 1.1.1.6 2010/09/07 14:11:56 joerg Exp $"); +__RCSID("$NetBSD: make.c,v 1.1.1.7 2011/06/18 22:18:02 bsiegert Exp $"); #endif #endif /* not lint */ #endif @@ -94,12 +94,12 @@ __RCSID("$NetBSD: make.c,v 1.1.1.6 2010/09/07 14:11:56 joerg Exp $"); * * Make_Update Update all parents of a given child. Performs * various bookkeeping chores like the updating - * of the cmtime field of the parent, filling + * of the cmgn field of the parent, filling * of the IMPSRC context variable, etc. It will * place the parent on the toBeMade queue if it * should be. * - * Make_TimeStamp Function to set the parent's cmtime field + * Make_TimeStamp Function to set the parent's cmgn field * based on a child's modification time. * * Make_DoAllVar Set up the various local variables for a @@ -154,7 +154,7 @@ make_abort(GNode *gn, int line) /*- *----------------------------------------------------------------------- * Make_TimeStamp -- - * Set the cmtime field of a parent node based on the mtime stamp in its + * Set the cmgn field of a parent node based on the mtime stamp in its * child. Called from MakeOODate via Lst_ForEach. * * Input: @@ -165,15 +165,15 @@ make_abort(GNode *gn, int line) * Always returns 0. * * Side Effects: - * The cmtime of the parent node will be changed if the mtime + * The cmgn of the parent node will be changed if the mtime * field of the child is greater than it. *----------------------------------------------------------------------- */ int Make_TimeStamp(GNode *pgn, GNode *cgn) { - if (cgn->mtime > pgn->cmtime) { - pgn->cmtime = cgn->mtime; + if (pgn->cmgn == NULL || cgn->mtime > pgn->cmgn->mtime) { + pgn->cmgn = cgn; } return (0); } @@ -207,7 +207,7 @@ MakeTimeStamp(void *pgn, void *cgn) * TRUE if the node is out of date. FALSE otherwise. * * Side Effects: - * The mtime field of the node and the cmtime field of its parents + * The mtime field of the node and the cmgn field of its parents * will/may be changed. *----------------------------------------------------------------------- */ @@ -265,7 +265,7 @@ Make_OODate(GNode *gn) * or non-existent. */ oodate = (gn->mtime == 0 || Arch_LibOODate(gn) || - (gn->cmtime == 0 && (gn->type & OP_DOUBLEDEP))); + (gn->cmgn == NULL && (gn->type & OP_DOUBLEDEP))); } else if (gn->type & OP_JOIN) { /* * A target with the .JOIN attribute is only considered @@ -293,21 +293,22 @@ Make_OODate(GNode *gn) } } oodate = TRUE; - } else if (gn->mtime < gn->cmtime || - (gn->cmtime == 0 && + } else if ((gn->cmgn != NULL && gn->mtime < gn->cmgn->mtime) || + (gn->cmgn == NULL && ((gn->mtime == 0 && !(gn->type & OP_OPTIONAL)) || gn->type & OP_DOUBLEDEP))) { /* * A node whose modification time is less than that of its - * youngest child or that has no children (cmtime == 0) and + * youngest child or that has no children (cmgn == NULL) and * either doesn't exist (mtime == 0) and it isn't optional * or was the object of a * :: operator is out-of-date. * Why? Because that's the way Make does it. */ if (DEBUG(MAKE)) { - if (gn->mtime < gn->cmtime) { - fprintf(debug_file, "modified before source..."); + if (gn->cmgn != NULL && gn->mtime < gn->cmgn->mtime) { + fprintf(debug_file, "modified before source %s...", + gn->cmgn->path); } else if (gn->mtime == 0) { fprintf(debug_file, "non-existent and no sources..."); } else { @@ -330,6 +331,12 @@ Make_OODate(GNode *gn) oodate = (gn->flags & FORCE) ? TRUE : FALSE; } +#ifdef USE_META + if (useMeta) { + oodate = meta_oodate(gn, oodate); + } +#endif + /* * If the target isn't out-of-date, the parents need to know its * modification time. Note that targets that appear to be out-of-date @@ -389,7 +396,7 @@ MakeAddChild(void *gnp, void *lp) * Always returns 0 * * Side Effects: - * The path and mtime of the node and the cmtime of the parent are + * The path and mtime of the node and the cmgn of the parent are * updated; the unmade children count of the parent is decremented. *----------------------------------------------------------------------- */ @@ -657,12 +664,12 @@ Make_Recheck(GNode *gn) * the toBeMade queue if this field becomes 0. * * If the child was made, the parent's flag CHILDMADE field will be - * set true and its cmtime set to now. + * set true. * * If the child is not up-to-date and still does not exist, * set the FORCE flag on the parents. * - * If the child wasn't made, the cmtime field of the parent will be + * If the child wasn't made, the cmgn field of the parent will be * altered if the child's mtime is big enough. * * Finally, if the child is the implied source for the parent, the diff --git a/devel/bmake/files/make.h b/devel/bmake/files/make.h index 856b3dfa2a0..796e3683ecf 100644 --- a/devel/bmake/files/make.h +++ b/devel/bmake/files/make.h @@ -1,4 +1,4 @@ -/* $NetBSD: make.h,v 1.1.1.6 2010/04/24 20:33:59 joerg Exp $ */ +/* $NetBSD: make.h,v 1.1.1.7 2011/06/18 22:18:03 bsiegert Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -203,8 +203,7 @@ typedef struct GNode { int unmade; /* The number of unmade children */ time_t mtime; /* Its modification time */ - time_t cmtime; /* The modification time of its youngest - * child */ + struct GNode *cmgn; /* The youngest child */ Lst iParents; /* Links to parents for which this is an * implied source, if any */ @@ -276,6 +275,9 @@ typedef struct GNode { #define OP_PHONY 0x00010000 /* Not a file target; run always */ #define OP_NOPATH 0x00020000 /* Don't search for file in the path */ #define OP_WAIT 0x00040000 /* .WAIT phony node */ +#define OP_NOMETA 0x00080000 /* .NOMETA do not create a .meta file */ +#define OP_META 0x00100000 /* .META we _do_ want a .meta file */ +#define OP_NOMETA_CMP 0x00200000 /* Do not compare commands in .meta file */ /* Attributes applied by PMake */ #define OP_TRANSFORM 0x80000000 /* The node is a transformation rule */ #define OP_MEMBER 0x40000000 /* Target is a member of an archive */ @@ -408,6 +410,7 @@ extern Boolean oldVars; /* Do old-style variable substitution */ extern Lst sysIncPath; /* The system include path. */ extern Lst defIncPath; /* The default include path. */ +extern char curdir[]; /* Startup directory */ extern char *progname; /* The program name */ extern char *makeDependfile; /* .depend */ @@ -449,6 +452,8 @@ extern int debug; #define DEBUG_SHELL 0x00800 #define DEBUG_ERROR 0x01000 #define DEBUG_LOUD 0x02000 +#define DEBUG_META 0x04000 + #define DEBUG_GRAPH3 0x10000 #define DEBUG_SCRIPT 0x20000 #define DEBUG_PARSE 0x40000 @@ -474,6 +479,7 @@ void PrintOnError(GNode *, const char *); void Main_ExportMAKEFLAGS(Boolean); Boolean Main_SetObjdir(const char *); int mkTempFile(const char *, char **); +int str2Lst_Append(Lst, char *, const char *); #ifdef __GNUC__ #define UNCONST(ptr) ({ \ diff --git a/devel/bmake/files/make_malloc.c b/devel/bmake/files/make_malloc.c index 83d37ac4d0f..f6f8a421d56 100644 --- a/devel/bmake/files/make_malloc.c +++ b/devel/bmake/files/make_malloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: make_malloc.c,v 1.1.1.1 2009/09/18 20:55:23 joerg Exp $ */ +/* $NetBSD: make_malloc.c,v 1.1.1.2 2011/06/18 22:18:03 bsiegert Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ #ifdef MAKE_NATIVE #include <sys/cdefs.h> -__RCSID("$NetBSD: make_malloc.c,v 1.1.1.1 2009/09/18 20:55:23 joerg Exp $"); +__RCSID("$NetBSD: make_malloc.c,v 1.1.1.2 2011/06/18 22:18:03 bsiegert Exp $"); #endif #include <stdio.h> @@ -48,7 +48,7 @@ enomem(void) { extern char *progname; - (void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno)); + (void)fprintf(stderr, "%s: %s.\n", progname, strerror(ENOMEM)); exit(2); } diff --git a/devel/bmake/files/meta.c b/devel/bmake/files/meta.c new file mode 100644 index 00000000000..cacb9a40626 --- /dev/null +++ b/devel/bmake/files/meta.c @@ -0,0 +1,1305 @@ +/* $NetBSD: meta.c,v 1.1.1.1 2011/06/18 22:18:04 bsiegert Exp $ */ + +/* + * Implement 'meta' mode. + * Adapted from John Birrell's patches to FreeBSD make. + * --sjg + */ +/* + * Copyright (c) 2009-2010, Juniper Networks, Inc. + * Portions Copyright (c) 2009, John Birrell. + * + * 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. + */ +#if defined(USE_META) + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <fcntl.h> +#include <libgen.h> +#include <errno.h> +#if !defined(HAVE_CONFIG_H) || defined(HAVE_ERR_H) +#include <err.h> +#endif + +#include "make.h" +#include "job.h" + +#ifdef HAVE_FILEMON_H +# include <filemon.h> +#endif +#if !defined(USE_FILEMON) && defined(FILEMON_SET_FD) +# define USE_FILEMON +#endif + +static BuildMon Mybm; /* for compat */ +static Lst metaBailiwick; /* our scope of control */ + +Boolean useMeta = FALSE; +static Boolean useFilemon = FALSE; +static Boolean writeMeta = FALSE; +static Boolean metaEnv = FALSE; /* don't save env unless asked */ +static Boolean metaVerbose = FALSE; +static Boolean metaIgnoreCMDs = FALSE; /* ignore CMDs in .meta files */ +static Boolean metaCurdirOk = FALSE; /* write .meta in .CURDIR Ok? */ + +extern Boolean forceJobs; +extern Boolean comatMake; + +#define MAKE_META_PREFIX ".MAKE.META.PREFIX" + +#ifndef N2U +# define N2U(n, u) (((n) + ((u) - 1)) / (u)) +#endif +#ifndef ROUNDUP +# define ROUNDUP(n, u) (N2U((n), (u)) * (u)) +#endif + +#if !defined(HAVE_STRSEP) +# define strsep(s, d) stresep((s), (d), 0) +#endif + +/* + * Filemon is a kernel module which snoops certain syscalls. + * + * C chdir + * E exec + * F [v]fork + * L [sym]link + * M rename + * R read + * W write + * S stat + * + * See meta_oodate below - we mainly care about 'E' and 'R'. + * + * We can still use meta mode without filemon, but + * the benefits are more limited. + */ +#ifdef USE_FILEMON +# ifndef _PATH_FILEMON +# define _PATH_FILEMON "/dev/filemon" +# endif + +/* + * Open the filemon device. + */ +static void +filemon_open(BuildMon *pbm) +{ + int retry; + + pbm->mon_fd = pbm->filemon_fd = -1; + if (!useFilemon) + return; + + for (retry = 5; retry >= 0; retry--) { + if ((pbm->filemon_fd = open(_PATH_FILEMON, O_RDWR)) >= 0) + break; + } + + if (pbm->filemon_fd < 0) { + useFilemon = FALSE; + warn("Could not open %s", _PATH_FILEMON); + return; + } + + /* + * We use a file outside of '.' + * to avoid a FreeBSD kernel bug where unlink invalidates + * cwd causing getcwd to do a lot more work. + * We only care about the descriptor. + */ + pbm->mon_fd = mkTempFile("filemon.XXXXXX", NULL); + if (ioctl(pbm->filemon_fd, FILEMON_SET_FD, &pbm->mon_fd) < 0) { + err(1, "Could not set filemon file descriptor!"); + } + /* we don't need these once we exec */ + (void)fcntl(pbm->mon_fd, F_SETFD, 1); + (void)fcntl(pbm->filemon_fd, F_SETFD, 1); +} + +/* + * Read the build monitor output file and write records to the target's + * metadata file. + */ +static void +filemon_read(FILE *mfp, int fd) +{ + FILE *fp; + char buf[BUFSIZ]; + + /* Check if we're not writing to a meta data file.*/ + if (mfp == NULL) { + if (fd >= 0) + close(fd); /* not interested */ + return; + } + /* rewind */ + lseek(fd, SEEK_SET, 0); + if ((fp = fdopen(fd, "r")) == NULL) + err(1, "Could not read build monitor file '%d'", fd); + + fprintf(mfp, "-- filemon acquired metadata --\n"); + + while (fgets(buf, sizeof(buf), fp)) { + fprintf(mfp, "%s", buf); + } + fflush(mfp); + clearerr(fp); + fclose(fp); +} +#endif + +/* + * when realpath() fails, + * we use this, to clean up ./ and ../ + */ +static void +eat_dots(char *buf, size_t bufsz, int dots) +{ + char *cp; + char *cp2; + const char *eat; + size_t eatlen; + + switch (dots) { + case 1: + eat = "/./"; + eatlen = 2; + break; + case 2: + eat = "/../"; + eatlen = 3; + break; + default: + return; + } + + do { + cp = strstr(buf, eat); + if (cp) { + cp2 = cp + eatlen; + if (dots == 2 && cp > buf) { + do { + cp--; + } while (cp > buf && *cp != '/'); + } + if (*cp == '/') { + strlcpy(cp, cp2, bufsz - (cp - buf)); + } else { + return; /* can't happen? */ + } + } + } while (cp); +} + +static char * +meta_name(struct GNode *gn, char *mname, size_t mnamelen, + const char *dname, + const char *tname) +{ + char buf[MAXPATHLEN]; + char cwd[MAXPATHLEN]; + char *rp; + char *cp; + char *tp; + char *p[4]; /* >= number of possible uses */ + int i; + + i = 0; + if (!dname) + dname = Var_Value(".OBJDIR", gn, &p[i++]); + if (!tname) + tname = Var_Value(TARGET, gn, &p[i++]); + + if (realpath(dname, cwd)) + dname = cwd; + + /* + * Weed out relative paths from the target file name. + * We have to be careful though since if target is a + * symlink, the result will be unstable. + * So we use realpath() just to get the dirname, and leave the + * basename as given to us. + */ + if ((cp = strrchr(tname, '/'))) { + if (realpath(tname, buf)) { + if ((rp = strrchr(buf, '/'))) { + rp++; + cp++; + if (strcmp(cp, rp) != 0) + strlcpy(rp, cp, sizeof(buf) - (rp - buf)); + } + tname = buf; + } else { + /* + * We likely have a directory which is about to be made. + * We pretend realpath() succeeded, to have a chance + * of generating the same meta file name that we will + * next time through. + */ + if (tname[0] == '/') { + strlcpy(buf, tname, sizeof(buf)); + } else { + snprintf(buf, sizeof(buf), "%s/%s", cwd, tname); + } + eat_dots(buf, sizeof(buf), 1); /* ./ */ + eat_dots(buf, sizeof(buf), 2); /* ../ */ + tname = buf; + } + } + /* on some systems dirname may modify its arg */ + tp = bmake_strdup(tname); + if (strcmp(dname, dirname(tp)) == 0) + snprintf(mname, mnamelen, "%s.meta", tname); + else { + snprintf(mname, mnamelen, "%s/%s.meta", dname, tname); + + /* + * Replace path separators in the file name after the + * current object directory path. + */ + cp = mname + strlen(dname) + 1; + + while (*cp != '\0') { + if (*cp == '/') + *cp = '_'; + cp++; + } + } + free(tp); + for (i--; i >= 0; i--) { + if (p[i]) + free(p[i]); + } + return (mname); +} + +/* + * Return true if running ${.MAKE} + * Bypassed if target is flagged .MAKE + */ +static int +is_submake(void *cmdp, void *gnp) +{ + static char *p_make = NULL; + static int p_len; + char *cmd = cmdp; + GNode *gn = gnp; + char *mp = NULL; + char *cp; + char *cp2; + int rc = 0; /* keep looking */ + + if (!p_make) { + p_make = Var_Value(".MAKE", gn, &cp); + p_len = strlen(p_make); + } + cp = strchr(cmd, '$'); + if ((cp)) { + mp = Var_Subst(NULL, cmd, gn, FALSE); + cmd = mp; + } + cp2 = strstr(cmd, p_make); + if ((cp2)) { + switch (cp2[p_len]) { + case '\0': + case ' ': + case '\t': + case '\n': + rc = 1; + break; + } + if (cp2 > cmd && rc > 0) { + switch (cp2[-1]) { + case ' ': + case '\t': + case '\n': + break; + default: + rc = 0; /* no match */ + break; + } + } + } + if (mp) + free(mp); + return (rc); +} + +typedef struct meta_file_s { + FILE *fp; + GNode *gn; +} meta_file_t; + +static int +printCMD(void *cmdp, void *mfpp) +{ + meta_file_t *mfp = mfpp; + char *cmd = cmdp; + char *cp = NULL; + + if (strchr(cmd, '$')) { + cmd = cp = Var_Subst(NULL, cmd, mfp->gn, FALSE); + } + fprintf(mfp->fp, "CMD %s\n", cmd); + if (cp) + free(cp); + return 0; +} + +/* + * Certain node types never get a .meta file + */ +#define SKIP_META_TYPE(_type) do { \ + if ((gn->type & __CONCAT(OP_, _type))) { \ + if (DEBUG(META)) { \ + fprintf(debug_file, "Skipping meta for %s: .%s\n", \ + gn->name, __STRING(_type)); \ + } \ + return (NULL); \ + } \ +} while (0) + +static FILE * +meta_create(BuildMon *pbm, GNode *gn) +{ + extern char **environ; + meta_file_t mf; + char buf[MAXPATHLEN]; + char objdir[MAXPATHLEN]; + char **ptr; + const char *dname; + const char *tname; + char *fname; + const char *cp; + char *p[4]; /* >= possible uses */ + int i; + struct stat fs; + + + /* This may be a phony node which we don't want meta data for... */ + /* Skip .meta for .BEGIN, .END, .ERROR etc as well. */ + /* Or it may be explicitly flagged as .NOMETA */ + SKIP_META_TYPE(NOMETA); + /* Unless it is explicitly flagged as .META */ + if (!(gn->type & OP_META)) { + SKIP_META_TYPE(PHONY); + SKIP_META_TYPE(SPECIAL); + SKIP_META_TYPE(MAKE); + } + + mf.fp = NULL; + + i = 0; + + dname = Var_Value(".OBJDIR", gn, &p[i++]); + tname = Var_Value(TARGET, gn, &p[i++]); + + /* The object directory may not exist. Check it.. */ + if (stat(dname, &fs) != 0) { + if (DEBUG(META)) + fprintf(debug_file, "Skipping meta for %s: no .OBJDIR\n", + gn->name); + goto out; + } + /* Check if there are no commands to execute. */ + if (Lst_IsEmpty(gn->commands)) { + if (DEBUG(META)) + fprintf(debug_file, "Skipping meta for %s: no commands\n", + gn->name); + goto out; + } + + /* make sure these are canonical */ + if (realpath(dname, objdir)) + dname = objdir; + + /* If we aren't in the object directory, don't create a meta file. */ + if (!metaCurdirOk && strcmp(curdir, dname) == 0) { + if (DEBUG(META)) + fprintf(debug_file, "Skipping meta for %s: .OBJDIR == .CURDIR\n", + gn->name); + goto out; + } + if (!(gn->type & OP_META)) { + /* We do not generate .meta files for sub-makes */ + if (Lst_ForEach(gn->commands, is_submake, gn)) { + if (DEBUG(META)) + fprintf(debug_file, "Skipping meta for %s: .MAKE\n", + gn->name); + goto out; + } + } + + if (metaVerbose) { + char *mp; + + /* Describe the target we are building */ + mp = Var_Subst(NULL, "${" MAKE_META_PREFIX "}", gn, 0); + if (*mp) + fprintf(stdout, "%s\n", mp); + free(mp); + } + /* Get the basename of the target */ + if ((cp = strrchr(tname, '/')) == NULL) { + cp = tname; + } else { + cp++; + } + + fflush(stdout); + + if (strcmp(cp, makeDependfile) == 0) + goto out; + + if (!writeMeta) + /* Don't create meta data. */ + goto out; + + fname = meta_name(gn, pbm->meta_fname, sizeof(pbm->meta_fname), + dname, tname); + +#ifdef DEBUG_META_MODE + if (DEBUG(META)) + fprintf(debug_file, "meta_create: %s\n", fname); +#endif + + if ((mf.fp = fopen(fname, "w")) == NULL) + err(1, "Could not open meta file '%s'", fname); + + fprintf(mf.fp, "# Meta data file %s\n", fname); + + mf.gn = gn; + + Lst_ForEach(gn->commands, printCMD, &mf); + + fprintf(mf.fp, "CWD %s\n", getcwd(buf, sizeof(buf))); + fprintf(mf.fp, "TARGET %s\n", tname); + + if (metaEnv) { + for (ptr = environ; *ptr != NULL; ptr++) + fprintf(mf.fp, "ENV %s\n", *ptr); + } + + fprintf(mf.fp, "-- command output --\n"); + fflush(mf.fp); + + Var_Append(".MAKE.META.FILES", fname, VAR_GLOBAL); + Var_Append(".MAKE.META.CREATED", fname, VAR_GLOBAL); + + out: + for (i--; i >= 0; i--) { + if (p[i]) + free(p[i]); + } + + return (mf.fp); +} + +static Boolean +boolValue(char *s) +{ + switch(*s) { + case '0': + case 'N': + case 'n': + case 'F': + case 'f': + return FALSE; + } + return TRUE; +} + +void +meta_init(const char *make_mode) +{ + static int once = 0; + char *cp; + + useMeta = TRUE; + useFilemon = TRUE; + writeMeta = TRUE; + + if (make_mode) { + if (strstr(make_mode, "env")) + metaEnv = TRUE; + if (strstr(make_mode, "verb")) + metaVerbose = TRUE; + if (strstr(make_mode, "read")) + writeMeta = FALSE; + if (strstr(make_mode, "nofilemon")) + useFilemon = FALSE; + if ((cp = strstr(make_mode, "curdirok="))) { + metaCurdirOk = boolValue(&cp[9]); + } + if (strstr(make_mode, "ignore-cmd")) + metaIgnoreCMDs = TRUE; + /* for backwards compatability */ + Var_Set(".MAKE.META_CREATED", "${.MAKE.META.CREATED}", VAR_GLOBAL, 0); + Var_Set(".MAKE.META_FILES", "${.MAKE.META.FILES}", VAR_GLOBAL, 0); + } + if (metaVerbose && !Var_Exists(MAKE_META_PREFIX, VAR_GLOBAL)) { + /* + * The default value for MAKE_META_PREFIX + * prints the absolute path of the target. + * This works be cause :H will generate '.' if there is no / + * and :tA will resolve that to cwd. + */ + Var_Set(MAKE_META_PREFIX, "Building ${.TARGET:H:tA}/${.TARGET:T}", VAR_GLOBAL, 0); + } + if (once) + return; + once = 1; + memset(&Mybm, 0, sizeof(Mybm)); + /* + * We consider ourselves master of all within ${.MAKE.META.BAILIWICK} + */ + metaBailiwick = Lst_Init(FALSE); + cp = Var_Subst(NULL, "${.MAKE.META.BAILIWICK:O:u:tA}", VAR_GLOBAL, 0); + if (cp) { + str2Lst_Append(metaBailiwick, cp, NULL); + } +} + +/* + * In each case below we allow for job==NULL + */ +void +meta_job_start(Job *job, GNode *gn) +{ + BuildMon *pbm; + + if (job != NULL) { + pbm = &job->bm; + } else { + pbm = &Mybm; + } + pbm->mfp = meta_create(pbm, gn); +#ifdef USE_FILEMON_ONCE + /* compat mode we open the filemon dev once per command */ + if (job == NULL) + return; +#endif +#ifdef USE_FILEMON + if (pbm->mfp != NULL && useFilemon) { + filemon_open(pbm); + } else { + pbm->mon_fd = pbm->filemon_fd = -1; + } +#endif +} + +/* + * The child calls this before doing anything. + * It does not disturb our state. + */ +void +meta_job_child(Job *job) +{ +#ifdef USE_FILEMON + BuildMon *pbm; + pid_t pid; + + if (job != NULL) { + pbm = &job->bm; + } else { + pbm = &Mybm; + } + pid = getpid(); + if (pbm->mfp != NULL && useFilemon) { + if (ioctl(pbm->filemon_fd, FILEMON_SET_PID, &pid) < 0) { + err(1, "Could not set filemon pid!"); + } + } +#endif +} + +void +meta_job_error(Job *job, GNode *gn, int flags, int status) +{ + char cwd[MAXPATHLEN]; + BuildMon *pbm; + + if (job != NULL) { + pbm = &job->bm; + } else { + if (!gn) + gn = job->node; + pbm = &Mybm; + } + if (pbm->mfp != NULL) { + fprintf(pbm->mfp, "*** Error code %d%s\n", + status, + (flags & JOB_IGNERR) ? + "(ignored)" : ""); + } + if (gn) { + Var_Set(".ERROR_TARGET", gn->path ? gn->path : gn->name, VAR_GLOBAL, 0); + } + getcwd(cwd, sizeof(cwd)); + Var_Set(".ERROR_CWD", cwd, VAR_GLOBAL, 0); + if (pbm && pbm->meta_fname[0]) { + Var_Set(".ERROR_META_FILE", pbm->meta_fname, VAR_GLOBAL, 0); + } + meta_job_finish(job); +} + +void +meta_job_output(Job *job, char *cp, const char *nl) +{ + BuildMon *pbm; + + if (job != NULL) { + pbm = &job->bm; + } else { + pbm = &Mybm; + } + if (pbm->mfp != NULL) { + if (metaVerbose) { + static char *meta_prefix = NULL; + static int meta_prefix_len; + + if (!meta_prefix) { + char *cp2; + + meta_prefix = Var_Subst(NULL, "${" MAKE_META_PREFIX "}", VAR_GLOBAL, 0); + if ((cp2 = strchr(meta_prefix, '$'))) + meta_prefix_len = cp2 - meta_prefix; + else + meta_prefix_len = strlen(meta_prefix); + } + if (strncmp(cp, meta_prefix, meta_prefix_len) == 0) { + cp = strchr(cp+1, '\n'); + if (!cp++) + return; + } + } + fprintf(pbm->mfp, "%s%s", cp, nl); + } +} + +void +meta_cmd_finish(void *pbmp) +{ +#ifdef USE_FILEMON + BuildMon *pbm = pbmp; + + if (!pbm) + pbm = &Mybm; + + if (pbm->filemon_fd >= 0) { + close(pbm->filemon_fd); + filemon_read(pbm->mfp, pbm->mon_fd); + pbm->filemon_fd = pbm->mon_fd = -1; + } +#endif +} + +void +meta_job_finish(Job *job) +{ + BuildMon *pbm; + + if (job != NULL) { + pbm = &job->bm; + } else { + pbm = &Mybm; + } + if (pbm->mfp != NULL) { + meta_cmd_finish(pbm); + fclose(pbm->mfp); + pbm->mfp = NULL; + pbm->meta_fname[0] = '\0'; + } +} + +/* + * Fetch a full line from fp - growing bufp if needed + * Return length in bufp. + */ +static int +fgetLine(char **bufp, size_t *szp, int o, FILE *fp) +{ + char *buf = *bufp; + size_t bufsz = *szp; + struct stat fs; + int x; + + if (fgets(&buf[o], bufsz - o, fp) != NULL) { + check_newline: + x = o + strlen(&buf[o]); + if (buf[x - 1] == '\n') + return x; + /* + * We need to grow the buffer. + * The meta file can give us a clue. + */ + if (fstat(fileno(fp), &fs) == 0) { + size_t newsz; + char *p; + + newsz = ROUNDUP((fs.st_size / 2), BUFSIZ); + if (newsz <= bufsz) + newsz = ROUNDUP(fs.st_size, BUFSIZ); + if (DEBUG(META)) + fprintf(debug_file, "growing buffer %u -> %u\n", + bufsz, newsz); + p = bmake_realloc(buf, newsz); + if (p) { + *bufp = buf = p; + *szp = bufsz = newsz; + /* fetch the rest */ + if (!fgets(&buf[x], bufsz - x, fp)) + return x; /* truncated! */ + goto check_newline; + } + } + } + return 0; +} + +static int +prefix_match(void *p, void *q) +{ + const char *prefix = p; + const char *path = q; + size_t n = strlen(prefix); + + return (0 == strncmp(path, prefix, n)); +} + +static int +string_match(const void *p, const void *q) +{ + const char *p1 = p; + const char *p2 = q; + + return strcmp(p1, p2); +} + + +/* + * When running with 'meta' functionality, a target can be out-of-date + * if any of the references in it's meta data file is more recent. + * We have to track the latestdir on a per-process basis. + */ +#define LDIR_VNAME_FMT ".meta.%d.ldir" + +Boolean +meta_oodate(GNode *gn, Boolean oodate) +{ + static char *tmpdir = NULL; + static char cwd[MAXPATHLEN]; + char ldir_vname[64]; + char latestdir[MAXPATHLEN]; + char fname[MAXPATHLEN]; + char fname1[MAXPATHLEN]; + char fname2[MAXPATHLEN]; + char *p; + char *cp; + static size_t cwdlen = 0; + static size_t tmplen = 0; + FILE *fp; + Boolean ignoreOODATE = FALSE; + Lst missingFiles; + + if (oodate) + return oodate; /* we're done */ + + missingFiles = Lst_Init(FALSE); + + /* + * We need to check if the target is out-of-date. This includes + * checking if the expanded command has changed. This in turn + * requires that all variables are set in the same way that they + * would be if the target needs to be re-built. + */ + Make_DoAllVar(gn); + + meta_name(gn, fname, sizeof(fname), NULL, NULL); + +#ifdef DEBUG_META_MODE + if (DEBUG(META)) + fprintf(debug_file, "meta_oodate: %s\n", fname); +#endif + + if ((fp = fopen(fname, "r")) != NULL) { + static char *buf = NULL; + static size_t bufsz; + int lineno = 0; + int lastpid = 0; + int pid; + int f = 0; + int x; + LstNode ln; + struct stat fs; + + if (!buf) { + bufsz = 8 * BUFSIZ; + buf = bmake_malloc(bufsz); + } + + if (!cwdlen) { + if (getcwd(cwd, sizeof(cwd)) == NULL) + err(1, "Could not get current working directory"); + cwdlen = strlen(cwd); + } + + if (!tmpdir) { + tmpdir = getTmpdir(); + tmplen = strlen(tmpdir); + } + + /* we want to track all the .meta we read */ + Var_Append(".MAKE.META.FILES", fname, VAR_GLOBAL); + + ln = Lst_First(gn->commands); + while (!oodate && (x = fgetLine(&buf, &bufsz, 0, fp)) > 0) { + lineno++; + if (buf[x - 1] == '\n') + buf[x - 1] = '\0'; + else + warnx("%s: %d: line truncated at %u", fname, lineno, x); + + /* Find the start of the build monitor section. */ + if (!f) { + if (strncmp(buf, "-- filemon", 10) == 0) { + f = 1; + continue; + } + if (strncmp(buf, "# buildmon", 10) == 0) { + f = 1; + continue; + } + } + + /* Delimit the record type. */ + p = buf; +#ifdef DEBUG_META_MODE + if (DEBUG(META)) + fprintf(debug_file, "%s: %d: %s\n", fname, lineno, buf); +#endif + strsep(&p, " "); + if (f) { + /* + * We are in the 'filemon' output section. + * Each record from filemon follows the general form: + * + * <key> <pid> <data> + * + * Where: + * <key> is a single letter, denoting the syscall. + * <pid> is the process that made the syscall. + * <data> is the arguments (of interest). + */ + switch(buf[0]) { + case '#': /* comment */ + case 'V': /* version */ + break; + default: + /* + * We need to track pathnames per-process. + * + * Each process run by make, starts off in the 'CWD' + * recorded in the .meta file, if it chdirs ('C') + * elsewhere we need to track that - but only for + * that process. If it forks ('F'), we initialize + * the child to have the same cwd as its parent. + * + * We also need to track the 'latestdir' of + * interest. This is usually the same as cwd, but + * not if a process is reading directories. + * + * Each time we spot a different process ('pid') + * we save the current value of 'latestdir' in a + * variable qualified by 'lastpid', and + * re-initialize 'latestdir' to any pre-saved + * value for the current 'pid' and 'CWD' if none. + */ + pid = atoi(p); + if (pid > 0 && pid != lastpid) { + char *ldir; + char *tp; + + if (lastpid > 0) { + /* We need to remember this. */ + Var_Set(ldir_vname, latestdir, VAR_GLOBAL, 0); + } + snprintf(ldir_vname, sizeof(ldir_vname), LDIR_VNAME_FMT, pid); + lastpid = pid; + ldir = Var_Value(ldir_vname, VAR_GLOBAL, &tp); + if (ldir) { + strlcpy(latestdir, ldir, sizeof(latestdir)); + if (tp) + free(tp); + } else + strlcpy(latestdir, cwd, sizeof(latestdir)); + } + /* Skip past the pid. */ + if (strsep(&p, " ") == NULL) + continue; +#ifdef DEBUG_META_MODE + if (DEBUG(META)) + fprintf(debug_file, "%s: %d: cwd=%s ldir=%s\n", fname, lineno, cwd, latestdir); +#endif + break; + } + + /* Process according to record type. */ + switch (buf[0]) { + case 'X': /* eXit */ + Var_Delete(ldir_vname, VAR_GLOBAL); + lastpid = 0; /* no need to save ldir_vname */ + break; + + case 'F': /* [v]Fork */ + { + char cldir[64]; + int child; + + child = atoi(p); + if (child > 0) { + snprintf(cldir, sizeof(cldir), LDIR_VNAME_FMT, child); + Var_Set(cldir, latestdir, VAR_GLOBAL, 0); + } + } + break; + + case 'C': /* Chdir */ + /* Update the latest directory. */ + strlcpy(latestdir, p, sizeof(latestdir)); + break; + + case 'M': /* renaMe */ + if (Lst_IsEmpty(missingFiles)) + break; + /* 'L' and 'M' put single quotes around the args */ + if (*p == '\'') { + char *ep; + + p++; + if ((ep = strchr(p, '\''))) + *ep = '\0'; + } + /* FALLTHROUGH */ + case 'D': /* unlink */ + if (*p == '/' && !Lst_IsEmpty(missingFiles)) { + /* remove p from the missingFiles list if present */ + if ((ln = Lst_Find(missingFiles, p, string_match)) != NULL) { + char *tp = Lst_Datum(ln); + Lst_Remove(missingFiles, ln); + free(tp); + } + } + break; + case 'L': /* Link */ + /* we want the target */ + if (strsep(&p, " ") == NULL) + continue; + /* 'L' and 'M' put single quotes around the args */ + if (*p == '\'') { + char *ep; + + p++; + if ((ep = strchr(p, '\''))) + *ep = '\0'; + } + /* FALLTHROUGH */ + case 'W': /* Write */ + /* + * If a file we generated within our bailiwick + * but outside of .OBJDIR is missing, + * we need to do it again. + */ + /* ignore non-absolute paths */ + if (*p != '/') + break; + + if (Lst_IsEmpty(metaBailiwick)) + break; + + /* ignore cwd - normal dependencies handle those */ + if (strncmp(p, cwd, cwdlen) == 0) + break; + + if (!Lst_ForEach(metaBailiwick, prefix_match, p)) + break; + + /* tmpdir might be within */ + if (tmplen > 0 && strncmp(p, tmpdir, tmplen) == 0) + break; + + /* ignore anything containing the string "tmp" */ + if ((strstr("tmp", p))) + break; + + if (stat(p, &fs) < 0) { + Lst_AtEnd(missingFiles, bmake_strdup(p)); + } + break; + case 'R': /* Read */ + case 'E': /* Exec */ + /* + * Check for runtime files that can't + * be part of the dependencies because + * they are _expected_ to change. + */ + if (strncmp(p, "/tmp/", 5) == 0 || + (tmplen > 0 && strncmp(p, tmpdir, tmplen) == 0)) + break; + + if (strncmp(p, "/var/", 5) == 0) + break; + + /* Ignore device files. */ + if (strncmp(p, "/dev/", 5) == 0) + break; + + /* Ignore /etc/ files. */ + if (strncmp(p, "/etc/", 5) == 0) + break; + + /* + * The rest of the record is the file name. + * Check if it's not an absolute path. + */ + { + char *sdirs[4]; + char **sdp; + int sdx = 0; + int found = 0; + + if (*p == '/') { + sdirs[sdx++] = p; /* done */ + } else { + if (strcmp(".", p) == 0) + continue; /* no point */ + + /* Check vs latestdir */ + snprintf(fname1, sizeof(fname1), "%s/%s", latestdir, p); + sdirs[sdx++] = fname1; + + if (strcmp(latestdir, cwd) != 0) { + /* Check vs cwd */ + snprintf(fname2, sizeof(fname2), "%s/%s", cwd, p); + sdirs[sdx++] = fname2; + } + } + sdirs[sdx++] = NULL; + + for (sdp = sdirs; *sdp && !found; sdp++) { +#ifdef DEBUG_META_MODE + if (DEBUG(META)) + fprintf(debug_file, "%s: %d: looking for: %s\n", fname, lineno, *sdp); +#endif + if (stat(*sdp, &fs) == 0) { + found = 1; + p = *sdp; + } + } + if (found) { +#ifdef DEBUG_META_MODE + if (DEBUG(META)) + fprintf(debug_file, "%s: %d: found: %s\n", fname, lineno, p); +#endif + if (!S_ISDIR(fs.st_mode) && + fs.st_mtime > gn->mtime) { + if (DEBUG(META)) + fprintf(debug_file, "%s: %d: file '%s' is newer than the target...\n", fname, lineno, p); + oodate = TRUE; + } else if (S_ISDIR(fs.st_mode)) { + /* Update the latest directory. */ + realpath(p, latestdir); + } + } else if (errno == ENOENT && *p == '/' && + strncmp(p, cwd, cwdlen) != 0) { + /* + * A referenced file outside of CWD is missing. + * We cannot catch every eventuality here... + */ + if (DEBUG(META)) + fprintf(debug_file, "%s: %d: file '%s' may have moved?...\n", fname, lineno, p); + oodate = TRUE; + } + } + break; + default: + break; + } + } else if (strcmp(buf, "CMD") == 0) { + /* + * Compare the current command with the one in the + * meta data file. + */ + if (ln == NULL) { + if (DEBUG(META)) + fprintf(debug_file, "%s: %d: there were more build commands in the meta data file than there are now...\n", fname, lineno); + oodate = TRUE; + } else { + char *cmd = (char *)Lst_Datum(ln); + + if (!ignoreOODATE) { + if (strstr(cmd, "$?")) + ignoreOODATE = TRUE; + else if ((cp = strstr(cmd, ".OODATE"))) { + /* check for $[{(].OODATE[)}] */ + if (cp > cmd + 2 && cp[-2] == '$') + ignoreOODATE = TRUE; + } + if (ignoreOODATE && DEBUG(META)) + fprintf(debug_file, "%s: %d: cannot compare commands using .OODATE\n", fname, lineno); + } + cmd = Var_Subst(NULL, cmd, gn, TRUE); + + if ((cp = strchr(cmd, '\n'))) { + int n; + + /* + * This command contains newlines, we need to + * fetch more from the .meta file before we + * attempt a comparison. + */ + /* first put the newline back at buf[x - 1] */ + buf[x - 1] = '\n'; + do { + /* now fetch the next line */ + if ((n = fgetLine(&buf, &bufsz, x, fp)) <= 0) + break; + x = n; + lineno++; + if (buf[x - 1] != '\n') { + warnx("%s: %d: line truncated at %u", fname, lineno, x); + break; + } + cp = strchr(++cp, '\n'); + } while (cp); + if (buf[x - 1] == '\n') + buf[x - 1] = '\0'; + } + if (!ignoreOODATE && + !(gn->type & OP_NOMETA_CMP) && + strcmp(p, cmd) != 0) { + if (DEBUG(META)) + fprintf(debug_file, "%s: %d: a build command has changed\n%s\nvs\n%s\n", fname, lineno, p, cmd); + if (!metaIgnoreCMDs) + oodate = TRUE; + } + free(cmd); + ln = Lst_Succ(ln); + } + } else if (strcmp(buf, "CWD") == 0) { + /* + * Check if there are extra commands now + * that weren't in the meta data file. + */ + if (!oodate && ln != NULL) { + if (DEBUG(META)) + fprintf(debug_file, "%s: %d: there are extra build commands now that weren't in the meta data file\n", fname, lineno); + oodate = TRUE; + } + if (strcmp(p, cwd) != 0) { + if (DEBUG(META)) + fprintf(debug_file, "%s: %d: the current working directory has changed from '%s' to '%s'\n", fname, lineno, p, curdir); + oodate = TRUE; + } + } + } + + fclose(fp); + if (!Lst_IsEmpty(missingFiles)) { + if (DEBUG(META)) + fprintf(debug_file, "%s: missing files: %s...\n", + fname, (char *)Lst_Datum(Lst_First(missingFiles))); + oodate = TRUE; + Lst_Destroy(missingFiles, (FreeProc *)free); + } + } + if (oodate && ignoreOODATE) { + /* + * Target uses .OODATE, so we need to re-compute it. + * We need to clean up what Make_DoAllVar() did. + */ + Var_Delete(ALLSRC, gn); + Var_Delete(OODATE, gn); + gn->flags &= ~DONE_ALLSRC; + } + return oodate; +} + +/* support for compat mode */ + +static int childPipe[2]; + +void +meta_compat_start(void) +{ +#ifdef USE_FILEMON_ONCE + /* + * We need to re-open filemon for each cmd. + */ + BuildMon *pbm = &Mybm; + + if (pbm->mfp != NULL && useFilemon) { + filemon_open(pbm); + } else { + pbm->mon_fd = pbm->filemon_fd = -1; + } +#endif + if (pipe(childPipe) < 0) + Punt("Cannot create pipe: %s", strerror(errno)); + /* Set close-on-exec flag for both */ + (void)fcntl(childPipe[0], F_SETFD, 1); + (void)fcntl(childPipe[1], F_SETFD, 1); +} + +void +meta_compat_child(void) +{ + meta_job_child(NULL); + if (dup2(childPipe[1], 1) < 0 || + dup2(1, 2) < 0) { + execError("dup2", "pipe"); + _exit(1); + } +} + +void +meta_compat_parent(void) +{ + FILE *fp; + char buf[BUFSIZ]; + + close(childPipe[1]); /* child side */ + fp = fdopen(childPipe[0], "r"); + while (fgets(buf, sizeof(buf), fp)) { + meta_job_output(NULL, buf, ""); + printf("%s", buf); + } + fclose(fp); +} + +#endif /* USE_META */ diff --git a/devel/bmake/files/meta.h b/devel/bmake/files/meta.h new file mode 100644 index 00000000000..e47ad89b677 --- /dev/null +++ b/devel/bmake/files/meta.h @@ -0,0 +1,54 @@ +/* $NetBSD: meta.h,v 1.1.1.1 2011/06/18 22:18:04 bsiegert Exp $ */ + +/* + * Things needed for 'meta' mode. + */ +/* + * Copyright (c) 2009-2010, Juniper Networks, Inc. + * + * 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 copyright holders 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 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. + */ + +typedef struct BuildMon { + char meta_fname[MAXPATHLEN]; + int filemon_fd; + int mon_fd; + FILE *mfp; +} BuildMon; + +extern Boolean useMeta; + +struct Job; /* not defined yet */ +void meta_init(const char *); +void meta_job_start(struct Job *, GNode *); +void meta_job_child(struct Job *); +void meta_job_error(struct Job *, GNode *, int, int); +void meta_job_output(struct Job *, char *, const char *); +void meta_cmd_finish(void *); +void meta_job_finish(struct Job *); +Boolean meta_oodate(GNode *, Boolean); +void meta_compat_start(void); +void meta_compat_child(void); +void meta_compat_parent(void); diff --git a/devel/bmake/files/nonints.h b/devel/bmake/files/nonints.h index ee4ac64c5df..ebc91b46664 100644 --- a/devel/bmake/files/nonints.h +++ b/devel/bmake/files/nonints.h @@ -1,4 +1,4 @@ -/* $NetBSD: nonints.h,v 1.1.1.7 2010/09/07 14:11:58 joerg Exp $ */ +/* $NetBSD: nonints.h,v 1.1.1.8 2011/06/18 22:18:04 bsiegert Exp $ */ /*- * Copyright (c) 1988, 1989, 1990, 1993 @@ -126,6 +126,7 @@ int PrintAddr(void *, void *); void Finish(int); int eunlink(const char *); void execError(const char *, const char *); +char *getTmpdir(void); /* parse.c */ void Parse_Error(int, const char *, ...) @@ -137,7 +138,7 @@ void Parse_AddIncludeDir(char *); void Parse_File(const char *, int); void Parse_Init(void); void Parse_End(void); -void Parse_SetInput(const char *, int, int, char *(*)(void *), void *); +void Parse_SetInput(const char *, int, int, char *(*)(void *, size_t *), void *); Lst Parse_MainName(void); /* str.c */ diff --git a/devel/bmake/files/parse.c b/devel/bmake/files/parse.c index 5e549f0c6c4..40a14cba1a6 100644 --- a/devel/bmake/files/parse.c +++ b/devel/bmake/files/parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.1.1.8 2010/09/07 14:12:02 joerg Exp $ */ +/* $NetBSD: parse.c,v 1.1.1.9 2011/06/18 22:18:06 bsiegert Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: parse.c,v 1.1.1.8 2010/09/07 14:12:02 joerg Exp $"; +static char rcsid[] = "$NetBSD: parse.c,v 1.1.1.9 2011/06/18 22:18:06 bsiegert Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: parse.c,v 1.1.1.8 2010/09/07 14:12:02 joerg Exp $"); +__RCSID("$NetBSD: parse.c,v 1.1.1.9 2011/06/18 22:18:06 bsiegert Exp $"); #endif #endif /* not lint */ #endif @@ -123,12 +123,22 @@ __RCSID("$NetBSD: parse.c,v 1.1.1.8 2010/09/07 14:12:02 joerg Exp $"); * Parse_MainName Returns a Lst of the main target to create. */ +#include <sys/types.h> +#include <sys/stat.h> +#include <assert.h> #include <ctype.h> #include <errno.h> #include <fcntl.h> #include <stdarg.h> #include <stdio.h> +#ifndef MAP_FILE +#define MAP_FILE 0 +#endif +#ifndef MAP_COPY +#define MAP_COPY MAP_PRIVATE +#endif + #include "make.h" #include "hash.h" #include "dir.h" @@ -136,56 +146,47 @@ __RCSID("$NetBSD: parse.c,v 1.1.1.8 2010/09/07 14:12:02 joerg Exp $"); #include "buf.h" #include "pathnames.h" -/* - * These values are returned by ParseEOF to tell Parse_File whether to - * CONTINUE parsing, i.e. it had only reached the end of an include file, - * or if it's DONE. - */ -#define CONTINUE 1 -#define DONE 0 -static Lst targets; /* targets we're working on */ -#ifdef CLEANUP -static Lst targCmds; /* command lines for targets */ +#ifdef HAVE_MMAP +#include <sys/mman.h> + +#ifndef MAP_COPY +#define MAP_COPY MAP_PRIVATE #endif -static Boolean inLine; /* true if currently in a dependency - * line or its commands */ -static int fatals = 0; +#ifndef MAP_FILE +#define MAP_FILE 0 +#endif +#endif + +//////////////////////////////////////////////////////////// +// types and constants -static GNode *mainNode; /* The main target to create. This is the - * first target on the first dependency - * line in the first makefile */ +/* + * Structure for a file being read ("included file") + */ typedef struct IFile { const char *fname; /* name of file */ int lineno; /* current line number in file */ int first_lineno; /* line number of start of text */ - int fd; /* the open file */ int cond_depth; /* 'if' nesting when file opened */ char *P_str; /* point to base of string buffer */ char *P_ptr; /* point to next char of string buffer */ char *P_end; /* point to the end of string buffer */ - int P_buflen; /* current size of file buffer */ - char *(*nextbuf)(void *); /* Function to get more data */ + char *(*nextbuf)(void *, size_t *); /* Function to get more data */ void *nextbuf_arg; /* Opaque arg for nextbuf() */ + struct loadedfile *lf; /* loadedfile object, if any */ } IFile; -#define IFILE_BUFLEN 0x8000 -static IFile *curFile; - /* - * Definitions for handling #include specifications + * These values are returned by ParseEOF to tell Parse_File whether to + * CONTINUE parsing, i.e. it had only reached the end of an include file, + * or if it's DONE. */ +#define CONTINUE 1 +#define DONE 0 -static Lst includes; /* stack of IFiles generated by .includes */ -Lst parseIncPath; /* list of directories for "..." includes */ -Lst sysIncPath; /* list of directories for <...> includes */ -Lst defIncPath; /* default directories for <...> includes */ - -/*- - * specType contains the SPECial TYPE of the current target. It is - * Not if the target is unspecial. If it *is* special, however, the children - * are linked as children of the parent but not vice versa. This variable is - * set in ParseDoDependency +/* + * Tokens for target attributes */ typedef enum { Begin, /* .BEGIN */ @@ -196,10 +197,13 @@ typedef enum { Includes, /* .INCLUDES */ Interrupt, /* .INTERRUPT */ Libs, /* .LIBS */ + Meta, /* .META */ MFlags, /* .MFLAGS or .MAKEFLAGS */ Main, /* .MAIN and we don't have anything user-specified to * make */ NoExport, /* .NOEXPORT */ + NoMeta, /* .NOMETA */ + NoMetaCmp, /* .NOMETA_CMP */ NoPath, /* .NOPATH */ Not, /* Not special */ NotParallel, /* .NOTPARALLEL */ @@ -221,16 +225,74 @@ typedef enum { Attribute /* Generic attribute */ } ParseSpecial; +/* + * Other tokens + */ +#define LPAREN '(' +#define RPAREN ')' + + +//////////////////////////////////////////////////////////// +// result data + +/* + * The main target to create. This is the first target on the first + * dependency line in the first makefile. + */ +static GNode *mainNode; + +//////////////////////////////////////////////////////////// +// eval state + +/* targets we're working on */ +static Lst targets; + +#ifdef CLEANUP +/* command lines for targets */ +static Lst targCmds; +#endif + +/* + * specType contains the SPECial TYPE of the current target. It is + * Not if the target is unspecial. If it *is* special, however, the children + * are linked as children of the parent but not vice versa. This variable is + * set in ParseDoDependency + */ static ParseSpecial specType; -#define LPAREN '(' -#define RPAREN ')' /* * Predecessor node for handling .ORDER. Initialized to NULL when .ORDER * seen, then set to each successive source on the line. */ static GNode *predecessor; +//////////////////////////////////////////////////////////// +// parser state + +/* true if currently in a dependency line or its commands */ +static Boolean inLine; + +/* number of fatal errors */ +static int fatals = 0; + +/* + * Variables for doing includes + */ + +/* current file being read */ +static IFile *curFile; + +/* stack of IFiles generated by .includes */ +static Lst includes; + +/* include paths (lists of directories) */ +Lst parseIncPath; /* dirs for "..." includes */ +Lst sysIncPath; /* dirs for <...> includes */ +Lst defIncPath; /* default for sysIncPath */ + +//////////////////////////////////////////////////////////// +// parser tables + /* * The parseKeywords table is searched using binary search when deciding * if a target or source is special. The 'spec' field is the ParseSpecial @@ -238,7 +300,7 @@ static GNode *predecessor; * 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) */ -static struct { +static const struct { const char *name; /* Name of keyword */ ParseSpecial spec; /* Type when used as a target */ int op; /* Operator when used as a source */ @@ -258,7 +320,10 @@ static struct { { ".MAIN", Main, 0 }, { ".MAKE", Attribute, OP_MAKE }, { ".MAKEFLAGS", MFlags, 0 }, +{ ".META", Meta, OP_META }, { ".MFLAGS", MFlags, 0 }, +{ ".NOMETA", NoMeta, OP_NOMETA }, +{ ".NOMETA_CMP", NoMetaCmp, OP_NOMETA_CMP }, { ".NOPATH", NoPath, OP_NOPATH }, { ".NOTMAIN", Attribute, OP_NOTMAIN }, { ".NOTPARALLEL", NotParallel, 0 }, @@ -284,6 +349,9 @@ static struct { { ".WAIT", Wait, 0 }, }; +//////////////////////////////////////////////////////////// +// local functions + static int ParseIsEscaped(const char *, const char *); static void ParseErrorInternal(const char *, size_t, int, const char *, ...) __attribute__((__format__(__printf__, 4, 5))); @@ -309,8 +377,216 @@ static char *ParseReadLine(void); static void ParseFinishLine(void); static void ParseMark(GNode *); -extern int maxJobs; +//////////////////////////////////////////////////////////// +// file loader +struct loadedfile { + const char *path; /* name, for error reports */ + char *buf; /* contents buffer */ + size_t len; /* length of contents */ + size_t maplen; /* length of mmap area, or 0 */ + Boolean used; /* XXX: have we used the data yet */ +}; + +/* + * Constructor/destructor for loadedfile + */ +static struct loadedfile * +loadedfile_create(const char *path) +{ + struct loadedfile *lf; + + lf = bmake_malloc(sizeof(*lf)); + lf->path = (path == NULL ? "(stdin)" : path); + lf->buf = NULL; + lf->len = 0; + lf->maplen = 0; + lf->used = FALSE; + return lf; +} + +static void +loadedfile_destroy(struct loadedfile *lf) +{ + if (lf->buf != NULL) { + if (lf->maplen > 0) { +#ifdef HAVE_MMAP + munmap(lf->buf, lf->maplen); +#endif + } else { + free(lf->buf); + } + } + free(lf); +} + +/* + * nextbuf() operation for loadedfile, as needed by the weird and twisted + * logic below. Once that's cleaned up, we can get rid of lf->used... + */ +static char * +loadedfile_nextbuf(void *x, size_t *len) +{ + struct loadedfile *lf = x; + + if (lf->used) { + return NULL; + } + lf->used = TRUE; + *len = lf->len; + return lf->buf; +} + +/* + * Try to get the size of a file. + */ +static ReturnStatus +load_getsize(int fd, size_t *ret) +{ + struct stat st; + + if (fstat(fd, &st) < 0) { + return FAILURE; + } + + if (!S_ISREG(st.st_mode)) { + return FAILURE; + } + + /* + * st_size is an off_t, which is 64 bits signed; *ret is + * size_t, which might be 32 bits unsigned or 64 bits + * unsigned. Rather than being elaborate, just punt on + * files that are more than 2^31 bytes. We should never + * see a makefile that size in practice... + * + * While we're at it reject negative sizes too, just in case. + */ + if (st.st_size < 0 || st.st_size > 0x7fffffff) { + return FAILURE; + } + + *ret = (size_t) st.st_size; + return SUCCESS; +} + +/* + * Read in a file. + * + * Until the path search logic can be moved under here instead of + * being in the caller in another source file, we need to have the fd + * passed in already open. Bleh. + * + * If the path is NULL use stdin and (to insure against fd leaks) + * assert that the caller passed in -1. + */ +static struct loadedfile * +loadfile(const char *path, int fd) +{ + struct loadedfile *lf; +#ifdef HAVE_MMAP + long pagesize; +#endif + ssize_t result; + size_t bufpos; + + lf = loadedfile_create(path); + + if (path == NULL) { + assert(fd == -1); + fd = STDIN_FILENO; + } else { +#if 0 /* notyet */ + fd = open(path, O_RDONLY); + if (fd < 0) { + ... + Error("%s: %s", path, strerror(errno)); + exit(1); + } +#endif + } + +#ifdef HAVE_MMAP + if (load_getsize(fd, &lf->len) == SUCCESS) { + /* found a size, try mmap */ + pagesize = sysconf(_SC_PAGESIZE); + if (pagesize <= 0) { + pagesize = 0x1000; + } + /* round size up to a page */ + lf->maplen = pagesize * ((lf->len + pagesize - 1)/pagesize); + + /* + * XXX hack for dealing with empty files; remove when + * we're no longer limited by interfacing to the old + * logic elsewhere in this file. + */ + if (lf->maplen == 0) { + lf->maplen = pagesize; + } + + /* + * FUTURE: remove PROT_WRITE when the parser no longer + * needs to scribble on the input. + */ + lf->buf = mmap(NULL, lf->maplen, PROT_READ|PROT_WRITE, + MAP_FILE|MAP_COPY, fd, 0); + if (lf->buf != MAP_FAILED) { + /* succeeded */ + if (lf->len == lf->maplen && lf->buf[lf->len - 1] != '\n') { + char *b = malloc(lf->len + 1); + b[lf->len] = '\n'; + memcpy(b, lf->buf, lf->len++); + munmap(lf->buf, lf->maplen); + lf->maplen = 0; + lf->buf = b; + } + goto done; + } + } +#endif + /* cannot mmap; load the traditional way */ + + lf->maplen = 0; + lf->len = 1024; + lf->buf = bmake_malloc(lf->len); + + bufpos = 0; + while (1) { + assert(bufpos <= lf->len); + if (bufpos == lf->len) { + lf->len *= 2; + lf->buf = bmake_realloc(lf->buf, lf->len); + } + result = read(fd, lf->buf + bufpos, lf->len - bufpos); + if (result < 0) { + Error("%s: read error: %s", path, strerror(errno)); + exit(1); + } + if (result == 0) { + break; + } + bufpos += result; + } + assert(bufpos <= lf->len); + lf->len = bufpos; + + /* truncate malloc region to actual length (maybe not useful) */ + if (lf->len > 0) { + lf->buf = bmake_realloc(lf->buf, lf->len); + } + +#ifdef HAVE_MMAP +done: +#endif + if (path != NULL) { + close(fd); + } + return lf; +} + +//////////////////////////////////////////////////////////// +// old code /*- *---------------------------------------------------------------------- @@ -404,7 +680,7 @@ ParseVErrorInternal(FILE *f, const char *cfname, size_t clineno, int type, const char *dir; /* - * Nothing is more anoying than not knowing + * Nothing is more annoying than not knowing * which Makefile is the culprit. */ dir = Var_Value(".PARSEDIR", VAR_GLOBAL, &cp); @@ -1786,6 +2062,7 @@ Parse_AddIncludeDir(char *dir) static void Parse_include_file(char *file, Boolean isSystem, int silent) { + struct loadedfile *lf; char *fullname; /* full pathname of file */ char *newName; char *prefEnd, *incdir; @@ -1876,8 +2153,12 @@ Parse_include_file(char *file, Boolean isSystem, int silent) return; } + /* load it */ + lf = loadfile(fullname, fd); + /* Start reading from this file next */ - Parse_SetInput(fullname, 0, fd, NULL, NULL); + Parse_SetInput(fullname, 0, -1, loadedfile_nextbuf, lf); + curFile->lf = lf; } static void @@ -1955,7 +2236,7 @@ ParseSetParseFile(const char *filename) slash = strrchr(filename, '/'); if (slash == NULL) { - Var_Set(".PARSEDIR", ".", VAR_GLOBAL, 0); + Var_Set(".PARSEDIR", curdir, VAR_GLOBAL, 0); Var_Set(".PARSEFILE", filename, VAR_GLOBAL, 0); } else { len = slash - filename; @@ -2014,9 +2295,11 @@ ParseTrackInput(const char *name) *--------------------------------------------------------------------- */ void -Parse_SetInput(const char *name, int line, int fd, char *(*nextbuf)(void *), void *arg) +Parse_SetInput(const char *name, int line, int fd, + char *(*nextbuf)(void *, size_t *), void *arg) { char *buf; + size_t len; if (name == NULL) name = curFile->fname; @@ -2047,33 +2330,22 @@ Parse_SetInput(const char *name, int line, int fd, char *(*nextbuf)(void *), voi curFile->fname = name; curFile->lineno = line; curFile->first_lineno = line; - curFile->fd = fd; curFile->nextbuf = nextbuf; curFile->nextbuf_arg = arg; + curFile->lf = NULL; - if (nextbuf == NULL) { - /* - * Allocate a 32k data buffer (as stdio seems to). - * Set pointers so that first ParseReadc has to do a file read. - */ - buf = bmake_malloc(IFILE_BUFLEN); - buf[0] = 0; - curFile->P_str = buf; - curFile->P_ptr = buf; - curFile->P_end = buf; - curFile->P_buflen = IFILE_BUFLEN; - } else { - /* Get first block of input data */ - buf = curFile->nextbuf(curFile->nextbuf_arg); - if (buf == NULL) { - /* Was all a waste of time ... */ - free(curFile); - return; - } - curFile->P_str = buf; - curFile->P_ptr = buf; - curFile->P_end = NULL; + assert(nextbuf != NULL); + + /* Get first block of input data */ + buf = curFile->nextbuf(curFile->nextbuf_arg, &len); + if (buf == NULL) { + /* Was all a waste of time ... */ + free(curFile); + return; } + curFile->P_str = buf; + curFile->P_ptr = buf; + curFile->P_end = buf+len; curFile->cond_depth = Cond_save_depth(); ParseSetParseFile(name); @@ -2162,26 +2434,31 @@ static int ParseEOF(void) { char *ptr; - - if (curFile->nextbuf != NULL) { - /* eg .for loop data, get next iteration */ - ptr = curFile->nextbuf(curFile->nextbuf_arg); - curFile->P_ptr = ptr; - curFile->P_str = ptr; - curFile->lineno = curFile->first_lineno; - if (ptr != NULL) { - /* Iterate again */ - return CONTINUE; - } + size_t len; + + assert(curFile->nextbuf != NULL); + + /* get next input buffer, if any */ + ptr = curFile->nextbuf(curFile->nextbuf_arg, &len); + curFile->P_ptr = ptr; + curFile->P_str = ptr; + curFile->P_end = ptr + len; + curFile->lineno = curFile->first_lineno; + if (ptr != NULL) { + /* Iterate again */ + return CONTINUE; } /* Ensure the makefile (or loop) didn't have mismatched conditionals */ Cond_restore_depth(curFile->cond_depth); + if (curFile->lf != NULL) { + loadedfile_destroy(curFile->lf); + curFile->lf = NULL; + } + /* Dispose of curFile info */ /* Leak curFile->fname because all the gnodes have pointers to it */ - if (curFile->fd != -1) - close(curFile->fd); free(curFile->P_str); free(curFile); @@ -2195,8 +2472,8 @@ ParseEOF(void) } if (DEBUG(PARSE)) - fprintf(debug_file, "ParseEOF: returning to file %s, line %d, fd %d\n", - curFile->fname, curFile->lineno, curFile->fd); + fprintf(debug_file, "ParseEOF: returning to file %s, line %d\n", + curFile->fname, curFile->lineno); /* Restore the PARSEDIR/PARSEFILE variables */ ParseSetParseFile(curFile->fname); @@ -2217,7 +2494,6 @@ ParseGetLine(int flags, int *length) char *escaped; char *comment; char *tp; - int len, dist; /* Loop through blank lines and comment lines */ for (;;) { @@ -2228,67 +2504,25 @@ ParseGetLine(int flags, int *length) escaped = NULL; comment = NULL; for (;;) { + if (cf->P_end != NULL && ptr == cf->P_end) { + /* end of buffer */ + ch = 0; + break; + } ch = *ptr; if (ch == 0 || (ch == '\\' && ptr[1] == 0)) { if (cf->P_end == NULL) /* End of string (aka for loop) data */ break; - /* End of data read from file, read more data */ - if (ptr != cf->P_end && (ch != '\\' || ptr + 1 != cf->P_end)) { - Parse_Error(PARSE_FATAL, "Zero byte read from file"); - return NULL; - } - /* Move existing data to (near) start of file buffer */ - len = cf->P_end - cf->P_ptr; - tp = cf->P_str + 32; - memmove(tp, cf->P_ptr, len); - dist = cf->P_ptr - tp; - /* Update all pointers to reflect moved data */ - ptr -= dist; - line -= dist; - line_end -= dist; - if (escaped) - escaped -= dist; - if (comment) - comment -= dist; - cf->P_ptr = tp; - tp += len; - cf->P_end = tp; - /* Try to read more data from file into buffer space */ - len = cf->P_str + cf->P_buflen - tp - 32; - if (len <= 0) { - /* We need a bigger buffer to hold this line */ - tp = bmake_realloc(cf->P_str, cf->P_buflen + IFILE_BUFLEN); - cf->P_ptr = cf->P_ptr - cf->P_str + tp; - cf->P_end = cf->P_end - cf->P_str + tp; - ptr = ptr - cf->P_str + tp; - line = line - cf->P_str + tp; - line_end = line_end - cf->P_str + tp; - if (escaped) - escaped = escaped - cf->P_str + tp; - if (comment) - comment = comment - cf->P_str + tp; - cf->P_str = tp; - tp = cf->P_end; - len += IFILE_BUFLEN; - cf->P_buflen += IFILE_BUFLEN; - } - len = read(cf->fd, tp, len); - if (len <= 0) { - if (len < 0) { - Parse_Error(PARSE_FATAL, "Makefile read error: %s", - strerror(errno)); - return NULL; - } - /* End of file */ + if (cf->nextbuf != NULL) { + /* + * End of this buffer; return EOF and outer logic + * will get the next one. (eww) + */ break; } - /* 0 terminate the data, and update end pointer */ - tp += len; - cf->P_end = tp; - *tp = 0; - /* Process newly read characters */ - continue; + Parse_Error(PARSE_FATAL, "Zero byte read from file"); + return NULL; } if (ch == '\\') { @@ -2459,7 +2693,7 @@ ParseReadLine(void) line = ParseGetLine(PARSE_RAW, &lineLength); if (line == NULL) { Parse_Error(PARSE_FATAL, - "Unexpected end of file in for loop.\n"); + "Unexpected end of file in for loop."); break; } } while (For_Accum(line)); @@ -2522,11 +2756,19 @@ Parse_File(const char *name, int fd) { char *cp; /* pointer into the line */ char *line; /* the line we're working on */ + struct loadedfile *lf; + + lf = loadfile(name, fd); inLine = FALSE; fatals = 0; - Parse_SetInput(name, 0, fd, NULL, NULL); + if (name == NULL) { + name = "(stdin)"; + } + + Parse_SetInput(name, 0, -1, loadedfile_nextbuf, lf); + curFile->lf = lf; do { for (; (line = ParseReadLine()) != NULL; ) { @@ -2719,7 +2961,7 @@ Parse_File(const char *name, int fd) if (fatals) { (void)fflush(stdout); (void)fprintf(stderr, - "%s: Fatal errors encountered -- cannot continue\n", + "%s: Fatal errors encountered -- cannot continue", progname); PrintOnError(NULL, NULL); exit(1); diff --git a/devel/bmake/files/sigcompat.c b/devel/bmake/files/sigcompat.c index b44e111502b..f88b3fcef56 100644 --- a/devel/bmake/files/sigcompat.c +++ b/devel/bmake/files/sigcompat.c @@ -104,7 +104,7 @@ #if defined(LIBC_SCCS) && !defined(lint) /*static char *sccsid = "from: @(#)sigcompat.c 5.3 (Berkeley) 2/24/91";*/ -static char *rcsid = "$Id: sigcompat.c,v 1.1.1.4 2009/09/18 20:55:31 joerg Exp $"; +static char *rcsid = "$Id: sigcompat.c,v 1.1.1.5 2011/06/18 22:18:07 bsiegert Exp $"; #endif /* LIBC_SCCS and not lint */ #undef signal @@ -163,9 +163,7 @@ static char *rcsid = "$Id: sigcompat.c,v 1.1.1.4 2009/09/18 20:55:31 joerg Exp $ #endif int _signalFlags = SIGNAL_FLAGS; -SIG_HDLR(*signal(sig, handler)) __P((int)) - int sig; - SIG_HDLR(*handler) __P((int)); +SIG_HDLR(*signal(int sig, SIG_HDLR(*handler)(int)))(int) { _DBUG(static int depth_signal = 0); struct sigaction act, oact; @@ -183,11 +181,9 @@ SIG_HDLR(*signal(sig, handler)) __P((int)) return (oact.sa_handler); } #else -SIG_HDLR(*signal(sig, handler)) __P((int)) - int sig; - SIG_HDLR(*handler) __P((int)); +SIG_HDLR(*signal(int sig, SIG_HDLR(*handler)(int)))(int) { - extern SIG_HDLR(*Signal __P((int, void (*) __P((int))))) __P((int)); + extern SIG_HDLR(*Signal(int, void (*)(int)))(int); _DBUG(static int depth_signal = 0); SIG_HDLR(*old) __P((int)); @@ -210,8 +206,7 @@ SIG_HDLR(*signal(sig, handler)) __P((int)) # define m2ss(ss, m) *ss = (sigset_t) *(m) #else static MASK_T -ss2m(ss) - sigset_t *ss; +ss2m(sigset_t *ss) { MASK_T ma[(sizeof(sigset_t) / sizeof(MASK_T)) + 1]; @@ -220,9 +215,7 @@ ss2m(ss) } static void -m2ss(ss, m) - sigset_t *ss; - MASK_T *m; +m2ss(sigset_t *ss, MASK_T *m) { if (sizeof(sigset_t) > sizeof(MASK_T)) memset((char *) ss, 0, sizeof(sigset_t)); @@ -233,8 +226,7 @@ m2ss(ss, m) #if !defined(HAVE_SIGSETMASK) || defined(FORCE_POSIX_SIGNALS) MASK_T -sigsetmask(mask) - MASK_T mask; +sigsetmask(MASK_T mask) { _DBUG(static int depth_sigsetmask = 0); sigset_t m, omask; @@ -253,8 +245,7 @@ sigsetmask(mask) MASK_T -sigblock(mask) - MASK_T mask; +sigblock(MASK_T mask) { _DBUG(static int depth_sigblock = 0); sigset_t m, omask; @@ -274,8 +265,7 @@ sigblock(mask) #undef sigpause /* Linux at least */ PAUSE_MASK_T -sigpause(mask) - PAUSE_MASK_T mask; +sigpause(PAUSE_MASK_T mask) { _DBUG(static int depth_sigpause = 0); sigset_t m; @@ -292,9 +282,7 @@ sigpause(mask) #if defined(HAVE_SIGVEC) && defined(FORCE_POSIX_SIGNALS) int -sigvec(signo, sv, osv) - int signo; - struct sigvec *sv, *osv; +sigvec(int signo, struct sigvec *sv, struct sigvec *osv) { _DBUG(static int depth_sigvec = 0); int ret; @@ -321,9 +309,7 @@ sigvec(signo, sv, osv) # endif int -main(argc, argv) - int argc; - char **argv; +main(int argc, char *argv[]) { MASK_T old = 0; diff --git a/devel/bmake/files/stresep.c b/devel/bmake/files/stresep.c new file mode 100644 index 00000000000..42ad8d08a6c --- /dev/null +++ b/devel/bmake/files/stresep.c @@ -0,0 +1,89 @@ +/* $NetBSD: stresep.c,v 1.1.1.1 2011/06/18 22:18:07 bsiegert 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. + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <sys/cdefs.h> + +#include <assert.h> +#include <string.h> + +#if !defined(HAVE_STRESEP) +char * stresep(char **stringp, const char *delim, int esc); +/* + * Get next token from string *stringp, where tokens are possibly-empty + * strings separated by characters from delim. If esc is not NUL, then + * the characters followed by esc are ignored and are not taken into account + * when splitting the string. + * + * Writes NULs into the string at *stringp to end tokens. + * delim need not remain constant from call to call. + * On return, *stringp points past the last NUL written (if there might + * be further tokens), or is NULL (if there are definitely no more tokens). + * + * If *stringp is NULL, stresep returns NULL. + */ +char * +stresep(char **stringp, const char *delim, int esc) +{ + char *s; + const char *spanp; + int c, sc; + char *tok; + + if (stringp == NULL || delim == NULL) + return NULL; + + if ((s = *stringp) == NULL) + return NULL; + for (tok = s;;) { + c = *s++; + while (esc != '\0' && c == esc) { + (void)strcpy(s - 1, s); + c = *s++; + } + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *stringp = s; + return tok; + } + } while (sc != 0); + } +} +#endif + diff --git a/devel/bmake/files/strlcpy.c b/devel/bmake/files/strlcpy.c new file mode 100644 index 00000000000..f9b87ffbb3d --- /dev/null +++ b/devel/bmake/files/strlcpy.c @@ -0,0 +1,63 @@ +/* $NetBSD: strlcpy.c,v 1.1.1.1 2011/06/18 22:18:07 bsiegert Exp $ */ +/* $OpenBSD: strlcpy.c,v 1.7 2003/04/12 21:56:39 millert Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE + * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif +#ifndef HAVE_STRLCPY + +#include <sys/cdefs.h> + +#include <sys/types.h> +#include <string.h> + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +strlcpy(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + + if (!dst || !src) + return 0; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} +#endif diff --git a/devel/bmake/files/targ.c b/devel/bmake/files/targ.c index 3402a9ab143..7a45320331f 100644 --- a/devel/bmake/files/targ.c +++ b/devel/bmake/files/targ.c @@ -1,4 +1,4 @@ -/* $NetBSD: targ.c,v 1.1.1.5 2009/09/18 20:55:31 joerg Exp $ */ +/* $NetBSD: targ.c,v 1.1.1.6 2011/06/18 22:18:10 bsiegert Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: targ.c,v 1.1.1.5 2009/09/18 20:55:31 joerg Exp $"; +static char rcsid[] = "$NetBSD: targ.c,v 1.1.1.6 2011/06/18 22:18:10 bsiegert Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: targ.c,v 1.1.1.5 2009/09/18 20:55:31 joerg Exp $"); +__RCSID("$NetBSD: targ.c,v 1.1.1.6 2011/06/18 22:18:10 bsiegert Exp $"); #endif #endif /* not lint */ #endif @@ -248,8 +248,9 @@ Targ_NewGN(const char *name) gn->centurion = NULL; gn->made = UNMADE; gn->flags = 0; - gn->checked = 0; - gn->mtime = gn->cmtime = 0; + gn->checked = 0; + gn->mtime = 0; + gn->cmgn = NULL; gn->iParents = Lst_Init(FALSE); gn->cohorts = Lst_Init(FALSE); gn->parents = Lst_Init(FALSE); diff --git a/devel/bmake/files/unit-tests/Makefile.in b/devel/bmake/files/unit-tests/Makefile.in index f11296b86c8..e5a11d643b5 100644 --- a/devel/bmake/files/unit-tests/Makefile.in +++ b/devel/bmake/files/unit-tests/Makefile.in @@ -1,6 +1,6 @@ -# $Id: Makefile.in,v 1.1.1.8 2010/09/07 14:12:27 joerg Exp $ +# $Id: Makefile.in,v 1.1.1.9 2011/06/18 22:18:21 bsiegert Exp $ # -# $NetBSD: Makefile.in,v 1.1.1.8 2010/09/07 14:12:27 joerg Exp $ +# $NetBSD: Makefile.in,v 1.1.1.9 2011/06/18 22:18:21 bsiegert Exp $ # # Unit tests for make(1) # The main targets are: @@ -31,6 +31,8 @@ SUBFILES= \ doterror \ dotwait \ forsubst \ + hash \ + misc \ moderrs \ modmatch \ modmisc \ @@ -39,6 +41,7 @@ SUBFILES= \ modword \ posix \ qequals \ + sysv \ ternary \ unexport \ unexport-env \ @@ -66,12 +69,9 @@ TOOL_DIFF?= diff DIFF_FLAGS?= @diff_u@ # ensure consistent results from sort(1) +LC_ALL= C LANG= C -.export LANG - -# ensure consistent results from sort(1) -LANG= C -.export LANG +.export LANG LC_ALL # The driver. # We always pretend .MAKE was called 'make' diff --git a/devel/bmake/files/unit-tests/cond1 b/devel/bmake/files/unit-tests/cond1 index c8e2ef8eabf..8e17e74e868 100644 --- a/devel/bmake/files/unit-tests/cond1 +++ b/devel/bmake/files/unit-tests/cond1 @@ -1,4 +1,4 @@ -# $Id: cond1,v 1.1.1.4 2009/09/18 20:55:34 joerg Exp $ +# $Id: cond1,v 1.1.1.5 2011/06/18 22:18:21 bsiegert Exp $ # hard code these! TEST_UNAME_S= NetBSD @@ -95,6 +95,11 @@ C=clever C=dim .endif +.if defined(nosuch) && ${nosuch:Mx} != "" +# this should not happen +.info nosuch is x +.endif + all: @echo "$n is $X prime" @echo "A='$A' B='$B' C='$C' o='$o,${o2}'" diff --git a/devel/bmake/files/unit-tests/hash b/devel/bmake/files/unit-tests/hash new file mode 100644 index 00000000000..1ed84e776d0 --- /dev/null +++ b/devel/bmake/files/unit-tests/hash @@ -0,0 +1,18 @@ +STR1= +STR2= a +STR3= ab +STR4= abc +STR5= abcd +STR6= abcde +STR7= abcdef +STR8= abcdefghijklmnopqrstuvwxyz + +all: + @echo ${STR1:hash} + @echo ${STR2:hash} + @echo ${STR3:hash} + @echo ${STR4:hash} + @echo ${STR5:hash} + @echo ${STR6:hash} + @echo ${STR7:hash} + @echo ${STR8:hash} diff --git a/devel/bmake/files/unit-tests/misc b/devel/bmake/files/unit-tests/misc new file mode 100644 index 00000000000..43683dfba89 --- /dev/null +++ b/devel/bmake/files/unit-tests/misc @@ -0,0 +1,16 @@ +# $Id: misc,v 1.1.1.1 2011/06/18 22:18:21 bsiegert Exp $ + +.if !exists(${.CURDIR}/) +.warning ${.CURDIR}/ doesn't exist ? +.endif + +.if !exists(${.CURDIR}/.) +.warning ${.CURDIR}/. doesn't exist ? +.endif + +.if !exists(${.CURDIR}/..) +.warning ${.CURDIR}/.. doesn't exist ? +.endif + +all: + @: all is well diff --git a/devel/bmake/files/unit-tests/modmisc b/devel/bmake/files/unit-tests/modmisc index 375accca28d..1fd75acd5a2 100644 --- a/devel/bmake/files/unit-tests/modmisc +++ b/devel/bmake/files/unit-tests/modmisc @@ -1,4 +1,4 @@ -# $Id: modmisc,v 1.1.1.4 2010/04/24 20:34:05 joerg Exp $ +# $Id: modmisc,v 1.1.1.5 2011/06/18 22:18:21 bsiegert Exp $ # # miscellaneous modifier tests @@ -15,7 +15,10 @@ MOD_HOMES=S,/home/,/homes/, MOD_OPT=@d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@ MOD_SEP=S,:, ,g -all: modvar modvarloop +all: modvar modvarloop modsysv + +modsysv: + @echo "The answer is ${libfoo.a:L:libfoo.a=42}" modvar: @echo "path='${path}'" diff --git a/devel/bmake/files/unit-tests/modts b/devel/bmake/files/unit-tests/modts index d0efd6d19c0..616bd8944f2 100644 --- a/devel/bmake/files/unit-tests/modts +++ b/devel/bmake/files/unit-tests/modts @@ -9,6 +9,17 @@ B.aaa= Baaa all: mod-ts +# Use print or printf iff they are builtin. +# XXX note that this causes problems, when make decides +# there is no need to use a shell, so avoid where possible. +.if ${type print 2> /dev/null || echo:L:sh:Mbuiltin} != "" +PRINT= print -r -- +.elif ${type printf 2> /dev/null || echo:L:sh:Mbuiltin} != "" +PRINT= printf '%s\n' +.else +PRINT= echo +.endif + mod-ts: @echo 'LIST="${LIST}"' @echo 'LIST:ts,="${LIST:ts,}"' @@ -22,11 +33,11 @@ mod-ts: @echo 'LIST:S/two/2/:ts="${LIST:S/two/2/:ts}"' @echo 'LIST:ts/:S/two/2/="${LIST:ts/:S/two/2/}"' @echo "Pretend the '/' in '/n' etc. below are back-slashes." - @echo 'LIST:ts/n="${LIST:ts\n}"' - @echo 'LIST:ts/t="${LIST:ts\t}"' - @echo 'LIST:ts/012:tu="${LIST:ts\012:tu}"' - @echo 'LIST:tx="${LIST:tx}"' - @echo 'LIST:ts/x:tu="${LIST:ts\x:tu}"' - @echo 'FU_$@="${FU_${@:ts}:ts}"' - @echo 'FU_$@:ts:T="${FU_${@:ts}:ts:T}" == cool?' - @echo 'B.$${AAA:ts}="${B.${AAA:ts}}" == Baaa?' + @${PRINT} 'LIST:ts/n="${LIST:ts\n}"' + @${PRINT} 'LIST:ts/t="${LIST:ts\t}"' + @${PRINT} 'LIST:ts/012:tu="${LIST:ts\012:tu}"' + @${PRINT} 'LIST:tx="${LIST:tx}"' + @${PRINT} 'LIST:ts/x:tu="${LIST:ts\x:tu}"' + @${PRINT} 'FU_$@="${FU_${@:ts}:ts}"' + @${PRINT} 'FU_$@:ts:T="${FU_${@:ts}:ts:T}" == cool?' + @${PRINT} 'B.$${AAA:ts}="${B.${AAA:ts}}" == Baaa?' diff --git a/devel/bmake/files/unit-tests/sysv b/devel/bmake/files/unit-tests/sysv new file mode 100644 index 00000000000..76fbdc083bd --- /dev/null +++ b/devel/bmake/files/unit-tests/sysv @@ -0,0 +1,26 @@ +# $Id: sysv,v 1.1.1.1 2011/06/18 22:18:21 bsiegert Exp $ + +FOO ?= +FOOBAR = $(FOO:=bar) + +_this := ${.PARSEDIR}/${.PARSEFILE} + +B = /b +S = / +FUN = ${B}${S}fun +SUN = the Sun + +# we expect nothing when FOO is empty +all: foo fun + +foo: + @echo FOOBAR = $(FOOBAR) +.if empty(FOO) + @FOO="foo fu" ${.MAKE} -f ${_this} foo +.endif + +fun: + @echo ${FUN:T} + @echo ${FUN:${B}${S}fun=fun} + @echo ${FUN:${B}${S}%=%} + @echo ${In:L:%=% ${SUN}} diff --git a/devel/bmake/files/unit-tests/test.exp b/devel/bmake/files/unit-tests/test.exp index 347bb9f2409..cc49d4b454d 100644 --- a/devel/bmake/files/unit-tests/test.exp +++ b/devel/bmake/files/unit-tests/test.exp @@ -81,6 +81,14 @@ make: Graph cycles through `cycle.2.97' cycle.1.99 cycle.1.99 .for with :S;... OK +b2af338b +3360ac65 +7747f046 +9ca87054 +880fe816 +208fcbd3 +d5d376eb +de41416c Expect: Unknown modifier 'Z' make: Unknown modifier 'Z' VAR:Z= @@ -120,6 +128,7 @@ path='/bin':'/tmp':'/':'/no/such/dir' path_/usr/xbin=/opt/xbin/ paths=/bin /tmp / /no/such/dir /opt/xbin PATHS=/BIN /TMP / /NO/SUCH/DIR /OPT/XBIN +The answer is 42 LIST = one two three four five six seven eight nine ten LIST:O = eight five four nine one seven six ten three two LIST:Ox = Ok @@ -306,6 +315,12 @@ Now we expect an error... *** Error code 1 (continuing) `all' not remade because of errors. V.i386 ?= OK +FOOBAR = +FOOBAR = foobar fubar +fun +fun +fun +In the Sun The answer is unknown The answer is unknown The answer is empty diff --git a/devel/bmake/files/util.c b/devel/bmake/files/util.c index cb6b055e6d7..89210546bf3 100644 --- a/devel/bmake/files/util.c +++ b/devel/bmake/files/util.c @@ -1,18 +1,18 @@ -/* $NetBSD: util.c,v 1.1.1.8 2010/09/07 14:12:10 joerg Exp $ */ +/* $NetBSD: util.c,v 1.1.1.9 2011/06/18 22:18:10 bsiegert Exp $ */ /* * Missing stuff from OS's * - * $Id: util.c,v 1.1.1.8 2010/09/07 14:12:10 joerg Exp $ + * $Id: util.c,v 1.1.1.9 2011/06/18 22:18:10 bsiegert Exp $ */ #include "make.h" #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: util.c,v 1.1.1.8 2010/09/07 14:12:10 joerg Exp $"; +static char rcsid[] = "$NetBSD: util.c,v 1.1.1.9 2011/06/18 22:18:10 bsiegert Exp $"; #else #ifndef lint -__RCSID("$NetBSD: util.c,v 1.1.1.8 2010/09/07 14:12:10 joerg Exp $"); +__RCSID("$NetBSD: util.c,v 1.1.1.9 2011/06/18 22:18:10 bsiegert Exp $"); #endif #endif @@ -47,7 +47,7 @@ findenv(const char *name, int *offset) char *p, *q; for (i = 0; (q = environ[i]); i++) { - char *p = strchr(q, '='); + p = strchr(q, '='); if (p == NULL) continue; if (strncmp(name, q, len = p - q) == 0) { @@ -526,3 +526,90 @@ killpg(int pid, int sig) } #endif #endif + +#if !defined(HAVE_WARNX) +static void +vwarnx(const char *fmt, va_list args) +{ + fprintf(stderr, "%s: ", progname); + if ((fmt)) { + vfprintf(stderr, fmt, args); + fprintf(stderr, ": "); + } +} +#endif + +#if !defined(HAVE_WARN) +static void +vwarn(const char *fmt, va_list args) +{ + vwarnx(fmt, args); + fprintf(stderr, "%s\n", strerror(errno)); +} +#endif + +#if !defined(HAVE_ERR) +static void +verr(int eval, const char *fmt, va_list args) +{ + vwarn(fmt, args); + exit(eval); +} +#endif + +#if !defined(HAVE_ERRX) +static void +verrx(int eval, const char *fmt, va_list args) +{ + vwarnx(fmt, args); + exit(eval); +} +#endif + +#if !defined(HAVE_ERR) +void +err(int eval, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + verr(eval, fmt, ap); + va_end(ap); +} +#endif + +#if !defined(HAVE_ERRX) +void +errx(int eval, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + verrx(eval, fmt, ap); + va_end(ap); +} +#endif + +#if !defined(HAVE_WARN) +void +warn(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vwarn(fmt, ap); + va_end(ap); +} +#endif + +#if !defined(HAVE_WARNX) +void +warnx(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vwarnx(fmt, ap); + va_end(ap); +} +#endif diff --git a/devel/bmake/files/var.c b/devel/bmake/files/var.c index 17de1040051..28fa6c30e57 100644 --- a/devel/bmake/files/var.c +++ b/devel/bmake/files/var.c @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.1.1.8 2010/09/07 14:12:15 joerg Exp $ */ +/* $NetBSD: var.c,v 1.1.1.9 2011/06/18 22:18:13 bsiegert Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: var.c,v 1.1.1.8 2010/09/07 14:12:15 joerg Exp $"; +static char rcsid[] = "$NetBSD: var.c,v 1.1.1.9 2011/06/18 22:18:13 bsiegert Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: var.c,v 1.1.1.8 2010/09/07 14:12:15 joerg Exp $"); +__RCSID("$NetBSD: var.c,v 1.1.1.9 2011/06/18 22:18:13 bsiegert Exp $"); #endif #endif /* not lint */ #endif @@ -129,8 +129,10 @@ __RCSID("$NetBSD: var.c,v 1.1.1.8 2010/09/07 14:12:15 joerg Exp $"); #include <regex.h> #endif #include <ctype.h> +#include <inttypes.h> #include <stdlib.h> #include <limits.h> +#include <time.h> #include "make.h" #include "buf.h" @@ -302,6 +304,7 @@ static char *VarGetPattern(GNode *, Var_Parse_State *, VarPattern *); static char *VarQuote(char *); static char *VarChangeCase(char *, int); +static char *VarHash(char *); static char *VarModify(GNode *, Var_Parse_State *, const char *, Boolean (*)(GNode *, Var_Parse_State *, char *, Boolean, Buffer *, void *), @@ -379,6 +382,12 @@ VarFind(const char *name, GNode *ctxt, int flags) name = TARGET; break; } +#ifdef notyet + /* for compatibility with gmake */ + if (name[0] == '^' && name[1] == '\0') + name = ALLSRC; +#endif + /* * First look for the variable in the given context. If it's not there, * look for it in VAR_CMD, VAR_GLOBAL and the environment, in that order, @@ -2256,6 +2265,79 @@ VarQuote(char *str) /*- *----------------------------------------------------------------------- + * VarHash -- + * Hash the string using the MurmurHash3 algorithm. + * Output is computed using 32bit Little Endian arithmetic. + * + * Input: + * str String to modify + * + * Results: + * Hash value of str, encoded as 8 hex digits. + * + * Side Effects: + * None. + * + *----------------------------------------------------------------------- + */ +static char * +VarHash(char *str) +{ + static const char hexdigits[16] = "0123456789abcdef"; + Buffer buf; + size_t len, len2; + unsigned char *ustr = (unsigned char *)str; + uint32_t h, k, c1, c2; + int done; + + done = 1; + h = 0x971e137bU; + c1 = 0x95543787U; + c2 = 0x2ad7eb25U; + len2 = strlen(str); + + for (len = len2; len; ) { + k = 0; + switch (len) { + default: + k = (ustr[3] << 24) | (ustr[2] << 16) | (ustr[1] << 8) | ustr[0]; + len -= 4; + ustr += 4; + break; + case 3: + k |= (ustr[2] << 16); + case 2: + k |= (ustr[1] << 8); + case 1: + k |= 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; + } while (!done); + h ^= len2; + h *= 0x85ebca6b; + h ^= h >> 13; + h *= 0xc2b2ae35; + h ^= h >> 16; + + Buf_Init(&buf, 0); + for (len = 0; len < 8; ++len) { + Buf_AddByte(&buf, hexdigits[h & 15]); + h >>= 4; + } + + return Buf_Destroy(&buf, FALSE); +} + +/*- + *----------------------------------------------------------------------- * VarChangeCase -- * Change the string to all uppercase or all lowercase * @@ -2285,6 +2367,21 @@ VarChangeCase(char *str, int upper) return Buf_Destroy(&buf, FALSE); } +static char * +VarStrftime(const char *fmt, int zulu) +{ + char buf[BUFSIZ]; + time_t utc; + + time(&utc); + if (!*fmt) + fmt = "%c"; + strftime(buf, sizeof(buf), fmt, zulu ? gmtime(&utc) : localtime(&utc)); + + buf[sizeof(buf) - 1] = '\0'; + return bmake_strdup(buf); +} + /* * Now we need to apply any modifiers the user wants applied. * These are: @@ -2370,6 +2467,10 @@ VarChangeCase(char *str, int upper) * variable. */ +/* we now have some modifiers with long names */ +#define STRMOD_MATCH(s, want, n) \ + (strncmp(s, want, n) == 0 && (s[n] == endc || s[n] == ':')) + static char * ApplyModifiers(char *nstr, const char *tstr, int startc, int endc, @@ -2397,14 +2498,28 @@ ApplyModifiers(char *nstr, const char *tstr, if (*tstr == '$') { /* - * We have some complex modifiers in a variable. + * We may have some complex modifiers in a variable. */ void *freeIt; char *rval; int rlen; + int c; rval = Var_Parse(tstr, ctxt, errnum, &rlen, &freeIt); + /* + * If we have not parsed up to endc or ':', + * we are not interested. + */ + if (rval != NULL && *rval && + (c = tstr[rlen]) != '\0' && + c != ':' && + c != endc) { + if (freeIt) + free(freeIt); + goto apply_mods; + } + if (DEBUG(VAR)) { fprintf(debug_file, "Got '%s' from '%.*s'%.*s\n", rval, rlen, tstr, rlen, tstr + rlen); @@ -2436,6 +2551,7 @@ ApplyModifiers(char *nstr, const char *tstr, } continue; } + apply_mods: if (DEBUG(VAR)) { fprintf(debug_file, "Applying :%c to \"%s\"\n", *tstr, nstr); } @@ -2486,7 +2602,7 @@ ApplyModifiers(char *nstr, const char *tstr, cp = ++tstr; break; } - delim = BRCLOSE; + delim = startc == PROPEN ? PRCLOSE : BRCLOSE; pattern.flags = 0; pattern.rhs = VarGetPattern(ctxt, &parsestate, errnum, @@ -2815,6 +2931,36 @@ ApplyModifiers(char *nstr, const char *tstr, } } + case 'g': + cp = tstr + 1; /* make sure it is set */ + if (STRMOD_MATCH(tstr, "gmtime", 6)) { + newStr = VarStrftime(nstr, 1); + cp = tstr + 6; + termc = *cp; + } else { + goto default_case; + } + break; + case 'h': + cp = tstr + 1; /* make sure it is set */ + if (STRMOD_MATCH(tstr, "hash", 4)) { + newStr = VarHash(nstr); + cp = tstr + 4; + termc = *cp; + } else { + goto default_case; + } + break; + case 'l': + cp = tstr + 1; /* make sure it is set */ + if (STRMOD_MATCH(tstr, "localtime", 9)) { + newStr = VarStrftime(nstr, 0); + cp = tstr + 9; + termc = *cp; + } else { + goto default_case; + } + break; case 't': { cp = tstr + 1; /* make sure it is set */ @@ -3340,9 +3486,13 @@ ApplyModifiers(char *nstr, const char *tstr, */ termc = *--cp; delim = '\0'; - newStr = VarModify(ctxt, &parsestate, nstr, - VarSYSVMatch, - &pattern); + if (pattern.leftLen == 0 && *nstr == '\0') { + newStr = nstr; /* special case */ + } else { + newStr = VarModify(ctxt, &parsestate, nstr, + VarSYSVMatch, + &pattern); + } free(UNCONST(pattern.lhs)); free(UNCONST(pattern.rhs)); } else @@ -3740,7 +3890,7 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr, nstr = bmake_strndup(start, *lengthPtr); *freePtr = nstr; } else { - nstr = var_Error; + nstr = errnum ? var_Error : varNoError; } } if (nstr != Buf_GetAll(&v->val, NULL)) |