[Midnightbsd-cvs] src [11140] trunk/contrib/bmake: update to 20170720

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Tue Jun 26 20:20:04 EDT 2018


Revision: 11140
          http://svnweb.midnightbsd.org/src/?rev=11140
Author:   laffer1
Date:     2018-06-26 20:20:04 -0400 (Tue, 26 Jun 2018)
Log Message:
-----------
update to 20170720

Modified Paths:
--------------
    trunk/contrib/bmake/ChangeLog
    trunk/contrib/bmake/Makefile
    trunk/contrib/bmake/PSD.doc/tutorial.ms
    trunk/contrib/bmake/README
    trunk/contrib/bmake/arch.c
    trunk/contrib/bmake/bmake.1
    trunk/contrib/bmake/bmake.cat1
    trunk/contrib/bmake/boot-strap
    trunk/contrib/bmake/buf.h
    trunk/contrib/bmake/compat.c
    trunk/contrib/bmake/cond.c
    trunk/contrib/bmake/config.h.in
    trunk/contrib/bmake/configure
    trunk/contrib/bmake/configure.in
    trunk/contrib/bmake/dir.c
    trunk/contrib/bmake/dir.h
    trunk/contrib/bmake/dirname.c
    trunk/contrib/bmake/for.c
    trunk/contrib/bmake/getopt.c
    trunk/contrib/bmake/hash.h
    trunk/contrib/bmake/job.c
    trunk/contrib/bmake/main.c
    trunk/contrib/bmake/make-bootstrap.sh.in
    trunk/contrib/bmake/make.1
    trunk/contrib/bmake/make.c
    trunk/contrib/bmake/make.h
    trunk/contrib/bmake/make_malloc.c
    trunk/contrib/bmake/meta.c
    trunk/contrib/bmake/meta.h
    trunk/contrib/bmake/mk/ChangeLog
    trunk/contrib/bmake/mk/FILES
    trunk/contrib/bmake/mk/auto.dep.mk
    trunk/contrib/bmake/mk/auto.obj.mk
    trunk/contrib/bmake/mk/autodep.mk
    trunk/contrib/bmake/mk/dirdeps.mk
    trunk/contrib/bmake/mk/doc.mk
    trunk/contrib/bmake/mk/dpadd.mk
    trunk/contrib/bmake/mk/final.mk
    trunk/contrib/bmake/mk/gendirdeps.mk
    trunk/contrib/bmake/mk/inc.mk
    trunk/contrib/bmake/mk/init.mk
    trunk/contrib/bmake/mk/install-mk
    trunk/contrib/bmake/mk/lib.mk
    trunk/contrib/bmake/mk/libnames.mk
    trunk/contrib/bmake/mk/meta.autodep.mk
    trunk/contrib/bmake/mk/meta.stage.mk
    trunk/contrib/bmake/mk/meta.sys.mk
    trunk/contrib/bmake/mk/meta2deps.py
    trunk/contrib/bmake/mk/meta2deps.sh
    trunk/contrib/bmake/mk/nls.mk
    trunk/contrib/bmake/mk/own.mk
    trunk/contrib/bmake/mk/prog.mk
    trunk/contrib/bmake/mk/scripts.mk
    trunk/contrib/bmake/mk/subdir.mk
    trunk/contrib/bmake/mk/sys/AIX.mk
    trunk/contrib/bmake/mk/sys/Darwin.mk
    trunk/contrib/bmake/mk/sys/Generic.mk
    trunk/contrib/bmake/mk/sys/HP-UX.mk
    trunk/contrib/bmake/mk/sys/IRIX.mk
    trunk/contrib/bmake/mk/sys/Linux.mk
    trunk/contrib/bmake/mk/sys/NetBSD.mk
    trunk/contrib/bmake/mk/sys/OSF1.mk
    trunk/contrib/bmake/mk/sys/OpenBSD.mk
    trunk/contrib/bmake/mk/sys/SunOS.mk
    trunk/contrib/bmake/mk/sys/UnixWare.mk
    trunk/contrib/bmake/mk/sys.clean-env.mk
    trunk/contrib/bmake/mk/sys.dependfile.mk
    trunk/contrib/bmake/mk/sys.mk
    trunk/contrib/bmake/mk/warnings.mk
    trunk/contrib/bmake/nonints.h
    trunk/contrib/bmake/os.sh
    trunk/contrib/bmake/parse.c
    trunk/contrib/bmake/sprite.h
    trunk/contrib/bmake/str.c
    trunk/contrib/bmake/suff.c
    trunk/contrib/bmake/targ.c
    trunk/contrib/bmake/var.c

Added Paths:
-----------
    trunk/contrib/bmake/mk/files.mk
    trunk/contrib/bmake/mk/sys.debug.mk
    trunk/contrib/bmake/mk/sys.vars.mk

Removed Paths:
-------------
    trunk/contrib/bmake/missing/
    trunk/contrib/bmake/unit-tests/comment
    trunk/contrib/bmake/unit-tests/cond1
    trunk/contrib/bmake/unit-tests/doterror
    trunk/contrib/bmake/unit-tests/dotwait
    trunk/contrib/bmake/unit-tests/error
    trunk/contrib/bmake/unit-tests/export
    trunk/contrib/bmake/unit-tests/export-all
    trunk/contrib/bmake/unit-tests/export-env
    trunk/contrib/bmake/unit-tests/forloop
    trunk/contrib/bmake/unit-tests/forsubst
    trunk/contrib/bmake/unit-tests/hash
    trunk/contrib/bmake/unit-tests/misc
    trunk/contrib/bmake/unit-tests/moderrs
    trunk/contrib/bmake/unit-tests/modmatch
    trunk/contrib/bmake/unit-tests/modmisc
    trunk/contrib/bmake/unit-tests/modorder
    trunk/contrib/bmake/unit-tests/modts
    trunk/contrib/bmake/unit-tests/modword
    trunk/contrib/bmake/unit-tests/order
    trunk/contrib/bmake/unit-tests/phony-end
    trunk/contrib/bmake/unit-tests/posix
    trunk/contrib/bmake/unit-tests/qequals
    trunk/contrib/bmake/unit-tests/sunshcmd
    trunk/contrib/bmake/unit-tests/sysv
    trunk/contrib/bmake/unit-tests/ternary
    trunk/contrib/bmake/unit-tests/test.exp
    trunk/contrib/bmake/unit-tests/unexport
    trunk/contrib/bmake/unit-tests/unexport-env
    trunk/contrib/bmake/unit-tests/varcmd

Property Changed:
----------------
    trunk/contrib/bmake/

Index: trunk/contrib/bmake
===================================================================
--- trunk/contrib/bmake	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake	2018-06-27 00:20:04 UTC (rev 11140)

Property changes on: trunk/contrib/bmake
___________________________________________________________________
Added: svn:mergeinfo
## -0,0 +1 ##
+/vendor/NetBSD/bmake/dist:6784-11139
\ No newline at end of property
Modified: trunk/contrib/bmake/ChangeLog
===================================================================
--- trunk/contrib/bmake/ChangeLog	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/ChangeLog	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,3 +1,296 @@
+2017-07-20  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170720
+	  Merge with NetBSD make, pick up
+	  o compat.c: pass SIGINT etc onto child and wait for it to exit
+	    before we self-terminate.
+
+2017-07-11  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170711
+	  forgot to update after merge on 20170708 ;-)
+	  o main.c: refactor to reduce size of main function.
+	    add -v option to always fully expand values.
+	  o meta.c: ensure command output in meta file has ending newline
+	    even when filemon not being used.
+	    When matching ${.MAKE.META.IGNORE_PATTERNS} do not use
+	    pathname via ':L' since any ':' in pathname breaks that.
+	    Instead set a '${.p.}' to pathname in the target context and
+	    use that.
+
+2017-05-10  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170510
+	  Merge with NetBSD make, pick up
+	  o main.c: Main_SetObjdir: ensure buf2 is in scope
+
+2017-05-08  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170505
+	  see mk/ChangeLog
+
+2017-05-05  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* parse.c: not everyone has stdint.h
+
+2017-05-01  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170501
+	  see mk/ChangeLog
+
+2017-04-21  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170421
+	  Merge with NetBSD make, pick up
+	  o str.c: Str_Match: fix closure tests for [^] and add unit-test.
+
+2017-04-20  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170420
+	  Merge with NetBSD make, pick up
+	  o main.c: only use -C arg "as is" if it contains no 
+	    relative component.
+
+2017-04-18  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170418
+	  Merge with NetBSD make, pick up
+	  o main.c: fix Main_SetObjdir() for relative paths (eg obj).
+
+2017-04-17  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170417
+	  Merge with NetBSD make, pick up
+	  o fixes a number of coverity complaints
+	    - check return value of fseek, fcntl
+	    - plug memory leak in Dir_FindFile, Var_LoopExpand,
+	      JobPrintCommand, ParseTraditionalInclude
+	    - use bmake_malloc() where NULL is not tollerated
+	    - use MAKE_ATTR_UNUSED rather that kludges like 
+	      return(unused ? 0 : 0)
+	    - use purge_cached_realpaths() rather than abuse cached_realpath()
+
+2017-04-13  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170413
+	  Merge with NetBSD make, pick up
+	  o main.c: when setting .OBJDIR ignore '$' in paths.
+
+	* job.c: use MALLOC_OPTIONS to set malloc_options.
+
+2017-04-11  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170411
+	  Merge with NetBSD make, pick up
+	  o str.c: Str_Match: allow [^a-z] to behave as expected.
+
+2017-03-26  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170326
+	  Merge with NetBSD make, pick up
+	  o main.c: purge relative paths from realpath cache when .OBJDIR
+	    is changed.
+
+2017-03-11  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170311
+	  Merge with NetBSD make, pick up
+          o main.c: only use -C arg "as is" if it starts with '/'.
+
+2017-03-01  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170301
+	  Merge with NetBSD make, pick up
+	  o main.c: use -C arg "as is" rather than getcwd()
+	    if they identify the same directory.
+	  o parse.c: ensure loadfile buffer is \n terminated in non-mmap case
+
+2017-02-01  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170201
+	  Merge with NetBSD make, pick up
+	  o var.c: allow :_=var and avoid use of special context.
+
+2017-01-30  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170130
+	  Merge with NetBSD make, pick up
+	  o var.c: add :range and :_
+	  o main.c: partially initialize Dir_* before MainParseArgs()
+	    can be called.
+	    If -V, skip Main_ExportMAKEFLAGS()
+
+2017-01-14  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20170114
+	  Merge with NetBSD make, pick up
+	  o var.c: allow specifying the utc value used by :{gm,local}time
+
+2016-12-12  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20161212
+	  Merge with NetBSD make, pick up
+          o main.c: look for obj.${MACHINE}-${MACHINE_ARCH} too.
+
+2016-12-09  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20161209
+	  Merge with NetBSD make, pick up
+	  o main.c: cleanup setting of .OBJDIR
+	  o parse.c: avoid coredump from (var)=val
+
+2016-11-26  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20161126
+	  Merge with NetBSD make, pick up
+	  o make.c: Make_OODate: report src node name if path not set
+
+2016-09-26  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20160926
+	  Merge with NetBSD make, pick up
+	  o support for .DELETE_ON_ERROR: (remove targets that fail)
+	
+2016-09-26  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile MAN: tweak .Dt to match ${PROG}
+
+2016-08-18  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20160818
+	  its a neater number; pick up whitespace fixes to man page.
+
+2016-08-17  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20160817
+	  Merge with NetBSD make, pick up
+	  o meta.c: move handling of .MAKE.META.IGNORE_* to meta_ignore()
+	    so we can call it before adding entries to missingFiles.
+	    Thus we do not track files we have been told to ignore.
+
+2016-08-15  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20160815
+	  Merge with NetBSD make, pick up
+	  o meta_oodate: apply .MAKE.META.IGNORE_FILTER (if defined) to
+	    pathnames, and skip if the expansion is empty.
+	    Useful for dirdeps.mk when checking DIRDEPS_CACHE.
+
+2016-08-12  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20160812
+	  Merge with NetBSD make, pick up
+	  o meta.c: remove all missingFiles entries that match a deleted
+	    dir.
+	  o main.c: set .ERROR_CMD if possible.
+	  
+2016-06-06  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20160606
+	  Merge with NetBSD make, pick up
+	  o dir.c: extend mtimes cache to others via cached_stat()
+
+2016-06-04  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20160604
+	  Merge with NetBSD make, pick up
+	  o meta.c: missing filemon data is only relevant if we read a
+	    meta file.
+	    Also do not return oodate for a missing metafile if gn->path
+	    points to .CURDIR
+	
+2016-06-02  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20160602
+	  Merge with NetBSD make, pick up
+	  o cached_realpath(): avoid hitting filesystem more than necessary.
+	  o meta.c: refactor need_meta decision, add knobs for 
+	    missing meta file and filemon data wrt out-of-datedness.
+
+2016-05-28  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20160528
+
+	* boot-strap, make-bootstrap.sh.in: Makefile now uses _MAKE_VERSION 
+
+2016-05-12  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20160512
+	  Merge with NetBSD make, pick up
+	  o meta.c: ignore paths that match .MAKE.META.IGNORE_PATTERNS
+	    this is useful for gcov builds.
+	  o propagate errors from filemon(4).
+	
+2016-05-09  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20160509
+	  Merge with NetBSD make, pick up
+	  o remove use of non-standard types u_int etc.
+	  o meta.c: apply realpath() before matching against metaIgnorePaths
+
+2016-04-04  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20160404
+	  Merge with NetBSD make, pick up
+	  o allow makefile to set .MAKE.JOBS
+
+	* Makefile (PROG_NAME): use ${_MAKE_VERSION}
+
+2016-03-15  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): 20160315
+	  Merge with NetBSD make, pick up
+	  o fix handling of archive members
+
+2016-03-13  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (_MAKE_VERSION): rename variable to avoid interference
+	  with checks for ${MAKE_VERSION}
+
+2016-03-10  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (MAKE_VERSION): 20160310
+	  Merge with NetBSD make, pick up
+	  o meta.c: treat missing Read file same as Write, incase we Delete it.
+
+2016-03-07  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (MAKE_VERSION): 20160307
+	  Merge with NetBSD make, pick up
+	  o var.c: fix :ts\nnn to be octal by default.
+	  o meta.c: meta_finish() to cleanup memory.
+
+2016-02-26  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (MAKE_VERSION): 20160226
+	  Merge with NetBSD make, pick up
+	  o meta.c: allow meta file for makeDepend if makefiles want it.
+
+2016-02-19  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* var.c: default .MAKE.SAVE_DOLLARS to FALSE
+	  for backwards compatability.
+
+	* Makefile (MAKE_VERSION): 20160220
+	  Merge with NetBSD make, pick up
+	  o var.c: add knob to control handling of '$$' in :=
+
+2016-02-18  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (MAKE_VERSION): 20160218
+	  Merge with NetBSD make, pick up
+	  o var.c: add .export-literal allows us to fix sys.clean-env.mk
+	    post the changes to Var_Subst.
+	    Var_Subst now takes flags, and does not consume '$$' in :=
+
+2016-02-17  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Makefile (MAKE_VERSION): 20160217
+	  Merge with NetBSD make, pick up
+	  o var.c: preserve '$$' in :=
+	  o parse.c: add .dinclude for handling included 
+	    makefile like .depend
+
 2015-12-20  Simon J. Gerraty  <sjg at bad.crufty.net>
 
 	* Makefile (MAKE_VERSION): 20151220

Modified: trunk/contrib/bmake/Makefile
===================================================================
--- trunk/contrib/bmake/Makefile	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/Makefile	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,7 +1,7 @@
-#	$Id: Makefile,v 1.49 2015/12/20 22:54:40 sjg Exp $
+#	$Id: Makefile,v 1.95 2017/07/20 19:36:13 sjg Exp $
 
 # Base version on src date
-MAKE_VERSION= 20151220
+_MAKE_VERSION= 20170720
 
 PROG=	bmake
 
@@ -76,7 +76,7 @@
 CFLAGS+= -D_PATH_DEFSYSPATH=\"${DEFAULT_SYS_PATH}\"
 CFLAGS+= -I. -I${srcdir} ${XDEFS} -DMAKE_NATIVE
 CFLAGS+= ${COPTS.${.ALLSRC:M*.c:T:u}}
-COPTS.main.c+= "-DMAKE_VERSION=\"${MAKE_VERSION}\""
+COPTS.main.c+= "-DMAKE_VERSION=\"${_MAKE_VERSION}\""
 
 # meta mode can be useful even without filemon 
 FILEMON_H ?= /usr/include/dev/filemon/filemon.h
@@ -95,7 +95,7 @@
 # we skip a lot of this when building as part of FreeBSD etc.
 
 # list of OS's which are derrived from BSD4.4
-BSD44_LIST= NetBSD FreeBSD OpenBSD DragonFly MirBSD Bitrig MidnightBSD
+BSD44_LIST= NetBSD FreeBSD OpenBSD DragonFly MirBSD Bitrig
 # we are...
 OS!= uname -s
 # are we 4.4BSD ?
@@ -131,9 +131,9 @@
 .include <own.mk>
 
 .if ${MK_PROG_VERSION} == "yes"
-PROG_NAME= ${PROG}-${MAKE_VERSION}
+PROG_NAME= ${PROG}-${_MAKE_VERSION}
 .if ${MK_PROG_LINK} == "yes"
-SYMLINKS+= ${PROG}-${MAKE_VERSION} ${BINDIR}/${PROG}
+SYMLINKS+= ${PROG_NAME} ${BINDIR}/${PROG}
 .endif
 .endif
 
@@ -156,7 +156,10 @@
 .NOPATH: ${MAN}
 ${MAN}:	make.1 my.history
 	@echo making $@
-	@sed -e 's/^.Nx/NetBSD/' -e '/^.Nm/s/make/${PROG}/' \
+	@sed \
+	-e '/^.Dt/s/MAKE/${PROG:tu}/' \
+	-e 's/^.Nx/NetBSD/' \
+	-e '/^.Nm/s/make/${PROG}/' \
 	-e '/^.Sh HISTORY/rmy.history' \
 	-e '/^.Sh HISTORY/,$$s,^.Nm,make,' ${srcdir}/make.1 > $@
 

Modified: trunk/contrib/bmake/PSD.doc/tutorial.ms
===================================================================
--- trunk/contrib/bmake/PSD.doc/tutorial.ms	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/PSD.doc/tutorial.ms	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-.\"	$NetBSD: tutorial.ms,v 1.12 2014/09/30 21:33:14 christos Exp $
+.\"	$NetBSD: tutorial.ms,v 1.13 2017/03/01 13:05:11 kre Exp $
 .\" Copyright (c) 1988, 1989, 1993
 .\"	The Regents of the University of California.  All rights reserved.
 .\"
@@ -117,6 +117,15 @@
 .de No
 .br
 .ne 0.5i
+.ie n \{\
+.nr g3 \w'NOTE '
+.po -\\n(g3u
+.br
+NOTE
+.br
+.po +\\n(g3u
+.\}
+.el \{\
 .po -0.5i
 .br
 .mk 
@@ -148,12 +157,14 @@
 .rt 
 .ft \\n(g3
 .ps \\n(g4
+.\}
 ..
 .de Bp
 .ie !\\n(.$ .IP \(bu 2
 .el .IP "\&" 2
 ..
-.po +.3i
+.ie n .po +\w'NOTE  'u
+.el .po +.3i
 .TL
 PMake \*- A Tutorial
 .AU

Modified: trunk/contrib/bmake/README
===================================================================
--- trunk/contrib/bmake/README	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/README	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,47 +1,52 @@
 			       bmake
+			       *****
 
-This directory contains a port of the BSD make tool (from NetBSD)
-I have run it on SunOS,Solaris,HP-UX,AIX,IRIX,FreeBSD and Linux.
+This directory contains a port of the BSD make tool (from NetBSD).
+Since 1993 I have run it on AIX, BSDi, Darwin, FreeBSD, HP-UX, IRIX,
+Linux, Minix, OSF, Solaris, SunOS and even UTS.
+Others have run it on many more systems.
 
-Version 3 was re-worked from scratch to better facilitate
-importing newer make(1) versions from NetBSD.  The original code base
-was NetBSD-1.0, so version 3 was built by doing a fresh import of the
-NetBSD-1.0 usr.bin/make, adding the autoconf and other portability
-patches to sync it with bmake v2, and then NetBSD's make 
-of Feb 20, 2000 was imported and conflicts dealt with.
-NetBSD's make was again imported on June 6 and December 15, 2000.
+Currently each release is tested on NetBSD, FreeBSD, Solaris and Linux.
 
-In 2003 bmake switched to a date based version (first was 20030714)
+Since 2003 bmake switched to a date based version (first was 20030714)
 which generally represents the date it was last merged with NetBSD's
 make.  Since then, NetBSD's make is imported within a week of any
 interesting changes, so that bmake tracks it very closely.
 
-Building:
+Building
+========
 
-The preferred way to bootstrap bmake is:
+The preferred way to bootstrap bmake is::
 
-./bmake/boot-strap
+	./bmake/boot-strap
 
 there are a number of args - most of which get passed to configure,
 eg.
+::
 
-./bmake/boot-strap --prefix=/opt
+	./bmake/boot-strap --prefix=/opt
 
 see the boot-strap script for details.
 
+For folk that hate to read anything, since 20121212 you can also use
+the GNU standard process of::
+
+	./configure; make; make install
+
 To make much use of bmake you will need the bsd.*.mk macros or my
-portable *.mk macros.  See 
+portable *.mk macros which are included with bmake since 20121212
+and separately available from
 http://www.crufty.net/ftp/pub/sjg/mk.tar.gz
 which will be links to the latest versions.
 
-On a non-BSD system, you would want to unpack mk[-YYYYmmdd].tar.gz in
-the same directory as bmake (so ./mk and ./bmake exist), and
-./bmake/boot-strap will do the rest.
+Porting
+=======
 
-If you want to do it all by hand then read boot-strap first to get the
-idea.
+If you encounter a system that bmake does not build or work on *out of
+the box*, I welcome patches.
+If you can provide access to a suitable machine - even better.
 
-Even if you have an earlier version of bmake installed, use boot-strap
-to ensure that all goes well.
+More info can be found at http://www.crufty.net/help/sjg/bmake.htm
 
---sjg
+--sjg <sjg at crufty.net>
+

Modified: trunk/contrib/bmake/arch.c
===================================================================
--- trunk/contrib/bmake/arch.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/arch.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.64 2015/10/11 04:51:24 sjg Exp $	*/
+/*	$NetBSD: arch.c,v 1.70 2017/04/16 20:49:09 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.64 2015/10/11 04:51:24 sjg Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.70 2017/04/16 20:49:09 riastradh Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -76,7 +76,7 @@
 #if 0
 static char sccsid[] = "@(#)arch.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: arch.c,v 1.64 2015/10/11 04:51:24 sjg Exp $");
+__RCSID("$NetBSD: arch.c,v 1.70 2017/04/16 20:49:09 riastradh Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -136,7 +136,6 @@
 #include    <sys/stat.h>
 #include    <sys/time.h>
 #include    <sys/param.h>
-#include    <ctype.h>
 #ifdef HAVE_AR_H
 #include    <ar.h>
 #else
@@ -156,7 +155,6 @@
 #if defined(HAVE_RANLIB_H) && !(defined(__ELF__) || defined(NO_RANLIB))
 #include    <ranlib.h>
 #endif
-#include    <fcntl.h>
 #include    <stdio.h>
 #include    <stdlib.h>
 #ifdef HAVE_UTIME_H
@@ -254,8 +252,7 @@
 	free(Hash_GetValue(entry));
 
     free(a->name);
-    if (a->fnametab)
-	free(a->fnametab);
+    free(a->fnametab);
     Hash_DeleteTable(&a->members);
     free(a);
 }
@@ -310,9 +307,10 @@
 	    void	*freeIt;
 	    char	*result;
 
-	    result = Var_Parse(cp, ctxt, TRUE, TRUE, &length, &freeIt);
-	    if (freeIt)
-		free(freeIt);
+	    result = Var_Parse(cp, ctxt, VARF_UNDEFERR|VARF_WANTRES,
+			       &length, &freeIt);
+	    free(freeIt);
+
 	    if (result == var_Error) {
 		return(FAILURE);
 	    } else {
@@ -325,7 +323,7 @@
 
     *cp++ = '\0';
     if (subLibName) {
-	libName = Var_Subst(NULL, libName, ctxt, TRUE, TRUE);
+	libName = Var_Subst(NULL, libName, ctxt, VARF_UNDEFERR|VARF_WANTRES);
     }
 
 
@@ -351,9 +349,10 @@
 		void	*freeIt;
 		char	*result;
 
-		result = Var_Parse(cp, ctxt, TRUE, TRUE, &length, &freeIt);
-		if (freeIt)
-		    free(freeIt);
+		result = Var_Parse(cp, ctxt, VARF_UNDEFERR|VARF_WANTRES,
+				   &length, &freeIt);
+		free(freeIt);
+
 		if (result == var_Error) {
 		    return(FAILURE);
 		} else {
@@ -404,7 +403,8 @@
 	    char    *oldMemName = memName;
 	    size_t   sz;
 
-	    memName = Var_Subst(NULL, memName, ctxt, TRUE, TRUE);
+	    memName = Var_Subst(NULL, memName, ctxt,
+				VARF_UNDEFERR|VARF_WANTRES);
 
 	    /*
 	     * Now form an archive spec and recurse to deal with nested
@@ -726,7 +726,8 @@
 		if (fread(memName, elen, 1, arch) != 1)
 			goto badarch;
 		memName[elen] = '\0';
-		fseek(arch, -elen, SEEK_CUR);
+		if (fseek(arch, -elen, SEEK_CUR) != 0)
+			goto badarch;
 		if (DEBUG(ARCH) || DEBUG(MAKE)) {
 		    fprintf(debug_file, "ArchStat: Extended format entry for %s\n", memName);
 		}
@@ -737,7 +738,8 @@
 	    Hash_SetValue(he, bmake_malloc(sizeof(struct ar_hdr)));
 	    memcpy(Hash_GetValue(he), &arh, sizeof(struct ar_hdr));
 	}
-	fseek(arch, (size + 1) & ~1, SEEK_CUR);
+	if (fseek(arch, (size + 1) & ~1, SEEK_CUR) != 0)
+	    goto badarch;
     }
 
     fclose(arch);
@@ -759,8 +761,7 @@
 badarch:
     fclose(arch);
     Hash_DeleteTable(&ar->members);
-    if (ar->fnametab)
-	free(ar->fnametab);
+    free(ar->fnametab);
     free(ar);
     return NULL;
 }
@@ -833,7 +834,7 @@
 	    }
 	if (DEBUG(ARCH)) {
 	    fprintf(debug_file, "Found svr4 archive name table with %lu entries\n",
-	            (u_long)entry);
+	            (unsigned long)entry);
 	}
 	return 0;
     }
@@ -851,7 +852,7 @@
     if (entry >= ar->fnamesize) {
 	if (DEBUG(ARCH)) {
 	    fprintf(debug_file, "SVR4 entry offset %s is greater than %lu\n",
-		   name, (u_long)ar->fnamesize);
+		   name, (unsigned long)ar->fnamesize);
 	}
 	return 2;
     }
@@ -957,7 +958,10 @@
 		 * the file at the actual member, rather than its header, but
 		 * not here...
 		 */
-		fseek(arch, -sizeof(struct ar_hdr), SEEK_CUR);
+		if (fseek(arch, -sizeof(struct ar_hdr), SEEK_CUR) != 0) {
+		    fclose(arch);
+		    return NULL;
+		}
 		return (arch);
 	    }
 	} else
@@ -987,10 +991,17 @@
 		}
 		if (strncmp(ename, member, len) == 0) {
 			/* Found as extended name */
-			fseek(arch, -sizeof(struct ar_hdr) - elen, SEEK_CUR);
+			if (fseek(arch, -sizeof(struct ar_hdr) - elen,
+				SEEK_CUR) != 0) {
+			    fclose(arch);
+			    return NULL;
+			}
 			return (arch);
 		}
-		fseek(arch, -elen, SEEK_CUR);
+		if (fseek(arch, -elen, SEEK_CUR) != 0) {
+		    fclose(arch);
+		    return NULL;
+		}
 		goto skip;
 	} else
 #endif
@@ -1003,9 +1014,12 @@
 	     * extract the size of the file from the 'size' field of the
 	     * header and round it up during the seek.
 	     */
-	    arhPtr->ar_size[sizeof(arhPtr->AR_SIZE)-1] = '\0';
+	    arhPtr->AR_SIZE[sizeof(arhPtr->AR_SIZE)-1] = '\0';
 	    size = (int)strtol(arhPtr->AR_SIZE, NULL, 10);
-	    fseek(arch, (size + 1) & ~1, SEEK_CUR);
+	    if (fseek(arch, (size + 1) & ~1, SEEK_CUR) != 0) {
+		fclose(arch);
+		return NULL;
+	    }
 	}
     }
 
@@ -1045,10 +1059,10 @@
     arch = ArchFindMember(Var_Value(ARCHIVE, gn, &p1),
 			  Var_Value(MEMBER, gn, &p2),
 			  &arh, "r+");
-    if (p1)
-	free(p1);
-    if (p2)
-	free(p2);
+
+    free(p1);
+    free(p2);
+
     snprintf(arh.AR_DATE, sizeof(arh.AR_DATE), "%-12ld", (long) now);
 
     if (arch != NULL) {
@@ -1127,11 +1141,10 @@
     arhPtr = ArchStatMember(Var_Value(ARCHIVE, gn, &p1),
 			     Var_Value(MEMBER, gn, &p2),
 			     TRUE);
-    if (p1)
-	free(p1);
-    if (p2)
-	free(p2);
 
+    free(p1);
+    free(p2);
+
     if (arhPtr != NULL) {
 	modTime = (time_t)strtol(arhPtr->AR_DATE, NULL, 10);
     } else {

Modified: trunk/contrib/bmake/bmake.1
===================================================================
--- trunk/contrib/bmake/bmake.1	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/bmake.1	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-.\"	$NetBSD: make.1,v 1.249 2015/06/05 07:33:40 wiz Exp $
+.\"	$NetBSD: make.1,v 1.271 2017/07/03 21:34:20 wiz Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,8 +29,8 @@
 .\"
 .\"	from: @(#)make.1	8.4 (Berkeley) 3/19/94
 .\"
-.Dd June 4, 2015
-.Dt MAKE 1
+.Dd June 22, 2017
+.Dt BMAKE 1
 .Os
 .Sh NAME
 .Nm bmake
@@ -48,6 +48,7 @@
 .Op Fl m Ar directory
 .Op Fl T Ar file
 .Op Fl V Ar variable
+.Op Fl v Ar variable
 .Op Ar variable=value
 .Op Ar target ...
 .Sh DESCRIPTION
@@ -206,7 +207,9 @@
 .It Ar V
 Force the
 .Fl V
-option to print raw values of variables.
+option to print raw values of variables, overriding the default behavior
+set via
+.Va .MAKE.EXPAND_VARIABLES .
 .It Ar v
 Print debugging information about variable assignment.
 .It Ar x
@@ -293,7 +296,7 @@
 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.
+the Makefile and then works upward towards the root of the file system.
 If the search is successful, then the resulting directory replaces the
 .Qq \&.../
 specification in the
@@ -334,20 +337,39 @@
 Rather than re-building a target as specified in the makefile, create it
 or update its modification time to make it appear up-to-date.
 .It Fl V Ar variable
-Print
-.Nm Ns 's
-idea of the value of
-.Ar variable ,
-in the global context.
+Print the value of
+.Ar variable .
 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.
+The value printed is extracted from the global context after all
+makefiles have been read.
+By default, the raw variable contents (which may
+include additional unexpanded variable references) are shown.
 If
 .Ar variable
 contains a
 .Ql \&$
-then the value will be expanded before printing.
+then the value will be recursively expanded to its complete resultant
+text before printing.
+The expanded value will also be printed if
+.Va .MAKE.EXPAND_VARIABLES
+is set to true and
+the
+.Fl dV
+option has not been used to override it.
+Note that loop-local and target-local variables, as well as values
+taken temporarily by global variables during makefile processing, are
+not accessible via this option.
+The
+.Fl dv
+debug mode can be used to see these at the cost of generating
+substantial extraneous output.
+.It Fl v Ar variable
+Like
+.Fl V
+but the variable is always expanded to its complete value.
 .It Fl W
 Treat any warnings during makefile parsing as errors.
 .It Fl w
@@ -657,7 +679,7 @@
 .Bl -tag -width ".ARCHIVE" -offset indent
 .It Va .ALLSRC
 The list of all sources for this target; also known as
-.Ql Va \&\*[Gt] .
+.Ql Va \&> .
 .It Va .ARCHIVE
 The name of the archive file; also known as
 .Ql Va \&! .
@@ -666,7 +688,7 @@
 target is to be transformed (the
 .Dq implied
 source); also known as
-.Ql Va \&\*[Lt] .
+.Ql Va \&< .
 It is not defined in explicit rules.
 .It Va .MEMBER
 The name of the archive member; also known as
@@ -685,12 +707,15 @@
 .It Va .TARGET
 The name of the target; also known as
 .Ql Va @ .
+For compatibility with other makes this is an alias for
+.Ic .ARCHIVE
+in archive member rules.
 .El
 .Pp
 The shorter forms
-.Ql ( Va \*[Gt] ,
+.Ql ( Va > ,
 .Ql Va \&! ,
-.Ql Va \*[Lt] ,
+.Ql Va < ,
 .Ql Va % ,
 .Ql Va \&? ,
 .Ql Va * ,
@@ -773,6 +798,10 @@
 A boolean that controls the default behavior of the
 .Fl V
 option.
+If true, variable values printed with
+.Fl V
+are fully expanded; if false, the raw variable contents (which may
+include additional unexpanded variable references) are shown.
 .It Va .MAKE.EXPORTED
 The list of variables exported by
 .Nm .
@@ -843,7 +872,7 @@
 .Nm
 runs in.
 It can contain a number of keywords:
-.Bl -hang -width ignore-cmd
+.Bl -hang -width missing-filemon=bf.
 .It Pa compat
 Like
 .Fl B ,
@@ -867,8 +896,19 @@
 This can be overridden by setting
 .Va bf
 to a value which represents True.
+.It Pa missing-meta= Ar bf
+If
+.Va bf
+is True, then a missing .meta file makes the target out-of-date.
+.It Pa missing-filemon= Ar bf
+If
+.Va bf
+is True, then missing filemon data makes the target out-of-date.
+.It Pa nofilemon
+Do not use
+.Xr filemon 4 .
 .It Pa env
-For debugging, it can be useful to inlcude the environment
+For debugging, it can be useful to include the environment
 in the .meta file.
 .It Pa verbose
 If in "meta" mode, print a clue about the target being built.
@@ -910,6 +950,12 @@
 because the contents are expected to change over time.
 The default list includes:
 .Ql Pa /dev /etc /proc /tmp /var/run /var/tmp
+.It Va .MAKE.META.IGNORE_PATTERNS
+Provides a list of patterns to match against pathnames.
+Ignore any that match.
+.It Va .MAKE.META.IGNORE_FILTER
+Provides a list of variable modifiers to apply to each pathname.
+Ignore if the expansion is an empty string.
 .It Va .MAKE.META.PREFIX
 Defines the message printed for each meta file updated in "meta verbose" mode.
 The default value is:
@@ -918,7 +964,7 @@
 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
 .Ql Ev MAKEFLAGS .
-This behaviour can be disabled by assigning an empty value to
+This behavior can be disabled by assigning an empty value to
 .Ql Va .MAKEOVERRIDES
 within a makefile.
 Extra variables can be exported from a makefile
@@ -941,10 +987,35 @@
 .It Va .MAKE.PPID
 The parent process-id of
 .Nm .
+.It Va .MAKE.SAVE_DOLLARS
+value should be a boolean that controls whether
+.Ql $$
+are preserved when doing
+.Ql :=
+assignments.
+The default is false, for backwards compatibility.
+Set to true for compatability with other makes.
+If set to false,
+.Ql $$
+becomes
+.Ql $
+per normal evaluation rules.
 .It Va MAKE_PRINT_VAR_ON_ERROR
 When
 .Nm
-stops due to an error, it prints its name and the value of
+stops due to an error, it sets
+.Ql Va .ERROR_TARGET
+to the name of the target that failed,
+.Ql Va .ERROR_CMD
+to the commands of the failed target,
+and in "meta" mode, it also sets
+.Ql Va .ERROR_CWD
+to the
+.Xr getcwd 3 ,
+and
+.Ql Va .ERROR_META_FILE
+to the path of the meta file (if any) describing the failed target.
+It then prints its name and the value of
 .Ql Va .CURDIR
 as well as the value of any variables named in
 .Ql Va MAKE_PRINT_VAR_ON_ERROR .
@@ -1044,7 +1115,7 @@
 to the value of
 .Ql Ev PWD
 instead.
-This behaviour is disabled if
+This behavior is disabled if
 .Ql Ev MAKEOBJDIRPREFIX
 is set or
 .Ql Ev MAKEOBJDIR
@@ -1114,7 +1185,7 @@
 As a consequence of the way values are split into words, matched,
 and then joined, a construct like
 .Dl ${VAR:M*}
-will normalise the inter-word spacing, removing all leading and
+will normalize the inter-word spacing, removing all leading and
 trailing space, and converting multiple consecutive spaces
 to single spaces.
 .
@@ -1134,7 +1205,7 @@
 The results will be different each time you are referring to the
 modified variable; use the assignment with expansion
 .Pq Ql Cm \&:=
-to prevent such behaviour.
+to prevent such behavior.
 For example,
 .Bd -literal -offset indent
 LIST=			uno due tre quattro
@@ -1160,18 +1231,28 @@
 .Nm .
 .It Cm \&:R
 Replaces each word in the variable with everything but its suffix.
-.It Cm \&:gmtime
+.It Cm \&:range[=count]
+The value is an integer sequence representing the words of the original
+value, or the supplied
+.Va count .
+.It Cm \&:gmtime[=utc]
 The value is a format string for
 .Xr strftime 3 ,
-using the current
+using
 .Xr gmtime 3 .
+If a
+.Va utc
+value is not provided or is 0, the current time is used.
 .It Cm \&:hash
-Compute a 32bit hash of the value and encode it as hex digits.
-.It Cm \&:localtime
+Compute a 32-bit hash of the value and encode it as hex digits.
+.It Cm \&:localtime[=utc]
 The value is a format string for
 .Xr strftime 3 ,
-using the current
+using
 .Xr localtime 3 .
+If a
+.Va utc
+value is not provided or is 0, the current time is used.
 .It Cm \&:tA
 Attempt to convert variable to an absolute path using
 .Xr realpath 3 ,
@@ -1232,7 +1313,7 @@
 Inside
 .Ar new_string ,
 an ampersand
-.Pq Ql \*[Am]
+.Pq Ql &
 is replaced by
 .Ar old_string
 (without any
@@ -1371,6 +1452,27 @@
 .Pp
 However a single character variable is often more readable:
 .Dl ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}
+.It Cm \&:_[=var]
+Save the current variable value in
+.Ql $_
+or the named
+.Va var
+for later reference.
+Example usage:
+.Bd -literal -offset indent
+M_cmpv.units = 1 1000 1000000
+M_cmpv = S,., ,g:_:range:@i at + $${_:[-$$i]} \&\\
+\\* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh
+
+.Dv .if ${VERSION:${M_cmpv}} < ${3.1.12:L:${M_cmpv}}
+
+.Ed
+Here
+.Ql $_
+is used to save the result of the
+.Ql :S
+modifier which is later referenced using the index values from
+.Ql :range .
 .It Cm \&:U Ns Ar newval
 If the variable is undefined
 .Ar newval
@@ -1444,7 +1546,7 @@
 .Pp
 Ordinarily, a value is treated as a sequence of words
 delimited by white space.
-Some modifiers suppress this behaviour,
+Some modifiers suppress this behavior,
 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,
@@ -1530,6 +1632,7 @@
 .Nm
 .Ql include file ...
 is also accepted.
+.Pp
 If the include statement is written as
 .Cm .-include
 or as
@@ -1536,6 +1639,13 @@
 .Cm .sinclude
 then errors locating and/or opening include files are ignored.
 .Pp
+If the include statement is written as
+.Cm .dinclude
+not only are errors locating and/or opening include files ignored,
+but stale dependencies within the included file will be ignored
+just like
+.Va .MAKE.DEPENDFILE .
+.Pp
 Conditional expressions are also preceded by a single dot as the first
 character of a line.
 The possible conditionals are as follows:
@@ -1571,6 +1681,10 @@
 used by
 .Nm
 internally.
+.It Ic .export-literal Ar variable ...
+The same as
+.Ql .export-env ,
+except that variables in the value are not expanded.
 .It Ic .info Ar message
 The message is printed along with the name of the makefile and line number.
 .It Ic .undef Ar variable
@@ -1663,7 +1777,7 @@
 .Bl -tag -width "Cm XX"
 .It Cm \&|\&|
 Logical OR.
-.It Cm \&\*[Am]\*[Am]
+.It Cm \&&&
 Logical
 .Tn AND ;
 of higher precedence than
@@ -1680,7 +1794,7 @@
 may be used to logically negate an entire
 conditional.
 It is of higher precedence than
-.Ql Ic \&\*[Am]\*[Am] .
+.Ql Ic \&&& .
 .Pp
 The value of
 .Ar expression
@@ -1954,6 +2068,14 @@
 .Ic .DEFAULT Ns 's
 commands is set
 to the target's own name.
+.It Ic .DELETE_ON_ERROR
+If this target is present in the makefile, it globally causes make to
+delete targets whose commands fail.
+(By default, only targets whose commands are interrupted during
+execution are deleted.
+This is the historical behavior.)
+This setting can be used to help prevent half-finished or malformed
+targets from being left around and corrupting future rebuilds.
 .It Ic .END
 Any command lines attached to this target are executed after everything
 else is done.
@@ -2068,7 +2190,7 @@
 pairs.
 .Bl -tag -width hasErrCtls
 .It Ar name
-This is the minimal specification, used to select one of the builtin
+This is the minimal specification, used to select one of the built-in
 shell specs;
 .Ar sh ,
 .Ar ksh ,

Modified: trunk/contrib/bmake/bmake.cat1
===================================================================
--- trunk/contrib/bmake/bmake.cat1	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/bmake.cat1	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-MAKE(1)                 NetBSD General Commands Manual                 MAKE(1)
+BMAKE(1)                NetBSD General Commands Manual                BMAKE(1)
 
 NNAAMMEE
      bbmmaakkee -- maintain program dependencies
@@ -6,8 +6,8 @@
 SSYYNNOOPPSSIISS
      bbmmaakkee [--BBeeiikkNNnnqqrrssttWWwwXX] [--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 _._._.]
+           [--mm _d_i_r_e_c_t_o_r_y] [--TT _f_i_l_e] [--VV _v_a_r_i_a_b_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-
@@ -118,7 +118,9 @@
              _t       Print debugging information about target list mainte-
                      nance.
 
-             _V       Force the --VV option to print raw values of variables.
+             _V       Force the --VV option to print raw values of variables,
+                     overriding the default behavior set via
+                     _._M_A_K_E_._E_X_P_A_N_D___V_A_R_I_A_B_L_E_S.
 
              _v       Print debugging information about variable assignment.
 
@@ -178,11 +180,11 @@
              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).
+             towards the root of the file system.  If the search is success-
+             ful, then the resulting directory replaces the ".../" specifica-
+             tion 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-
@@ -209,13 +211,26 @@
              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.
+             Print the value of _v_a_r_i_a_b_l_e.  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 unde-
+             fined variable.  The value printed is extracted from the global
+             context after all makefiles have been read.  By default, the raw
+             variable contents (which may include additional unexpanded vari-
+             able references) are shown.  If _v_a_r_i_a_b_l_e contains a `$' then the
+             value will be recursively expanded to its complete resultant text
+             before printing.  The expanded value will also be printed if
+             _._M_A_K_E_._E_X_P_A_N_D___V_A_R_I_A_B_L_E_S is set to true and the --ddVV option has not
+             been used to override it.  Note that loop-local and target-local
+             variables, as well as values taken temporarily by global vari-
+             ables during makefile processing, are not accessible via this
+             option.  The --ddvv debug mode can be used to see these at the cost
+             of generating substantial extraneous output.
 
+     --vv _v_a_r_i_a_b_l_e
+             Like --VV but the variable is always expanded to its complete
+             value.
+
      --WW      Treat any warnings during makefile parsing as errors.
 
      --ww      Print entering and leaving directory messages, pre and post pro-
@@ -438,7 +453,9 @@
                      suffixes declared with ..SSUUFFFFIIXXEESS or it will not be recog-
                      nized.
 
-           _._T_A_R_G_E_T   The name of the target; also known as `_@'.
+           _._T_A_R_G_E_T   The name of the target; also known as `_@'.  For compati-
+                     bility with other makes this is an alias for ..AARRCCHHIIVVEE in
+                     archive member rules.
 
      The shorter forms (`_>', `_!', `_<', `_%', `_?', `_*', and `_@') are permitted
      for backward compatibility with historical makefiles and legacy POSIX
@@ -486,7 +503,10 @@
 
      _._M_A_K_E_._E_X_P_A_N_D___V_A_R_I_A_B_L_E_S
                      A boolean that controls the default behavior of the --VV
-                     option.
+                     option.  If true, variable values printed with --VV are
+                     fully expanded; if false, the raw variable contents
+                     (which may include additional unexpanded variable refer-
+                     ences) are shown.
 
      _._M_A_K_E_._E_X_P_O_R_T_E_D  The list of variables exported by bbmmaakkee.
 
@@ -529,38 +549,52 @@
                      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.
+                     _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.
+                     _m_e_t_a                 Puts bbmmaakkee into "meta" mode, where
+                                          meta files are created for each tar-
+                                          get to capture the command run, the
+                                          output generated and if filemon(4)
+                                          is available, the system calls which
+                                          are of interest to bbmmaakkee.  The cap-
+                                          tured 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.
+                     _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 setting _b_f to a value
+                                          which represents True.
 
-                     _e_n_v         For debugging, it can be useful to inlcude
-                                 the environment in the .meta file.
+                     _m_i_s_s_i_n_g_-_m_e_t_a_= _b_f     If _b_f is True, then a missing .meta
+                                          file makes the target out-of-date.
 
-                     _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.
+                     _m_i_s_s_i_n_g_-_f_i_l_e_m_o_n_= _b_f  If _b_f is True, then missing filemon
+                                          data makes the target out-of-date.
 
-                     _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.
+                     _n_o_f_i_l_e_m_o_n            Do not use filemon(4).
 
-                     _s_i_l_e_n_t_= _b_f  If _b_f is True, when a .meta file is created,
-                                 mark the target ..SSIILLEENNTT.
+                     _e_n_v                  For debugging, it can be useful to
+                                          include the environment in the .meta
+                                          file.
 
+                     _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 deter-
+                                          mining whether a target is out of
+                                          date in "meta" mode.  See also
+                                          ..NNOOMMEETTAA__CCMMPP.
+
+                     _s_i_l_e_n_t_= _b_f           If _b_f is True, when a .meta file is
+                                          created, mark the target ..SSIILLEENNTT.
+
      _._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
@@ -584,6 +618,14 @@
                      The default list includes: `_/_d_e_v _/_e_t_c _/_p_r_o_c _/_t_m_p _/_v_a_r_/_r_u_n
                      _/_v_a_r_/_t_m_p'
 
+     _._M_A_K_E_._M_E_T_A_._I_G_N_O_R_E___P_A_T_T_E_R_N_S
+                     Provides a list of patterns to match against pathnames.
+                     Ignore any that match.
+
+     _._M_A_K_E_._M_E_T_A_._I_G_N_O_R_E___F_I_L_T_E_R
+                     Provides a list of variable modifiers to apply to each
+                     pathname.  Ignore if the expansion is an empty string.
+
      _._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:
@@ -591,7 +633,7 @@
 
      _._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
+                     exported as part of `MAKEFLAGS'.  This behavior 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'.
@@ -607,10 +649,22 @@
 
      _._M_A_K_E_._P_P_I_D      The parent process-id of bbmmaakkee.
 
+     _._M_A_K_E_._S_A_V_E___D_O_L_L_A_R_S
+                     value should be a boolean that controls whether `$$' are
+                     preserved when doing `:=' assignments.  The default is
+                     false, for backwards compatibility.  Set to true for com-
+                     patability with other makes.  If set to false, `$$'
+                     becomes `$' per normal evaluation rules.
+
      _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'.
+                     When bbmmaakkee stops due to an error, it sets `_._E_R_R_O_R___T_A_R_G_E_T'
+                     to the name of the target that failed, `_._E_R_R_O_R___C_M_D' to
+                     the commands of the failed target, and in "meta" mode, it
+                     also sets `_._E_R_R_O_R___C_W_D' to the getcwd(3), and
+                     `_._E_R_R_O_R___M_E_T_A___F_I_L_E' to the path of the meta file (if any)
+                     describing the failed target.  It then prints its name
+                     and the value of `_._C_U_R_D_I_R' as well as the value of any
+                     variables 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
@@ -670,7 +724,7 @@
                      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
+                     `_._C_U_R_D_I_R' to the value of `PWD' instead.  This behavior
                      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.
@@ -717,7 +771,7 @@
           of the way values are split into words, matched, and then joined, a
           construct like
                 ${VAR:M*}
-          will normalise the inter-word spacing, removing all leading and
+          will normalize the inter-word spacing, removing all leading and
           trailing space, and converting multiple consecutive spaces to single
           spaces.
 
@@ -730,7 +784,7 @@
 
      ::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,
+          with expansion (`::==') to prevent such behavior.  For example,
 
                 LIST=                   uno due tre quattro
                 RANDOM_LIST=            ${LIST:Ox}
@@ -753,16 +807,20 @@
 
      ::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).
+     ::rraannggee[[==ccoouunntt]]
+          The value is an integer sequence representing the words of the orig-
+          inal value, or the supplied _c_o_u_n_t.
 
+     ::ggmmttiimmee[[==uuttcc]]
+          The value is a format string for strftime(3), using gmtime(3).  If a
+          _u_t_c value is not provided or is 0, the current time is used.
+
      ::hhaasshh
-          Compute a 32bit hash of the value and encode it as hex digits.
+          Compute a 32-bit 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).
+     ::llooccaallttiimmee[[==uuttcc]]
+          The value is a format string for strftime(3), using localtime(3).
+          If a _u_t_c value is not provided or is 0, the current time is used.
 
      ::ttAA  Attempt to convert variable to an absolute path using realpath(3),
           if that fails, the value is unchanged.
@@ -863,6 +921,19 @@
           However a single character variable is often more readable:
                 ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}
 
+     ::__[[==vvaarr]]
+          Save the current variable value in `$_' or the named _v_a_r for later
+          reference.  Example usage:
+
+                M_cmpv.units = 1 1000 1000000
+                M_cmpv = S,., ,g:_:range:@i at + $${_:[-$$i]} \
+                \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh
+
+                .if ${VERSION:${M_cmpv}} < ${3.1.12:L:${M_cmpv}}
+
+          Here `$_' is used to save the result of the `:S' modifier which is
+          later referenced using the index values from `:range'.
+
      ::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
@@ -914,13 +985,13 @@
           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).
+          white space.  Some modifiers suppress this behavior, 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 inte-
+          gers (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:
@@ -957,9 +1028,15 @@
      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.
+     accepted.
 
+     If the include statement is written as ..--iinncclluuddee or as ..ssiinncclluuddee then
+     errors locating and/or opening include files are ignored.
+
+     If the include statement is written as ..ddiinncclluuddee not only are errors
+     locating and/or opening include files ignored, but stale dependencies
+     within the included file will be ignored just like _._M_A_K_E_._D_E_P_E_N_D_F_I_L_E.
+
      Conditional expressions are also preceded by a single dot as the first
      character of a line.  The possible conditionals are as follows:
 
@@ -982,6 +1059,10 @@
              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.
 
+     ..eexxppoorrtt--lliitteerraall _v_a_r_i_a_b_l_e _._._.
+             The same as `.export-env', except that variables in the value are
+             not expanded.
+
      ..iinnffoo _m_e_s_s_a_g_e
              The message is printed along with the name of the makefile and
              line number.
@@ -1239,6 +1320,14 @@
               target that inherits ..DDEEFFAAUULLTT's commands is set to the target's
               own name.
 
+     ..DDEELLEETTEE__OONN__EERRRROORR
+              If this target is present in the makefile, it globally causes
+              make to delete targets whose commands fail.  (By default, only
+              targets whose commands are interrupted during execution are
+              deleted.  This is the historical behavior.)  This setting can be
+              used to help prevent half-finished or malformed targets from
+              being left around and corrupting future rebuilds.
+
      ..EENNDD     Any command lines attached to this target are executed after
               everything else is done.
 
@@ -1307,7 +1396,7 @@
               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.
+                          one of the built-in shell specs; _s_h, _k_s_h, and _c_s_h.
 
               _p_a_t_h        Specifies the path to the shell.
 
@@ -1452,4 +1541,4 @@
 
      There is no way of escaping a space character in a filename.
 
-NetBSD 5.1                       June 4, 2015                       NetBSD 5.1
+NetBSD 7.1_RC1                   June 22, 2017                  NetBSD 7.1_RC1

Modified: trunk/contrib/bmake/boot-strap
===================================================================
--- trunk/contrib/bmake/boot-strap	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/boot-strap	2018-06-27 00:20:04 UTC (rev 11140)
@@ -111,7 +111,7 @@
 #	Simon J. Gerraty <sjg at crufty.net>
 
 # RCSid:
-#	$Id: boot-strap,v 1.48 2015/10/25 05:20:48 sjg Exp $
+#	$Id: boot-strap,v 1.49 2016/05/29 00:09:14 sjg Exp $
 #
 #	@(#) Copyright (c) 2001 Simon J. Gerraty
 #
@@ -451,7 +451,7 @@
 		op_install
 	else
 		op_test
-		MAKE_VERSION=`sed -n '/^MAKE_VERSION/ { s,.*=  *,,;p; }' $srcdir/Makefile`
+		MAKE_VERSION=`sed -n '/^_MAKE_VERSION/ { s,.*=  *,,;p; }' $srcdir/Makefile`
 		echo You can install by running:
 		echo
 		echo $0 $cmd_args op=install

Modified: trunk/contrib/bmake/buf.h
===================================================================
--- trunk/contrib/bmake/buf.h	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/buf.h	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: buf.h,v 1.17 2012/04/24 20:26:58 sjg Exp $	*/
+/*	$NetBSD: buf.h,v 1.19 2017/05/31 22:02:06 maya Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -77,8 +77,8 @@
  *	Header for users of the buf library.
  */
 
-#ifndef _BUF_H
-#define _BUF_H
+#ifndef MAKE_BUF_H
+#define MAKE_BUF_H
 
 typedef char Byte;
 
@@ -116,4 +116,4 @@
 Byte *Buf_Destroy(Buffer *, Boolean);
 Byte *Buf_DestroyCompact(Buffer *);
 
-#endif /* _BUF_H */
+#endif /* MAKE_BUF_H */

Modified: trunk/contrib/bmake/compat.c
===================================================================
--- trunk/contrib/bmake/compat.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/compat.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.101 2015/10/11 04:51:24 sjg Exp $	*/
+/*	$NetBSD: compat.c,v 1.107 2017/07/20 19:29:54 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,7 +70,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: compat.c,v 1.101 2015/10/11 04:51:24 sjg Exp $";
+static char rcsid[] = "$NetBSD: compat.c,v 1.107 2017/07/20 19:29:54 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -77,7 +77,7 @@
 #if 0
 static char sccsid[] = "@(#)compat.c	8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: compat.c,v 1.101 2015/10/11 04:51:24 sjg Exp $");
+__RCSID("$NetBSD: compat.c,v 1.107 2017/07/20 19:29:54 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -118,7 +118,28 @@
 static GNode	    *curTarg = NULL;
 static GNode	    *ENDNode;
 static void CompatInterrupt(int);
+static pid_t compatChild;
+static int compatSigno;
 
+/*
+ * CompatDeleteTarget -- delete a failed, interrupted, or otherwise
+ * duffed target if not inhibited by .PRECIOUS.
+ */
+static void
+CompatDeleteTarget(GNode *gn)
+{
+    if ((gn != NULL) && !Targ_Precious (gn)) {
+	char	  *p1;
+	char 	  *file = Var_Value(TARGET, gn, &p1);
+
+	if (!noExecute && eunlink(file) != -1) {
+	    Error("*** %s removed", file);
+	}
+
+	free(p1);
+    }
+}
+
 /*-
  *-----------------------------------------------------------------------
  * CompatInterrupt --
@@ -132,6 +153,9 @@
  *	The target is removed and the process exits. If .INTERRUPT exists,
  *	its commands are run first WITH INTERRUPTS IGNORED..
  *
+ * XXX: is .PRECIOUS supposed to inhibit .INTERRUPT? I doubt it, but I've
+ * left the logic alone for now. - dholland 20160826
+ *
  *-----------------------------------------------------------------------
  */
 static void
@@ -139,16 +163,9 @@
 {
     GNode   *gn;
 
+    CompatDeleteTarget(curTarg);
+
     if ((curTarg != NULL) && !Targ_Precious (curTarg)) {
-	char	  *p1;
-	char 	  *file = Var_Value(TARGET, curTarg, &p1);
-
-	if (!noExecute && eunlink(file) != -1) {
-	    Error("*** %s removed", file);
-	}
-	if (p1)
-	    free(p1);
-
 	/*
 	 * Run .INTERRUPT only if hit with interrupt signal
 	 */
@@ -158,12 +175,20 @@
 		Compat_Make(gn, gn);
 	    }
 	}
-
     }
     if (signo == SIGQUIT)
 	_exit(signo);
-    bmake_signal(signo, SIG_DFL);
-    kill(myPid, signo);
+    /*
+     * If there is a child running, pass the signal on
+     * we will exist after it has exited.
+     */
+    compatSigno = signo;
+    if (compatChild > 0) {
+	KILLPG(compatChild, signo);
+    } else {
+	bmake_signal(signo, SIG_DFL);
+	kill(myPid, signo);
+    }
 }
 

 /*-
@@ -213,7 +238,7 @@
     doIt = FALSE;
     
     cmdNode = Lst_Member(gn->commands, cmd);
-    cmdStart = Var_Subst(NULL, cmd, gn, FALSE, TRUE);
+    cmdStart = Var_Subst(NULL, cmd, gn, VARF_WANTRES);
 
     /*
      * brk_string will return an argv with a NULL in av[0], thus causing
@@ -356,7 +381,7 @@
     /*
      * Fork and execute the single command. If the fork fails, we abort.
      */
-    cpid = vFork();
+    compatChild = cpid = vFork();
     if (cpid < 0) {
 	Fatal("Could not fork");
     }
@@ -374,10 +399,10 @@
 	execError("exec", av[0]);
 	_exit(1);
     }
-    if (mav)
-	free(mav);
-    if (bp)
-	free(bp);
+
+    free(mav);
+    free(bp);
+
     Lst_Replace(cmdNode, NULL);
 
 #ifdef USE_META
@@ -447,7 +472,12 @@
 			 * continue.
 			 */
 			printf(" (continuing)\n");
+		    } else {
+			printf("\n");
 		    }
+		    if (deleteOnError) {
+			    CompatDeleteTarget(gn);
+		    }
 		} else {
 		    /*
 		     * Continue executing commands for this target.
@@ -464,7 +494,12 @@
 	}
     }
     free(cmdStart);
-
+    compatChild = 0;
+    if (compatSigno) {
+	bmake_signal(compatSigno, SIG_DFL);
+	kill(myPid, compatSigno);
+    }
+    
     return (status);
 }
 

@@ -516,8 +551,7 @@
 	if (Lst_Member(gn->iParents, pgn) != NULL) {
 	    char *p1;
 	    Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0);
-	    if (p1)
-		free(p1);
+	    free(p1);
 	}
 
 	/*
@@ -587,7 +621,8 @@
 	}
 #ifdef USE_META
 	if (useMeta && !NoExecute(gn)) {
-	    meta_job_finish(NULL);
+	    if (meta_job_finish(NULL) != 0)
+		gn->made = ERROR;
 	}
 #endif
 
@@ -607,7 +642,7 @@
 	} else if (keepgoing) {
 	    pgn->flags &= ~REMAKE;
 	} else {
-	    PrintOnError(gn, "\n\nStop.");
+	    PrintOnError(gn, "\nStop.");
 	    exit(1);
 	}
     } else if (gn->made == ERROR) {
@@ -620,8 +655,7 @@
 	if (Lst_Member(gn->iParents, pgn) != NULL) {
 	    char *p1;
 	    Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0);
-	    if (p1)
-		free(p1);
+	    free(p1);
 	}
 	switch(gn->made) {
 	    case BEINGMADE:
@@ -699,7 +733,7 @@
 	if (gn != NULL) {
 	    Compat_Make(gn, gn);
             if (gn->made == ERROR) {
-                PrintOnError(gn, "\n\nStop.");
+                PrintOnError(gn, "\nStop.");
                 exit(1);
             }
 	}
@@ -740,7 +774,7 @@
     if (errors == 0) {
 	Compat_Make(ENDNode, ENDNode);
 	if (gn->made == ERROR) {
-	    PrintOnError(gn, "\n\nStop.");
+	    PrintOnError(gn, "\nStop.");
 	    exit(1);
 	}
     }

Modified: trunk/contrib/bmake/cond.c
===================================================================
--- trunk/contrib/bmake/cond.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/cond.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.71 2015/12/02 00:28:24 sjg Exp $	*/
+/*	$NetBSD: cond.c,v 1.75 2017/04/16 20:59:04 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,7 +70,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: cond.c,v 1.71 2015/12/02 00:28:24 sjg Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.75 2017/04/16 20:59:04 riastradh Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -77,7 +77,7 @@
 #if 0
 static char sccsid[] = "@(#)cond.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: cond.c,v 1.71 2015/12/02 00:28:24 sjg Exp $");
+__RCSID("$NetBSD: cond.c,v 1.75 2017/04/16 20:59:04 riastradh Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -91,6 +91,7 @@
  *
  */
 
+#include    <assert.h>
 #include    <ctype.h>
 #include    <errno.h>    /* For strtoul() error checking */
 
@@ -289,10 +290,10 @@
 	    int		len;
 	    void	*freeIt;
 
-	    cp2 = Var_Parse(cp, VAR_CMD, TRUE, TRUE, &len, &freeIt);
+	    cp2 = Var_Parse(cp, VAR_CMD, VARF_UNDEFERR|VARF_WANTRES,
+			    &len, &freeIt);
 	    Buf_AddBytes(&buf, strlen(cp2), cp2);
-	    if (freeIt)
-		free(freeIt);
+	    free(freeIt);
 	    cp += len;
 	    continue;
 	}
@@ -346,8 +347,8 @@
     } else {
 	result = FALSE;
     }
-    if (p1)
-	free(p1);
+
+    free(p1);
     return (result);
 }
 

@@ -574,8 +575,9 @@
 	    break;
 	case '$':
 	    /* if we are in quotes, then an undefined variable is ok */
-	    str = Var_Parse(condExpr, VAR_CMD, (qt ? 0 : doEval),
-			    TRUE, &len, freeIt);
+	    str = Var_Parse(condExpr, VAR_CMD,
+			    ((!qt && doEval) ? VARF_UNDEFERR : 0) |
+			    VARF_WANTRES, &len, freeIt);
 	    if (str == var_Error) {
 		if (*freeIt) {
 		    free(*freeIt);
@@ -805,10 +807,8 @@
     }
 
 done:
-    if (lhsFree)
-	free(lhsFree);
-    if (rhsFree)
-	free(rhsFree);
+    free(lhsFree);
+    free(rhsFree);
     return t;
 }
 
@@ -827,7 +827,7 @@
     /* We do all the work here and return the result as the length */
     *argPtr = NULL;
 
-    val = Var_Parse(cp - 1, VAR_CMD, FALSE, TRUE, &length, &freeIt);
+    val = Var_Parse(cp - 1, VAR_CMD, VARF_WANTRES, &length, &freeIt);
     /*
      * Advance *linePtr to beyond the closing ). Note that
      * we subtract one because 'length' is calculated from 'cp - 1'.
@@ -848,8 +848,7 @@
      * true/false here.
      */
     length = *val ? 2 : 1;
-    if (freeIt)
-	free(freeIt);
+    free(freeIt);
     return length;
 }
 
@@ -900,8 +899,7 @@
 	}
 	/* Evaluate the argument using the required function. */
 	t = !doEval || fn_def->fn_proc(arglen, arg);
-	if (arg)
-	    free(arg);
+	free(arg);
 	condExpr = cp;
 	return t;
     }
@@ -933,8 +931,7 @@
      * be empty - even if it contained a variable expansion.
      */
     t = !doEval || if_info->defProc(arglen, arg) != if_info->doNot;
-    if (arg)
-	free(arg);
+    free(arg);
     return t;
 }
 
@@ -1178,8 +1175,9 @@
 		break;
 	dflt_info = info;
     }
+    assert(info != NULL);
 
-    if_info = info != NULL ? info : ifs + 4;
+    if_info = info;
     condExpr = line;
     condPushBack = TOK_NONE;
 

Modified: trunk/contrib/bmake/config.h.in
===================================================================
--- trunk/contrib/bmake/config.h.in	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/config.h.in	2018-06-27 00:20:04 UTC (rev 11140)
@@ -324,6 +324,9 @@
 /* Define to empty if `const' does not conform to ANSI C. */
 #undef const
 
+/* Define to `int' if <sys/types.h> does not define. */
+#undef mode_t
+
 /* Define to `long int' if <sys/types.h> does not define. */
 #undef off_t
 

Modified: trunk/contrib/bmake/configure
===================================================================
--- trunk/contrib/bmake/configure	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/configure	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.64 for bmake 20151022.
+# Generated by GNU Autoconf 2.64 for bmake 20160606.
 #
 # Report bugs to <sjg at NetBSD.org>.
 #
@@ -549,8 +549,8 @@
 # Identity of this package.
 PACKAGE_NAME='bmake'
 PACKAGE_TARNAME='bmake'
-PACKAGE_VERSION='20151022'
-PACKAGE_STRING='bmake 20151022'
+PACKAGE_VERSION='20160606'
+PACKAGE_STRING='bmake 20160606'
 PACKAGE_BUGREPORT='sjg at NetBSD.org'
 PACKAGE_URL=''
 
@@ -1221,7 +1221,7 @@
   # 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 20151022 to adapt to many kinds of systems.
+\`configure' configures bmake 20160606 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1282,7 +1282,7 @@
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of bmake 20151022:";;
+     short | recursive ) echo "Configuration of bmake 20160606:";;
    esac
   cat <<\_ACEOF
 
@@ -1387,7 +1387,7 @@
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-bmake configure 20151022
+bmake configure 20160606
 generated by GNU Autoconf 2.64
 
 Copyright (C) 2009 Free Software Foundation, Inc.
@@ -1960,7 +1960,7 @@
 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 20151022, which was
+It was created by bmake $as_me 20160606, which was
 generated by GNU Autoconf 2.64.  Invocation command line was
 
   $ $0 $@
@@ -5055,6 +5055,17 @@
 
 fi
 
+ac_fn_c_check_type "$LINENO" "mode_t" "ac_cv_type_mode_t" "$ac_includes_default"
+if test "x$ac_cv_type_mode_t" = x""yes; then :
+
+else
+
+cat >>confdefs.h <<_ACEOF
+#define mode_t int
+_ACEOF
+
+fi
+
 ac_fn_c_check_type "$LINENO" "off_t" "ac_cv_type_off_t" "$ac_includes_default"
 if test "x$ac_cv_type_off_t" = x""yes; then :
 
@@ -6502,7 +6513,7 @@
 # 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 20151022, which was
+This file was extended by bmake $as_me 20160606, which was
 generated by GNU Autoconf 2.64.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -6562,7 +6573,7 @@
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_version="\\
-bmake config.status 20151022
+bmake config.status 20160606
 configured by $0, generated by GNU Autoconf 2.64,
   with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
 

Modified: trunk/contrib/bmake/configure.in
===================================================================
--- trunk/contrib/bmake/configure.in	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/configure.in	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,11 +1,11 @@
 dnl
 dnl RCSid:
-dnl	$Id: configure.in,v 1.56 2015/10/25 05:20:48 sjg Exp $
+dnl	$Id: configure.in,v 1.57 2016/06/07 00:49:44 sjg Exp $
 dnl
 dnl Process this file with autoconf to produce a configure script
 dnl
 AC_PREREQ(2.50)
-AC_INIT([bmake], [20151022], [sjg at NetBSD.org])
+AC_INIT([bmake], [20160606], [sjg at NetBSD.org])
 AC_CONFIG_HEADERS(config.h)
 
 dnl make srcdir absolute
@@ -148,6 +148,7 @@
 AC_C___ATTRIBUTE__
 AC_C_BIGENDIAN
 AC_C_CONST
+AC_TYPE_MODE_T
 AC_TYPE_OFF_T
 AC_TYPE_PID_T
 AC_TYPE_SIZE_T

Modified: trunk/contrib/bmake/dir.c
===================================================================
--- trunk/contrib/bmake/dir.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/dir.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.67 2013/03/05 22:01:43 christos Exp $	*/
+/*	$NetBSD: dir.c,v 1.71 2017/04/16 21:14:47 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,7 +70,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: dir.c,v 1.67 2013/03/05 22:01:43 christos Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.71 2017/04/16 21:14:47 riastradh Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -77,7 +77,7 @@
 #if 0
 static char sccsid[] = "@(#)dir.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.67 2013/03/05 22:01:43 christos Exp $");
+__RCSID("$NetBSD: dir.c,v 1.71 2017/04/16 21:14:47 riastradh Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -244,6 +244,7 @@
 			     * be two rules to update a single file, so this
 			     * should be ok, but... */
 
+static Hash_Table lmtimes;  /* same as mtimes but for lstat */
 
 static int DirFindName(const void *, const void *);
 static int DirMatchFiles(const char *, Path *, Lst);
@@ -256,6 +257,80 @@
 static char *DirFindDot(Boolean, const char *, const char *);
 static char *DirLookupAbs(Path *, const char *, const char *);
 
+
+/*
+ * We use stat(2) a lot, cache the results
+ * mtime and mode are all we care about.
+ */
+struct cache_st {
+    time_t mtime;
+    mode_t  mode;
+};
+
+/* minimize changes below */
+static time_t
+Hash_GetTimeValue(Hash_Entry *entry)
+{
+    struct cache_st *cst;
+
+    cst = entry->clientPtr;
+    return cst->mtime;
+}
+
+#define CST_LSTAT 1
+#define CST_UPDATE 2
+
+static int
+cached_stats(Hash_Table *htp, const char *pathname, struct stat *st, int flags)
+{
+    Hash_Entry *entry;
+    struct cache_st *cst;
+    int rc;
+
+    if (!pathname || !pathname[0])
+	return -1;
+
+    entry = Hash_FindEntry(htp, pathname);
+
+    if (entry && (flags & CST_UPDATE) == 0) {
+	cst = entry->clientPtr;
+
+	memset(st, 0, sizeof(*st));
+	st->st_mtime = cst->mtime;
+	st->st_mode = cst->mode;
+	return 0;
+    }
+
+    rc = (flags & CST_LSTAT) ? lstat(pathname, st) : stat(pathname, st);
+    if (rc == -1)
+	return -1;
+
+    if (st->st_mtime == 0)
+	st->st_mtime = 1;      /* avoid confusion with missing file */
+
+    if (!entry)
+	entry = Hash_CreateEntry(htp, pathname, NULL);
+    if (!entry->clientPtr)
+	entry->clientPtr = bmake_malloc(sizeof(*cst));
+    cst = entry->clientPtr;
+    cst->mtime = st->st_mtime;
+    cst->mode = st->st_mode;
+
+    return 0;
+}
+
+int
+cached_stat(const char *pathname, void *st)
+{
+    return cached_stats(&mtimes, pathname, st, 0);
+}
+
+int
+cached_lstat(const char *pathname, void *st)
+{
+    return cached_stats(&lmtimes, pathname, st, CST_LSTAT);
+}
+
 /*-
  *-----------------------------------------------------------------------
  * Dir_Init --
@@ -271,10 +346,13 @@
 void
 Dir_Init(const char *cdname)
 {
-    dirSearchPath = Lst_Init(FALSE);
-    openDirectories = Lst_Init(FALSE);
-    Hash_InitTable(&mtimes, 0);
-
+    if (!cdname) {
+	dirSearchPath = Lst_Init(FALSE);
+	openDirectories = Lst_Init(FALSE);
+	Hash_InitTable(&mtimes, 0);
+	Hash_InitTable(&lmtimes, 0);
+	return;
+    }
     Dir_InitCur(cdname);
 
     dotLast = bmake_malloc(sizeof(Path));
@@ -725,11 +803,11 @@
  *-----------------------------------------------------------------------
  */
 static int
-DirPrintWord(void *word, void *dummy)
+DirPrintWord(void *word, void *dummy MAKE_ATTR_UNUSED)
 {
     fprintf(debug_file, "%s ", (char *)word);
 
-    return(dummy ? 0 : 0);
+    return 0;
 }
 
 /*-
@@ -901,7 +979,6 @@
 DirLookupSubdir(Path *p, const char *name)
 {
     struct stat	  stb;		/* Buffer for stat, if necessary */
-    Hash_Entry	 *entry;	/* Entry for mtimes table */
     char 	 *file;		/* the current filename to check */
 
     if (p != dot) {
@@ -917,9 +994,7 @@
 	fprintf(debug_file, "checking %s ...\n", file);
     }
 
-    if (stat(file, &stb) == 0) {
-	if (stb.st_mtime == 0)
-		stb.st_mtime = 1;
+    if (cached_stat(file, &stb) == 0) {
 	/*
 	 * Save the modification time so if it's needed, we don't have
 	 * to fetch it again.
@@ -928,8 +1003,6 @@
 	    fprintf(debug_file, "   Caching %s for %s\n", Targ_FmtTime(stb.st_mtime),
 		    file);
 	}
-	entry = Hash_CreateEntry(&mtimes, file, NULL);
-	Hash_SetTimeValue(entry, stb.st_mtime);
 	nearmisses += 1;
 	return (file);
     }
@@ -1242,8 +1315,14 @@
 	    fprintf(debug_file, "   Trying exact path matches...\n");
 	}
 
-	if (!hasLastDot && cur && (file = DirLookupAbs(cur, name, cp)) != NULL)
-	    return *file?file:NULL;
+	if (!hasLastDot && cur && ((file = DirLookupAbs(cur, name, cp))
+		!= NULL)) {
+	    if (file[0] == '\0') {
+		free(file);
+		return NULL;
+	    }
+	    return file;
+	}
 
 	(void)Lst_Open(path);
 	while ((ln = Lst_Next(path)) != NULL) {
@@ -1252,13 +1331,23 @@
 		continue;
 	    if ((file = DirLookupAbs(p, name, cp)) != NULL) {
 		Lst_Close(path);
-		return *file?file:NULL;
+		if (file[0] == '\0') {
+		    free(file);
+		    return NULL;
+		}
+		return file;
 	    }
 	}
 	Lst_Close(path);
 
-	if (hasLastDot && cur && (file = DirLookupAbs(cur, name, cp)) != NULL)
-	    return *file?file:NULL;
+	if (hasLastDot && cur && ((file = DirLookupAbs(cur, name, cp))
+		!= NULL)) {
+	    if (file[0] == '\0') {
+		free(file);
+		return NULL;
+	    }
+	    return file;
+	}
     }
 
     /*
@@ -1312,15 +1401,11 @@
 	    fprintf(debug_file, "   got it (in mtime cache)\n");
 	}
 	return(bmake_strdup(name));
-    } else if (stat(name, &stb) == 0) {
-	if (stb.st_mtime == 0)
-		stb.st_mtime = 1;
-	entry = Hash_CreateEntry(&mtimes, name, NULL);
+    } else if (cached_stat(name, &stb) == 0) {
 	if (DEBUG(DIR)) {
 	    fprintf(debug_file, "   Caching %s for %s\n", Targ_FmtTime(stb.st_mtime),
 		    name);
 	}
-	Hash_SetTimeValue(entry, stb.st_mtime);
 	return (bmake_strdup(name));
     } else {
 	if (DEBUG(DIR)) {
@@ -1368,7 +1453,7 @@
 
 		/* try and stat(2) it ... */
 		snprintf(try, sizeof(try), "%s/%s", dirbase, search_path);
-		if (stat(try, &st) != -1) {
+		if (cached_stat(try, &st) != -1) {
 			/*
 			 * success!  if we found a file, chop off
 			 * the filename so we return a directory.
@@ -1489,12 +1574,12 @@
     else
 	entry = NULL;
     if (entry != NULL) {
+	stb.st_mtime = Hash_GetTimeValue(entry);
 	if (DEBUG(DIR)) {
 	    fprintf(debug_file, "Using cached time %s for %s\n",
-		    Targ_FmtTime(Hash_GetTimeValue(entry)), fullName);
+		    Targ_FmtTime(stb.st_mtime), fullName);
 	}
-	stb.st_mtime = Hash_GetTimeValue(entry);
-    } else if (stat(fullName, &stb) < 0) {
+    } else if (cached_stats(&mtimes, fullName, &stb, recheck ? CST_UPDATE : 0) < 0) {
 	if (gn->type & OP_MEMBER) {
 	    if (fullName != gn->path)
 		free(fullName);
@@ -1502,18 +1587,8 @@
 	} else {
 	    stb.st_mtime = 0;
 	}
-    } else {
-	if (stb.st_mtime == 0) {
-		/*
-		 * 0 handled specially by the code, if the time is really 0,
-		 * return something else instead
-		 */
-		stb.st_mtime = 1;
-	}
-	entry = Hash_CreateEntry(&mtimes, fullName, NULL);
-	Hash_SetTimeValue(entry, stb.st_mtime);
     }
-	
+
     if (fullName && gn->path == NULL) {
 	gn->path = fullName;
     }
@@ -1792,10 +1867,10 @@
 }
 
 static int
-DirPrintDir(void *p, void *dummy)
+DirPrintDir(void *p, void *dummy MAKE_ATTR_UNUSED)
 {
     fprintf(debug_file, "%s ", ((Path *)p)->name);
-    return (dummy ? 0 : 0);
+    return 0;
 }
 
 void

Modified: trunk/contrib/bmake/dir.h
===================================================================
--- trunk/contrib/bmake/dir.h	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/dir.h	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.h,v 1.15 2012/04/07 18:29:08 christos Exp $	*/
+/*	$NetBSD: dir.h,v 1.18 2017/05/31 22:02:06 maya Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -75,8 +75,8 @@
 /* dir.h --
  */
 
-#ifndef	_DIR
-#define	_DIR
+#ifndef	MAKE_DIR_H
+#define	MAKE_DIR_H
 
 typedef struct Path {
     char         *name;	    	/* Name of directory */
@@ -105,4 +105,4 @@
 void Dir_Destroy(void *);
 void * Dir_CopyDir(void *);
 
-#endif /* _DIR */
+#endif /* MAKE_DIR_H */

Modified: trunk/contrib/bmake/dirname.c
===================================================================
--- trunk/contrib/bmake/dirname.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/dirname.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: dirname.c,v 1.11 2009/11/24 13:34:20 tnozaki Exp $	*/
+/*	$NetBSD: dirname.c,v 1.13 2014/07/16 10:52:26 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997, 2002 The NetBSD Foundation, Inc.
@@ -35,7 +35,10 @@
 #ifndef HAVE_DIRNAME
 
 #include <sys/cdefs.h>
-
+#include <sys/param.h>
+#ifdef HAVE_LIBGEN_H
+#include <libgen.h>
+#endif
 #ifdef HAVE_LIMITS_H
 #include <limits.h>
 #endif
@@ -45,12 +48,15 @@
 #ifndef PATH_MAX
 # define PATH_MAX 1024
 #endif
+#ifndef MIN
+# define MIN(a, b) ((a < b) ? a : b)
+#endif
 
-char *
-dirname(char *path)
+
+static size_t
+xdirname_r(const char *path, char *buf, size_t buflen)
 {
-	static char result[PATH_MAX];
-	const char *lastp;
+	const char *endp;
 	size_t len;
 
 	/*
@@ -57,39 +63,58 @@
 	 * 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;
+	if (path == NULL || *path == '\0') {
+		path = ".";
+		len = 1;
+		goto out;
+	}
 
-
 	/* Strip trailing slashes, if any. */
-	lastp = path + strlen(path) - 1;
-	while (lastp != path && *lastp == '/')
-		lastp--;
+	endp = path + strlen(path) - 1;
+	while (endp != path && *endp == '/')
+		endp--;
 
-	/* Terminate path at the last occurence of '/'. */
-	do {
-		if (*lastp == '/') {
-			/* Strip trailing slashes, if any. */
-			while (lastp != path && *lastp == '/')
-				lastp--;
+	/* Find the start of the dir */
+	while (endp > path && *endp != '/')
+		endp--;
 
-			/* ...and copy the result into the result buffer. */
-			len = (lastp - path) + 1 /* last char */;
-			if (len > (PATH_MAX - 1))
-				len = PATH_MAX - 1;
+	if (endp == path) {
+		path = *endp == '/' ? "/" : ".";
+		len = 1;
+		goto out;
+	}
 
-			memcpy(result, path, len);
-			result[len] = '\0';
+	do
+		endp--;
+	while (endp > path && *endp == '/');
 
-			return (result);
-		}
-	} while (--lastp >= path);
+	len = endp - path + 1;
+out:
+	if (buf != NULL && buflen != 0) {
+		buflen = MIN(len, buflen - 1);
+		memcpy(buf, path, buflen);
+		buf[buflen] = '\0';
+	}
+	return len;
+}
 
-	/* No /'s found, return a pointer to the string ".". */
-singledot:
-	result[0] = '.';
-	result[1] = '\0';
+char *
+dirname(char *path)
+{
+	static char result[PATH_MAX];
+	(void)xdirname_r(path, result, sizeof(result));
+	return result;
+}
 
-	return (result);
+#ifdef MAIN
+#include <stdlib.h>
+#include <stdio.h>
+
+int
+main(int argc, char *argv[])
+{
+	printf("%s\n", dirname(argv[1]));
+	exit(0);
 }
 #endif
+#endif

Modified: trunk/contrib/bmake/for.c
===================================================================
--- trunk/contrib/bmake/for.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/for.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.50 2015/10/11 04:51:24 sjg Exp $	*/
+/*	$NetBSD: for.c,v 1.53 2017/04/16 21:04:44 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -30,7 +30,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: for.c,v 1.50 2015/10/11 04:51:24 sjg Exp $";
+static char rcsid[] = "$NetBSD: for.c,v 1.53 2017/04/16 21:04:44 riastradh Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)for.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: for.c,v 1.50 2015/10/11 04:51:24 sjg Exp $");
+__RCSID("$NetBSD: for.c,v 1.53 2017/04/16 21:04:44 riastradh Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -216,7 +216,7 @@
      * We can't do the escapes here - because we don't know whether
      * we are substuting into ${...} or $(...).
      */
-    sub = Var_Subst(NULL, ptr, VAR_GLOBAL, FALSE, TRUE);
+    sub = Var_Subst(NULL, ptr, VAR_GLOBAL, VARF_WANTRES);
 
     /*
      * Split into words allowing for quoted strings.
@@ -427,7 +427,7 @@
     for (cp = cmd_cp; (cp = strchr(cp, '$')) != NULL;) {
 	char ech;
 	ch = *++cp;
-	if ((ch == '(' && (ech = ')')) || (ch == '{' && (ech = '}'))) {
+	if ((ch == '(' && (ech = ')', 1)) || (ch == '{' && (ech = '}', 1))) {
 	    cp++;
 	    /* Check variable name against the .for loop variables */
 	    STRLIST_FOREACH(var, &arg->vars, i) {

Modified: trunk/contrib/bmake/getopt.c
===================================================================
--- trunk/contrib/bmake/getopt.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/getopt.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,3 +1,5 @@
+/*	$NetBSD: getopt.c,v 1.29 2014/06/05 22:00:22 christos Exp $	*/
+
 /*
  * Copyright (c) 1987, 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -10,11 +12,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
  *
@@ -35,12 +33,8 @@
 # include "config.h"
 #endif
 #if !defined(HAVE_GETOPT) || defined(WANT_GETOPT_LONG) || defined(BROKEN_GETOPT)
+#include <sys/cdefs.h>
 
-#if defined(LIBC_SCCS) && !defined(lint)
-/* static char sccsid[] = "from: @(#)getopt.c	8.2 (Berkeley) 4/2/94"; */
-static char *rcsid = "$Id: getopt.c,v 1.3 1999/01/08 02:14:18 sjg Exp $";
-#endif /* LIBC_SCCS and not lint */
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -61,13 +55,10 @@
  *	Parse argc/argv argument vector.
  */
 int
-getopt(nargc, nargv, ostr)
-	int nargc;
-	char * const *nargv;
-	const char *ostr;
+getopt(int nargc, char * const nargv[], const char *ostr)
 {
 	extern char *__progname;
-	static char *place = EMSG;		/* option letter processing */
+	static const char *place = EMSG; 	/* option letter processing */
 	char *oli;				/* option letter list index */
 
 #ifndef BSD4_4
@@ -79,43 +70,63 @@
 	}
 #endif
 	
-	if (optreset || !*place) {		/* update scanning pointer */
+	if (optreset || *place == 0) {		/* update scanning pointer */
 		optreset = 0;
-		if (optind >= nargc || *(place = nargv[optind]) != '-') {
+		place = nargv[optind];
+		if (optind >= nargc || *place++ != '-') {
+			/* Argument is absent or is not an option */
 			place = EMSG;
 			return (-1);
 		}
-		if (place[1] && *++place == '-'	/* found "--" */
-		    && !place[1]) {		/* and not "--foo" */
+		optopt = *place++;
+		if (optopt == '-' && *place == 0) {
+			/* "--" => end of options */
 			++optind;
 			place = EMSG;
 			return (-1);
 		}
-	}					/* option letter okay? */
-	if ((optopt = (int)*place++) == (int)':' ||
-	    !(oli = strchr(ostr, optopt))) {
-		/*
-		 * if the user didn't specify '-' as an option,
-		 * assume it means -1.
-		 */
-		if (optopt == (int)'-')
-			return (-1);
-		if (!*place)
+		if (optopt == 0) {
+			/* Solitary '-', treat as a '-' option
+			   if the program (eg su) is looking for it. */
+			place = EMSG;
+			if (strchr(ostr, '-') == NULL)
+				return -1;
+			optopt = '-';
+		}
+	} else
+		optopt = *place++;
+
+	/* See if option letter is one the caller wanted... */
+	if (optopt == ':' || (oli = strchr(ostr, optopt)) == NULL) {
+		if (*place == 0)
 			++optind;
 		if (opterr && *ostr != ':')
 			(void)fprintf(stderr,
-			    "%s: illegal option -- %c\n", __progname, optopt);
+			    "%s: unknown option -- %c\n", __progname, optopt);
 		return (BADCH);
 	}
-	if (*++oli != ':') {			/* don't need argument */
+
+	/* Does this option need an argument? */
+	if (oli[1] != ':') {
+		/* don't need argument */
 		optarg = NULL;
-		if (!*place)
+		if (*place == 0)
 			++optind;
-	}
-	else {					/* need an argument */
-		if (*place)			/* no white space */
-			optarg = place;
-		else if (nargc <= ++optind) {	/* no arg */
+	} else {
+		/* Option-argument is either the rest of this argument or the
+		   entire next argument. */
+		if (*place)
+			optarg = __UNCONST(place);
+		else if (oli[2] == ':')
+			/*
+			 * GNU Extension, for optional arguments if the rest of
+			 * the argument is empty, we return NULL
+			 */
+			optarg = NULL;
+		else if (nargc > ++optind)
+			optarg = nargv[optind];
+		else {
+			/* option-argument absent */
 			place = EMSG;
 			if (*ostr == ':')
 				return (BADARG);
@@ -125,12 +136,10 @@
 				    __progname, optopt);
 			return (BADCH);
 		}
-	 	else				/* white space */
-			optarg = nargv[optind];
 		place = EMSG;
 		++optind;
 	}
-	return (optopt);			/* dump back option letter */
+	return (optopt);			/* return option letter */
 }
 #endif
 #ifdef MAIN

Modified: trunk/contrib/bmake/hash.h
===================================================================
--- trunk/contrib/bmake/hash.h	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/hash.h	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: hash.h,v 1.10 2009/01/24 10:59:09 dsl Exp $	*/
+/*	$NetBSD: hash.h,v 1.12 2017/05/31 21:07:03 maya Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -78,8 +78,8 @@
  * 	which maintains hash tables.
  */
 
-#ifndef	_HASH
-#define	_HASH
+#ifndef	_HASH_H
+#define	_HASH_H
 
 /*
  * The following defines one entry in the hash table.
@@ -89,10 +89,7 @@
     struct Hash_Entry *next;		/* Used to link together all the
     					 * entries associated with the same
 					 * bucket. */
-    union {
-	void	      *clientPtr;	/* Arbitrary pointer */
-	time_t	      clientTime;	/* Arbitrary Time */
-    } clientInfo;
+    void	      *clientPtr;	/* Arbitrary pointer */
     unsigned	      namehash;		/* hash value of key */
     char	      name[1];		/* key string */
 } Hash_Entry;
@@ -125,8 +122,7 @@
  *     Hash_Entry *h;
  */
 
-#define Hash_GetValue(h) ((h)->clientInfo.clientPtr)
-#define Hash_GetTimeValue(h) ((h)->clientInfo.clientTime)
+#define Hash_GetValue(h) ((h)->clientPtr)
 
 /*
  * Hash_SetValue(h, val);
@@ -134,8 +130,7 @@
  *     char *val;
  */
 
-#define Hash_SetValue(h, val) ((h)->clientInfo.clientPtr = (val))
-#define Hash_SetTimeValue(h, val) ((h)->clientInfo.clientTime = (val))
+#define Hash_SetValue(h, val) ((h)->clientPtr = (val))
 
 /*
  * Hash_Size(n) returns the number of words in an object of n bytes
@@ -151,4 +146,4 @@
 Hash_Entry *Hash_EnumFirst(Hash_Table *, Hash_Search *);
 Hash_Entry *Hash_EnumNext(Hash_Search *);
 
-#endif /* _HASH */
+#endif /* _HASH_H */

Modified: trunk/contrib/bmake/job.c
===================================================================
--- trunk/contrib/bmake/job.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/job.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.181 2015/10/11 04:51:24 sjg Exp $	*/
+/*	$NetBSD: job.c,v 1.191 2017/07/20 19:29:54 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,7 +70,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: job.c,v 1.181 2015/10/11 04:51:24 sjg Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.191 2017/07/20 19:29:54 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -77,7 +77,7 @@
 #if 0
 static char sccsid[] = "@(#)job.c	8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: job.c,v 1.181 2015/10/11 04:51:24 sjg Exp $");
+__RCSID("$NetBSD: job.c,v 1.191 2017/07/20 19:29:54 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -144,7 +144,6 @@
 
 #include <assert.h>
 #include <errno.h>
-#include <fcntl.h>
 #if !defined(USE_SELECT) && defined(HAVE_POLL_H)
 #include <poll.h>
 #else
@@ -365,11 +364,6 @@
 	    (void)fprintf(fp, TARG_FMT, targPrefix, gn->name)
 
 static sigset_t caught_signals;	/* Set of signals we handle */
-#if defined(SYSV)
-#define KILLPG(pid, sig)	kill(-(pid), (sig))
-#else
-#define KILLPG(pid, sig)	killpg((pid), (sig))
-#endif
 
 static void JobChildSig(int);
 static void JobContinueSig(int);
@@ -390,7 +384,10 @@
 static void JobSigUnlock(sigset_t *);
 static void JobSigReset(void);
 
-const char *malloc_options="A";
+#if !defined(MALLOC_OPTIONS)
+# define MALLOC_OPTIONS "A"
+#endif
+const char *malloc_options= MALLOC_OPTIONS;
 
 static void
 job_table_dump(const char *where)
@@ -405,6 +402,21 @@
 }
 
 /*
+ * Delete the target of a failed, interrupted, or otherwise
+ * unsuccessful job unless inhibited by .PRECIOUS.
+ */
+static void
+JobDeleteTarget(GNode *gn)
+{
+	if ((gn->type & (OP_JOIN|OP_PHONY)) == 0 && !Targ_Precious(gn)) {
+	    char *file = (gn->path == NULL ? gn->name : gn->path);
+	    if (!noExecute && eunlink(file) != -1) {
+		Error("*** %s removed", file);
+	    }
+	}
+}
+
+/*
  * JobSigLock/JobSigUnlock
  *
  * Signal lock routines to get exclusive access. Currently used to
@@ -426,7 +438,7 @@
 static void
 JobCreatePipe(Job *job, int minfd)
 {
-    int i, fd;
+    int i, fd, flags;
 
     if (pipe(job->jobPipe) == -1)
 	Punt("Cannot create pipe: %s", strerror(errno));
@@ -441,8 +453,10 @@
     }
     
     /* Set close-on-exec flag for both */
-    (void)fcntl(job->jobPipe[0], F_SETFD, 1);
-    (void)fcntl(job->jobPipe[1], F_SETFD, 1);
+    if (fcntl(job->jobPipe[0], F_SETFD, FD_CLOEXEC) == -1)
+	Punt("Cannot set close-on-exec: %s", strerror(errno));
+    if (fcntl(job->jobPipe[1], F_SETFD, FD_CLOEXEC) == -1)
+	Punt("Cannot set close-on-exec: %s", strerror(errno));
 
     /*
      * We mark the input side of the pipe non-blocking; we poll(2) the
@@ -450,8 +464,12 @@
      * race for the token when a new one becomes available, so the read 
      * from the pipe should not block.
      */
-    fcntl(job->jobPipe[0], F_SETFL, 
-	fcntl(job->jobPipe[0], F_GETFL, 0) | O_NONBLOCK);
+    flags = fcntl(job->jobPipe[0], F_GETFL, 0);
+    if (flags == -1)
+	Punt("Cannot get flags: %s", strerror(errno));
+    flags |= O_NONBLOCK;
+    if (fcntl(job->jobPipe[0], F_SETFL, flags) == -1)
+	Punt("Cannot set flags: %s", strerror(errno));
 }
 
 /*-
@@ -731,7 +749,7 @@
 
     numCommands += 1;
 
-    cmdStart = cmd = Var_Subst(NULL, cmd, job->node, FALSE, TRUE);
+    cmdStart = cmd = Var_Subst(NULL, cmd, job->node, VARF_WANTRES);
 
     cmdTemplate = "%s\n";
 
@@ -753,6 +771,7 @@
 		 * but this one needs to be - use compat mode just for it.
 		 */
 		CompatRunCommand(cmdp, job->node);
+		free(cmdStart);
 		return 0;
 	    }
 	    break;
@@ -882,8 +901,7 @@
     
     DBPRINTF(cmdTemplate, cmd);
     free(cmdStart);
-    if (escCmd)
-        free(escCmd);
+    free(escCmd);
     if (errOff) {
 	/*
 	 * If echoing is already off, there's no point in issuing the
@@ -919,7 +937,7 @@
 static int
 JobSaveCommand(void *cmd, void *gn)
 {
-    cmd = Var_Subst(NULL, (char *)cmd, (GNode *)gn, FALSE, TRUE);
+    cmd = Var_Subst(NULL, (char *)cmd, (GNode *)gn, VARF_WANTRES);
     (void)Lst_AtEnd(postCommands->commands, cmd);
     return(0);
 }
@@ -1051,6 +1069,9 @@
 		if (job->flags & JOB_IGNERR) {
 		    WAIT_STATUS(status) = 0;
 		} else {
+		    if (deleteOnError) {
+			JobDeleteTarget(job->node);
+		    }
 		    PrintOnError(job->node, NULL);
 		}
 	    } else if (DEBUG(JOB)) {
@@ -1068,6 +1089,9 @@
 	    }
 	    (void)printf("*** [%s] Signal %d\n",
 			job->node->name, WTERMSIG(status));
+	    if (deleteOnError) {
+		JobDeleteTarget(job->node);
+	    }
 	}
 	(void)fflush(stdout);
     }
@@ -1074,7 +1098,11 @@
 
 #ifdef USE_META
     if (useMeta) {
-	meta_job_finish(job);
+	int x;
+
+	if ((x = meta_job_finish(job)) != 0 && status == 0) {
+	    status = x;
+	}
     }
 #endif
     
@@ -1250,8 +1278,7 @@
 	     */
 	    Make_HandleUse(DEFAULT, gn);
 	    Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), gn, 0);
-	    if (p1)
-		free(p1);
+	    free(p1);
 	} else if (Dir_MTime(gn, 0) == 0 && (gn->type & OP_SPECIAL) == 0) {
 	    /*
 	     * The node wasn't the target of an operator we have no .DEFAULT
@@ -1373,8 +1400,14 @@
 	    execError("dup2", "job->cmdFILE");
 	    _exit(1);
 	}
-	(void)fcntl(0, F_SETFD, 0);
-	(void)lseek(0, (off_t)0, SEEK_SET);
+	if (fcntl(0, F_SETFD, 0) == -1) {
+	    execError("fcntl clear close-on-exec", "stdin");
+	    _exit(1);
+	}
+	if (lseek(0, (off_t)0, SEEK_SET) == -1) {
+	    execError("lseek to 0", "stdin");
+	    _exit(1);
+	}
 
 	if (Always_pass_job_queue ||
 	    (job->node->type & (OP_MAKE | OP_SUBMAKE))) {
@@ -1381,8 +1414,14 @@
 		/*
 		 * Pass job token pipe to submakes.
 		 */
-		fcntl(tokenWaitJob.inPipe, F_SETFD, 0);
-		fcntl(tokenWaitJob.outPipe, F_SETFD, 0);		
+		if (fcntl(tokenWaitJob.inPipe, F_SETFD, 0) == -1) {
+		    execError("clear close-on-exec", "tokenWaitJob.inPipe");
+		    _exit(1);
+		}
+		if (fcntl(tokenWaitJob.outPipe, F_SETFD, 0) == -1) {
+		    execError("clear close-on-exec", "tokenWaitJob.outPipe");
+		    _exit(1);
+		}
 	}
 	
 	/*
@@ -1399,7 +1438,10 @@
 	 * it before routing the shell's error output to the same place as
 	 * its standard output.
 	 */
-	(void)fcntl(1, F_SETFD, 0);
+	if (fcntl(1, F_SETFD, 0) == -1) {
+	    execError("clear close-on-exec", "stdout");
+	    _exit(1);
+	}
 	if (dup2(1, 2) == -1) {
 	    execError("dup2", "1, 2");
 	    _exit(1);
@@ -1615,7 +1657,7 @@
 	if (job->cmdFILE == NULL) {
 	    Punt("Could not fdopen %s", tfile);
 	}
-	(void)fcntl(FILENO(job->cmdFILE), F_SETFD, 1);
+	(void)fcntl(FILENO(job->cmdFILE), F_SETFD, FD_CLOEXEC);
 	/*
 	 * Send the commands to the command file, flush all its buffers then
 	 * rewind and remove the thing.
@@ -2212,7 +2254,7 @@
     }
 
     targPrefix = Var_Subst(NULL, "${" MAKE_JOB_PREFIX "}",
-			   VAR_GLOBAL, FALSE, TRUE);
+			   VAR_GLOBAL, VARF_WANTRES);
 }
 
 /*-
@@ -2425,8 +2467,7 @@
 	line++;
     }
 
-    if (shellArgv)
-	free(UNCONST(shellArgv));
+    free(UNCONST(shellArgv));
 
     memset(&newShell, 0, sizeof(newShell));
 
@@ -2601,12 +2642,7 @@
 
 	gn = job->node;
 
-	if ((gn->type & (OP_JOIN|OP_PHONY)) == 0 && !Targ_Precious(gn)) {
-	    char *file = (gn->path == NULL ? gn->name : gn->path);
-	    if (!noExecute && eunlink(file) != -1) {
-		Error("*** %s removed", file);
-	    }
-	}
+	JobDeleteTarget(gn);
 	if (job->pid) {
 	    if (DEBUG(JOB)) {
 		(void)fprintf(debug_file,
@@ -2674,8 +2710,7 @@
 Job_End(void)
 {
 #ifdef CLEANUP
-    if (shellArgv)
-	free(shellArgv);
+    free(shellArgv);
 #endif
 }
 
@@ -2880,8 +2915,8 @@
 	/* Pipe passed in from parent */
 	tokenWaitJob.inPipe = jp_0;
 	tokenWaitJob.outPipe = jp_1;
-	(void)fcntl(jp_0, F_SETFD, 1);
-	(void)fcntl(jp_1, F_SETFD, 1);
+	(void)fcntl(jp_0, F_SETFD, FD_CLOEXEC);
+	(void)fcntl(jp_1, F_SETFD, FD_CLOEXEC);
 	return;
     }
 

Modified: trunk/contrib/bmake/main.c
===================================================================
--- trunk/contrib/bmake/main.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/main.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.235 2015/10/25 05:24:44 sjg Exp $	*/
+/*	$NetBSD: main.c,v 1.272 2017/06/19 19:58:24 christos Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.235 2015/10/25 05:24:44 sjg Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.272 2017/06/19 19:58:24 christos Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -81,7 +81,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.235 2015/10/25 05:24:44 sjg Exp $");
+__RCSID("$NetBSD: main.c,v 1.272 2017/06/19 19:58:24 christos Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -125,7 +125,6 @@
 #include "wait.h"
 
 #include <errno.h>
-#include <fcntl.h>
 #include <signal.h>
 #include <stdarg.h>
 #include <stdio.h>
@@ -156,10 +155,13 @@
 time_t			now;		/* Time at start of make */
 GNode			*DEFAULT;	/* .DEFAULT node */
 Boolean			allPrecious;	/* .PRECIOUS given on line by itself */
+Boolean			deleteOnError;	/* .DELETE_ON_ERROR: set */
 
 static Boolean		noBuiltins;	/* -r flag */
 static Lst		makefiles;	/* ordered list of makefiles to read */
-static Boolean		printVars;	/* print value of one or more vars */
+static int		printVars;	/* -[vV] argument */
+#define COMPAT_VARS 1
+#define EXPAND_VARS 2
 static Lst		variables;	/* list of variables to print */
 int			maxJobs;	/* -j argument */
 static int		maxJobTokens;	/* -j argument */
@@ -187,6 +189,7 @@
 static void		MainParseArgs(int, char **);
 static int		ReadMakefile(const void *, const void *);
 static void		usage(void) MAKE_ATTR_DEAD;
+static void		purge_cached_realpaths(void);
 
 static Boolean		ignorePWD;	/* if we use -C, PWD is meaningless */
 static char objdir[MAXPATHLEN + 1];	/* where we chdir'ed to */
@@ -336,7 +339,7 @@
 				goto debug_setbuf;
 			}
 			len = strlen(modules);
-			fname = malloc(len + 20);
+			fname = bmake_malloc(len + 20);
 			memcpy(fname, modules, len + 1);
 			/* Let the filename be modified by the pid */
 			if (strcmp(fname + len - 3, ".%d") == 0)
@@ -367,6 +370,32 @@
 	}
 }
 
+/*
+ * does path contain any relative components
+ */
+static int
+is_relpath(const char *path)
+{
+	const char *cp;
+
+	if (path[0] != '/')
+		return TRUE;
+	cp = path;
+	do {
+		cp = strstr(cp, "/.");
+		if (!cp)
+			break;
+		cp += 2;
+		if (cp[0] == '/' || cp[0] == '\0')
+			return TRUE;
+		else if (cp[0] == '.') {
+			if (cp[1] == '/' || cp[1] == '\0')
+				return TRUE;
+		}
+	} while (cp);
+	return FALSE;
+}
+
 /*-
  * MainParseArgs --
  *	Parse a given argument vector. Called from main() and from
@@ -389,11 +418,12 @@
 	int arginc;
 	char *argvalue;
 	const char *getopt_def;
+	struct stat sa, sb;
 	char *optscan;
 	Boolean inOption, dashDash = FALSE;
 	char found_path[MAXPATHLEN + 1];	/* for searching for sys.mk */
 
-#define OPTFLAGS "BC:D:I:J:NST:V:WXd:ef:ij:km:nqrstw"
+#define OPTFLAGS "BC:D:I:J:NST:V:WXd:ef:ij:km:nqrstv:w"
 /* Can't actually use getopt(3) because rescanning is not portable */
 
 	getopt_def = OPTFLAGS;
@@ -457,6 +487,12 @@
 				(void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno));
 				exit(2);
 			}
+			if (!is_relpath(argvalue) &&
+			    stat(argvalue, &sa) != -1 &&
+			    stat(curdir, &sb) != -1 &&
+			    sa.st_ino == sb.st_ino &&
+			    sa.st_dev == sb.st_dev)
+				strncpy(curdir, argvalue, MAXPATHLEN);
 			ignorePWD = TRUE;
 			break;
 		case 'D':
@@ -512,8 +548,9 @@
 			Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
 			break;
 		case 'V':
+		case 'v':
 			if (argvalue == NULL) goto noarg;
-			printVars = TRUE;
+			printVars = c == 'v' ? EXPAND_VARS : COMPAT_VARS;
 			(void)Lst_AtEnd(variables, argvalue);
 			Var_Append(MAKEFLAGS, "-V", VAR_GLOBAL);
 			Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
@@ -696,8 +733,7 @@
 #endif
 	buf = bmake_malloc(len = strlen(line) + strlen(argv0) + 2);
 	(void)snprintf(buf, len, "%s %s", argv0, line);
-	if (p1)
-		free(p1);
+	free(p1);
 
 	argv = brk_string(buf, &argc, TRUE, &args);
 	if (argv == NULL) {
@@ -713,22 +749,22 @@
 }
 
 Boolean
-Main_SetObjdir(const char *path)
+Main_SetObjdir(const char *fmt, ...)
 {
 	struct stat sb;
-	char *p = NULL;
+	char *path;
 	char buf[MAXPATHLEN + 1];
+	char buf2[MAXPATHLEN + 1];
 	Boolean rc = FALSE;
+	va_list ap;
 
-	/* expand variable substitutions */
-	if (strchr(path, '$') != 0) {
-		snprintf(buf, MAXPATHLEN, "%s", path);
-		path = p = Var_Subst(NULL, buf, VAR_GLOBAL, FALSE, TRUE);
-	}
+	va_start(ap, fmt);
+	vsnprintf(path = buf, MAXPATHLEN, fmt, ap);
+	va_end(ap);
 
 	if (path[0] != '/') {
-		snprintf(buf, MAXPATHLEN, "%s/%s", curdir, path);
-		path = buf;
+		snprintf(buf2, MAXPATHLEN, "%s/%s", curdir, path);
+		path = buf2;
 	}
 
 	/* look for the directory and try to chdir there */
@@ -741,6 +777,7 @@
 			Var_Set(".OBJDIR", objdir, VAR_GLOBAL, 0);
 			setenv("PWD", objdir, 1);
 			Dir_InitDot();
+			purge_cached_realpaths();
 			rc = TRUE;
 			if (enterFlag && strcmp(objdir, curdir) != 0)
 				enterFlagObj = TRUE;
@@ -747,11 +784,31 @@
 		}
 	}
 
-	if (p)
-		free(p);
 	return rc;
 }
 
+static Boolean
+Main_SetVarObjdir(const char *var, const char *suffix)
+{
+	char *p, *path, *xpath;
+
+	if ((path = Var_Value(var, VAR_CMD, &p)) == NULL)
+		return FALSE;
+
+	/* expand variable substitutions */
+	if (strchr(path, '$') != 0)
+		xpath = Var_Subst(NULL, path, VAR_GLOBAL, VARF_WANTRES);
+	else
+		xpath = path;
+
+	(void)Main_SetObjdir("%s%s", xpath, suffix);
+
+	if (xpath != path)
+		free(xpath);
+	free(p);
+	return TRUE;
+}
+
 /*-
  * ReadAllMakefiles --
  *	wrapper around ReadMakefile() to read all.
@@ -807,7 +864,7 @@
 
     if (!mode)
 	mode = mp = Var_Subst(NULL, "${" MAKE_MODE ":tl}",
-			      VAR_GLOBAL, FALSE, TRUE);
+			      VAR_GLOBAL, VARF_WANTRES);
 
     if (mode && *mode) {
 	if (strstr(mode, "compat")) {
@@ -819,10 +876,93 @@
 	    meta_mode_init(mode);
 #endif
     }
-    if (mp)
-	free(mp);
+
+    free(mp);
 }
 
+static void
+doPrintVars(void)
+{
+	LstNode ln;
+	Boolean expandVars;
+
+	if (printVars == EXPAND_VARS)
+		expandVars = TRUE;
+	else if (debugVflag)
+		expandVars = FALSE;
+	else
+		expandVars = getBoolean(".MAKE.EXPAND_VARIABLES", FALSE);
+
+	for (ln = Lst_First(variables); ln != NULL;
+	    ln = Lst_Succ(ln)) {
+		char *var = (char *)Lst_Datum(ln);
+		char *value;
+		char *p1;
+		
+		if (strchr(var, '$')) {
+			value = p1 = Var_Subst(NULL, var, VAR_GLOBAL,
+			    VARF_WANTRES);
+		} else if (expandVars) {
+			char tmp[128];
+			int len = snprintf(tmp, sizeof(tmp), "${%s}", var);
+							
+			if (len >= (int)sizeof(tmp))
+				Fatal("%s: variable name too big: %s",
+				    progname, var);
+			value = p1 = Var_Subst(NULL, tmp, VAR_GLOBAL,
+			    VARF_WANTRES);
+		} else {
+			value = Var_Value(var, VAR_GLOBAL, &p1);
+		}
+		printf("%s\n", value ? value : "");
+		free(p1);
+	}
+}
+
+static Boolean
+runTargets(void)
+{
+	Lst targs;	/* target nodes to create -- passed to Make_Init */
+	Boolean outOfDate; 	/* FALSE if all targets up to date */
+
+	/*
+	 * Have now read the entire graph and need to make a list of
+	 * targets to create. If none was given on the command line,
+	 * we consult the parsing module to find the main target(s)
+	 * to create.
+	 */
+	if (Lst_IsEmpty(create))
+		targs = Parse_MainName();
+	else
+		targs = Targ_FindList(create, TARG_CREATE);
+
+	if (!compatMake) {
+		/*
+		 * Initialize job module before traversing the graph
+		 * now that any .BEGIN and .END targets have been read.
+		 * This is done only if the -q flag wasn't given
+		 * (to prevent the .BEGIN from being executed should
+		 * it exist).
+		 */
+		if (!queryFlag) {
+			Job_Init();
+			jobsRunning = TRUE;
+		}
+
+		/* Traverse the graph, checking on all the targets */
+		outOfDate = Make_Run(targs);
+	} else {
+		/*
+		 * Compat_Init will take care of creating all the
+		 * targets as well as initializing the module.
+		 */
+		Compat_Run(targs);
+		outOfDate = FALSE;
+	}
+	Lst_Destroy(targs, NULL);
+	return outOfDate;
+}
+
 /*-
  * main --
  *	The main function, for obvious reasons. Initializes variables
@@ -843,8 +983,7 @@
 int
 main(int argc, char **argv)
 {
-	Lst targs;	/* target nodes to create -- passed to Make_Init */
-	Boolean outOfDate = FALSE; 	/* FALSE if all targets up to date */
+	Boolean outOfDate; 	/* FALSE if all targets up to date */
 	struct stat sb, sa;
 	char *p1, *path;
 	char mdpath[MAXPATHLEN];
@@ -973,7 +1112,7 @@
 
 	create = Lst_Init(FALSE);
 	makefiles = Lst_Init(FALSE);
-	printVars = FALSE;
+	printVars = 0;
 	debugVflag = FALSE;
 	variables = Lst_Init(FALSE);
 	beSilent = FALSE;		/* Print commands as executed */
@@ -982,6 +1121,7 @@
 	noRecursiveExecute = FALSE;	/* Execute all .MAKE targets */
 	keepgoing = FALSE;		/* Stop on error */
 	allPrecious = FALSE;		/* Remove targets when interrupted */
+	deleteOnError = FALSE;		/* Historical default behavior */
 	queryFlag = FALSE;		/* This is not just a check-run */
 	noBuiltins = FALSE;		/* Read the built-in rules */
 	touchFlag = FALSE;		/* Actually update targets */
@@ -1017,7 +1157,7 @@
 	    /*
 	     * A relative path, canonicalize it.
 	     */
-	    p1 = realpath(argv[0], mdpath);
+	    p1 = cached_realpath(argv[0], mdpath);
 	    if (!p1 || *p1 != '/' || stat(p1, &sb) < 0) {
 		p1 = argv[0];		/* realpath failed */
 	    }
@@ -1056,6 +1196,8 @@
 #ifdef USE_META
 	meta_init();
 #endif
+	Dir_Init(NULL);		/* Dir_* safe to call from MainParseArgs */
+
 	/*
 	 * First snag any flags out of the MAKE environment variable.
 	 * (Note this is *not* MAKEFLAGS since /bin/make uses that and it's
@@ -1131,38 +1273,21 @@
 	 * MAKEOBJDIR is set in the environment, try only that value
 	 * and fall back to .CURDIR if it does not exist.
 	 *
-	 * Otherwise, try _PATH_OBJDIR.MACHINE, _PATH_OBJDIR, and
-	 * finally _PATH_OBJDIRPREFIX`pwd`, in that order.  If none
+	 * Otherwise, try _PATH_OBJDIR.MACHINE-MACHINE_ARCH, _PATH_OBJDIR.MACHINE,
+	 * and * finally _PATH_OBJDIRPREFIX`pwd`, in that order.  If none
 	 * of these paths exist, just use .CURDIR.
 	 */
 	Dir_Init(curdir);
-	(void)Main_SetObjdir(curdir);
+	(void)Main_SetObjdir("%s", curdir);
 
-	if ((path = Var_Value("MAKEOBJDIRPREFIX", VAR_CMD, &p1)) != NULL) {
-		(void)snprintf(mdpath, MAXPATHLEN, "%s%s", path, curdir);
-		(void)Main_SetObjdir(mdpath);
-		free(p1);
-	} else if ((path = Var_Value("MAKEOBJDIR", VAR_CMD, &p1)) != NULL) {
-		(void)Main_SetObjdir(path);
-		free(p1);
-	} else {
-		(void)snprintf(mdpath, MAXPATHLEN, "%s.%s", _PATH_OBJDIR, machine);
-		if (!Main_SetObjdir(mdpath) && !Main_SetObjdir(_PATH_OBJDIR)) {
-			(void)snprintf(mdpath, MAXPATHLEN, "%s%s", 
-					_PATH_OBJDIRPREFIX, curdir);
-			(void)Main_SetObjdir(mdpath);
-		}
-	}
+	if (!Main_SetVarObjdir("MAKEOBJDIRPREFIX", curdir) &&
+	    !Main_SetVarObjdir("MAKEOBJDIR", "") &&
+	    !Main_SetObjdir("%s.%s-%s", _PATH_OBJDIR, machine, machine_arch) &&
+	    !Main_SetObjdir("%s.%s", _PATH_OBJDIR, machine) &&
+	    !Main_SetObjdir("%s", _PATH_OBJDIR))
+		(void)Main_SetObjdir("%s%s", _PATH_OBJDIRPREFIX, curdir);
 
 	/*
-	 * Be compatible if user did not specify -j and did not explicitly
-	 * turned compatibility on
-	 */
-	if (!compatMake && !forceJobs) {
-		compatMake = TRUE;
-	}
-	
-	/*
 	 * Initialize archive, target and suffix modules in preparation for
 	 * parsing the makefile(s)
 	 */
@@ -1253,7 +1378,7 @@
 			    (char *)Lst_Datum(ln));
 	} else {
 	    p1 = Var_Subst(NULL, "${" MAKEFILE_PREFERENCE "}",
-	        VAR_CMD, FALSE, TRUE);
+		VAR_CMD, VARF_WANTRES);
 	    if (p1) {
 		(void)str2Lst_Append(makefiles, p1, NULL);
 		(void)Lst_Find(makefiles, NULL, ReadMakefile);
@@ -1264,7 +1389,7 @@
 	/* In particular suppress .depend for '-r -V .OBJDIR -f /dev/null' */
 	if (!noBuiltins || !printVars) {
 	    makeDependfile = Var_Subst(NULL, "${.MAKE.DEPENDFILE:T}",
-		VAR_CMD, FALSE, TRUE);
+		VAR_CMD, VARF_WANTRES);
 	    doing_depend = TRUE;
 	    (void)ReadMakefile(makeDependfile, NULL);
 	    doing_depend = FALSE;
@@ -1276,9 +1401,38 @@
 	MakeMode(NULL);
 
 	Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1), VAR_GLOBAL);
-	if (p1)
-	    free(p1);
+	free(p1);
 
+	if (!forceJobs && !compatMake &&
+	    Var_Exists(".MAKE.JOBS", VAR_GLOBAL)) {
+	    char *value;
+	    int n;
+
+	    value = Var_Subst(NULL, "${.MAKE.JOBS}", VAR_GLOBAL, VARF_WANTRES);
+	    n = strtol(value, NULL, 0);
+	    if (n < 1) {
+		(void)fprintf(stderr, "%s: illegal value for .MAKE.JOBS -- must be positive integer!\n",
+		    progname);
+		exit(1);
+	    }
+	    if (n != maxJobs) {
+		Var_Append(MAKEFLAGS, "-j", VAR_GLOBAL);
+		Var_Append(MAKEFLAGS, value, VAR_GLOBAL);
+	    }
+	    maxJobs = n;
+	    maxJobTokens = maxJobs;
+	    forceJobs = TRUE;
+	    free(value);
+	}
+
+	/*
+	 * Be compatible if user did not specify -j and did not explicitly
+	 * turned compatibility on
+	 */
+	if (!compatMake && !forceJobs) {
+	    compatMake = TRUE;
+	}
+
 	if (!compatMake)
 	    Job_ServerStart(maxJobTokens, jp_0, jp_1);
 	if (DEBUG(JOB))
@@ -1285,8 +1439,9 @@
 	    fprintf(debug_file, "job_pipe %d %d, maxjobs %d, tokens %d, compat %d\n",
 		jp_0, jp_1, maxJobs, maxJobTokens, compatMake);
 
-	Main_ExportMAKEFLAGS(TRUE);	/* initial export */
-
+	if (!printVars)
+	    Main_ExportMAKEFLAGS(TRUE);	/* initial export */
+	
 	/*
 	 * For compatibility, look at the directories in the VPATH variable
 	 * and add them to the search path, if the variable is defined. The
@@ -1302,7 +1457,7 @@
 		 */
 		static char VPATH[] = "${VPATH}";
 
-		vpath = Var_Subst(NULL, VPATH, VAR_CMD, FALSE, TRUE);
+		vpath = Var_Subst(NULL, VPATH, VAR_CMD, VARF_WANTRES);
 		path = vpath;
 		do {
 			/* skip to end of directory */
@@ -1336,74 +1491,13 @@
 
 	/* print the values of any variables requested by the user */
 	if (printVars) {
-		LstNode ln;
-		Boolean expandVars;
-
-		if (debugVflag)
-			expandVars = FALSE;
-		else
-			expandVars = getBoolean(".MAKE.EXPAND_VARIABLES", FALSE);
-		for (ln = Lst_First(variables); ln != NULL;
-		    ln = Lst_Succ(ln)) {
-			char *var = (char *)Lst_Datum(ln);
-			char *value;
-			
-			if (strchr(var, '$')) {
-			    value = p1 = Var_Subst(NULL, var, VAR_GLOBAL,
-						   FALSE, TRUE);
-			} else if (expandVars) {
-				char tmp[128];
-								
-				if (snprintf(tmp, sizeof(tmp), "${%s}", var) >= (int)(sizeof(tmp)))
-					Fatal("%s: variable name too big: %s",
-					      progname, var);
-				value = p1 = Var_Subst(NULL, tmp, VAR_GLOBAL,
-						       FALSE, TRUE);
-			} else {
-				value = Var_Value(var, VAR_GLOBAL, &p1);
-			}
-			printf("%s\n", value ? value : "");
-			if (p1)
-				free(p1);
-		}
+		doPrintVars();
+		outOfDate = FALSE;
 	} else {
-		/*
-		 * Have now read the entire graph and need to make a list of
-		 * targets to create. If none was given on the command line,
-		 * we consult the parsing module to find the main target(s)
-		 * to create.
-		 */
-		if (Lst_IsEmpty(create))
-			targs = Parse_MainName();
-		else
-			targs = Targ_FindList(create, TARG_CREATE);
-
-		if (!compatMake) {
-			/*
-			 * Initialize job module before traversing the graph
-			 * now that any .BEGIN and .END targets have been read.
-			 * This is done only if the -q flag wasn't given
-			 * (to prevent the .BEGIN from being executed should
-			 * it exist).
-			 */
-			if (!queryFlag) {
-				Job_Init();
-				jobsRunning = TRUE;
-			}
-
-			/* Traverse the graph, checking on all the targets */
-			outOfDate = Make_Run(targs);
-		} else {
-			/*
-			 * Compat_Init will take care of creating all the
-			 * targets as well as initializing the module.
-			 */
-			Compat_Run(targs);
-		}
+		outOfDate = runTargets();
 	}
 
 #ifdef CLEANUP
-	Lst_Destroy(targs, NULL);
 	Lst_Destroy(variables, NULL);
 	Lst_Destroy(makefiles, NULL);
 	Lst_Destroy(create, (FreeProc *)free);
@@ -1420,6 +1514,9 @@
 	if (enterFlag)
 		printf("%s: Leaving directory `%s'\n", progname, curdir);
 
+#ifdef USE_META
+	meta_finish();
+#endif
 	Suff_End();
         Targ_End();
 	Arch_End();
@@ -1488,8 +1585,7 @@
 			name = Dir_FindFile(fname,
 				Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath);
 		if (!name || (fd = open(name, O_RDONLY)) == -1) {
-			if (name)
-				free(name);
+			free(name);
 			free(path);
 			return(-1);
 		}
@@ -1860,11 +1956,71 @@
 "usage: %s [-BeikNnqrstWwX] \n\
             [-C directory] [-D variable] [-d flags] [-f makefile]\n\
             [-I directory] [-J private] [-j max_jobs] [-m directory] [-T file]\n\
-            [-V variable] [variable=value] [target ...]\n", progname);
+            [-V variable] [-v variable] [variable=value] [target ...]\n",
+	    progname);
 	exit(2);
 }
 
+/*
+ * realpath(3) can get expensive, cache results...
+ */
+static GNode *cached_realpaths = NULL;
 
+static GNode *
+get_cached_realpaths(void)
+{
+
+    if (!cached_realpaths) {
+	cached_realpaths = Targ_NewGN("Realpath");
+#ifndef DEBUG_REALPATH_CACHE
+	cached_realpaths->flags = INTERNAL;
+#endif
+    }
+
+    return cached_realpaths;
+}
+
+/* purge any relative paths */
+static void
+purge_cached_realpaths(void)
+{
+    GNode *cache = get_cached_realpaths();
+    Hash_Entry *he, *nhe;
+    Hash_Search hs;
+
+    he = Hash_EnumFirst(&cache->context, &hs);
+    while (he) {
+	nhe = Hash_EnumNext(&hs);
+	if (he->name[0] != '/') {
+	    if (DEBUG(DIR))
+		fprintf(stderr, "cached_realpath: purging %s\n", he->name);
+	    Hash_DeleteEntry(&cache->context, he);
+	}
+	he = nhe;
+    }
+}
+
+char *
+cached_realpath(const char *pathname, char *resolved)
+{
+    GNode *cache;
+    char *rp, *cp;
+
+    if (!pathname || !pathname[0])
+	return NULL;
+
+    cache = get_cached_realpaths();
+
+    if ((rp = Var_Value(pathname, cache, &cp)) != NULL) {
+	/* a hit */
+	strlcpy(resolved, rp, MAXPATHLEN);
+    } else if ((rp = realpath(pathname, resolved)) != NULL) {
+	Var_Set(pathname, rp, cache, 0);
+    }
+    free(cp);
+    return rp ? resolved : NULL;
+}
+
 int
 PrintAddr(void *a, void *b)
 {
@@ -1873,6 +2029,14 @@
 }
 
 
+static int
+addErrorCMD(void *cmdp, void *gnp MAKE_ATTR_UNUSED)
+{
+    if (cmdp == NULL)
+	return 1;			/* stop */
+    Var_Append(".ERROR_CMD", cmdp, VAR_GLOBAL);
+    return 0;
+}
 
 void
 PrintOnError(GNode *gn, const char *s)
@@ -1893,10 +2057,12 @@
 	 * We can print this even if there is no .ERROR target.
 	 */
 	Var_Set(".ERROR_TARGET", gn->name, VAR_GLOBAL, 0);
+	Var_Delete(".ERROR_CMD", VAR_GLOBAL);
+	Lst_ForEach(gn->commands, addErrorCMD, gn);
     }
     strncpy(tmp, "${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'\n@}",
 	    sizeof(tmp) - 1);
-    cp = Var_Subst(NULL, tmp, VAR_GLOBAL, FALSE, TRUE);
+    cp = Var_Subst(NULL, tmp, VAR_GLOBAL, VARF_WANTRES);
     if (cp) {
 	if (*cp)
 	    printf("%s", cp);
@@ -1927,7 +2093,7 @@
     
     strncpy(tmp, "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}",
 	    sizeof(tmp));
-    s = Var_Subst(NULL, tmp, VAR_CMD, FALSE, TRUE);
+    s = Var_Subst(NULL, tmp, VAR_CMD, VARF_WANTRES);
     if (s && *s) {
 #ifdef POSIX
 	setenv("MAKEFLAGS", s, 1);
@@ -1950,7 +2116,7 @@
 	 * Ensure it ends with /.
 	 */
 	tmpdir = Var_Subst(NULL, "${TMPDIR:tA:U" _PATH_TMP "}/", VAR_GLOBAL,
-			   FALSE, TRUE);
+			   VARF_WANTRES);
 	if (stat(tmpdir, &st) < 0 || !S_ISDIR(st.st_mode)) {
 	    free(tmpdir);
 	    tmpdir = bmake_strdup(_PATH_TMP);
@@ -1990,6 +2156,44 @@
     return fd;
 }
 
+/*
+ * Convert a string representation of a boolean.
+ * Anything that looks like "No", "False", "Off", "0" etc,
+ * is FALSE, otherwise TRUE.
+ */
+Boolean
+s2Boolean(const char *s, Boolean bf)
+{
+    if (s) {
+	switch(*s) {
+	case '\0':			/* not set - the default wins */
+	    break;
+	case '0':
+	case 'F':
+	case 'f':
+	case 'N':
+	case 'n':
+	    bf = FALSE;
+	    break;
+	case 'O':
+	case 'o':
+	    switch (s[1]) {
+	    case 'F':
+	    case 'f':
+		bf = FALSE;
+		break;
+	    default:
+		bf = TRUE;
+		break;
+	    }
+	    break;
+	default:
+	    bf = TRUE;
+	    break;
+	}
+    }
+    return (bf);
+}
 
 /*
  * Return a Boolean based on setting of a knob.
@@ -2004,32 +2208,11 @@
     char tmp[64];
     char *cp;
 
-    if (snprintf(tmp, sizeof(tmp), "${%s:tl}", name) < (int)(sizeof(tmp))) {
-	cp = Var_Subst(NULL, tmp, VAR_GLOBAL, FALSE, TRUE);
+    if (snprintf(tmp, sizeof(tmp), "${%s:U:tl}", name) < (int)(sizeof(tmp))) {
+	cp = Var_Subst(NULL, tmp, VAR_GLOBAL, VARF_WANTRES);
 
 	if (cp) {
-	    switch(*cp) {
-	    case '\0':			/* not set - the default wins */
-		break;
-	    case '0':
-	    case 'f':
-	    case 'n':
-		bf = FALSE;
-		break;
-	    case 'o':
-		switch (cp[1]) {
-		case 'f':
-		    bf = FALSE;
-		    break;
-		default:
-		    bf = TRUE;
-		    break;
-		}
-		break;
-	    default:
-		bf = TRUE;
-		break;
-	    }
+	    bf = s2Boolean(cp, bf);
 	    free(cp);
 	}
     }

Modified: trunk/contrib/bmake/make-bootstrap.sh.in
===================================================================
--- trunk/contrib/bmake/make-bootstrap.sh.in	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/make-bootstrap.sh.in	2018-06-27 00:20:04 UTC (rev 11140)
@@ -13,7 +13,7 @@
 CC="@CC@"
 CFLAGS="@CFLAGS@ -I. -I${srcdir} @DEFS@ @CPPFLAGS@ -DMAKE_NATIVE ${XDEFS} -DBMAKE_PATH_MAX=@bmake_path_max@"
 
-MAKE_VERSION=`sed -n '/^MAKE_VERSION=/s,.*=[^0-9]*,,p' $srcdir/Makefile`
+MAKE_VERSION=`sed -n '/^_MAKE_VERSION=/s,.*=[^0-9]*,,p' $srcdir/Makefile`
 
 MDEFS="-DMAKE_VERSION=\"$MAKE_VERSION\" \
 -D at force_machine@MACHINE=\"@machine@\" -DMACHINE_ARCH=\"@machine_arch@\" \

Modified: trunk/contrib/bmake/make.1
===================================================================
--- trunk/contrib/bmake/make.1	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/make.1	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-.\"	$NetBSD: make.1,v 1.249 2015/06/05 07:33:40 wiz Exp $
+.\"	$NetBSD: make.1,v 1.271 2017/07/03 21:34:20 wiz 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 4, 2015
+.Dd June 22, 2017
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -48,6 +48,7 @@
 .Op Fl m Ar directory
 .Op Fl T Ar file
 .Op Fl V Ar variable
+.Op Fl v Ar variable
 .Op Ar variable=value
 .Op Ar target ...
 .Sh DESCRIPTION
@@ -206,7 +207,9 @@
 .It Ar V
 Force the
 .Fl V
-option to print raw values of variables.
+option to print raw values of variables, overriding the default behavior
+set via
+.Va .MAKE.EXPAND_VARIABLES .
 .It Ar v
 Print debugging information about variable assignment.
 .It Ar x
@@ -293,7 +296,7 @@
 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.
+the Makefile and then works upward towards the root of the file system.
 If the search is successful, then the resulting directory replaces the
 .Qq \&.../
 specification in the
@@ -334,20 +337,39 @@
 Rather than re-building a target as specified in the makefile, create it
 or update its modification time to make it appear up-to-date.
 .It Fl V Ar variable
-Print
-.Nm Ns 's
-idea of the value of
-.Ar variable ,
-in the global context.
+Print the value of
+.Ar variable .
 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.
+The value printed is extracted from the global context after all
+makefiles have been read.
+By default, the raw variable contents (which may
+include additional unexpanded variable references) are shown.
 If
 .Ar variable
 contains a
 .Ql \&$
-then the value will be expanded before printing.
+then the value will be recursively expanded to its complete resultant
+text before printing.
+The expanded value will also be printed if
+.Va .MAKE.EXPAND_VARIABLES
+is set to true and
+the
+.Fl dV
+option has not been used to override it.
+Note that loop-local and target-local variables, as well as values
+taken temporarily by global variables during makefile processing, are
+not accessible via this option.
+The
+.Fl dv
+debug mode can be used to see these at the cost of generating
+substantial extraneous output.
+.It Fl v Ar variable
+Like
+.Fl V
+but the variable is always expanded to its complete value.
 .It Fl W
 Treat any warnings during makefile parsing as errors.
 .It Fl w
@@ -657,7 +679,7 @@
 .Bl -tag -width ".ARCHIVE" -offset indent
 .It Va .ALLSRC
 The list of all sources for this target; also known as
-.Ql Va \&\*[Gt] .
+.Ql Va \&> .
 .It Va .ARCHIVE
 The name of the archive file; also known as
 .Ql Va \&! .
@@ -666,7 +688,7 @@
 target is to be transformed (the
 .Dq implied
 source); also known as
-.Ql Va \&\*[Lt] .
+.Ql Va \&< .
 It is not defined in explicit rules.
 .It Va .MEMBER
 The name of the archive member; also known as
@@ -685,12 +707,15 @@
 .It Va .TARGET
 The name of the target; also known as
 .Ql Va @ .
+For compatibility with other makes this is an alias for
+.Ic .ARCHIVE
+in archive member rules.
 .El
 .Pp
 The shorter forms
-.Ql ( Va \*[Gt] ,
+.Ql ( Va > ,
 .Ql Va \&! ,
-.Ql Va \*[Lt] ,
+.Ql Va < ,
 .Ql Va % ,
 .Ql Va \&? ,
 .Ql Va * ,
@@ -784,6 +809,10 @@
 A boolean that controls the default behavior of the
 .Fl V
 option.
+If true, variable values printed with
+.Fl V
+are fully expanded; if false, the raw variable contents (which may
+include additional unexpanded variable references) are shown.
 .It Va .MAKE.EXPORTED
 The list of variables exported by
 .Nm .
@@ -854,7 +883,7 @@
 .Nm
 runs in.
 It can contain a number of keywords:
-.Bl -hang -width ignore-cmd
+.Bl -hang -width missing-filemon=bf.
 .It Pa compat
 Like
 .Fl B ,
@@ -878,8 +907,19 @@
 This can be overridden by setting
 .Va bf
 to a value which represents True.
+.It Pa missing-meta= Ar bf
+If
+.Va bf
+is True, then a missing .meta file makes the target out-of-date.
+.It Pa missing-filemon= Ar bf
+If
+.Va bf
+is True, then missing filemon data makes the target out-of-date.
+.It Pa nofilemon
+Do not use
+.Xr filemon 4 .
 .It Pa env
-For debugging, it can be useful to inlcude the environment
+For debugging, it can be useful to include the environment
 in the .meta file.
 .It Pa verbose
 If in "meta" mode, print a clue about the target being built.
@@ -921,6 +961,12 @@
 because the contents are expected to change over time.
 The default list includes:
 .Ql Pa /dev /etc /proc /tmp /var/run /var/tmp
+.It Va .MAKE.META.IGNORE_PATTERNS
+Provides a list of patterns to match against pathnames.
+Ignore any that match.
+.It Va .MAKE.META.IGNORE_FILTER
+Provides a list of variable modifiers to apply to each pathname.
+Ignore if the expansion is an empty string.
 .It Va .MAKE.META.PREFIX
 Defines the message printed for each meta file updated in "meta verbose" mode.
 The default value is:
@@ -929,7 +975,7 @@
 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
 .Ql Ev MAKEFLAGS .
-This behaviour can be disabled by assigning an empty value to
+This behavior can be disabled by assigning an empty value to
 .Ql Va .MAKEOVERRIDES
 within a makefile.
 Extra variables can be exported from a makefile
@@ -952,10 +998,35 @@
 .It Va .MAKE.PPID
 The parent process-id of
 .Nm .
+.It Va .MAKE.SAVE_DOLLARS
+value should be a boolean that controls whether
+.Ql $$
+are preserved when doing
+.Ql :=
+assignments.
+The default is false, for backwards compatibility.
+Set to true for compatability with other makes.
+If set to false,
+.Ql $$
+becomes
+.Ql $
+per normal evaluation rules.
 .It Va MAKE_PRINT_VAR_ON_ERROR
 When
 .Nm
-stops due to an error, it prints its name and the value of
+stops due to an error, it sets
+.Ql Va .ERROR_TARGET
+to the name of the target that failed,
+.Ql Va .ERROR_CMD
+to the commands of the failed target,
+and in "meta" mode, it also sets
+.Ql Va .ERROR_CWD
+to the
+.Xr getcwd 3 ,
+and
+.Ql Va .ERROR_META_FILE
+to the path of the meta file (if any) describing the failed target.
+It then prints its name and the value of
 .Ql Va .CURDIR
 as well as the value of any variables named in
 .Ql Va MAKE_PRINT_VAR_ON_ERROR .
@@ -1055,7 +1126,7 @@
 to the value of
 .Ql Ev PWD
 instead.
-This behaviour is disabled if
+This behavior is disabled if
 .Ql Ev MAKEOBJDIRPREFIX
 is set or
 .Ql Ev MAKEOBJDIR
@@ -1125,7 +1196,7 @@
 As a consequence of the way values are split into words, matched,
 and then joined, a construct like
 .Dl ${VAR:M*}
-will normalise the inter-word spacing, removing all leading and
+will normalize the inter-word spacing, removing all leading and
 trailing space, and converting multiple consecutive spaces
 to single spaces.
 .
@@ -1145,7 +1216,7 @@
 The results will be different each time you are referring to the
 modified variable; use the assignment with expansion
 .Pq Ql Cm \&:=
-to prevent such behaviour.
+to prevent such behavior.
 For example,
 .Bd -literal -offset indent
 LIST=			uno due tre quattro
@@ -1171,18 +1242,28 @@
 .Nm .
 .It Cm \&:R
 Replaces each word in the variable with everything but its suffix.
-.It Cm \&:gmtime
+.It Cm \&:range[=count]
+The value is an integer sequence representing the words of the original
+value, or the supplied
+.Va count .
+.It Cm \&:gmtime[=utc]
 The value is a format string for
 .Xr strftime 3 ,
-using the current
+using
 .Xr gmtime 3 .
+If a
+.Va utc
+value is not provided or is 0, the current time is used.
 .It Cm \&:hash
-Compute a 32bit hash of the value and encode it as hex digits.
-.It Cm \&:localtime
+Compute a 32-bit hash of the value and encode it as hex digits.
+.It Cm \&:localtime[=utc]
 The value is a format string for
 .Xr strftime 3 ,
-using the current
+using
 .Xr localtime 3 .
+If a
+.Va utc
+value is not provided or is 0, the current time is used.
 .It Cm \&:tA
 Attempt to convert variable to an absolute path using
 .Xr realpath 3 ,
@@ -1243,7 +1324,7 @@
 Inside
 .Ar new_string ,
 an ampersand
-.Pq Ql \*[Am]
+.Pq Ql &
 is replaced by
 .Ar old_string
 (without any
@@ -1382,6 +1463,27 @@
 .Pp
 However a single character variable is often more readable:
 .Dl ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}
+.It Cm \&:_[=var]
+Save the current variable value in
+.Ql $_
+or the named
+.Va var
+for later reference.
+Example usage:
+.Bd -literal -offset indent
+M_cmpv.units = 1 1000 1000000
+M_cmpv = S,., ,g:_:range:@i at + $${_:[-$$i]} \&\\
+\\* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh
+
+.Dv .if ${VERSION:${M_cmpv}} < ${3.1.12:L:${M_cmpv}}
+
+.Ed
+Here
+.Ql $_
+is used to save the result of the
+.Ql :S
+modifier which is later referenced using the index values from
+.Ql :range .
 .It Cm \&:U Ns Ar newval
 If the variable is undefined
 .Ar newval
@@ -1455,7 +1557,7 @@
 .Pp
 Ordinarily, a value is treated as a sequence of words
 delimited by white space.
-Some modifiers suppress this behaviour,
+Some modifiers suppress this behavior,
 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,
@@ -1541,6 +1643,7 @@
 .Nm
 .Ql include file ...
 is also accepted.
+.Pp
 If the include statement is written as
 .Cm .-include
 or as
@@ -1547,6 +1650,13 @@
 .Cm .sinclude
 then errors locating and/or opening include files are ignored.
 .Pp
+If the include statement is written as
+.Cm .dinclude
+not only are errors locating and/or opening include files ignored,
+but stale dependencies within the included file will be ignored
+just like
+.Va .MAKE.DEPENDFILE .
+.Pp
 Conditional expressions are also preceded by a single dot as the first
 character of a line.
 The possible conditionals are as follows:
@@ -1582,6 +1692,10 @@
 used by
 .Nm
 internally.
+.It Ic .export-literal Ar variable ...
+The same as
+.Ql .export-env ,
+except that variables in the value are not expanded.
 .It Ic .info Ar message
 The message is printed along with the name of the makefile and line number.
 .It Ic .undef Ar variable
@@ -1674,7 +1788,7 @@
 .Bl -tag -width "Cm XX"
 .It Cm \&|\&|
 Logical OR.
-.It Cm \&\*[Am]\*[Am]
+.It Cm \&&&
 Logical
 .Tn AND ;
 of higher precedence than
@@ -1691,7 +1805,7 @@
 may be used to logically negate an entire
 conditional.
 It is of higher precedence than
-.Ql Ic \&\*[Am]\*[Am] .
+.Ql Ic \&&& .
 .Pp
 The value of
 .Ar expression
@@ -1965,6 +2079,14 @@
 .Ic .DEFAULT Ns 's
 commands is set
 to the target's own name.
+.It Ic .DELETE_ON_ERROR
+If this target is present in the makefile, it globally causes make to
+delete targets whose commands fail.
+(By default, only targets whose commands are interrupted during
+execution are deleted.
+This is the historical behavior.)
+This setting can be used to help prevent half-finished or malformed
+targets from being left around and corrupting future rebuilds.
 .It Ic .END
 Any command lines attached to this target are executed after everything
 else is done.
@@ -2079,7 +2201,7 @@
 pairs.
 .Bl -tag -width hasErrCtls
 .It Ar name
-This is the minimal specification, used to select one of the builtin
+This is the minimal specification, used to select one of the built-in
 shell specs;
 .Ar sh ,
 .Ar ksh ,

Modified: trunk/contrib/bmake/make.c
===================================================================
--- trunk/contrib/bmake/make.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/make.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.c,v 1.92 2015/10/11 04:51:24 sjg Exp $	*/
+/*	$NetBSD: make.c,v 1.96 2016/11/10 23:41:58 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.92 2015/10/11 04:51:24 sjg Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.96 2016/11/10 23:41:58 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -76,7 +76,7 @@
 #if 0
 static char sccsid[] = "@(#)make.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: make.c,v 1.92 2015/10/11 04:51:24 sjg Exp $");
+__RCSID("$NetBSD: make.c,v 1.96 2016/11/10 23:41:58 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -308,7 +308,7 @@
 	if (DEBUG(MAKE)) {
 	    if (gn->cmgn != NULL && gn->mtime < gn->cmgn->mtime) {
 		fprintf(debug_file, "modified before source %s...",
-		    gn->cmgn->path);
+		    gn->cmgn->path ? gn->cmgn->path : gn->cmgn->name);
 	    } else if (gn->mtime == 0) {
 		fprintf(debug_file, "non-existent and no sources...");
 	    } else {
@@ -482,10 +482,9 @@
 	    if (gn->uname == NULL) {
 		gn->uname = gn->name;
 	    } else {
-		if (gn->name)
-		    free(gn->name);
+		free(gn->name);
 	    }
-	    gn->name = Var_Subst(NULL, gn->uname, pgn, FALSE, TRUE);
+	    gn->name = Var_Subst(NULL, gn->uname, pgn, VARF_WANTRES);
 	    if (gn->name && gn->uname && strcmp(gn->name, gn->uname) != 0) {
 		/* See if we have a target for this node. */
 		tgn = Targ_FindNode(gn->name, TARG_NOCREATE);
@@ -692,8 +691,7 @@
     checked++;
 
     cname = Var_Value(TARGET, cgn, &p1);
-    if (p1)
-	free(p1);
+    free(p1);
 
     if (DEBUG(MAKE))
 	fprintf(debug_file, "Make_Update: %s%s\n", cgn->name, cgn->cohort_num);
@@ -838,8 +836,7 @@
 		    Var_Set(PREFIX, cpref, pgn, 0);
 	    }
 	}
-	if (p1)
-	    free(p1);
+	free(p1);
 	Lst_Close(cgn->iParents);
     }
 }
@@ -907,8 +904,7 @@
 	}
 	if (allsrc != NULL)
 		Var_Append(ALLSRC, allsrc, pgn);
-	if (p2)
-	    free(p2);
+	free(p2);
 	if (pgn->type & OP_JOIN) {
 	    if (cgn->made == MADE) {
 		Var_Append(OODATE, child, pgn);
@@ -934,8 +930,7 @@
 	     */
 	    Var_Append(OODATE, child, pgn);
 	}
-	if (p1)
-	    free(p1);
+	free(p1);
     }
     return (0);
 }
@@ -981,8 +976,7 @@
     if (gn->type & OP_JOIN) {
 	char *p1;
 	Var_Set(TARGET, Var_Value(ALLSRC, gn, &p1), gn, 0);
-	if (p1)
-	    free(p1);
+	free(p1);
     }
     gn->flags |= DONE_ALLSRC;
 }

Modified: trunk/contrib/bmake/make.h
===================================================================
--- trunk/contrib/bmake/make.h	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/make.h	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.96 2015/09/21 21:50:16 pooka Exp $	*/
+/*	$NetBSD: make.h,v 1.103 2017/07/20 19:29:54 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -88,6 +88,7 @@
 #include <sys/param.h>
 
 #include <ctype.h>
+#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #ifdef HAVE_STRING_H
@@ -98,6 +99,10 @@
 #include <unistd.h>
 #include <sys/cdefs.h>
 
+#ifndef FD_CLOEXEC
+#define FD_CLOEXEC 1
+#endif
+
 #if defined(__GNUC__)
 #define	MAKE_GNUC_PREREQ(x, y)						\
 	((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) ||			\
@@ -194,6 +199,7 @@
 #define DONE_ALLSRC	0x40	/* We do it once only */
 #define CYCLE		0x1000  /* Used by MakePrintStatus */
 #define DONECYCLE	0x2000  /* Used by MakePrintStatus */
+#define INTERNAL	0x4000	/* Internal use only */
     enum enum_made {
 	UNMADE, DEFERRED, REQUESTED, BEINGMADE,
 	MADE, UPTODATE, ERROR, ABORTED
@@ -383,6 +389,7 @@
 extern Boolean  noExecute;    	/* True if should execute nothing */
 extern Boolean  noRecursiveExecute;    	/* True if should execute nothing */
 extern Boolean  allPrecious;   	/* True if every target is precious */
+extern Boolean  deleteOnError;	/* True if failed targets should be deleted */
 extern Boolean  keepgoing;    	/* True if should continue on unaffected
 				 * portions of the graph when have an error
 				 * in one portion */
@@ -497,10 +504,16 @@
 void Check_Cwd(const char **);
 void PrintOnError(GNode *, const char *);
 void Main_ExportMAKEFLAGS(Boolean);
-Boolean Main_SetObjdir(const char *);
+Boolean Main_SetObjdir(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
 int mkTempFile(const char *, char **);
 int str2Lst_Append(Lst, char *, const char *);
+int cached_lstat(const char *, void *);
+int cached_stat(const char *, void *);
 
+#define	VARF_UNDEFERR	1
+#define	VARF_WANTRES	2
+#define	VARF_ASSIGN	4
+
 #ifdef __GNUC__
 #define UNCONST(ptr)	({ 		\
     union __unconst {			\
@@ -530,4 +543,10 @@
 #define PATH_MAX	MAXPATHLEN
 #endif
 
+#if defined(SYSV)
+#define KILLPG(pid, sig)	kill(-(pid), (sig))
+#else
+#define KILLPG(pid, sig)	killpg((pid), (sig))
+#endif
+
 #endif /* _MAKE_H_ */

Modified: trunk/contrib/bmake/make_malloc.c
===================================================================
--- trunk/contrib/bmake/make_malloc.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/make_malloc.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: make_malloc.c,v 1.10 2012/06/20 17:46:28 sjg Exp $	*/
+/*	$NetBSD: make_malloc.c,v 1.11 2017/04/16 20:20:24 dholland 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.10 2012/06/20 17:46:28 sjg Exp $");
+__RCSID("$NetBSD: make_malloc.c,v 1.11 2017/04/16 20:20:24 dholland Exp $");
 #endif
 
 #include <stdio.h>
@@ -39,13 +39,13 @@
 #include "make.h"
 
 #ifndef USE_EMALLOC
-static void enomem(void) MAKE_ATTR_DEAD;
+static MAKE_ATTR_DEAD void enomem(void);
 
 /*
  * enomem --
  *	die when out of memory.
  */
-static void
+static MAKE_ATTR_DEAD void
 enomem(void)
 {
 	(void)fprintf(stderr, "%s: %s.\n", progname, strerror(ENOMEM));

Modified: trunk/contrib/bmake/meta.c
===================================================================
--- trunk/contrib/bmake/meta.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/meta.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.c,v 1.41 2015/11/30 23:37:56 sjg Exp $ */
+/*      $NetBSD: meta.c,v 1.68 2017/07/09 04:54:00 sjg Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -6,7 +6,7 @@
  * --sjg
  */
 /*
- * Copyright (c) 2009-2010, Juniper Networks, Inc.
+ * Copyright (c) 2009-2016, Juniper Networks, Inc.
  * Portions Copyright (c) 2009, John Birrell.
  * 
  * Redistribution and use in source and binary forms, with or without
@@ -37,8 +37,8 @@
 #endif
 #include <sys/stat.h>
 #include <sys/ioctl.h>
-#include <fcntl.h>
 #ifdef HAVE_LIBGEN_H
+#ifdef HAVE_LIBGEN_H
 #include <libgen.h>
 #elif !defined(HAVE_DIRNAME)
 char * dirname(char *);
@@ -60,18 +60,30 @@
 
 static BuildMon Mybm;			/* for compat */
 static Lst metaBailiwick;		/* our scope of control */
+static char *metaBailiwickStr;		/* string storage for the list */
 static Lst metaIgnorePaths;		/* paths we deliberately ignore */
+static char *metaIgnorePathsStr;	/* string storage for the list */
 
 #ifndef MAKE_META_IGNORE_PATHS
 #define MAKE_META_IGNORE_PATHS ".MAKE.META.IGNORE_PATHS"
 #endif
+#ifndef MAKE_META_IGNORE_PATTERNS
+#define MAKE_META_IGNORE_PATTERNS ".MAKE.META.IGNORE_PATTERNS"
+#endif
+#ifndef MAKE_META_IGNORE_FILTER
+#define MAKE_META_IGNORE_FILTER ".MAKE.META.IGNORE_FILTER"
+#endif
 
 Boolean useMeta = FALSE;
 static Boolean useFilemon = FALSE;
 static Boolean writeMeta = FALSE;
+static Boolean metaMissing = FALSE;	/* oodate if missing */
+static Boolean filemonMissing = FALSE;	/* oodate if missing */
 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 metaIgnorePatterns = FALSE; /* do we need to do pattern matches */
+static Boolean metaIgnoreFilter = FALSE;   /* do we have more complex filtering? */
 static Boolean metaCurdirOk = FALSE;	/* write .meta in .CURDIR Ok? */
 static Boolean metaSilent = FALSE;	/* if we have a .meta be SILENT */
 
@@ -148,8 +160,8 @@
 	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);
+    (void)fcntl(pbm->mon_fd, F_SETFD, FD_CLOEXEC);
+    (void)fcntl(pbm->filemon_fd, F_SETFD, FD_CLOEXEC);
 }
 
 /*
@@ -156,28 +168,33 @@
  * Read the build monitor output file and write records to the target's
  * metadata file.
  */
-static void
+static int
 filemon_read(FILE *mfp, int fd)
 {
     char buf[BUFSIZ];
     int n;
+    int error;
 
     /* Check if we're not writing to a meta data file.*/
     if (mfp == NULL) {
 	if (fd >= 0)
 	    close(fd);			/* not interested */
-	return;
+	return 0;
     }
     /* rewind */
     (void)lseek(fd, (off_t)0, SEEK_SET);
 
+    error = 0;
     fprintf(mfp, "\n-- filemon acquired metadata --\n");
 
     while ((n = read(fd, buf, sizeof(buf))) > 0) {
-	fwrite(buf, 1, n, mfp);
+	if ((int)fwrite(buf, 1, n, mfp) < n)
+	    error = EIO;
     }
     fflush(mfp);
-    close(fd);
+    if (close(fd) < 0)
+	error = errno;
+    return error;
 }
 #endif
 
@@ -225,27 +242,16 @@
 }
 
 static char *
-meta_name(struct GNode *gn, char *mname, size_t mnamelen,
+meta_name(char *mname, size_t mnamelen,
 	  const char *dname,
-	  const char *tname)
+	  const char *tname,
+	  const char *cwd)
 {
     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
@@ -254,7 +260,7 @@
      * basename as given to us.
      */
     if ((cp = strrchr(tname, '/'))) {
-	if (realpath(tname, buf)) {
+	if (cached_realpath(tname, buf)) {
 	    if ((rp = strrchr(buf, '/'))) {
 		rp++;
 		cp++;
@@ -299,10 +305,6 @@
 	}
     }
     free(tp);
-    for (i--; i >= 0; i--) {
-	if (p[i])
-	    free(p[i]);
-    }
     return (mname);
 }
 
@@ -328,7 +330,7 @@
     }
     cp = strchr(cmd, '$');
     if ((cp)) {
-	mp = Var_Subst(NULL, cmd, gn, FALSE, TRUE);
+	mp = Var_Subst(NULL, cmd, gn, VARF_WANTRES);
 	cmd = mp;
     }
     cp2 = strstr(cmd, p_make);
@@ -353,8 +355,7 @@
 	    }
 	}
     }
-    if (mp)
-	free(mp);
+    free(mp);
     return (rc);
 }
 
@@ -371,11 +372,10 @@
     char *cp = NULL;
 
     if (strchr(cmd, '$')) {
-	cmd = cp = Var_Subst(NULL, cmd, mfp->gn, FALSE, TRUE);
+	cmd = cp = Var_Subst(NULL, cmd, mfp->gn, VARF_WANTRES);
     }
     fprintf(mfp->fp, "CMD %s\n", cmd);
-    if (cp)
-	free(cp);
+    free(cp);
     return 0;
 }
 
@@ -384,29 +384,26 @@
  */
 #define SKIP_META_TYPE(_type) do { \
     if ((gn->type & __CONCAT(OP_, _type))) {	\
-	if (DEBUG(META)) { \
+	if (verbose) { \
 	    fprintf(debug_file, "Skipping meta for %s: .%s\n", \
 		    gn->name, __STRING(_type));		       \
 	} \
-	return (NULL); \
+	return FALSE; \
     } \
 } while (0)
 
-static FILE *
-meta_create(BuildMon *pbm, GNode *gn)
+
+/*
+ * Do we need/want a .meta file ?
+ */
+static Boolean
+meta_needed(GNode *gn, const char *dname,
+	     char *objdir, int verbose)
 {
-    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;
 
+    if (verbose)
+	verbose = DEBUG(META);
     
     /* This may be a phony node which we don't want meta data for... */
     /* Skip .meta for .BEGIN, .END, .ERROR etc as well. */
@@ -419,54 +416,76 @@
 	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))
+	if (verbose)
 	    fprintf(debug_file, "Skipping meta for %s: no commands\n",
 		    gn->name);
-	goto out;
+	return FALSE;
     }
+    if ((gn->type & (OP_META|OP_SUBMAKE)) == OP_SUBMAKE) {
+	/* OP_SUBMAKE is a bit too aggressive */
+	if (Lst_ForEach(gn->commands, is_submake, gn)) {
+	    if (DEBUG(META))
+		fprintf(debug_file, "Skipping meta for %s: .SUBMAKE\n",
+			gn->name);
+	    return FALSE;
+	}
+    }
 
+    /* The object directory may not exist. Check it.. */
+    if (cached_stat(dname, &fs) != 0) {
+	if (verbose)
+	    fprintf(debug_file, "Skipping meta for %s: no .OBJDIR\n",
+		    gn->name);
+	return FALSE;
+    }
+
     /* make sure these are canonical */
-    if (realpath(dname, objdir))
+    if (cached_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))
+	if (verbose)
 	    fprintf(debug_file, "Skipping meta for %s: .OBJDIR == .CURDIR\n",
 		    gn->name);
-	goto out;
+	return FALSE;
     }
-    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;
-	}
-    }
+    return TRUE;
+}
 
+    
+static FILE *
+meta_create(BuildMon *pbm, GNode *gn)
+{
+    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;
+
+    mf.fp = NULL;
+    i = 0;
+
+    dname = Var_Value(".OBJDIR", gn, &p[i++]);
+    tname = Var_Value(TARGET, gn, &p[i++]);
+
+    /* if this succeeds objdir is realpath of dname */
+    if (!meta_needed(gn, dname, objdir, TRUE))
+	goto out;
+    dname = objdir;
+
     if (metaVerbose) {
 	char *mp;
 
 	/* Describe the target we are building */
-	mp = Var_Subst(NULL, "${" MAKE_META_PREFIX "}", gn, FALSE, TRUE);
+	mp = Var_Subst(NULL, "${" MAKE_META_PREFIX "}", gn, VARF_WANTRES);
 	if (*mp)
 	    fprintf(stdout, "%s\n", mp);
 	free(mp);
@@ -480,15 +499,12 @@
 
     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);
+    fname = meta_name(pbm->meta_fname, sizeof(pbm->meta_fname),
+		      dname, tname, objdir);
 
 #ifdef DEBUG_META_MODE
     if (DEBUG(META))
@@ -524,8 +540,7 @@
     }
  out:
     for (i--; i >= 0; i--) {
-	if (p[i])
-	    free(p[i]);
+	free(p[i]);
     }
 
     return (mf.fp);
@@ -558,6 +573,10 @@
 }
 
 
+#define get_mode_bf(bf, token) \
+    if ((cp = strstr(make_mode, token))) \
+	bf = boolValue(&cp[sizeof(token) - 1])
+
 /*
  * Initialization we need after reading makefiles.
  */
@@ -580,17 +599,13 @@
 	    writeMeta = FALSE;
 	if (strstr(make_mode, "nofilemon"))
 	    useFilemon = FALSE;
-	if ((cp = strstr(make_mode, "curdirok="))) {
-	    metaCurdirOk = boolValue(&cp[9]);
-	}
-	if ((cp = strstr(make_mode, "silent="))) {
-	    metaSilent = boolValue(&cp[7]);
-	}
 	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 (useFilemon)
+	    get_mode_bf(filemonMissing, "missing-filemon=");
+	get_mode_bf(metaCurdirOk, "curdirok=");
+	get_mode_bf(metaMissing, "missing-meta=");
+	get_mode_bf(metaSilent, "silent=");
     }
     if (metaVerbose && !Var_Exists(MAKE_META_PREFIX, VAR_GLOBAL)) {
 	/*
@@ -609,10 +624,10 @@
      * 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,
-		   FALSE, TRUE);
-    if (cp) {
-	str2Lst_Append(metaBailiwick, cp, NULL);
+    metaBailiwickStr = Var_Subst(NULL, "${.MAKE.META.BAILIWICK:O:u:tA}",
+	VAR_GLOBAL, VARF_WANTRES);
+    if (metaBailiwickStr) {
+	str2Lst_Append(metaBailiwick, metaBailiwickStr, NULL);
     }
     /*
      * We ignore any paths that start with ${.MAKE.META.IGNORE_PATHS}
@@ -620,12 +635,26 @@
     metaIgnorePaths = Lst_Init(FALSE);
     Var_Append(MAKE_META_IGNORE_PATHS,
 	       "/dev /etc /proc /tmp /var/run /var/tmp ${TMPDIR}", VAR_GLOBAL);
-    cp = Var_Subst(NULL,
+    metaIgnorePathsStr = Var_Subst(NULL,
 		   "${" MAKE_META_IGNORE_PATHS ":O:u:tA}", VAR_GLOBAL,
-		   FALSE, TRUE);
-    if (cp) {
-	str2Lst_Append(metaIgnorePaths, cp, NULL);
+		   VARF_WANTRES);
+    if (metaIgnorePathsStr) {
+	str2Lst_Append(metaIgnorePaths, metaIgnorePathsStr, NULL);
     }
+
+    /*
+     * We ignore any paths that match ${.MAKE.META.IGNORE_PATTERNS}
+     */
+    cp = NULL;
+    if (Var_Value(MAKE_META_IGNORE_PATTERNS, VAR_GLOBAL, &cp)) {
+	metaIgnorePatterns = TRUE;
+	free(cp);
+    }
+    cp = NULL;
+    if (Var_Value(MAKE_META_IGNORE_FILTER, VAR_GLOBAL, &cp)) {
+	metaIgnoreFilter = TRUE;
+	free(cp);
+    }
 }
 
 /*
@@ -693,13 +722,13 @@
 
     if (job != NULL) {
 	pbm = &job->bm;
-    } else {
 	if (!gn)
 	    gn = job->node;
+    } else {
 	pbm = &Mybm;
     }
     if (pbm->mfp != NULL) {
-	fprintf(pbm->mfp, "*** Error code %d%s\n",
+	fprintf(pbm->mfp, "\n*** Error code %d%s\n",
 		status,
 		(flags & JOB_IGNERR) ?
 		"(ignored)" : "");
@@ -709,7 +738,7 @@
     }
     getcwd(cwd, sizeof(cwd));
     Var_Set(".ERROR_CWD", cwd, VAR_GLOBAL, 0);
-    if (pbm && pbm->meta_fname[0]) {
+    if (pbm->meta_fname[0]) {
 	Var_Set(".ERROR_META_FILE", pbm->meta_fname, VAR_GLOBAL, 0);
     }
     meta_job_finish(job);
@@ -734,7 +763,7 @@
 		char *cp2;
 
 		meta_prefix = Var_Subst(NULL, "${" MAKE_META_PREFIX "}",
-					VAR_GLOBAL, FALSE, TRUE);
+					VAR_GLOBAL, VARF_WANTRES);
 		if ((cp2 = strchr(meta_prefix, '$')))
 		    meta_prefix_len = cp2 - meta_prefix;
 		else
@@ -750,27 +779,36 @@
     }
 }
 
-void
+int
 meta_cmd_finish(void *pbmp)
 {
-#ifdef USE_FILEMON
+    int error = 0;
     BuildMon *pbm = pbmp;
+    int x;
 
     if (!pbm)
 	pbm = &Mybm;
 
+#ifdef USE_FILEMON
     if (pbm->filemon_fd >= 0) {
-	close(pbm->filemon_fd);
-	filemon_read(pbm->mfp, pbm->mon_fd);
+	if (close(pbm->filemon_fd) < 0)
+	    error = errno;
+	x = filemon_read(pbm->mfp, pbm->mon_fd);
+	if (error == 0 && x != 0)
+	    error = x;
 	pbm->filemon_fd = pbm->mon_fd = -1;
-    }
+    } else
 #endif
+	fprintf(pbm->mfp, "\n");	/* ensure end with newline */
+    return error;
 }
 
-void
+int
 meta_job_finish(Job *job)
 {
     BuildMon *pbm;
+    int error = 0;
+    int x;
 
     if (job != NULL) {
 	pbm = &job->bm;
@@ -778,13 +816,25 @@
 	pbm = &Mybm;
     }
     if (pbm->mfp != NULL) {
-	meta_cmd_finish(pbm);
-	fclose(pbm->mfp);
+	error = meta_cmd_finish(pbm);
+	x = fclose(pbm->mfp);
+	if (error == 0 && x != 0)
+	    error = errno;
 	pbm->mfp = NULL;
 	pbm->meta_fname[0] = '\0';
     }
+    return error;
 }
 
+void
+meta_finish(void)
+{
+    Lst_Destroy(metaBailiwick, NULL);
+    free(metaBailiwickStr);
+    Lst_Destroy(metaIgnorePaths, NULL);
+    free(metaIgnorePathsStr);
+}
+
 /*
  * Fetch a full line from fp - growing bufp if needed
  * Return length in bufp.
@@ -813,6 +863,8 @@
 	    newsz = ROUNDUP((fs.st_size / 2), BUFSIZ);
 	    if (newsz <= bufsz)
 		newsz = ROUNDUP(fs.st_size, BUFSIZ);
+	    if (newsz <= bufsz)
+		return x;		/* truncated */
 	    if (DEBUG(META)) 
 		fprintf(debug_file, "growing buffer %u -> %u\n",
 			(unsigned)bufsz, (unsigned)newsz);
@@ -830,6 +882,7 @@
     return 0;
 }
 
+/* Lst_ForEach wants 1 to stop search */
 static int
 prefix_match(void *p, void *q)
 {
@@ -840,7 +893,33 @@
     return (0 == strncmp(path, prefix, n));
 }
 
+/*
+ * looking for exact or prefix/ match to
+ * Lst_Find wants 0 to stop search
+ */
 static int
+path_match(const void *p, const void *q)
+{
+    const char *prefix = q;
+    const char *path = p;
+    size_t n = strlen(prefix);
+    int rc;
+
+    if ((rc = strncmp(path, prefix, n)) == 0) {
+	switch (path[n]) {
+	case '\0':
+	case '/':
+	    break;
+	default:
+	    rc = 1;
+	    break;
+	}
+    }
+    return rc;
+}
+
+/* Lst_Find wants 0 to stop search */
+static int
 string_match(const void *p, const void *q)
 {
     const char *p1 = p;
@@ -850,6 +929,67 @@
 }
 
 
+static int
+meta_ignore(GNode *gn, const char *p)
+{
+    char fname[MAXPATHLEN];
+
+    if (p == NULL)
+	return TRUE;
+
+    if (*p == '/') {
+	cached_realpath(p, fname); /* clean it up */
+	if (Lst_ForEach(metaIgnorePaths, prefix_match, fname)) {
+#ifdef DEBUG_META_MODE
+	    if (DEBUG(META))
+		fprintf(debug_file, "meta_oodate: ignoring path: %s\n",
+			p);
+#endif
+	    return TRUE;
+	}
+    }
+
+    if (metaIgnorePatterns) {
+	char *pm;
+
+	Var_Set(".p.", p, gn, 0);
+	pm = Var_Subst(NULL,
+		       "${" MAKE_META_IGNORE_PATTERNS ":@m@${.p.:M$m}@}",
+		       gn, VARF_WANTRES);
+	if (*pm) {
+#ifdef DEBUG_META_MODE
+	    if (DEBUG(META))
+		fprintf(debug_file, "meta_oodate: ignoring pattern: %s\n",
+			p);
+#endif
+	    free(pm);
+	    return TRUE;
+	}
+	free(pm);
+    }
+
+    if (metaIgnoreFilter) {
+	char *fm;
+
+	/* skip if filter result is empty */
+	snprintf(fname, sizeof(fname),
+		 "${%s:L:${%s:ts:}}",
+		 p, MAKE_META_IGNORE_FILTER);
+	fm = Var_Subst(NULL, fname, gn, VARF_WANTRES);
+	if (*fm == '\0') {
+#ifdef DEBUG_META_MODE
+	    if (DEBUG(META))
+		fprintf(debug_file, "meta_oodate: ignoring filtered: %s\n",
+			p);
+#endif
+	    free(fm);
+	    return TRUE;
+	}
+	free(fm);
+    }
+    return FALSE;
+}
+
 /*
  * When running with 'meta' functionality, a target can be out-of-date
  * if any of the references in its meta data file is more recent.
@@ -889,6 +1029,8 @@
     char fname1[MAXPATHLEN];
     char fname2[MAXPATHLEN];
     char fname3[MAXPATHLEN];
+    const char *dname;
+    const char *tname;
     char *p;
     char *cp;
     char *link_src;
@@ -898,10 +1040,23 @@
     FILE *fp;
     Boolean needOODATE = FALSE;
     Lst missingFiles;
-    
+    char *pa[4];			/* >= possible uses */
+    int i;
+    int have_filemon = FALSE;
+
     if (oodate)
 	return oodate;		/* we're done */
 
+    i = 0;
+
+    dname = Var_Value(".OBJDIR", gn, &pa[i++]);
+    tname = Var_Value(TARGET, gn, &pa[i++]);
+
+    /* if this succeeds fname3 is realpath of dname */
+    if (!meta_needed(gn, dname, fname3, FALSE))
+	goto oodate_out;
+    dname = fname3;
+
     missingFiles = Lst_Init(FALSE);
 
     /*
@@ -912,7 +1067,7 @@
      */
     Make_DoAllVar(gn);
 
-    meta_name(gn, fname, sizeof(fname), NULL, NULL);
+    meta_name(fname, sizeof(fname), dname, tname, dname);
 
 #ifdef DEBUG_META_MODE
     if (DEBUG(META))
@@ -925,7 +1080,6 @@
 	int lineno = 0;
 	int lastpid = 0;
 	int pid;
-	int f = 0;
 	int x;
 	LstNode ln;
 	struct stat fs;
@@ -964,13 +1118,13 @@
 	    link_src = NULL;
 	    move_target = NULL;
 	    /* Find the start of the build monitor section. */
-	    if (!f) {
+	    if (!have_filemon) {
 		if (strncmp(buf, "-- filemon", 10) == 0) {
-		    f = 1;
+		    have_filemon = TRUE;
 		    continue;
 		}
 		if (strncmp(buf, "# buildmon", 10) == 0) {
-		    f = 1;
+		    have_filemon = TRUE;
 		    continue;
 		}
 	    }		    
@@ -982,7 +1136,7 @@
 		fprintf(debug_file, "%s: %d: %s\n", fname, lineno, buf);
 #endif
 	    strsep(&p, " ");
-	    if (f) {
+	    if (have_filemon) {
 		/*
 		 * We are in the 'filemon' output section.
 		 * Each record from filemon follows the general form:
@@ -1035,14 +1189,12 @@
 			ldir = Var_Value(ldir_vname, VAR_GLOBAL, &tp);
 			if (ldir) {
 			    strlcpy(latestdir, ldir, sizeof(latestdir));
-			    if (tp)
-				free(tp);
+			    free(tp);
 			}
 			ldir = Var_Value(lcwd_vname, VAR_GLOBAL, &tp);
 			if (ldir) {
 			    strlcpy(lcwd, ldir, sizeof(lcwd));
-			    if (tp)
-				free(tp);
+			    free(tp);
 			}
 		    }
 		    /* Skip past the pid. */
@@ -1119,12 +1271,19 @@
 		    /* 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);
-			    ln = NULL;	/* we're done with it */
+			/* remove any missingFiles entries that match p */
+			if ((ln = Lst_Find(missingFiles, p,
+					   path_match)) != NULL) {
+			    LstNode nln;
+			    char *tp;
+
+			    do {
+				nln = Lst_FindFrom(missingFiles, Lst_Succ(ln),
+						   p, path_match);
+				tp = Lst_Datum(ln);
+				Lst_Remove(missingFiles, ln);
+				free(tp);
+			    } while ((ln = nln) != NULL);
 			}
 		    }
 		    if (buf[0] == 'M') {
@@ -1187,9 +1346,12 @@
 		    if ((strstr("tmp", p)))
 			break;
 
-		    if ((link_src != NULL && lstat(p, &fs) < 0) ||
-			(link_src == NULL && stat(p, &fs) < 0)) {
-			Lst_AtEnd(missingFiles, bmake_strdup(p));
+		    if ((link_src != NULL && cached_lstat(p, &fs) < 0) ||
+			(link_src == NULL && cached_stat(p, &fs) < 0)) {
+			if (!meta_ignore(gn, p)) {
+			    if (Lst_Find(missingFiles, p, string_match) == NULL)
+				Lst_AtEnd(missingFiles, bmake_strdup(p));
+			}
 		    }
 		    break;
 		check_link_src:
@@ -1207,16 +1369,9 @@
 		     * be part of the dependencies because
 		     * they are _expected_ to change.
 		     */
-		    if (*p == '/' &&
-			Lst_ForEach(metaIgnorePaths, prefix_match, p)) {
-#ifdef DEBUG_META_MODE
-			if (DEBUG(META))
-			    fprintf(debug_file, "meta_oodate: ignoring: %s\n",
-				    p);
-#endif
+		    if (meta_ignore(gn, p))
 			break;
-		    }
-
+		    
 		    /*
 		     * The rest of the record is the file name.
 		     * Check if it's not an absolute path.
@@ -1255,7 +1410,7 @@
 			    if (DEBUG(META))
 				fprintf(debug_file, "%s: %d: looking for: %s\n", fname, lineno, *sdp);
 #endif
-			    if (stat(*sdp, &fs) == 0) {
+			    if (cached_stat(*sdp, &fs) == 0) {
 				found = 1;
 				p = *sdp;
 			    }
@@ -1272,7 +1427,7 @@
 				oodate = TRUE;
 			    } else if (S_ISDIR(fs.st_mode)) {
 				/* Update the latest directory. */
-				realpath(p, latestdir);
+				cached_realpath(p, latestdir);
 			    }
 			} else if (errno == ENOENT && *p == '/' &&
 				   strncmp(p, cwd, cwdlen) != 0) {
@@ -1280,9 +1435,8 @@
 			     * 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;
+			    if (Lst_Find(missingFiles, p, string_match) == NULL)
+				    Lst_AtEnd(missingFiles, bmake_strdup(p));
 			}
 		    }
 		    if (buf[0] == 'E') {
@@ -1320,7 +1474,7 @@
 			if (DEBUG(META))
 			    fprintf(debug_file, "%s: %d: cannot compare command using .OODATE\n", fname, lineno);
 		    }
-		    cmd = Var_Subst(NULL, cmd, gn, TRUE, TRUE);
+		    cmd = Var_Subst(NULL, cmd, gn, VARF_WANTRES|VARF_UNDEFERR);
 
 		    if ((cp = strchr(cmd, '\n'))) {
 			int n;
@@ -1382,15 +1536,33 @@
 		fprintf(debug_file, "%s: missing files: %s...\n",
 			fname, (char *)Lst_Datum(Lst_First(missingFiles)));
 	    oodate = TRUE;
-	    Lst_Destroy(missingFiles, (FreeProc *)free);
 	}
-    } else {
-	if ((gn->type & OP_META)) {
+	if (!oodate && !have_filemon && filemonMissing) {
 	    if (DEBUG(META))
-		fprintf(debug_file, "%s: required but missing\n", fname);
+		fprintf(debug_file, "%s: missing filemon data\n", fname);
 	    oodate = TRUE;
 	}
+    } else {
+	if (writeMeta && metaMissing) {
+	    cp = NULL;
+
+	    /* if target is in .CURDIR we do not need a meta file */
+	    if (gn->path && (cp = strrchr(gn->path, '/')) && cp > gn->path) {
+		if (strncmp(curdir, gn->path, (cp - gn->path)) != 0) {
+		    cp = NULL;		/* not in .CURDIR */
+		}
+	    }
+	    if (!cp) {
+		if (DEBUG(META))
+		    fprintf(debug_file, "%s: required but missing\n", fname);
+		oodate = TRUE;
+		needOODATE = TRUE;	/* assume the worst */
+	    }
+	}
     }
+
+    Lst_Destroy(missingFiles, (FreeProc *)free);
+
     if (oodate && needOODATE) {
 	/*
 	 * Target uses .OODATE which is empty; or we wouldn't be here.
@@ -1399,9 +1571,13 @@
 	 */
 	Var_Delete(OODATE, gn);
 	Var_Set(OODATE, Var_Value(ALLSRC, gn, &cp), gn, 0);
-	if (cp)
-	    free(cp);
+	free(cp);
     }
+
+ oodate_out:
+    for (i--; i >= 0; i--) {
+	free(pa[i]);
+    }
     return oodate;
 }
 
@@ -1427,8 +1603,8 @@
     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)fcntl(childPipe[0], F_SETFD, FD_CLOEXEC);
+    (void)fcntl(childPipe[1], F_SETFD, FD_CLOEXEC);
 }
 
 void
@@ -1453,6 +1629,7 @@
     while (fgets(buf, sizeof(buf), fp)) {
 	meta_job_output(NULL, buf, "");
 	printf("%s", buf);
+	fflush(stdout);
     }
     fclose(fp);
 }

Modified: trunk/contrib/bmake/meta.h
===================================================================
--- trunk/contrib/bmake/meta.h	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/meta.h	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.h,v 1.3 2013/03/23 05:31:29 sjg Exp $ */
+/*      $NetBSD: meta.h,v 1.5 2016/05/12 20:28:34 sjg Exp $ */
 
 /*
  * Things needed for 'meta' mode.
@@ -42,13 +42,14 @@
 
 struct Job;				/* not defined yet */
 void meta_init(void);
+void meta_finish(void);
 void meta_mode_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 *);
+int  meta_cmd_finish(void *);
+int  meta_job_finish(struct Job *);
 Boolean meta_oodate(GNode *, Boolean);
 void meta_compat_start(void);
 void meta_compat_child(void);

Modified: trunk/contrib/bmake/mk/ChangeLog
===================================================================
--- trunk/contrib/bmake/mk/ChangeLog	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/ChangeLog	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,3 +1,334 @@
+2017-06-30  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20170630
+
+	* meta.stage.mk: avoid triggering stage_* targets with nothing to do.
+
+2017-05-23  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* meta2deps.py: take special care of '..'
+
+2017-05-15  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20170515
+
+	* dirdeps.mk (DEP_EXPORT_VARS): on rare occasions it is
+	useful/necessary for a Makefile.depend file to export some knobs.
+	This is complicated when we are doing DIRDEPS_CACHE, so we will
+	handle export of any variables listed in DEP_EXPORT_VARS.
+
+2017-05-08  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20170505
+
+	* meta2deps.py: fix botched indenation.
+
+2017-05-05  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* sys/*.mk: Remove setting of MAKE it is unnecessary and
+	  in many cases wrong (basname rather than full path)
+
+	* scripts.mk (SCRIPTSGROUPS): make this more like files.mk and inc.mk
+
+	* init.mk: define realbuild to simplify logic in {lib,prog}.mk etc
+
+2017-05-01  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20170501
+
+	* doc.mk: fix typo in DOC_INSTALL_OWN
+
+	* inc.mk: handle INCGROUPS similar to freebsd
+
+	* files.mk: add something for files too
+
+	* add staging logic to lib.mk prog.mk etc.
+
+2017-04-24  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20170424
+
+	* dirdeps.mk: set NO_DIRDEPS when bootstrapping.
+	  also target of bootstrap-this when sed is needed should be ${_want:T}
+
+2017-04-18  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20170418
+
+	* auto.obj.mk: if using MAKEOBJDIRPREFIX check if it is a
+	  prefix match for .CURDIR - in which case .CURDIR *is* __objdir.
+
+2017-04-01  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20170401
+
+	* meta2deps.py: add is_src so we can check if obj dependency
+	  is also a src dependency.
+
+2017-03-26  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20170326
+
+	* meta.stage.mk: do nothing if NO_STAGING is defined.
+
+2017-03-24  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* auto.obj.mk: handle the case of __objdir=obj or obj.${MACHINE} etc.
+
+2017-03-18  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* mkopt.sh: treat WITH_*=NO like no; ie. WITHOUT_*
+
+2017-03-01  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20170301
+
+	* dirdeps.mk (_build_all_dirs): update this outside test for empty
+	  DIRDEPS.
+
+	* meta.stage.mk: allow multiple inclusion to the extent it makes
+	  sense.
+
+2017-02-14  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* prog.mk (install_links): depends on realinstall
+
+2017-02-12  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20170212
+
+	* dpadd.mk: avoid applying :T:R twice to DPLIBS entries
+
+2017-01-30  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20170130
+
+	* dirdeps.mk: use :range if we can.
+
+	* sys.vars.mk: provide M_cmpv if MAKE_VERSION >= 20170130
+
+	* meta2deps.py: clean paths without using realpath() where possible.
+	  fix sort_unique.
+
+2016-12-12  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20161212
+	
+	* meta2deps.py: set pid_cwd[pid] when we process 'C'hdir, 
+	rather than when we detect pid change.
+
+2016-12-07  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20161207
+
+	* meta.stage.mk: add stage_as_and_symlink for staging packages.
+	  We build foo.tgz stage_as foo-${VERSION}.tgz but want to be able
+	  to use foo.tgz to reference the latest staged version - so we
+	  make foo.tgz a symlink to it.
+	  Using a target to do both operations ensures we stay in sync.
+	
+2016-11-26  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20161126
+
+	* dirdeps.mk: set DIRDEPS_CACHE before we include local.dirdeps.mk
+	  so it can add dependencies.
+
+2016-10-10  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* dirdeps.mk: set DEP_* before we expand .MAKE.DEPENDFILE_PREFERENCE
+	  do that they can influence the result correctly.
+
+	* dirdeps.mk (${DIRDEPS_CACHE}): make sure we pass on TARGET_SPEC
+
+	* dirdeps.mk: Add ONLY_TARGET_SPEC_LIST and NOT_TARGET_SPEC_LIST
+	  similar to ONLY_MACHINE_LIST and NOT_MACHINE_LIST
+
+2016-10-05  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* dirdeps.mk: remove dependence on jot (normal situations anyway).
+	  Before we read another Makefile.depend* set DEP_* vars from
+	  _DEP_TARGET_SPEC in case it uses any of them with :=
+	  When bootstrapping, trim any ,* from extention of chosen _src
+	  Makefile.depend* to get the machine value we subst for.
+
+2016-09-30  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* dirdeps.mk: use TARGET_SPEC_VARS to qualify components added to
+	  DEP_SKIP_DIR and DEP_DIRDEPS_FILTER
+
+	* sys.mk: extract some bits to sys.{debug,vars}.mk
+	  for easier re-use by others.
+
+2016-09-23  Simon Gerraty  <sjg at sjg-mba13>
+
+	* lib.mk: Use ${PICO} for extension for PIC objects.
+	  default to .pico (like NetBSD) safe on case insensitive filesystem.
+
+2016-08-19  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* meta.sys.mk (META_COOKIE_TOUCH): use ${.OBJDIR}/${.TARGET:T} as default
+
+2016-08-15  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20160815
+
+	* dirdeps.mk (.MAKE.META.IGNORE_FILTER): set filter to only
+	consider Makefile.depend* when checking if DIRDEPS_CACHE is up-to-date.
+
+2016-08-13  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* meta.sys.mk (.MAKE.META.IGNORE_PATHS): 
+	  in meta mode we can ignore the mtime of makefiles
+
+2016-08-02  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20160802
+	
+	* lib.mk (libinstall): depends on beforinstall
+
+	* prog.mk (proginstall): depends on beforinstall
+	  patch from Lauri Tirkkonen
+	
+	* dirdeps.mk (bootstrap): When bootstrapping; creat
+	.MAKE.DEPENDFILE_DEFAULT and allow additional filtering via
+	.MAKE.DEPENDFILE_BOOTSTRAP_SED
+
+	* dirdeps.mk: move some comments to where they make sense.
+
+2016-07-27  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* dirdeps.mk (DIRDEPS_CACHE): no dirname.
+
+2016-06-02  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20160602
+	* meta.autodep.mk: when passing META_FILES to gendirdeps.mk
+	  do not apply :T to META_XTRAS
+	  patch from Bryan Drewery at FreeBSD.org.
+
+2016-05-30  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20160530
+	* meta.stage.mk: we assume ${CLEANFILES} gets .NOPATH
+	  make it so.
+	
+2016-05-12  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20160512
+
+	* dpadd.mk: always include local.dpadd.mk if it exists
+	  remove some things that better belong in local.dpadd.mk
+	  skip INCLUDES_* for staged libs unless SRC_* defined.
+
+	* own.mk: add INCLUDEDIR
+	
+2016-04-18  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* dirdeps.mk: when doing -f dirdeps.mk if target suppies no
+	  TARGET_MACHINE - :E will be empty or match part of path, use
+	  ${MACHINE}
+
+2016-04-07  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* meta.autodep.mk: issue a warning if UPDATE_DEPENDFILE=NO due to
+	  NO_FILEMON_COOKIE  
+
+	* dirdeps.mk: move the logic that allows for 
+	  make -f dirdeps.mk some/dir.${TARGET_SPEC}
+	  inside the check for !target(_DIRDEP_USE)
+
+2016-04-04  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* Use <> when including local*.mk and others which may exist
+	  elsewhere so that user can better control what they get.
+	
+	* meta.autodep.mk (NO_FILEMON_COOKIE): 
+	  create a cookie if we ever build dir with nofilemon
+	  so that UPDATE_DEPENDFILE will be forced to NO until cleaned.
+
+2016-04-01  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20160401
+	
+	* meta2deps.py: fix old print statement when debugging.
+
+	* gendirdeps.mk: META2DEPS_CMD append M2D_EXCLUDES with -X
+	  patch from Bryan Drewery
+
+2016-03-22  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20160317 (St. Pats)
+	
+	* warnings.mk: g++ does not like -Wimplicit
+	
+	* sys.mk sys/*.mk lib.mk prog.mk: use CXX_SUFFIXES to handle the
+	  pelthora of common suffixes for C++
+	
+	* lib.mk: use .So for shared objects
+
+2016-03-15  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20160315
+
+	* meta.stage.mk (LN_CP_SCRIPT): do not ln(1) if we have to chmod(1)
+	  normally only applies to scripts.
+	
+	* dirdeps.mk: NO_DIRDEPS_BELOW to supress DIRDEPS below RELDIR as
+	  well as outside it. 
+
+2016-03-10  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20160310
+
+	* dirdeps.mk: use targets rather than a list to track DIRDEPS that
+	  we have processed; the list gets very inefficient as number of
+	  DIRDEPS gets large.
+
+	* sys.dependfile.mk: fix comment wrt MACHINE
+
+	* meta.autodep.mk: ignore staged DPADDs when bootstrapping.
+	  patch from Bryan Drewery
+
+2016-03-02  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* meta2deps.sh: don't ignore subdirs.
+	  patch from Bryan Drewery
+
+2016-02-26  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20160226
+
+	* gendirdeps.mk: mark _DEPENDFILE .NOMETA
+
+2016-02-20  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* dirdeps.mk: we shouldn't normally include .depend but if we do
+	  use .dinclude if we can.
+
+2016-02-18  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* install-mk (MK_VERSION): 20160218
+	* sys.clean-env.mk: with recent change to Var_Subst()
+	  we cannot use the '$$' trick, but .export-literal does the job
+	  we need.
+	* auto.dep.mk: make use .dinclude if we can.
+	
+
+2016-02-05  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* dirdeps.mk: 
+	  Add _build_all_dirs such that local.dirdeps.mk can
+	  add fully qualified dirs to it.
+	  These will be built normally but the current 
+	  DEP_RELDIR will not depend on then (to avoid cycles).
+	  This makes it easy to hook things like unit-tests into build.
+	
+
+2016-01-21  Simon J. Gerraty  <sjg at bad.crufty.net>
+
+	* dirdeps.mk: add bootstrap-empty
+
 2015-12-12  Simon J. Gerraty  <sjg at bad.crufty.net>
 
 	* install-mk (MK_VERSION): 20151212

Modified: trunk/contrib/bmake/mk/FILES
===================================================================
--- trunk/contrib/bmake/mk/FILES	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/FILES	2018-06-27 00:20:04 UTC (rev 11140)
@@ -9,6 +9,7 @@
 dep.mk
 doc.mk
 dpadd.mk
+files.mk
 final.mk
 host-target.mk
 host.libnames.mk
@@ -38,7 +39,9 @@
 subdir.mk
 sys.mk
 sys.clean-env.mk
+sys.debug.mk
 sys.dependfile.mk
+sys.vars.mk
 sys/AIX.mk
 sys/Darwin.mk
 sys/Generic.mk

Modified: trunk/contrib/bmake/mk/auto.dep.mk
===================================================================
--- trunk/contrib/bmake/mk/auto.dep.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/auto.dep.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,6 +1,6 @@
 #
 # RCSid:
-#	$Id: auto.dep.mk,v 1.3 2014/08/04 05:19:10 sjg Exp $
+#	$Id: auto.dep.mk,v 1.5 2016/04/05 15:58:37 sjg Exp $
 #
 #	@(#) Copyright (c) 2010, Simon J. Gerraty
 #
@@ -45,6 +45,7 @@
 
 CLEANFILES += .depend ${.MAKE.DEPENDFILE} *.d
 
+.if ${MAKE_VERSION} < 20160218
 # skip generating dependfile for misc targets
 .if ${.TARGETS:Uall:M*all} != ""
 .END:	${.MAKE.DEPENDFILE}
@@ -60,5 +61,14 @@
 	- at for f in ${.ALLSRC:M*o:T:O:u:%=%.d}; do \
 		echo ".-include \"$$f\""; \
 	done > $@
+.else
+# we have .dinclude
+.if empty(_SKIP_BUILD)
+_all_objs = ${OBJS} ${POBJS} ${SOBJS}
+.for d in ${_all_objs:M*o:T:O:u:%=%.d}
+.dinclude <$d>
+.endfor
+.endif
 
 .endif
+.endif

Modified: trunk/contrib/bmake/mk/auto.obj.mk
===================================================================
--- trunk/contrib/bmake/mk/auto.obj.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/auto.obj.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-# $Id: auto.obj.mk,v 1.12 2015/12/16 01:57:06 sjg Exp $
+# $Id: auto.obj.mk,v 1.14 2017/04/18 23:53:18 sjg Exp $
 #
 #	@(#) Copyright (c) 2004, Simon J. Gerraty
 #
@@ -41,6 +41,10 @@
 # Use __objdir here so it is easier to tweak without impacting
 # the logic.
 .if !empty(MAKEOBJDIRPREFIX)
+.if ${.CURDIR:M${MAKEOBJDIRPREFIX}/*} != ""
+# we are already in obj tree!
+__objdir?= ${.CURDIR}
+.endif
 __objdir?= ${MAKEOBJDIRPREFIX}${.CURDIR}
 .endif
 __objdir?= ${MAKEOBJDIR:Uobj}
@@ -57,7 +61,10 @@
 # This causes make to use the specified directory as .OBJDIR
 .OBJDIR: ${__objdir}
 .if ${.OBJDIR:tA} != ${__objdir:tA} && ${__objdir_made:Uno:M${__objdir}/*} != ""
+# watch out for __objdir being relative path
+.if !(${__objdir:M/*} == "" && ${.OBJDIR:tA} == ${${.CURDIR}/${__objdir}:L:tA})
 .error could not use ${__objdir}: .OBJDIR=${.OBJDIR}
 .endif
 .endif
 .endif
+.endif

Modified: trunk/contrib/bmake/mk/autodep.mk
===================================================================
--- trunk/contrib/bmake/mk/autodep.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/autodep.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,6 +1,6 @@
 #
 # RCSid:
-#	$Id: autodep.mk,v 1.34 2014/08/04 05:12:27 sjg Exp $
+#	$Id: autodep.mk,v 1.36 2016/04/05 15:58:37 sjg Exp $
 #
 #	@(#) Copyright (c) 1999-2010, Simon J. Gerraty
 #
@@ -25,7 +25,11 @@
 DEPENDFILE?= .depend
 .for d in ${DEPENDFILE:N.depend}
 # bmake only groks .depend
-.-include "$d"
+.if ${MAKE_VERSION} < 20160218
+.-include <$d>
+.else
+.dinclude <$d>
+.endif
 .endfor
 
 # it does nothing if SRCS is not defined or is empty
@@ -75,6 +79,9 @@
 CC_MD?=${CC}
 CXX_MD?=${CXX}
 
+# should have been set by sys.mk
+CXX_SUFFIXES?= .cc .cpp .cxx .C
+
 # so we can do an explicit make depend, but not otherwise
 .if make(depend)
 .SUFFIXES:	.d
@@ -100,7 +107,7 @@
 	@echo updating dependencies for $<
 	@${SHELL} -ec "${CC_MD} -M ${CPPFLAGS_MD} ${AINC} $< | sed '/:/s/^/$@ /' > $@" || { ${RM} -f $@; false; }
 
-.cc.d .cpp.d .C.d .cxx.d:
+${CXX_SUFFIXES:%=%.d}:
 	@echo updating dependencies for $<
 	@${SHELL} -ec "${CXX_MD} -M ${CXXFLAGS_MD} $< | sed '/:/s/^/$@ /' > $@" || { ${RM} -f $@; false; }
 .else
@@ -120,7 +127,7 @@
 .s.d .S.d:
 	${CC_MD} ${CFLAGS_MD:S/D//} ${CPPFLAGS_MD} ${AINC} $< > $@ || { ${RM} -f $@; false; }
 
-.cc.d .cpp.d .C.d .cxx.d:
+${CXX_SUFFIXES:%=%.d}:
 	${CXX_MD} ${CFLAGS_MD:S/D//} ${CXXFLAGS_MD} $< > $@ || { ${RM} -f $@; false; }
 .endif
 

Modified: trunk/contrib/bmake/mk/dirdeps.mk
===================================================================
--- trunk/contrib/bmake/mk/dirdeps.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/dirdeps.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-# $Id: dirdeps.mk,v 1.55 2015/10/20 22:04:53 sjg Exp $
+# $Id: dirdeps.mk,v 1.89 2017/05/17 17:41:47 sjg Exp $
 
 # Copyright (c) 2010-2013, Juniper Networks, Inc.
 # All rights reserved.
@@ -56,9 +56,12 @@
 #	.MAKE.DEPENDFILE_PREFIX) to refer to these makefiles to
 #	distinguish them from others.
 #	
-#	Each Makefile.depend file sets DEP_RELDIR to be the
-#	the RELDIR (path relative to SRCTOP) for its directory, and
-#	since each Makefile.depend file includes dirdeps.mk, this
+#	Before each Makefile.depend file is read, we set 
+#	DEP_RELDIR to be the RELDIR (path relative to SRCTOP) for
+#	its directory, and DEP_MACHINE etc according to the .<target_spec>
+#	represented by the suffix of the corresponding target.
+#	
+#	Since each Makefile.depend file includes dirdeps.mk, this
 #	processing is recursive and results in .MAKE.LEVEL 0 learning the
 #	dependencies of the tree wrt the initial directory (_DEP_RELDIR).
 #
@@ -110,17 +113,45 @@
 #		# as we may need it to find Makefile.depend*
 #		TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,}
 #	
+#	The following variables can influence the initial DIRDEPS
+#	computation with regard to the TARGET_SPECs that will be
+#	built.
+#	Most should also be considered by init.mk
+#	
+#	ONLY_TARGET_SPEC_LIST
+#		Defines a list of TARGET_SPECs for which the current
+#		directory can be built.
+#		If ALL_MACHINES is defined, we build for all the
+#		TARGET_SPECs listed.
+#
+#	ONLY_MACHINE_LIST
+#		As for ONLY_TARGET_SPEC_LIST but only specifies
+#		MACHINEs.
+#
+#	NOT_TARGET_SPEC_LIST
+#		A list of TARGET_SPECs for which the current
+#		directory should not be built.
+#
+#	NOT_MACHINE_LIST
+#		A list of MACHINEs the current directory should not be
+#		built for.
+#
 
+.if !target(bootstrap) && (make(bootstrap) || \
+	make(bootstrap-this) || \
+	make(bootstrap-recurse) || \
+	make(bootstrap-empty))
+# disable most of below
+.MAKE.LEVEL = 1
+.endif
+
 # touch this at your peril
 _DIRDEP_USE_LEVEL?= 0
 .if ${.MAKE.LEVEL} == ${_DIRDEP_USE_LEVEL}
 # only the first instance is interested in all this
 
-# First off, we want to know what ${MACHINE} to build for.
-# This can be complicated if we are using a mixture of ${MACHINE} specific
-# and non-specific Makefile.depend*
+.if !target(_DIRDEP_USE)
 
-.if !target(_DIRDEP_USE)
 # do some setup we only need once
 _CURDIR ?= ${.CURDIR}
 _OBJDIR ?= ${.OBJDIR}
@@ -130,9 +161,30 @@
 start_utc := ${now_utc}
 .endif
 
+.if ${MAKEFILE:T} == ${.PARSEFILE} && empty(DIRDEPS) && ${.TARGETS:Uall:M*/*} != ""
+# This little trick let's us do
+#
+# mk -f dirdeps.mk some/dir.${TARGET_SPEC}
+#
+all:
+${.TARGETS:Nall}: all
+DIRDEPS := ${.TARGETS:M*[/.]*}
+# so that -DNO_DIRDEPS works
+DEP_RELDIR := ${DIRDEPS:[1]:R}
+# this will become DEP_MACHINE below
+TARGET_MACHINE := ${DIRDEPS:[1]:E:C/,.*//}
+.if ${TARGET_MACHINE:N*/*} == ""
+TARGET_MACHINE := ${MACHINE}
+.endif
+# disable DIRDEPS_CACHE as it does not like this trick
+MK_DIRDEPS_CACHE = no
+.endif
+
+# make sure we get the behavior we expect
+.MAKE.SAVE_DOLLARS = no
+
 # make sure these are empty to start with
 _DEP_TARGET_SPEC =
-_DIRDEP_CHECKED =
 
 # If TARGET_SPEC_VARS is other than just MACHINE
 # it should be set by sys.mk or similar by now.
@@ -153,9 +205,15 @@
 # we compute below are fully qualified wrt DEP_TARGET_SPEC.
 # The makefiles may only partially specify (eg. MACHINE only),
 # so we need to construct a set of modifiers to fill in the gaps.
-# jot 10 should output 1 2 3 .. 10
-JOT ?= jot
-_tspec_x := ${${JOT} ${TARGET_SPEC_VARS:[#]}:L:sh}
+.if ${MAKE_VERSION} >= 20170130
+_tspec_x := ${TARGET_SPEC_VARS:range}
+.elif ${TARGET_SPEC_VARS:[#]} > 10
+# seriously? better have jot(1) or equivalent to produce suitable sequence
+_tspec_x := ${${JOT:Ujot} ${TARGET_SPEC_VARS:[#]}:L:sh}
+.else
+# we can provide the sequence ourselves
+_tspec_x := ${1 2 3 4 5 6 7 8 9 10:L:[1..${TARGET_SPEC_VARS:[#]}]}
+.endif
 # this handles unqualified entries
 M_dep_qual_fixes = C;(/[^/.,]+)$$;\1.$${DEP_TARGET_SPEC};
 # there needs to be at least one item missing for these to make sense
@@ -201,6 +259,10 @@
 
 .endif				# !target(_DIRDEP_USE)
 
+# First off, we want to know what ${MACHINE} to build for.
+# This can be complicated if we are using a mixture of ${MACHINE} specific
+# and non-specific Makefile.depend*
+
 # if we were included recursively _DEP_TARGET_SPEC should be valid.
 .if empty(_DEP_TARGET_SPEC)
 # we may or may not have included a dependfile yet
@@ -222,7 +284,7 @@
 .endif
 .if !empty(_last_dependfile)
 # record that we've read dependfile for this
-_DIRDEP_CHECKED += ${_CURDIR}.${TARGET_SPEC}
+_dirdeps_checked.${_CURDIR}.${TARGET_SPEC}:
 .endif
 .endif
 
@@ -242,26 +304,9 @@
 DEP_MACHINE := ${_DEP_TARGET_SPEC}
 .endif
 
-.if ${MAKEFILE:T} == ${.PARSEFILE} && empty(DIRDEPS) && ${.TARGETS:Uall:M*/*} != ""
-# This little trick let's us do
-#
-# mk -f dirdeps.mk some/dir.${TARGET_SPEC}
-#
-all:
-${.TARGETS:Nall}: all
-DIRDEPS := ${.TARGETS:M*/*}
-# so that -DNO_DIRDEPS works
-DEP_RELDIR := ${DIRDEPS:R:[1]}
-# disable DIRDEPS_CACHE as it does not like this trick
-MK_DIRDEPS_CACHE = no
-.endif
+# reset each time through
+_build_all_dirs =
 
-
-# pickup customizations
-# as below you can use !target(_DIRDEP_USE) to protect things
-# which should only be done once.
-.-include "local.dirdeps.mk"
-
 # the first time we are included the _DIRDEP_USE target will not be defined
 # we can use this as a clue to do initialization and other one time things.
 .if !target(_DIRDEP_USE)
@@ -280,6 +325,26 @@
 # remember the initial value of DEP_RELDIR - we test for it below.
 _DEP_RELDIR := ${DEP_RELDIR}
 
+.endif
+
+# DIRDEPS_CACHE can be very handy for debugging.
+# Also if repeatedly building the same target, 
+# we can avoid the overhead of re-computing the tree dependencies.
+MK_DIRDEPS_CACHE ?= no
+BUILD_DIRDEPS_CACHE ?= no
+BUILD_DIRDEPS ?= yes
+
+.if ${MK_DIRDEPS_CACHE} == "yes"
+# this is where we will cache all our work
+DIRDEPS_CACHE ?= ${_OBJDIR:tA}/dirdeps.cache${.TARGETS:Nall:O:u:ts-:S,/,_,g:S,^,.,:N.}
+.endif
+
+# pickup customizations
+# as below you can use !target(_DIRDEP_USE) to protect things
+# which should only be done once.
+.-include <local.dirdeps.mk>
+
+.if !target(_DIRDEP_USE)
 # things we skip for host tools
 SKIP_HOSTDIR ?=
 
@@ -292,14 +357,24 @@
 
 DEP_SKIP_DIR = ${SKIP_DIR} \
 	${SKIP_DIR.${DEP_TARGET_SPEC}:U} \
-	${SKIP_DIR.${DEP_MACHINE}:U} \
-	${SKIP_DIRDEPS.${DEP_MACHINE}:U}
+	${TARGET_SPEC_VARS:@v@${SKIP_DIR.${DEP_$v}:U}@} \
+	${SKIP_DIRDEPS.${DEP_TARGET_SPEC}:U} \
+	${TARGET_SPEC_VARS:@v@${SKIP_DIRDEPS.${DEP_$v}:U}@}
 
+
 NSkipDir = ${DEP_SKIP_DIR:${M_ListToSkip}}
 
-.if defined(NO_DIRDEPS) || defined(NODIRDEPS) || defined(WITHOUT_DIRDEPS)
-# confine ourselves to the original dir
+.if defined(NODIRDEPS) || defined(WITHOUT_DIRDEPS)
+NO_DIRDEPS =
+.elif defined(WITHOUT_DIRDEPS_BELOW)
+NO_DIRDEPS_BELOW =
+.endif
+
+.if defined(NO_DIRDEPS)
+# confine ourselves to the original dir and below.
 DIRDEPS_FILTER += M${_DEP_RELDIR}*
+.elif defined(NO_DIRDEPS_BELOW)
+DIRDEPS_FILTER += M${_DEP_RELDIR}
 .endif
 
 # this is what we run below
@@ -323,7 +398,7 @@
 .ifdef ALL_MACHINES
 # this is how you limit it to only the machines we have been built for
 # previously.
-.if empty(ONLY_MACHINE_LIST)
+.if empty(ONLY_TARGET_SPEC_LIST) && empty(ONLY_MACHINE_LIST)
 .if !empty(ALL_MACHINE_LIST)
 # ALL_MACHINE_LIST is the list of all legal machines - ignore anything else
 _machine_list != cd ${_CURDIR} && 'ls' -1 ${ALL_MACHINE_LIST:O:u:@m@${.MAKE.DEPENDFILE:T:R}.$m@} 2> /dev/null; echo
@@ -332,7 +407,7 @@
 .endif
 _only_machines := ${_machine_list:${NIgnoreFiles:UN*.bak}:E:O:u}
 .else
-_only_machines := ${ONLY_MACHINE_LIST}
+_only_machines := ${ONLY_TARGET_SPEC_LIST:U} ${ONLY_MACHINE_LIST:U}
 .endif
 
 .if empty(_only_machines)
@@ -341,30 +416,35 @@
 .endif
 
 .else				# ! ALL_MACHINES
-# if ONLY_MACHINE_LIST is set, we are limited to that
+# if ONLY_TARGET_SPEC_LIST or ONLY_MACHINE_LIST is set, we are limited to that.
+# Note that ONLY_TARGET_SPEC_LIST should be fully qualified.
 # if TARGET_MACHINE is set - it is really the same as ONLY_MACHINE_LIST
 # otherwise DEP_MACHINE is it - so DEP_MACHINE will match.
+_only_machines := ${ONLY_TARGET_SPEC_LIST:U:M${DEP_MACHINE},*}
+.if empty(_only_machines)
 _only_machines := ${ONLY_MACHINE_LIST:U${TARGET_MACHINE:U${DEP_MACHINE}}:M${DEP_MACHINE}}
 .endif
+.endif
 
 .if !empty(NOT_MACHINE_LIST)
 _only_machines := ${_only_machines:${NOT_MACHINE_LIST:${M_ListToSkip}}}
 .endif
+.if !empty(NOT_TARGET_SPEC_LIST)
+# we must first qualify
+_dm := ${DEP_MACHINE}
+_only_machines := ${_only_machines:M*,*} ${_only_machines:N*,*:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:${M_dep_qual_fixes:ts:}:O:u:S,^.,,}
+DEP_MACHINE := ${_dm}
+_only_machines := ${_only_machines:${NOT_TARGET_SPEC_LIST:${M_ListToSkip}}}
+.endif
+# clean up
+_only_machines := ${_only_machines:O:u}
 
 # make sure we have a starting place?
 DIRDEPS ?= ${RELDIR}
 .endif				# target 
 
-# if repeatedly building the same target, 
-# we can avoid the overhead of re-computing the tree dependencies.
-MK_DIRDEPS_CACHE ?= no
-BUILD_DIRDEPS_CACHE ?= no
-BUILD_DIRDEPS ?= yes
-
-.if !defined(NO_DIRDEPS)
+.if !defined(NO_DIRDEPS) && !defined(NO_DIRDEPS_BELOW)
 .if ${MK_DIRDEPS_CACHE} == "yes"
-# this is where we will cache all our work
-DIRDEPS_CACHE?= ${_OBJDIR}/dirdeps.cache${.TARGETS:Nall:O:u:ts-:S,/,_,g:S,^,.,:N.}
 
 # just ensure this exists
 build-dirdeps:
@@ -376,6 +456,9 @@
 # we do this via sub-make
 BUILD_DIRDEPS = no
 
+# ignore anything but these
+.MAKE.META.IGNORE_FILTER = M*/${.MAKE.DEPENDFILE_PREFIX}*
+
 dirdeps: dirdeps-cached
 dirdeps-cached:	${DIRDEPS_CACHE} .MAKE
 	@echo "${TRACER}Using ${DIRDEPS_CACHE}"
@@ -396,9 +479,11 @@
 	} > ${.TARGET}.new
 	+ at MAKELEVEL=${.MAKE.LEVEL} DIRDEPS_CACHE=${DIRDEPS_CACHE} \
 	DIRDEPS="${DIRDEPS}" \
+	TARGET_SPEC=${TARGET_SPEC} \
 	MAKEFLAGS= ${.MAKE} -C ${_CURDIR} -f ${BUILD_DIRDEPS_MAKEFILE} \
 	${BUILD_DIRDEPS_TARGETS} BUILD_DIRDEPS_CACHE=yes \
 	.MAKE.DEPENDFILE=.none \
+	${.MAKEFLAGS:tW:S,-D ,-D,g:tw:M*WITH*} \
 	3>&1 1>&2 | sed 's,${SRCTOP},$${SRCTOP},g' >> ${.TARGET}.new && \
 	mv ${.TARGET}.new ${.TARGET}
 
@@ -442,7 +527,7 @@
 
 # on rare occasions, there can be a need for extra help
 _dep_hack := ${_this_dir}/${.MAKE.DEPENDFILE_PREFIX}.inc
-.-include "${_dep_hack}"
+.-include <${_dep_hack}>
 
 .if ${DEP_RELDIR} != ${_DEP_RELDIR} || ${DEP_TARGET_SPEC} != ${TARGET_SPEC}
 # this should be all
@@ -464,8 +549,10 @@
 _dm := ${DEP_MACHINE}
 # apply the same filtering that we do when qualifying DIRDEPS.
 # M_dep_qual_fixes expects .${MACHINE}* so add (and remove) '.'
-_machines := ${_machines:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:${M_dep_qual_fixes:ts:}:O:u:S,^.,,}
+# Again we expect that any already qualified machines are fully qualified.
+_machines := ${_machines:M*,*} ${_machines:N*,*:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:${M_dep_qual_fixes:ts:}:O:u:S,^.,,}
 DEP_MACHINE := ${_dm}
+_machines := ${_machines:O:u}
 .endif
 
 # reset each time through
@@ -479,10 +566,14 @@
 _build_dirs += ${_machines:N${DEP_TARGET_SPEC}:@m@${_CURDIR}.$m@}
 .if ${DEP_TARGET_SPEC} == ${TARGET_SPEC}
 # pickup local dependencies now
+.if ${MAKE_VERSION} < 20160220
 .-include <.depend>
+.else
+.dinclude <.depend>
 .endif
 .endif
 .endif
+.endif
 
 .if ${_debug_reldir}
 .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: DIRDEPS='${DIRDEPS}'
@@ -493,7 +584,7 @@
 # these we reset each time through as they can depend on DEP_MACHINE
 DEP_DIRDEPS_FILTER = \
 	${DIRDEPS_FILTER.${DEP_TARGET_SPEC}:U} \
-	${DIRDEPS_FILTER.${DEP_MACHINE}:U} \
+	${TARGET_SPEC_VARS:@v@${DIRDEPS_FILTER.${DEP_$v}:U}@} \
 	${DIRDEPS_FILTER:U} 
 .if empty(DEP_DIRDEPS_FILTER)
 # something harmless
@@ -533,25 +624,43 @@
 
 .endif				# empty DIRDEPS
 
+_build_all_dirs += ${_build_dirs}
+_build_all_dirs := ${_build_all_dirs:O:u}
+
 # Normally if doing make -V something,
 # we do not want to waste time chasing DIRDEPS
 # but if we want to count the number of Makefile.depend* read, we do.
 .if ${.MAKEFLAGS:M-V${_V_READ_DIRDEPS}} == ""
-.if !empty(_build_dirs)
+.if !empty(_build_all_dirs)
 .if ${BUILD_DIRDEPS_CACHE} == "yes"
 x!= { echo; echo '\# ${DEP_RELDIR}.${DEP_TARGET_SPEC}'; \
+	echo 'dirdeps: ${_build_all_dirs:${M_oneperline}}'; echo; } >&3; echo
+x!= { ${_build_all_dirs:@x@${target($x):?:echo '$x: _DIRDEP_USE';}@} echo; } >&3; echo
+.if !empty(DEP_EXPORT_VARS)
+# Discouraged, but there are always exceptions.
+# Handle it here rather than explain how.
+x!= { echo; ${DEP_EXPORT_VARS:@v at echo '$v=${$v}';@} echo '.export ${DEP_EXPORT_VARS}'; echo; } >&3; echo
+.endif
+.else
+.if ${BUILD_DIRDEPS_CACHE} == "yes"
+x!= { echo; echo '\# ${DEP_RELDIR}.${DEP_TARGET_SPEC}'; \
 	echo 'dirdeps: ${_build_dirs:${M_oneperline}}'; echo; } >&3; echo
 x!= { ${_build_dirs:@x@${target($x):?:echo '$x: _DIRDEP_USE';}@} echo; } >&3; echo
 .else
 # this makes it all happen
-dirdeps: ${_build_dirs}
+dirdeps: ${_build_all_dirs}
 .endif
-${_build_dirs}:	_DIRDEP_USE
+${_build_all_dirs}:	_DIRDEP_USE
 
 .if ${_debug_reldir}
 .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: needs: ${_build_dirs}
 .endif
 
+.if !empty(DEP_EXPORT_VARS)
+.export ${DEP_EXPORT_VARS}
+DEP_EXPORT_VARS=
+.endif
+
 # this builds the dependency graph
 .for m in ${_machines}
 # it would be nice to do :N${.TARGET}
@@ -580,15 +689,28 @@
 .endif
 
 # Now find more dependencies - and recurse.
-.for d in ${_build_dirs}
-.if ${_DIRDEP_CHECKED:M$d} == ""
+.for d in ${_build_all_dirs}
+.if !target(_dirdeps_checked.$d)
 # once only
-_DIRDEP_CHECKED += $d
+_dirdeps_checked.$d:
 .if ${_debug_search}
 .info checking $d
 .endif
-# Note: _build_dirs is fully qualifed so d:R is always the directory
+# Note: _build_all_dirs is fully qualifed so d:R is always the directory
 .if exists(${d:R})
+# we pass _DEP_TARGET_SPEC to tell the next step what we want
+_DEP_TARGET_SPEC := ${d:E}
+# some makefiles may still look at this
+_DEP_MACHINE := ${d:E:C/,.*//}
+# set these too in case Makefile.depend* uses them
+.if ${TARGET_SPEC_VARS:[#]} > 1
+_dtspec := ${_DEP_TARGET_SPEC:S/,/ /g}
+.for i in ${_tspec_x}
+DEP_${TARGET_SPEC_VARS:[$i]} := ${_dtspec:[$i]}
+.endfor
+.else
+DEP_MACHINE := ${_DEP_MACHINE}
+.endif
 # Warning: there is an assumption here that MACHINE is always 
 # the first entry in TARGET_SPEC_VARS.
 # If TARGET_SPEC and MACHINE are insufficient, you have a problem.
@@ -599,10 +721,6 @@
 .if ${_debug_search}
 .info Looking for ${_qm}
 .endif
-# we pass _DEP_TARGET_SPEC to tell the next step what we want
-_DEP_TARGET_SPEC := ${d:E}
-# some makefiles may still look at this
-_DEP_MACHINE := ${d:E:C/,.*//}
 # set this "just in case" 
 # we can skip :tA since we computed the path above
 DEP_RELDIR := ${_m:H:S,${SRCTOP}/,,}
@@ -627,28 +745,47 @@
 DEP_RELDIR := ${RELDIR}
 _DEP_RELDIR := ${RELDIR}
 # pickup local dependencies
+.if ${MAKE_VERSION} < 20160220
 .-include <.depend>
+.else
+.dinclude <.depend>
 .endif
+.endif
 
 # bootstrapping new dependencies made easy?
-.if (make(bootstrap) || make(bootstrap-recurse)) && !target(bootstrap)
+.if !target(bootstrap) && (make(bootstrap) || \
+	make(bootstrap-this) || \
+	make(bootstrap-recurse) || \
+	make(bootstrap-empty))
 
-.if exists(${.CURDIR}/${.MAKE.DEPENDFILE:T})
+# if we are bootstrapping create the default
+_want = ${.CURDIR}/${.MAKE.DEPENDFILE_DEFAULT:T}
+
+.if exists(${_want})
 # stop here
 ${.TARGETS:Mboot*}:
-.else
+.elif !make(bootstrap-empty)
 # find a Makefile.depend to use as _src
 _src != cd ${.CURDIR} && for m in ${.MAKE.DEPENDFILE_PREFERENCE:T:S,${MACHINE},*,}; do test -s $$m || continue; echo $$m; break; done; echo
 .if empty(_src)
-.error cannot find any of ${.MAKE.DEPENDFILE_PREFERENCE:T}
+.error cannot find any of ${.MAKE.DEPENDFILE_PREFERENCE:T}${.newline}Use: bootstrap-empty
 .endif
 
-_src?= ${.MAKE.DEPENDFILE:T}
+_src?= ${.MAKE.DEPENDFILE}
 
+.MAKE.DEPENDFILE_BOOTSTRAP_SED+= -e 's/${_src:E:C/,.*//}/${MACHINE}/g'
+
+# just create Makefile.depend* for this dir
 bootstrap-this:	.NOTMAIN
-	@echo Bootstrapping ${RELDIR}/${.MAKE.DEPENDFILE:T} from ${_src:T}
-	(cd ${.CURDIR} && sed 's,${_src:E},${MACHINE},g' ${_src} > ${.MAKE.DEPENDFILE:T})
+	@echo Bootstrapping ${RELDIR}/${_want:T} from ${_src:T}; \
+	echo You need to build ${RELDIR} to correctly populate it.
+.if ${_src:T} != ${.MAKE.DEPENDFILE_PREFIX:T}
+	(cd ${.CURDIR} && sed ${.MAKE.DEPENDFILE_BOOTSTRAP_SED} ${_src} > ${_want:T})
+.else
+	cp ${.CURDIR}/${_src:T} ${_want}
+.endif
 
+# create Makefile.depend* for this dir and its dependencies
 bootstrap: bootstrap-recurse
 bootstrap-recurse: bootstrap-this
 
@@ -663,4 +800,11 @@
 	done
 
 .endif
+
+# create an empty Makefile.depend* to get the ball rolling.
+bootstrap-empty: .NOTMAIN .NOMETA
+	@echo Creating empty ${RELDIR}/${_want:T}; \
+	echo You need to build ${RELDIR} to correctly populate it.
+	@{ echo DIRDEPS=; echo ".include <dirdeps.mk>"; } > ${_want}
+
 .endif

Modified: trunk/contrib/bmake/mk/doc.mk
===================================================================
--- trunk/contrib/bmake/mk/doc.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/doc.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-# $Id: doc.mk,v 1.5 2015/09/08 06:15:31 sjg Exp $
+# $Id: doc.mk,v 1.6 2017/05/01 21:24:10 sjg Exp $
 
 .if !target(__${.PARSEFILE}__)
 __${.PARSEFILE}__:
@@ -59,7 +59,7 @@
 .include <own.mk>
 
 .if !empty(DOCOWN)
-DOC_INSTALL_OWN?= -o ${DOCOWN} -g ${DOGGRP}
+DOC_INSTALL_OWN?= -o ${DOCOWN} -g ${DOCGRP}
 .endif
 
 .endif

Modified: trunk/contrib/bmake/mk/dpadd.mk
===================================================================
--- trunk/contrib/bmake/mk/dpadd.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/dpadd.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-# $Id: dpadd.mk,v 1.19 2014/04/05 22:56:54 sjg Exp $
+# $Id: dpadd.mk,v 1.23 2017/02/13 16:46:01 sjg Exp $
 #
 #	@(#) Copyright (c) 2004, Simon J. Gerraty
 #
@@ -21,71 +21,91 @@
 _OBJDIR?= ${.OBJDIR}
 _CURDIR?= ${.CURDIR}
 
+.if ${_CURDIR} == ${SRCTOP}
+RELDIR=.
+RELTOP=.
+.else
+RELDIR?= ${_CURDIR:S,${SRCTOP}/,,}
+.if ${RELDIR} == ${_CURDIR}
+RELDIR?= ${_OBJDIR:S,${OBJTOP}/,,}
+.endif
+RELTOP?= ${RELDIR:C,[^/]+,..,g}
+.endif
+RELOBJTOP?= ${OBJTOP}
+RELSRCTOP?= ${SRCTOP}
+
+# we get included just about everywhere so this is handy...
+# C*DEBUG_XTRA are for defining on cmd line etc 
+# so do not use in makefiles.
+.ifdef CFLAGS_DEBUG_XTRA
+CFLAGS_LAST += ${CFLAGS_DEBUG_XTRA}
+.endif
+.ifdef CXXFLAGS_DEBUG_XTRA
+CXXFLAGS_LAST += ${CXXFLAGS_DEBUG_XTRA}
+.endif
+
+.-include <local.dpadd.mk>
+
 # DPLIBS helps us ensure we keep DPADD and LDADD in sync
 DPLIBS+= ${DPLIBS_LAST}
-DPADD+= ${DPLIBS}
-.for __lib in ${DPLIBS:T:R}
-LDADD+= ${LDADD_${__lib}:U${__lib:T:R:S/lib/-l/:C/\.so.*//}}
+DPADD+= ${DPLIBS:N-*}
+.for __lib in ${DPLIBS}
+.if "${_lib:M-*}" != ""
+LDADD += ${__lib}
+.else
+LDADD += ${LDADD_${__lib:T:R}:U${__lib:T:R:S/lib/-l/:C/\.so.*//}}
+.endif
 .endfor
 
 # DPADD can contain things other than libs
-__dpadd_libs = ${DPADD:M*/lib*}
+__dpadd_libs := ${DPADD:M*/lib*}
 
 # some libs have dependencies...
 # DPLIBS_* allows bsd.libnames.mk to flag libs which must be included
 # in DPADD for a given library.
-.for __lib in ${__dpadd_libs:@d@${DPLIBS_${d:T:R}}@}
+# Gather all such dependencies into __ldadd_all_xtras
+# dups will be dealt with later.
+# Note: libfoo_pic uses DPLIBS_libfoo
+__ldadd_all_xtras=
+.for __lib in ${__dpadd_libs:@d@${DPLIBS_${d:T:R:S,_pic,,}}@}
+__ldadd_all_xtras+= ${LDADD_${__lib}:U${__lib:T:R:S/lib/-l/:C/\.so.*//}}
 .if "${DPADD:M${__lib}}" == ""
 DPADD+= ${__lib}
-LDADD+= ${LDADD_${__lib}:U${__lib:T:R:S/lib/-l/:C/\.so.*//}}
 .endif
 .endfor
 # Last of all... for libc and libgcc
 DPADD+= ${DPADD_LAST}
 
+# de-dupuplicate __ldadd_all_xtras into __ldadd_xtras
+# in reverse order so that libs end up listed after all that needed them.
+__ldadd_xtras=
+.for __lib in ${__ldadd_all_xtras:[-1..1]}
+.if "${__ldadd_xtras:M${__lib}}" == "" || ${NEED_IMPLICIT_LDADD:tl:Uno} != "no"
+__ldadd_xtras+= ${__lib}
+.endif
+.endfor
+
+.if !empty(__ldadd_xtras)
+# now back to the original order
+__ldadd_xtras:= ${__ldadd_xtras:[-1..1]}
+LDADD+= ${__ldadd_xtras}
+.endif
+
 # Convert DPADD into -I and -L options and add them to CPPFLAGS and LDADD
 # For the -I's convert the path to a relative one.  For separate objdirs
 # the DPADD paths will be to the obj tree so we need to subst anyway.
 
-# If USE_PROFILE is yes, then check for profiled versions of libs
-# and use them.
+# update this
+__dpadd_libs := ${DPADD:M*/lib*}
 
-USE_PROFILE?=no
-.if defined(LIBDL) && exists(${LIBDL})
-.if defined(PROG) && (make(${PROG}_p) || ${USE_PROFILE} == yes) && \
-	defined(LDFLAGS) && ${LDFLAGS:M-export-dynamic}
-# building profiled version of a prog that needs dlopen to work
-DPLIBS+= ${LIBDL}
-.endif
-.endif
-
-.if defined(LIBDMALLOC) && exists(${LIBDMALLOC})
-.if defined(USE_DMALLOC) && ${USE_DMALLOC} != no
-.if !defined(NO_DMALLOC)
-CPPFLAGS+= -DUSE_DMALLOC
-.endif
-DPLIBS+= ${LIBDMALLOC}
-.endif
-.endif
-
 # Order -L's to search ours first.
 # Avoids picking up old versions already installed.
 __dpadd_libdirs := ${__dpadd_libs:R:H:S/^/-L/g:O:u:N-L}
 LDADD += ${__dpadd_libdirs:M-L${OBJTOP}/*}
-LDADD += ${__dpadd_libdirs:N-L${OBJTOP}/*}
-
-.if ${.CURDIR} == ${SRCTOP}
-RELDIR=.
-RELTOP=.
-.else
-RELDIR?= ${.CURDIR:S,${SRCTOP}/,,}
-.if ${RELDIR} == ${.CURDIR}
-RELDIR?= ${.OBJDIR:S,${OBJTOP}/,,}
+LDADD += ${__dpadd_libdirs:N-L${OBJTOP}/*:N-L${HOST_LIBDIR:U/usr/lib}}
+.if defined(HOST_LIBDIR) && ${HOST_LIBDIR} != "/usr/lib"
+LDADD+= -L${HOST_LIBDIR}
 .endif
-RELTOP?= ${RELDIR:C,[^/]+,..,g}
-.endif
-RELOBJTOP?= ${OBJTOP}
-RELSRCTOP?= ${SRCTOP}
 
 .if !make(dpadd)
 .ifdef LIB
@@ -109,7 +129,8 @@
 DPMAGIC_LIBS += ${__dpadd_libs} \
 	${__dpadd_libs:@d@${DPMAGIC_LIBS_${d:T:R}}@}
 
-.for __lib in ${DPMAGIC_LIBS:O:u}
+# we skip this for staged libs
+.for __lib in ${DPMAGIC_LIBS:O:u:N${STAGE_OBJTOP:Unot}*/lib/*}
 # 
 # if SRC_libfoo is not set, then we assume that the srcdir corresponding
 # to where we found the library is correct.
@@ -127,6 +148,35 @@
 
 .endfor
 
+# even for staged libs we sometimes 
+# need to allow direct -I to avoid cicular dependencies 
+.for __lib in ${DPMAGIC_LIBS:O:u:T:R}
+.if !empty(SRC_${__lib}) && empty(INCLUDES_${__lib})
+# must be a staged lib
+.if exists(${SRC_${__lib}}/h)
+INCLUDES_${__lib} = -I${SRC_${__lib}}/h
+.else
+INCLUDES_${__lib} = -I${SRC_${__lib}}
+.endif
+.endif
+.endfor
+
+# when linking a shared lib, avoid non pic libs
+SHLDADD+= ${LDADD:N-[lL]*}
+.for __lib in ${__dpadd_libs:u}
+.if defined(SHLIB_NAME) && ${LDADD:M-l${__lib:T:R:S,lib,,}} != ""
+.if ${__lib:T:N*_pic.a:N*.so} == "" || exists(${__lib:R}.so)
+SHLDADD+= -l${__lib:T:R:S,lib,,}
+.elif exists(${__lib:R}_pic.a)
+SHLDADD+= -l${__lib:T:R:S,lib,,}_pic
+.else
+.warning ${RELDIR}.${TARGET_SPEC} needs ${__lib:T:R}_pic.a
+SHLDADD+= -l${__lib:T:R:S,lib,,}
+.endif
+SHLDADD+= -L${__lib:H}
+.endif
+.endfor
+
 # Now for the bits we actually need
 __dpadd_incs=
 .for __lib in ${__dpadd_libs:u}
@@ -134,21 +184,26 @@
 __ldadd=-l${__lib:T:R:S,lib,,}
 LDADD := ${LDADD:S,^${__ldadd}$,${__ldadd}_p,g}
 .endif
+.endfor
 
 #
-# Some libs generate headers, so we potentially need both
-# the src dir and the obj dir.
-# If ${INCLUDES_libfoo} contains a word ending in /h, we assume that either
-# 1. it does not generate headers or
-# 2. INCLUDES_libfoo will have been set correctly
-# XXX it gets ugly avoiding duplicates... 
-# use :? to ensure .for does not prevent correct evaluation
-#
 # We take care of duplicate suppression later.
-__dpadd_incs += ${"${INCLUDES_${__lib:T:R}:M*/h}":? :-I${OBJ_${__lib:T:R}}}
-__dpadd_incs += ${INCLUDES_${__lib:T:R}}
-.endfor
+# don't apply :T:R too early
+__dpadd_incs += ${__dpadd_libs:u:@x@${INCLUDES_${x:T:R}}@}
+__dpadd_incs += ${__dpadd_libs:O:u:@s@${SRC_LIBS_${s:T:R}:U}@:@x@${INCLUDES_${x:T:R}}@}
 
+__dpadd_last_incs += ${__dpadd_libs:u:@x@${INCLUDES_LAST_${x:T:R}}@}
+__dpadd_last_incs += ${__dpadd_libs:O:u:@s@${SRC_LIBS_${s:T:R}:U}@:@x@${INCLUDES_LAST_${x:T:R}}@}
+
+.if defined(HOSTPROG) || ${MACHINE} == "host"
+# we want any -I/usr/* last
+__dpadd_last_incs := \
+	${__dpadd_last_incs:N-I/usr/*} \
+	${__dpadd_incs:M-I/usr/*} \
+	${__dpadd_last_incs:M-I/usr/*} 
+__dpadd_incs := ${__dpadd_incs:N-I/usr/*}
+.endif
+
 #
 # eliminate any duplicates - but don't mess with the order
 # force evaluation now - to avoid giving make a headache
@@ -164,13 +219,21 @@
 .endfor
 .endfor
 
+.for t in CFLAGS_LAST CXXFLAGS_LAST
+# avoid duplicates
+__$t_incs:=${$t:M-I*:u}
+.for i in ${__dpadd_last_incs}
+.if "${__$t_incs:M$i}" == ""
+$t+= $i
+__$t_incs+= $i
+.endif
+.endfor
+.endfor
+
 # This target is used to gather a list of
 # dir: ${DPADD}
 # entries
 .if make(*dpadd*)
-# allow overrides
-.-include "dpadd++.mk"
-
 .if !target(dpadd)
 dpadd:	.NOTMAIN
 .if defined(DPADD) && ${DPADD} != ""
@@ -193,4 +256,17 @@
 .PATH: ${SRC_PATHADD}
 .endif
 
+# after all that, if doing -n we don't care
+.if ${.MAKEFLAGS:Ux:M-n} != ""
+DPADD =
+.elif ${.MAKE.MODE:Mmeta*} != "" && exists(${.MAKE.DEPENDFILE})
+DPADD_CLEAR_DPADD ?= yes
+.if ${DPADD_CLEAR_DPADD} == "yes"
+# save this
+__dpadd_libs := ${__dpadd_libs}
+# we have made what use of it we can of DPADD
+DPADD =
 .endif
+.endif
+
+.endif

Copied: trunk/contrib/bmake/mk/files.mk (from rev 11139, vendor/NetBSD/bmake/dist/mk/files.mk)
===================================================================
--- trunk/contrib/bmake/mk/files.mk	                        (rev 0)
+++ trunk/contrib/bmake/mk/files.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -0,0 +1,83 @@
+# $Id: files.mk,v 1.6 2017/05/07 02:21:02 sjg Exp $
+#
+#	@(#) Copyright (c) 2017, Simon J. Gerraty
+#
+#	This file is provided in the hope that it will
+#	be of use.  There is absolutely NO WARRANTY.
+#	Permission to copy, redistribute or otherwise
+#	use this file is hereby granted provided that 
+#	the above copyright notice and this notice are
+#	left intact. 
+#      
+#	Please send copies of changes and bug-fixes to:
+#	sjg at crufty.net
+#
+
+.include <init.mk>
+
+FILES_INSTALL_OWN ?= -o ${SHAREOWN} -g ${SHAREGRP}
+FILESMODE ?= ${SHAREMODE}
+FILES_COPY ?= -C
+
+FILESGROUPS ?= FILES
+FILESGROUPS := ${FILESGROUPS:O:u}
+
+.if !target(buildfiles)
+.for group in ${FILESGROUPS}
+buildfiles: ${${group}}
+.endfor
+.endif
+buildfiles:
+realbuild: buildfiles
+
+# there is no default FILESDIR so
+# ignore group if ${group}DIR is not defined
+.for group in ${FILESGROUPS}
+.if !empty(${group}) && defined(${group}DIR)
+.if ${group} != "FILES"
+${group}_INSTALL_OWN ?= ${FILES_INSTALL_OWN}
+.endif
+# incase we are staging
+STAGE_DIR.${group} ?= ${STAGE_OBJTOP}${${group}DIR}
+
+.for file in ${${group}:O:u}
+${group}_INSTALL_OWN.${file:T} ?= ${${group}_INSTALL_OWN}
+${group}DIR.${file:T} ?= ${${group}DIR}
+file_mkdir_list += ${${group}DIR.${file:T}}
+
+.if defined(${group}NAME.${file:T})
+STAGE_AS_SETS += ${group}
+STAGE_AS_${file} = ${${group}NAME.${file:T}}
+stage_as.${group}: ${file}
+
+installfiles: installfiles.${group}.${file:T}
+installfiles.${group}.${file:T}: ${file} file_mkdirs
+	${INSTALL} ${FILES_COPY} ${${group}_INSTALL_OWN.${file:T}} \
+	-m ${FILESMODE} ${.ALLSRC:Nfile_mkdirs} ${DESTDIR}${${group}DIR}/${${group}NAME.${file:T}}
+
+.else
+STAGE_SETS += ${group}
+stage_files.${group}: ${file}
+installfiles.${group}: ${file}
+installfiles: installfiles.${group}
+.endif
+
+.endfor				# file
+
+installfiles.${group}: file_mkdirs
+	${INSTALL} ${FILES_COPY} ${${group}_INSTALL_OWN} -m ${FILESMODE} \
+	${.ALLSRC:Nfile_mkdirs:O:u} ${DESTDIR}${${group}DIR}
+
+.endif				# !empty
+.endfor				# group
+
+file_mkdirs:
+	@for d in ${file_mkdir_list:O:u}; do \
+		test -d ${DESTDIR}$$d || \
+		${INSTALL} -d ${FILES_INSTALL_OWN} -m 775 ${DESTDIR}$$d; \
+	done
+
+beforeinstall:
+installfiles:
+realinstall:	installfiles
+.ORDER: beforeinstall installfiles

Modified: trunk/contrib/bmake/mk/final.mk
===================================================================
--- trunk/contrib/bmake/mk/final.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/final.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,14 +1,22 @@
-# $Id: final.mk,v 1.5 2011/03/11 05:22:38 sjg Exp $
+# $Id: final.mk,v 1.8 2017/05/07 20:30:08 sjg Exp $
 
 .if !target(__${.PARSEFILE}__)
 __${.PARSEFILE}__:
 
 # provide a hook for folk who want to do scary stuff
-.-include "${.CURDIR}/../Makefile-final.inc"
+.-include <${.CURDIR:H}/Makefile-final.inc>
 
-.if !empty(STAGE)
+.if ${MK_STAGING} == "yes"
+.include <meta.stage.mk>
+.elif !empty(STAGE)
 .-include <stage.mk>
 .endif
 
 .-include <local.final.mk>
+
+.if empty(_SKIP_BUILD)
+install: realinstall
 .endif
+realinstall:
+
+.endif

Modified: trunk/contrib/bmake/mk/gendirdeps.mk
===================================================================
--- trunk/contrib/bmake/mk/gendirdeps.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/gendirdeps.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-# $Id: gendirdeps.mk,v 1.29 2015/10/03 05:00:46 sjg Exp $
+# $Id: gendirdeps.mk,v 1.33 2016/10/11 22:37:28 sjg Exp $
 
 # Copyright (c) 2010-2013, Juniper Networks, Inc.
 # All rights reserved.
@@ -82,7 +82,7 @@
 .export META_FILES
 
 # pickup customizations
-.-include "local.gendirdeps.mk"
+.-include <local.gendirdeps.mk>
 
 # these are actually prefixes that we'll skip
 # they should all be absolute paths
@@ -138,7 +138,8 @@
 .endif
 META2DEPS_CMD += \
 	-R ${RELDIR} -H ${HOST_TARGET} \
-	${M2D_OBJROOTS:O:u:@o at -O $o@}
+	${M2D_OBJROOTS:O:u:@o at -O $o@} \
+	${M2D_EXCLUDES:O:u:@o at -X $o@} \
 
 
 M2D_OBJROOTS += ${OBJTOP} ${_OBJROOT} ${_objroot}
@@ -145,6 +146,9 @@
 .if defined(SB_OBJROOT)
 M2D_OBJROOTS += ${SB_OBJROOT}
 .endif
+.if defined(STAGE_ROOT)
+M2D_OBJROOTS += ${STAGE_ROOT}
+.endif
 .if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} == ""
 # meta2deps.py only groks objroot
 # so we need to give it what it expects
@@ -255,6 +259,7 @@
 
 .if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != ""
 .info ${RELDIR}: M2D_OBJROOTS=${M2D_OBJROOTS}
+.info ${RELDIR}: M2D_EXCLUDES=${M2D_EXCLUDES}
 .info ${RELDIR}: dir_list='${dir_list}'
 .info ${RELDIR}: dpadd_dir_list='${dpadd_dir_list}'
 .info ${RELDIR}: dirdep_list='${dirdep_list}'
@@ -309,7 +314,7 @@
 # .depend may contain things we don't want.
 # The sed command at the end of the stream, allows for the filters
 # to output _{VAR} tokens which we will turn into proper ${VAR} references.
-${_DEPENDFILE}: ${CAT_DEPEND:M.depend} ${META_FILES:O:u:@m@${exists($m):?$m:}@} ${_this} ${META2DEPS}
+${_DEPENDFILE}: .NOMETA ${CAT_DEPEND:M.depend} ${META_FILES:O:u:@m@${exists($m):?$m:}@} ${_this} ${META2DEPS}
 	@(${GENDIRDEPS_HEADER} echo '# Autogenerated - do NOT edit!'; echo; \
 	echo 'DIRDEPS = \'; \
 	echo '${DIRDEPS:@d@	$d \\${.newline}@}'; echo; \
@@ -329,7 +334,7 @@
 
 all:	${_DEPENDFILE}
 
-${_DEPENDFILE}: ${MAKEFILE} ${_this}
+${_DEPENDFILE}: .NOMETA ${MAKEFILE} ${_this}
 	@(${GENDIRDEPS_HEADER} echo '# Autogenerated - do NOT edit!'; echo; \
 	echo 'DIRDEPS = \'; \
 	echo '${DIRDEPS:@d@	$d \\${.newline}@}'; echo; \

Modified: trunk/contrib/bmake/mk/inc.mk
===================================================================
--- trunk/contrib/bmake/mk/inc.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/inc.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-# $Id: inc.mk,v 1.3 2011/03/11 05:23:05 sjg Exp $
+# $Id: inc.mk,v 1.7 2017/05/06 17:29:45 sjg Exp $
 #
 #	@(#) Copyright (c) 2008, Simon J. Gerraty
 #
@@ -15,8 +15,6 @@
 
 .include <init.mk>
 
-includes:	${INCS}
-
 .if !empty(LIBOWN)
 INC_INSTALL_OWN ?= -o ${LIBOWN} -g ${LIBGRP}
 .endif
@@ -24,12 +22,68 @@
 INC_COPY ?= -C
 INCSDIR ?= ${INCDIR}
 
-realinstall:	incinstall
+STAGE_INCSDIR?= ${STAGE_OBJTOP}${INCSDIR}
+
+# accommodate folk used to freebsd
+INCGROUPS ?= ${INCSGROUPS:UINCS}
+INCGROUPS := ${INCGROUPS:O:u}
+
+.if !target(buildincludes)
+.for group in ${INCGROUPS}
+buildincludes: ${${group}}
+.endfor
+.endif
+buildincludes:
+includes: buildincludes
+
 .if !target(incinstall)
-incinstall:
-.if !empty(INCS)
-	[ -d ${DESTDIR}${INCSDIR} ] || \
-	${INSTALL} -d ${INC_INSTALL_OWN} -m 775 ${DESTDIR}${INCSDIR}
-	${INSTALL} ${INC_COPY} ${INC_INSTALL_OWN} -m ${INCMODE} ${INCS} ${DESTDIR}${INCSDIR}
+.for group in ${INCGROUPS}
+.if !empty(${group})
+.if ${group} != "INC"
+${group}_INSTALL_OWN ?= ${INC_INSTALL_OWN}
+${group}DIR ?= ${INCDIR}
 .endif
+# incase we are staging
+STAGE_DIR.${group} ?= ${STAGE_OBJTOP}${${group}DIR}
+
+.for header in ${${group}:O:u}
+${group}_INSTALL_OWN.${header:T} ?= ${${group}_INSTALL_OWN}
+${group}DIR.${header:T} ?= ${${group}DIR}
+inc_mkdir_list += ${${group}DIR.${header:T}}
+
+.if defined(${group}NAME.${header:T})
+STAGE_AS_SETS += ${group}
+STAGE_AS_${header} = ${${group}NAME.${header:T}}
+stage_as.${group}: ${header}
+
+incinstall: incinstall.${group}.${header:T}
+incinstall.${group}.${header:T}: ${header} inc_mkdirs
+	${INSTALL} ${INC_COPY} ${${group}_INSTALL_OWN.${header:T}} -m ${INCMODE} ${.ALLSRC:Ninc_mkdirs} ${DESTDIR}${${group}DIR}/${${group}NAME.${header:T}}
+
+.else
+STAGE_SETS += ${group}
+stage_files.${group}: ${header}
+incinstall.${group}: ${header}
+incinstall: incinstall.${group}
 .endif
+
+.endfor				# header
+
+incinstall.${group}: inc_mkdirs
+	${INSTALL} ${INC_COPY} ${${group}_INSTALL_OWN} -m ${INCMODE} \
+	${.ALLSRC:Ninc_mkdirs:O:u} ${DESTDIR}${${group}DIR}
+
+.endif				# !empty
+.endfor				# group
+
+inc_mkdirs:
+	@for d in ${inc_mkdir_list:O:u}; do \
+		test -d ${DESTDIR}$$d || \
+		${INSTALL} -d ${INC_INSTALL_OWN} -m 775 ${DESTDIR}$$d; \
+	done
+
+.endif				# !target(incinstall)
+
+beforeinstall:
+realinstall:	incinstall
+.ORDER: beforeinstall incinstall

Modified: trunk/contrib/bmake/mk/init.mk
===================================================================
--- trunk/contrib/bmake/mk/init.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/init.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-# $Id: init.mk,v 1.10 2015/12/07 04:28:31 sjg Exp $
+# $Id: init.mk,v 1.15 2017/05/07 20:27:54 sjg Exp $
 #
 #	@(#) Copyright (c) 2002, Simon J. Gerraty
 #
@@ -23,11 +23,14 @@
 .endif
 
 .-include <local.init.mk>
-.-include "${.CURDIR:H}/Makefile.inc"
+.-include <${.CURDIR:H}/Makefile.inc>
 .include <own.mk>
 
 .MAIN:		all
 
+# should have been set by sys.mk
+CXX_SUFFIXES?= .cc .cpp .cxx .C
+
 .if !empty(WARNINGS_SET) || !empty(WARNINGS_SET_${MACHINE_ARCH})
 .include <warnings.mk>
 .endif
@@ -47,8 +50,20 @@
 _SKIP_BUILD = not building at level 0
 .endif
 
-.if !empty(_SKIP_BUILD)
+.if !defined(.PARSEDIR)
+# no-op is the best we can do if not bmake.
+.WAIT:
+.endif
+
+# define this once for consistency
+.if empty(_SKIP_BUILD)
+# beforebuild is a hook for things that must be done early
+all: beforebuild .WAIT realbuild
+.else
 all: .PHONY
 .warning ${_SKIP_BUILD}
 .endif
+beforebuild:
+realbuild:
+
 .endif

Modified: trunk/contrib/bmake/mk/install-mk
===================================================================
--- trunk/contrib/bmake/mk/install-mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/install-mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -55,7 +55,7 @@
 #       Simon J. Gerraty <sjg at crufty.net>
 
 # RCSid:
-#	$Id: install-mk,v 1.118 2015/12/16 01:57:06 sjg Exp $
+#	$Id: install-mk,v 1.148 2017/06/30 23:46:15 sjg Exp $
 #
 #	@(#) Copyright (c) 1994 Simon J. Gerraty
 #
@@ -70,7 +70,7 @@
 #	sjg at crufty.net
 #
 
-MK_VERSION=20151212
+MK_VERSION=20170630
 OWNER=
 GROUP=
 MODE=444
@@ -176,7 +176,7 @@
 [ "$OWNER" ] && $SKIP_MKFILES Do chown $OWNER $mk_files $sys_mk_files
 # if this is a BSD system the bsd.*.mk should exist and be used.
 if [ -z "$SKIP_BSD_MK" ]; then
-	for f in dep doc init lib links man nls obj own prog subdir
+	for f in dep doc files inc init lib links man nls obj own prog subdir
 	do
 		b=bsd.$f.mk
 		[ -s $b ] || Do ln -s $f.mk $b

Modified: trunk/contrib/bmake/mk/lib.mk
===================================================================
--- trunk/contrib/bmake/mk/lib.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/lib.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-# $Id: lib.mk,v 1.52 2015/11/14 18:09:57 sjg Exp $
+# $Id: lib.mk,v 1.62 2017/06/11 03:24:04 sjg Exp $
 
 .if !target(__${.PARSEFILE}__)
 __${.PARSEFILE}__:
@@ -9,44 +9,35 @@
 NEED_SOLINKS?= yes
 .endif
 
-.if exists(${.CURDIR}/shlib_version)
-SHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major
-SHLIB_MINOR != . ${.CURDIR}/shlib_version ; echo $$minor
+SHLIB_VERSION_FILE?= ${.CURDIR}/shlib_version
+.if !defined(SHLIB_MAJOR) && exists(${SHLIB_VERSION_FILE})
+SHLIB_MAJOR != . ${SHLIB_VERSION_FILE} ; echo $$major
+SHLIB_MINOR != . ${SHLIB_VERSION_FILE} ; echo $$minor
+SHLIB_TEENY != . ${SHLIB_VERSION_FILE} ; echo $$teeny
 .endif
 
-print-shlib-major:
-.if defined(SHLIB_MAJOR) && ${MK_PIC} != "no"
-	@echo ${SHLIB_MAJOR}
+.for x in major minor teeny
+print-shlib-$x:
+.if defined(SHLIB_${x:tu}) && ${MK_PIC} != "no"
+	@echo ${SHLIB_${x:tu}}
 .else
 	@false
 .endif
+.endfor
 
-print-shlib-minor:
-.if defined(SHLIB_MINOR) && ${MK_PIC} != "no"
-	@echo ${SHLIB_MINOR}
-.else
-	@false
-.endif
-
-print-shlib-teeny:
-.if defined(SHLIB_TEENY) && ${MK_PIC} != "no"
-	@echo ${SHLIB_TEENY}
-.else
-	@false
-.endif
-
 SHLIB_FULLVERSION ?= ${${SHLIB_MAJOR} ${SHLIB_MINOR} ${SHLIB_TEENY}:L:ts.}
 SHLIB_FULLVERSION := ${SHLIB_FULLVERSION}
 
 # add additional suffixes not exported.
 # .po is used for profiling object files.
-# .so is used for PIC object files.
-.SUFFIXES: .out .a .ln .so .po .o .s .S .c .cc .C .m .F .f .r .y .l .cl .p .h
+# ${PICO} is used for PIC object files.
+PICO?= .pico
+.SUFFIXES: .out .a .ln ${PICO} .po .o .s .S .c .cc .C .m .F .f .r .y .l .cl .p .h
 .SUFFIXES: .sh .m4 .m
 
 CFLAGS+=	${COPTS}
 
-# Derrived from NetBSD-1.6
+# Originally derrived from NetBSD-1.6
 
 # Set PICFLAGS to cc flags for producing position-independent code,
 # if not already set.  Includes -DPIC, if required.
@@ -62,12 +53,12 @@
 #			with ELF, also set shared-lib version for ld.so.
 # SHLIB_LDSTARTFILE:	support .o file, call C++ file-level constructors
 # SHLIB_LDENDFILE:	support .o file, call C++ file-level destructors
-# FPICFLAGS:		flags for ${FC} to compile .[fF] files to .so objects.
+# FPICFLAGS:		flags for ${FC} to compile .[fF] files to ${PICO} objects.
 # CPPICFLAGS:		flags for ${CPP} to preprocess .[sS] files for ${AS}
-# CPICFLAGS:		flags for ${CC} to compile .[cC] files to .so objects.
+# CPICFLAGS:		flags for ${CC} to compile .[cC] files to ${PICO} objects.
 # CAPICFLAGS		flags for {$CC} to compiling .[Ss] files
 #		 	(usually just ${CPPPICFLAGS} ${CPICFLAGS})
-# APICFLAGS:		flags for ${AS} to assemble .[sS] to .so objects.
+# APICFLAGS:		flags for ${AS} to assemble .[sS] to ${PICO} objects.
 
 .if ${TARGET_OSNAME} == "NetBSD"
 .if ${MACHINE_ARCH} == "alpha"
@@ -162,7 +153,7 @@
 LD_so=sl
 DLLIB=
 # HPsUX lorder does not grok anything but .o
-LD_sobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.so,'`
+LD_sobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,${PICO},'`
 LD_pobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.po,'`
 .elif ${TARGET_OSNAME} == "OSF1"
 LD_shared= -msym -shared -expect_unresolved '*'
@@ -169,7 +160,7 @@
 LD_solib= -all lib${LIB}_pic.a
 DLLIB=
 # lorder does not grok anything but .o
-LD_sobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.so,'`
+LD_sobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,${PICO},'`
 LD_pobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.po,'`
 AR_cq= -cqs
 .elif ${TARGET_OSNAME} == "FreeBSD"
@@ -252,9 +243,9 @@
 DLLIB ?= -ldl
 .endif
 
-# some libs have lots of objects, and scanning all .o, .po and .So meta files
+# some libs have lots of objects, and scanning all .o, .po and ${PICO} meta files
 # is a waste of time, this tells meta.autodep.mk to just pick one 
-# (typically .So)
+# (typically ${PICO})
 # yes, 42 is a random number.
 .if ${MK_DIRDEPS_BUILD} == "yes" && ${SRCS:Uno:[\#]} > 42
 OPTIMIZE_OBJECT_META_FILES ?= yes
@@ -275,47 +266,43 @@
 	${COMPILE.c} ${.IMPSRC}
 
 # for the normal .a we do not want to strip symbols
-.cc.o .C.o:
+${CXX_SUFFIXES:%=%.o}:
 	${COMPILE.cc} ${.IMPSRC}
 
 .S.o .s.o:
-	@echo ${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
-	@${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} 
+	${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} 
 
 .if (${LD_X} == "")
 .c.po:
 	${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}
 
-.cc.po .C.po:
+${CXX_SUFFIXES:%=%.po}:
 	${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}
 
-.S.so .s.so:
+.S${PICO} .s${PICO}:
 	${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
 .else
 .c.po:
-	@echo ${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}
-	@${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}.o
+	${COMPILE.c} ${CC_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}.o
 	@${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
 	@rm -f ${.TARGET}.o
 
-.cc.po .C.po:
-	@echo ${COMPILE.cc} ${CXX_PG} ${PROFFLAGS} ${.IMPSRC} -o ${.TARGET}
-	@${COMPILE.cc} ${CXX_PG} ${.IMPSRC} -o ${.TARGET}.o
-	@${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
+${CXX_SUFFIXES:%=%.po}:
+	${COMPILE.cc} ${CXX_PG} ${.IMPSRC} -o ${.TARGET}.o
+	${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
 	@rm -f ${.TARGET}.o
 
-.S.so .s.so:
-	@echo ${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
-	@${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
-	@${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
+.S${PICO} .s${PICO}:
+	${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
+	${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
 	@rm -f ${.TARGET}.o
 .endif
 
 .if (${LD_x} == "")
-.c.so:
+.c${PICO}:
 	${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
 
-.cc.so .C.so:
+${CXX_SUFFIXES:%=%${PICO}}:
 	${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
 
 .S.po .s.po:
@@ -322,22 +309,19 @@
 	${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
 .else
 
-.c.so:
-	@echo ${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
-	@${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}.o
-	@${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
+.c${PICO}:
+	${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}.o
+	${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
 	@rm -f ${.TARGET}.o
 
-.cc.so .C.so:
-	@echo ${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
-	@${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}.o
-	@${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
+${CXX_SUFFIXES:%=%${PICO}}:
+	${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}.o
+	${LD} ${LD_x} ${LD_r} ${.TARGET}.o -o ${.TARGET}
 	@rm -f ${.TARGET}.o
 
 .S.po .s.po:
-	@echo ${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
-	@${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
-	@${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
+	${COMPILE.S} ${PROFFLAGS} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
+	${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
 	@rm -f ${.TARGET}.o
 
 .endif
@@ -386,19 +370,18 @@
 .include <dpadd.mk>
 .endif
 
+.if empty(LIB)
+_LIBS=
+.endif
+
 .if !defined(_SKIP_BUILD)
-all: prebuild .WAIT ${_LIBS} 
-# a hook for things that must be done early
-prebuild:
-.if !defined(.PARSEDIR)
-# no-op is the best we can do if not bmake.
-.WAIT:
+realbuild: ${_LIBS} 
 .endif
-.endif
+
 all: _SUBDIRUSE
 
 .for s in ${SRCS:N*.h:M*/*}
-${.o .so .po .lo:L:@o@${s:T:R}$o@}: $s
+${.o ${PICO} .po .lo:L:@o@${s:T:R}$o@}: $s
 .endfor
 
 OBJS+=	${SRCS:T:N*.h:R:S/$/.o/g}
@@ -430,7 +413,7 @@
 .else  # MK_LIBTOOL=yes
 
 lib${LIB}.a:: ${OBJS}
-	@echo building standard ${LIB} library
+	@${META_NOECHO} building standard ${LIB} library
 	@rm -f ${.TARGET}
 	@${AR} ${AR_cq} ${.TARGET} ${LD_objs}
 	${RANLIB} ${.TARGET}
@@ -438,15 +421,15 @@
 POBJS+=	${OBJS:.o=.po}
 .NOPATH:	${POBJS}
 lib${LIB}_p.a:: ${POBJS}
-	@echo building profiled ${LIB} library
+	@${META_NOECHO} building profiled ${LIB} library
 	@rm -f ${.TARGET}
 	@${AR} ${AR_cq} ${.TARGET} ${LD_pobjs}
 	${RANLIB} ${.TARGET}
 
-SOBJS+=	${OBJS:.o=.so}
+SOBJS+=	${OBJS:.o=${PICO}}
 .NOPATH:	${SOBJS}
 lib${LIB}_pic.a:: ${SOBJS}
-	@echo building shared object ${LIB} library
+	@${META_NOECHO} building shared object ${LIB} library
 	@rm -f ${.TARGET}
 	@${AR} ${AR_cq} ${.TARGET} ${LD_sobjs}
 	${RANLIB} ${.TARGET}
@@ -456,7 +439,7 @@
 # bound to be non-portable...
 # this is known to work for NetBSD 1.6 and FreeBSD 4.2
 lib${LIB}.${LD_so}: ${SOLIB} ${DPADD}
-	@echo building shared ${LIB} library \(version ${SHLIB_FULLVERSION}\)
+	@${META_NOECHO} building shared ${LIB} library \(version ${SHLIB_FULLVERSION}\)
 	@rm -f ${.TARGET}
 .if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD" || ${TARGET_OSNAME} == "MidnightBSD"
 .if ${OBJECT_FMT} == "ELF"
@@ -480,7 +463,7 @@
 .NOPATH:	${LOBJS}
 LLIBS?=	-lc
 llib-l${LIB}.ln: ${LOBJS}
-	@echo building llib-l${LIB}.ln
+	@${META_NOECHO} building llib-l${LIB}.ln
 	@rm -f llib-l${LIB}.ln
 	@${LINT} -C${LIB} ${LOBJS} ${LLIBS}
 
@@ -504,7 +487,7 @@
 .if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
 afterdepend: .depend
 	@(TMP=/tmp/_depend$$$$; \
-	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \
+	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1${PICO} \1.ln:/' \
 	      < .depend > $$TMP; \
 	    mv $$TMP .depend)
 .endif
@@ -520,10 +503,8 @@
 
 .include <links.mk>
 
-.if !target(realinstall)
+.if !target(libinstall) && !empty(LIB)
 realinstall: libinstall
-.endif
-.if !target(libinstall)
 libinstall:
 	[ -d ${DESTDIR}/${LIBDIR} ] || \
 	${INSTALL} -d ${LIB_INSTALL_OWN} -m 775 ${DESTDIR}${LIBDIR}
@@ -563,12 +544,19 @@
 .endif
 .endif
 
+.if ${MK_MAN} != "no"
 install: maninstall _SUBDIRUSE
 maninstall: afterinstall
+.endif
 afterinstall: realinstall
+libinstall: beforeinstall
 realinstall: beforeinstall
 .endif
 
+.if defined(FILES) || defined(FILESGROUPS)
+.include <files.mk>
+.endif
+
 .if ${MK_MAN} != "no"
 .include <man.mk>
 .endif
@@ -601,5 +589,10 @@
 .endfor
 	@touch ${.TARGET}
 
+.if !empty(LIB)
+STAGE_LIBDIR?= ${STAGE_OBJTOP}${LIBDIR}
+stage_libs: ${_LIBS}
+.endif
+
 .include <final.mk>
 .endif

Modified: trunk/contrib/bmake/mk/libnames.mk
===================================================================
--- trunk/contrib/bmake/mk/libnames.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/libnames.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-# $Id: libnames.mk,v 1.7 2009/12/25 07:34:03 sjg Exp $
+# $Id: libnames.mk,v 1.8 2016/04/05 15:58:37 sjg Exp $
 #
 #	@(#) Copyright (c) 2007-2009, Simon J. Gerraty
 #
@@ -16,7 +16,7 @@
 DLIBEXT ?= .a
 DSHLIBEXT ?= .so
 
-.-include "local.libnames.mk"
-.-include "sjg.libnames.mk"
-.-include "fwall.libnames.mk"
-.-include "host.libnames.mk"
+.-include <local.libnames.mk>
+.-include <sjg.libnames.mk>
+.-include <fwall.libnames.mk>
+.-include <host.libnames.mk>

Modified: trunk/contrib/bmake/mk/meta.autodep.mk
===================================================================
--- trunk/contrib/bmake/mk/meta.autodep.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/meta.autodep.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-# $Id: meta.autodep.mk,v 1.39 2015/12/07 04:35:32 sjg Exp $
+# $Id: meta.autodep.mk,v 1.45 2016/06/03 17:22:32 sjg Exp $
 
 #
 #	@(#) Copyright (c) 2010, Simon J. Gerraty
@@ -18,7 +18,7 @@
 .if !target(__${_this}__)
 __${_this}__: .NOTMAIN
 
-.-include "local.autodep.mk"
+.-include <local.autodep.mk>
 
 .if defined(SRCS)
 # it would be nice to be able to query .SUFFIXES
@@ -55,6 +55,21 @@
 _OBJROOT ?= ${OBJROOT:U${_OBJTOP}}
 _DEPENDFILE := ${_CURDIR}/${.MAKE.DEPENDFILE:T}
 
+.if ${.MAKE.LEVEL} > 0 || ${BUILD_AT_LEVEL0:Uyes:tl} == "yes"
+# do not allow auto update if we ever built this dir without filemon
+NO_FILEMON_COOKIE = .nofilemon
+CLEANFILES += ${NO_FILEMON_COOKIE}
+.if ${.MAKE.MODE:Uno:Mnofilemon} != ""
+UPDATE_DEPENDFILE = NO
+all: ${NO_FILEMON_COOKIE}
+${NO_FILEMON_COOKIE}: .NOMETA
+	@echo UPDATE_DEPENDFILE=NO > ${.TARGET}
+.elif exists(${NO_FILEMON_COOKIE})
+UPDATE_DEPENDFILE = NO
+.warning ${RELDIR} built with nofilemon; UPDATE_DEPENDFILE=NO
+.endif
+.endif
+
 .if ${.MAKE.LEVEL} == 0
 .if ${BUILD_AT_LEVEL0:Uyes:tl} == "no"
 UPDATE_DEPENDFILE = NO
@@ -86,7 +101,7 @@
 .endif
 
 .if ${WANT_UPDATE_DEPENDFILE:Uno:tl} != "no"
-.if ${.MAKE.MODE:Mmeta*} == "" || ${.MAKE.MODE:M*read*} != ""
+.if ${.MAKE.MODE:Uno:Mmeta*} == "" || ${.MAKE.MODE:Uno:M*read*} != ""
 UPDATE_DEPENDFILE = no
 .endif
 
@@ -195,7 +210,7 @@
 # The pseudo machine "host" is used for HOST_TARGET
 DIRDEPS += \
 	${DPADD:M${_OBJTOP}*:H:C,${_OBJTOP}[^/]*/,,:N.:O:u} \
-	${DPADD:M${_OBJROOT}*:N${_OBJTOP}*:H:S,${_OBJROOT},,:C,^([^/]+)/(.*),\2.\1,:S,${HOST_TARGET}$,host,:N.*:O:u}
+	${DPADD:M${_OBJROOT}*:N${_OBJTOP}*:N${STAGE_ROOT:U${_OBJTOP}}/*:H:S,${_OBJROOT},,:C,^([^/]+)/(.*),\2.\1,:S,${HOST_TARGET}$,host,:N.*:O:u}
 
 .endif
 .endif
@@ -251,7 +266,7 @@
 	DPADD='${FORCE_DPADD:O:u}' ${_gendirdeps_mutex} \
 	MAKESYSPATH=${_makesyspath} \
 	${.MAKE} -f gendirdeps.mk RELDIR=${RELDIR} _DEPENDFILE=${_DEPENDFILE} \
-	META_FILES='${META_XTRAS:T:O:u} ${META_FILES:T:O:u:${META_FILE_FILTER:ts:}}')
+	META_FILES='${META_XTRAS:O:u} ${META_FILES:T:O:u:${META_FILE_FILTER:ts:}}')
 	@test -s $@ && touch $@; :
 .endif
 

Modified: trunk/contrib/bmake/mk/meta.stage.mk
===================================================================
--- trunk/contrib/bmake/mk/meta.stage.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/meta.stage.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,6 +1,6 @@
-# $Id: meta.stage.mk,v 1.41 2015/11/13 17:34:04 sjg Exp $
+# $Id: meta.stage.mk,v 1.54 2017/07/06 23:20:33 sjg Exp $
 #
-#	@(#) Copyright (c) 2011, Simon J. Gerraty
+#	@(#) Copyright (c) 2011-2017, Simon J. Gerraty
 #
 #	This file is provided in the hope that it will
 #	be of use.  There is absolutely NO WARRANTY.
@@ -13,8 +13,10 @@
 #	sjg at crufty.net
 #
 
+.ifndef NO_STAGING
+
 .if !target(__${.PARSEFILE}__)
-__${.PARSEFILE}__:
+# the guard target is defined later
 
 .if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} != ""
 # this is generally safer anyway
@@ -26,7 +28,7 @@
 CLEANFILES+= .dirdep
 
 # this allows us to trace dependencies back to their src dir
-.dirdep:
+.dirdep:	.NOPATH
 	@echo '${_dirdep}' > $@
 
 .if defined(NO_POSIX_SHELL) || ${type printf:L:sh:Mbuiltin} == ""
@@ -58,7 +60,7 @@
 
 LN_CP_SCRIPT = LnCp() { \
   rm -f $$2 2> /dev/null; \
-  ln $$1 $$2 2> /dev/null || \
+  { [ -z "$$mode" ] && ${LN:Uln} $$1 $$2 2> /dev/null; } || \
   cp -p $$1 $$2; }
 
 # a staging conflict should cause an error
@@ -127,27 +129,39 @@
   done; :; }
 
 # this is simple, a list of the "staged" files depends on this,
-_STAGE_BASENAME_USE:	.USE ${.TARGET:T}
+_STAGE_BASENAME_USE:	.USE .dirdep ${.TARGET:T}
 	@${STAGE_FILE_SCRIPT}; StageFiles ${.TARGET:H:${STAGE_DIR_FILTER}} ${.TARGET:T}
 
-_STAGE_AS_BASENAME_USE:        .USE ${.TARGET:T}
+_STAGE_AS_BASENAME_USE:        .USE .dirdep ${.TARGET:T}
 	@${STAGE_AS_SCRIPT}; StageAs ${.TARGET:H:${STAGE_DIR_FILTER}} ${.TARGET:T} ${STAGE_AS_${.TARGET:T}:U${.TARGET:T}}
 
+
+.endif				# first time
+
+
 .if !empty(STAGE_INCSDIR)
+.if !empty(STAGE_INCS)
+stage_incs: ${STAGE_INCS}
+.endif
+.if target(stage_incs) || !empty(.ALLTARGETS:Mstage_includes)
 STAGE_TARGETS += stage_incs
 STAGE_INCS ?= ${.ALLSRC:N.dirdep:Nstage_*}
-
 stage_includes: stage_incs
+stage_includes: stage_incs
 stage_incs:	.dirdep
 	@${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_INCSDIR:${STAGE_DIR_FILTER}} ${STAGE_INCS}
 	@touch $@
+
 .endif
+.endif
 
 .if !empty(STAGE_LIBDIR)
+.if !empty(STAGE_LIBS)
+stage_libs: ${STAGE_LIBS}
+.endif
+.if target(stage_libs)
 STAGE_TARGETS += stage_libs
-
 STAGE_LIBS ?= ${.ALLSRC:N.dirdep:Nstage_*}
-
 stage_libs:	.dirdep
 	@${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} ${STAGE_LIBS}
 .if !defined(NO_SHLIB_LINKS)
@@ -160,6 +174,7 @@
 .endif
 	@touch $@
 .endif
+.endif
 
 .if !empty(STAGE_DIR)
 STAGE_SETS += _default
@@ -169,8 +184,6 @@
 STAGE_FILES._default = ${STAGE_FILES}
 STAGE_LINKS._default = ${STAGE_LINKS}
 STAGE_SYMLINKS._default = ${STAGE_SYMLINKS}
-STAGE_FILES ?= ${.ALLSRC:N.dirdep:Nstage_*}
-STAGE_SYMLINKS ?= ${.ALLSRC:T:N.dirdep:Nstage_*}
 .endif
 
 .if !empty(STAGE_SETS)
@@ -178,22 +191,34 @@
 
 # some makefiles need to populate multiple directories
 .for s in ${STAGE_SETS:O:u}
+.if !empty(STAGE_FILES.$s)
+stage_files.$s: ${STAGE_FILES.$s}
+.endif
+.if target(stage_files.$s) || target(stage_files${s:S,^,.,:N._default})
+STAGE_TARGETS += stage_files
 STAGE_FILES.$s ?= ${.ALLSRC:N.dirdep:Nstage_*}
-STAGE_SYMLINKS.$s ?= ${.ALLSRC:N.dirdep:Nstage_*}
-STAGE_LINKS_DIR.$s ?= ${STAGE_OBJTOP}
-STAGE_SYMLINKS_DIR.$s ?= ${STAGE_OBJTOP}
-
-STAGE_TARGETS += stage_files
+.if !target(.stage_files.$s)
+.stage_files.$s:
 .if $s != "_default"
 stage_files:	stage_files.$s
 stage_files.$s:	.dirdep
 .else
+STAGE_FILES ?= ${.ALLSRC:N.dirdep:Nstage_*}
 stage_files:	.dirdep
 .endif
 	@${STAGE_FILE_SCRIPT}; StageFiles ${FLAGS.$@} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_FILES.$s}
 	@touch $@
+.endif
+.endif
 
+.if !empty(STAGE_LINKS.$s)
+stage_links.$s:
+.endif
+.if target(stage_links.$s) || target(stage_links${s:S,^,.,:N._default})
+STAGE_LINKS_DIR.$s ?= ${STAGE_OBJTOP}
 STAGE_TARGETS += stage_links
+.if !target(.stage_links.$s)
+.stage_links.$s:
 .if $s != "_default"
 stage_links:	stage_links.$s
 stage_links.$s:	.dirdep
@@ -202,8 +227,17 @@
 .endif
 	@${STAGE_LINKS_SCRIPT}; StageLinks ${STAGE_LINKS_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_LINKS.$s}
 	@touch $@
+.endif
+.endif
 
+.if !empty(STAGE_SYMLINKS.$s)
+stage_symlinks.$s:
+.endif
+.if target(stage_symlinks.$s) || target(stage_symlinks${s:S,^,.,:N._default})
+STAGE_SYMLINKS_DIR.$s ?= ${STAGE_OBJTOP}
 STAGE_TARGETS += stage_symlinks
+.if !target(.stage_symlinks.$s)
+.stage_symlinks.$s:
 .if $s != "_default"
 stage_symlinks:	stage_symlinks.$s
 stage_symlinks.$s:	.dirdep
@@ -212,6 +246,8 @@
 .endif
 	@${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_SYMLINKS_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_SYMLINKS.$s}
 	@touch $@
+.endif
+.endif
 
 .endfor
 .endif
@@ -219,29 +255,58 @@
 .if !empty(STAGE_AS_SETS)
 CLEANFILES += ${STAGE_AS_SETS:@s at stage*$s@}
 
-STAGE_TARGETS += stage_as
-
 # sometimes things need to be renamed as they are staged
 # each ${file} will be staged as ${STAGE_AS_${file:T}}
 # one could achieve the same with SYMLINKS
+# stage_as_and_symlink makes the original name a symlink to the new name
+# it is the same as using stage_as and stage_symlinks but ensures
+# both operations happen together
 .for s in ${STAGE_AS_SETS:O:u}
+.if !empty(STAGE_AS.$s)
+stage_as.$s: ${STAGE_AS.$s}
+.endif
+.if target(stage_as.$s)
+STAGE_TARGETS += stage_as
 STAGE_AS.$s ?= ${.ALLSRC:N.dirdep:Nstage_*}
-
+.if !target(.stage_as.$s)
+.stage_as.$s:
 stage_as:	stage_as.$s
 stage_as.$s:	.dirdep
 	@${STAGE_AS_SCRIPT}; StageAs ${FLAGS.$@} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_AS.$s:@f@$f ${STAGE_AS_${f:tA}:U${STAGE_AS_${f:T}:U${f:T}}}@}
 	@touch $@
+.endif
+.endif
 
+.if !empty(STAGE_AS_AND_SYMLINK.$s)
+stage_as_and_symlink.$s: ${STAGE_AS_AND_SYMLINK.$s}
+.endif
+.if target(stage_as_and_symlink.$s)
+STAGE_TARGETS += stage_as_and_symlink
+STAGE_AS_AND_SYMLINK.$s ?= ${.ALLSRC:N.dirdep:Nstage_*}
+.if !target(.stage_as_and_symlink.$s)
+.stage_as_and_symlink.$s:
+stage_as_and_symlink:	stage_as_and_symlink.$s
+stage_as_and_symlink.$s:	.dirdep
+	@${STAGE_AS_SCRIPT}; StageAs ${FLAGS.$@} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_AS_AND_SYMLINK.$s:@f@$f ${STAGE_AS_${f:tA}:U${STAGE_AS_${f:T}:U${f:T}}}@}
+	@${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_AS_AND_SYMLINK.$s:@f@${STAGE_AS_${f:tA}:U${STAGE_AS_${f:T}:U${f:T}}} $f@}
+	@touch $@
+.endif
+.endif
+
 .endfor
 .endif
 
 CLEANFILES += ${STAGE_TARGETS} stage_incs stage_includes
 
+# this lot also only makes sense the first time...
+.if !target(__${.PARSEFILE}__)
+__${.PARSEFILE}__:
+
 # stage_*links usually needs to follow any others.
 # for non-jobs mode the order here matters
 staging: ${STAGE_TARGETS:N*_links} ${STAGE_TARGETS:M*_links}
 
-.if ${.MAKE.JOBS:U0} > 0 && ${STAGE_TARGETS:M*_links} != ""
+.if ${.MAKE.JOBS:U0} > 0 && ${STAGE_TARGETS:U:M*_links} != ""
 # the above isn't sufficient
 .for t in ${STAGE_TARGETS:N*links:O:u}
 .ORDER: $t stage_links
@@ -270,6 +335,11 @@
 .NOPATH: ${STAGE_FILES}
 
 .if !empty(STAGE_TARGETS)
+# for backwards compat make sure they exist
+${STAGE_TARGETS}:
+
+.NOPATH: ${CLEANFILES}
+
 MK_STALE_STAGED?= no
 .if ${MK_STALE_STAGED} == "yes"
 all: stale_staged
@@ -290,3 +360,4 @@
 .endif
 .endif
 .endif
+.endif

Modified: trunk/contrib/bmake/mk/meta.sys.mk
===================================================================
--- trunk/contrib/bmake/mk/meta.sys.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/meta.sys.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-# $Id: meta.sys.mk,v 1.26 2015/11/14 21:16:13 sjg Exp $
+# $Id: meta.sys.mk,v 1.32 2017/06/11 03:24:04 sjg Exp $
 
 #
 #	@(#) Copyright (c) 2010, Simon J. Gerraty
@@ -20,11 +20,15 @@
 .if ${MAKE_VERSION:U0} > 20100901
 .if !target(.ERROR)
 
-.-include "local.meta.sys.mk"
+.-include <local.meta.sys.mk>
 
 # absoulte path to what we are reading.
 _PARSEDIR = ${.PARSEDIR:tA}
 
+.if !defined(SYS_MK_DIR)
+SYS_MK_DIR := ${_PARSEDIR}
+.endif
+
 META_MODE += meta verbose
 .MAKE.MODE ?= ${META_MODE}
 
@@ -102,7 +106,7 @@
 # some targets need to be .PHONY in non-meta mode
 META_NOPHONY= .PHONY
 # Are we, after all, in meta mode?
-.if ${.MAKE.MODE:Mmeta*} != ""
+.if ${.MAKE.MODE:Uno:Mmeta*} != ""
 MKDEP_MK = meta.autodep.mk
 
 .if ${.MAKE.MAKEFILES:M*sys.dependfile.mk} == ""
@@ -117,8 +121,18 @@
 
 # we can afford to use cookies to prevent some targets
 # re-running needlessly
-META_COOKIE_TOUCH= touch ${COOKIE.${.TARGET}:U${.OBJDIR}/${.TARGET}}
+META_COOKIE_TOUCH?= touch ${COOKIE.${.TARGET}:U${.OBJDIR}/${.TARGET:T}}
 META_NOPHONY=
+META_NOECHO= :
+
+# some targets involve old pre-built targets
+# ignore mtime of shell
+# and mtime of makefiles does not matter in meta mode
+.MAKE.META.IGNORE_PATHS += \
+        ${MAKEFILE} \
+        ${SHELL} \
+        ${SYS_MK_DIR}
+
 .if ${UPDATE_DEPENDFILE:Uyes:tl} != "no"
 .if ${.MAKEFLAGS:Uno:M-k} != ""
 # make this more obvious
@@ -149,5 +163,10 @@
 .endif
 
 .endif
+.else
+META_COOKIE_TOUCH=
+# some targets need to be .PHONY in non-meta mode
+META_NOPHONY= .PHONY
+META_NOECHO= echo
 .endif
 .endif

Modified: trunk/contrib/bmake/mk/meta2deps.py
===================================================================
--- trunk/contrib/bmake/mk/meta2deps.py	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/meta2deps.py	2018-06-27 00:20:04 UTC (rev 11140)
@@ -37,7 +37,7 @@
 
 """
 RCSid:
-	$Id: meta2deps.py,v 1.18 2015/04/03 18:23:25 sjg Exp $
+	$Id: meta2deps.py,v 1.27 2017/05/24 00:04:04 sjg Exp $
 
 	Copyright (c) 2011-2013, Juniper Networks, Inc.
 	All rights reserved.
@@ -90,6 +90,12 @@
     for d in [last_dir, cwd]:
         if not d:
             continue
+        if path == '..':
+            dw = d.split('/')
+            p = '/'.join(dw[:-1])
+            if not p:
+                p = '/'
+            return p
         p = '/'.join([d,path])
         if debug > 2:
             print("looking for:", p, end=' ', file=debug_out)
@@ -103,20 +109,39 @@
         return p
     return None
 
+def cleanpath(path):
+    """cleanup path without using realpath(3)"""
+    if path.startswith('/'):
+        r = '/'
+    else:
+        r = ''
+    p = []
+    w = path.split('/')
+    for d in w:
+        if not d or d == '.':
+            continue
+        if d == '..':
+            try:
+                p.pop()
+                continue
+            except:
+                break
+        p.append(d)
+
+    return r + '/'.join(p)
+
 def abspath(path, cwd, last_dir=None, debug=0, debug_out=sys.stderr):
     """
     Return an absolute path, resolving via cwd or last_dir if needed.
-    this gets called a lot, so we try to avoid calling realpath
-    until we know we have something.
+    this gets called a lot, so we try to avoid calling realpath.
     """
     rpath = resolve(path, cwd, last_dir, debug, debug_out)
     if rpath:
         path = rpath
     if (path.find('/') < 0 or
-	path.find('./') > 0 or
-        path.endswith('/..') or
-        os.path.islink(path)):
-        return os.path.realpath(path)
+        path.find('./') > 0 or
+        path.endswith('/..')):
+        path = cleanpath(path)
     return path
 
 def sort_unique(list, cmp=None, key=None, reverse=False):
@@ -126,6 +151,7 @@
     for e in list:
         if e == le:
             continue
+        le = e
         nl.append(e)
     return nl
 
@@ -153,38 +179,38 @@
         """if name is set we will parse it now.
         conf can have the follwing keys:
 
-        SRCTOPS	list of tops of the src tree(s).
+        SRCTOPS list of tops of the src tree(s).
 
-        CURDIR	the src directory 'bmake' was run from.
+        CURDIR  the src directory 'bmake' was run from.
 
-        RELDIR	the relative path from SRCTOP to CURDIR
+        RELDIR  the relative path from SRCTOP to CURDIR
 
-        MACHINE	the machine we built for.
-        	set to 'none' if we are not cross-building.
-		More specifically if machine cannot be deduced from objdirs.
+        MACHINE the machine we built for.
+                set to 'none' if we are not cross-building.
+                More specifically if machine cannot be deduced from objdirs.
 
         TARGET_SPEC
-        	Sometimes MACHINE isn't enough.
+                Sometimes MACHINE isn't enough.
                 
         HOST_TARGET
-		when we build for the pseudo machine 'host'
-		the object tree uses HOST_TARGET rather than MACHINE.
+                when we build for the pseudo machine 'host'
+                the object tree uses HOST_TARGET rather than MACHINE.
 
         OBJROOTS a list of the common prefix for all obj dirs it might
-		end in '/' or '-'.
+                end in '/' or '-'.
 
-        DPDEPS	names an optional file to which per file dependencies
-		will be appended.
-		For example if 'some/path/foo.h' is read from SRCTOP
-		then 'DPDEPS_some/path/foo.h +=' "RELDIR" is output.
-		This can allow 'bmake' to learn all the dirs within
- 		the tree that depend on 'foo.h'
+        DPDEPS  names an optional file to which per file dependencies
+                will be appended.
+                For example if 'some/path/foo.h' is read from SRCTOP
+                then 'DPDEPS_some/path/foo.h +=' "RELDIR" is output.
+                This can allow 'bmake' to learn all the dirs within
+                the tree that depend on 'foo.h'
 
-	EXCLUDES
-		A list of paths to ignore.
-		ccache(1) can otherwise be trouble.
+        EXCLUDES
+                A list of paths to ignore.
+                ccache(1) can otherwise be trouble.
 
-        debug	desired debug level
+        debug   desired debug level
 
         debug_out open file to send debug output to (sys.stderr)
 
@@ -228,8 +254,9 @@
                     if objroot.endswith(e):
                         # this is not what we want - fix it
                         objroot = objroot[0:-len(e)]
-                        if e.endswith('/'):
-                            objroot += '/'
+
+                if objroot[-1] != '/':
+                    objroot += '/'
                 if not objroot in self.objroots:
                     self.objroots.append(objroot)
                     _objroot = os.path.realpath(objroot)
@@ -292,6 +319,9 @@
             return None
         for f in sort_unique(self.file_deps):
             print('DPDEPS_%s += %s' % (f, self.reldir), file=out)
+        # these entries provide for reverse DIRDEPS lookup
+        for f in self.obj_deps:
+            print('DEPDIRS_%s += %s' % (f, self.reldir), file=out)
 
     def seenit(self, dir):
         """rememer that we have seen dir."""
@@ -359,20 +389,20 @@
     def parse(self, name=None, file=None):
         """A meta file looks like:
         
-	# Meta data file "path"
-	CMD "command-line"
-	CWD "cwd"
-	TARGET "target"
-	-- command output --
-	-- filemon acquired metadata --
-	# buildmon version 3
-	V 3
-	C "pid" "cwd"
-	E "pid" "path"
+        # Meta data file "path"
+        CMD "command-line"
+        CWD "cwd"
+        TARGET "target"
+        -- command output --
+        -- filemon acquired metadata --
+        # buildmon version 3
+        V 3
+        C "pid" "cwd"
+        E "pid" "path"
 	F "pid" "child"
-	R "pid" "path"
-	W "pid" "path"
-	X "pid" "status"
+        R "pid" "path"
+        W "pid" "path"
+        X "pid" "status"
 	D "pid" "path"
 	L "pid" "src" "target"
 	M "pid" "old" "new"
@@ -430,7 +460,6 @@
             pid = int(w[1])
             if pid != last_pid:
                 if last_pid:
-                    pid_cwd[last_pid] = cwd
                     pid_last_dir[last_pid] = self.last_dir
                 cwd = getv(pid_cwd, pid, self.cwd)
                 self.last_dir = getv(pid_last_dir, pid, self.cwd)
@@ -447,7 +476,8 @@
                 cwd = abspath(w[2], cwd, None, self.debug, self.debug_out)
                 if cwd.endswith('/.'):
                     cwd = cwd[0:-2]
-                self.last_dir = cwd
+                self.last_dir = pid_last_dir[pid] = cwd
+                pid_cwd[pid] = cwd
                 if self.debug > 1:
                     print("cwd=", cwd, file=self.debug_out)
                 continue
@@ -470,6 +500,21 @@
         if not file:
             f.close()
 
+    def is_src(self, base, dir, rdir):
+        """is base in srctop"""
+        for dir in [dir,rdir]:
+            if not dir:
+                continue
+            path = '/'.join([dir,base])
+            srctop = self.find_top(path, self.srctops)
+            if srctop:
+                if self.dpdeps:
+                    self.add(self.file_deps, path.replace(srctop,''), 'file')
+                self.add(self.src_deps, dir.replace(srctop,''), 'src')
+                self.seenit(dir)
+                return True
+        return False
+
     def parse_path(self, path, cwd, op=None, w=[]):
         """look at a path for the op specified"""
 
@@ -482,7 +527,7 @@
         for p in self.excludes:
             if p and path.startswith(p):
                 if self.debug > 2:
-                    print >> self.debug_out, "exclude:", p, path
+                    print("exclude:", p, path, file=self.debug_out)
                 return
         # we don't want to resolve the last component if it is
         # a symlink
@@ -498,7 +543,8 @@
         # to the src dir, we may need to add dependencies for each
         rdir = dir
         dir = abspath(dir, cwd, self.last_dir, self.debug, self.debug_out)
-        if rdir == dir or rdir.find('./') > 0:
+        rdir = os.path.realpath(dir)
+        if rdir == dir:
             rdir = None
         # now put path back together
         path = '/'.join([dir,base])
@@ -520,17 +566,9 @@
             # finally, we get down to it
             if dir == self.cwd or dir == self.curdir:
                 return
-            srctop = self.find_top(path, self.srctops)
-            if srctop:
-                if self.dpdeps:
-                    self.add(self.file_deps, path.replace(srctop,''), 'file')
-                self.add(self.src_deps, dir.replace(srctop,''), 'src')
+            if self.is_src(base, dir, rdir):
                 self.seenit(w[2])
-                self.seenit(dir)
-                if rdir and not rdir.startswith(srctop):
-                    dir = rdir      # for below
-                    rdir = None
-                else:
+                if not rdir:
                     return
 
             objroot = None
@@ -544,6 +582,9 @@
                 ddep = self.find_obj(objroot, dir, path, w[2])
                 if ddep:
                     self.add(self.obj_deps, ddep, 'obj')
+                    if self.dpdeps and objroot.endswith('/stage/'):
+                        sp = '/'.join(path.replace(objroot,'').split('/')[1:])
+                        self.add(self.file_deps, sp, 'file')
             else:
                 # don't waste time looking again
                 self.seenit(w[2])

Modified: trunk/contrib/bmake/mk/meta2deps.sh
===================================================================
--- trunk/contrib/bmake/mk/meta2deps.sh	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/meta2deps.sh	2018-06-27 00:20:04 UTC (rev 11140)
@@ -77,7 +77,7 @@
 
 
 # RCSid:
-#	$Id: meta2deps.sh,v 1.9 2015/04/03 18:23:25 sjg Exp $
+#	$Id: meta2deps.sh,v 1.12 2016/12/13 20:44:16 sjg Exp $
 
 # Copyright (c) 2010-2013, Juniper Networks, Inc.
 # All rights reserved.
@@ -255,7 +255,7 @@
 	*)
 	    case "$lpid" in
 	    "") ;;
-	    *) eval ldir_$lpid=$ldir cwd_$lpid=$cwd;;
+	    *) eval ldir_$lpid=$ldir;;
 	    esac
 	    eval ldir=\${ldir_$pid:-$CWD} cwd=\${cwd_$pid:-$CWD}
 	    lpid=$pid
@@ -271,9 +271,11 @@
 	    esac
 	    # watch out for temp dirs that no longer exist
 	    test -d ${cwd:-/dev/null/no/such} || cwd=$CWD
+	    eval cwd_$pid=$cwd
 	    continue
 	    ;;
-	F,*)  eval cwd_$path=$cwd ldir_$path=$ldir
+	F,*) # $path is new pid  
+	    eval cwd_$path=$cwd ldir_$path=$ldir
 	    continue
 	    ;;	  
 	*)  dir=${path%/*}
@@ -309,7 +311,7 @@
 	*)  seen=$dir;;
 	esac
 	case "$dir" in
-	${CURDIR:-.}|${CURDIR:-.}/*|"") continue;;
+	${CURDIR:-.}|"") continue;;
 	$src_re)
 	    # avoid repeating ourselves...
 	    case "$DPDEPS,$seensrc," in

Modified: trunk/contrib/bmake/mk/nls.mk
===================================================================
--- trunk/contrib/bmake/mk/nls.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/nls.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,9 +1,8 @@
 #	$NetBSD: bsd.nls.mk,v 1.3 1996/10/18 02:34:45 thorpej Exp $
 
 .if !target(.MAIN)
-.if exists(${.CURDIR}/../Makefile.inc)
-.include "${.CURDIR}/../Makefile.inc"
-.endif
+# init.mk not included
+.-include <${.CURDIR:H}/Makefile.inc>
 
 .MAIN: all
 .endif

Modified: trunk/contrib/bmake/mk/own.mk
===================================================================
--- trunk/contrib/bmake/mk/own.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/own.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-# $Id: own.mk,v 1.30 2015/11/14 18:09:57 sjg Exp $
+# $Id: own.mk,v 1.36 2017/07/08 21:58:46 sjg Exp $
 
 .if !target(__${.PARSEFILE}__)
 __${.PARSEFILE}__:
@@ -7,7 +7,7 @@
 .include "init.mk"
 .endif
 
-.ifndef NOMAKECONF
+.if !defined(NOMAKECONF) && !defined(NO_MAKECONF)
 MAKECONF?=	/etc/mk.conf
 .-include "${MAKECONF}"
 .endif
@@ -20,8 +20,8 @@
 TARGET_HOST?= ${HOST_TARGET}
 
 # these may or may not exist
-.-include "${TARGET_HOST}.mk"
-.-include "config.mk"
+.-include <${TARGET_HOST}.mk>
+.-include <config.mk>
 
 RM?= rm
 LN?= ln
@@ -35,7 +35,7 @@
 .endif
 
 # FreeBSD at least does not set this
-MACHINE_ARCH?=${MACHINE}
+MACHINE_ARCH?=	${MACHINE}
 # we need to make sure these are defined too in case sys.mk fails to.
 COMPILE.s?=	${CC} ${AFLAGS} -c
 LINK.s?=	${CC} ${AFLAGS} ${LDFLAGS}
@@ -79,7 +79,7 @@
 
 # we really like to have SRCTOP and OBJTOP defined...
 .if !defined(SRCTOP) || !defined(OBJTOP)
-.-include "srctop.mk"
+.-include <srctop.mk>
 .endif
 
 .if !defined(SRCTOP) || !defined(OBJTOP)
@@ -117,6 +117,7 @@
 	PICINSTALL/LINKLIB \
 	PICLIB/PIC \
 	PROFILE/LINKLIB \
+	STAGING_PROG/STAGING \
 
 .include <options.mk>
 
@@ -128,7 +129,7 @@
 USERGRP!=  id -g
 .export USERGRP
 .endif
-.for x in BIN CONF DOC INFO KMOD LIB MAN NLS SHARE
+.for x in BIN CONF DOC INC INFO FILES KMOD LIB MAN NLS PROG SHARE
 $xOWN=  ${USER}
 $xGRP=  ${USERGRP}
 $x_INSTALL_OWN=
@@ -145,6 +146,9 @@
 NONBINMODE?=	444
 DIRMODE?=	755
 
+INCLUDEDIR?=	${prefix}/include
+INCDIR?=	${INCLUDEDIR}
+
 # Define MANZ to have the man pages compressed (gzip)
 #MANZ=		1
 
@@ -154,6 +158,7 @@
 MANOWN?=	${BINOWN}
 MANMODE?=	${NONBINMODE}
 
+INCLUDEDIR?=	${libprefix}/include
 LIBDIR?=	${libprefix}/lib
 SHLIBDIR?=	${libprefix}/lib
 .if ${USE_SHLIBDIR:Uno} == "yes"
@@ -183,6 +188,10 @@
 KMODOWN?=	${BINOWN}
 KMODMODE?=	${NONBINMODE}
 
+SHAREGRP?=	${BINGRP}
+SHAREOWN?=	${BINOWN}
+SHAREMODE?=	${NONBINMODE}
+
 COPY?=		-c
 STRIP_FLAG?=	-s
 
@@ -247,4 +256,19 @@
 MK_NLS=		no
 .endif
 
+# :U incase not using our sys.mk
+.if ${MK_META_MODE:Uno} == "yes"
+# should all be set by sys.mk if not default
+TARGET_SPEC_VARS ?= MACHINE
+.if ${TARGET_SPEC_VARS:[#]} > 1
+TARGET_SPEC_VARS_REV := ${TARGET_SPEC_VARS:[-1..1]}
+.else
+TARGET_SPEC_VARS_REV = ${TARGET_SPEC_VARS}
 .endif
+.if ${MK_STAGING} == "yes"
+STAGE_ROOT?= ${OBJROOT}/stage
+STAGE_OBJTOP?= ${STAGE_ROOT}/${TARGET_SPEC_VARS_REV:ts/}
+.endif
+.endif
+
+.endif

Modified: trunk/contrib/bmake/mk/prog.mk
===================================================================
--- trunk/contrib/bmake/mk/prog.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/prog.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-#	$Id: prog.mk,v 1.25 2013/07/18 05:46:24 sjg Exp $
+#	$Id: prog.mk,v 1.32 2017/05/06 17:30:09 sjg Exp $
 
 .if !target(__${.PARSEFILE}__)
 __${.PARSEFILE}__:
@@ -66,21 +66,17 @@
 	@${CC} ${CFLAGS} -c x.c -o ${.TARGET}
 	@rm -f x.c
 
-.cc.o:
+${CXX_SUFFIXES:%=%.o}:
 	${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c -
 	@mv -f x.c x.cc
 	@${CXX} ${CXXFLAGS} -c x.cc -o ${.TARGET}
 	@rm -f x.cc
-
-.C.o:
-	${CXX} -E ${CXXFLAGS} ${.IMPSRC} | xstr -c -
-	@mv -f x.c x.C
-	@${CXX} ${CXXFLAGS} -c x.C -o ${.TARGET}
-	@rm -f x.C
 .endif
 
 
 .if defined(PROG)
+BINDIR ?= ${prefix}/bin
+
 SRCS?=	${PROG}.c
 .for s in ${SRCS:N*.h:N*.sh:M*/*}
 ${.o .po .lo:L:@o@${s:T:R}$o@}: $s
@@ -132,8 +128,9 @@
 .endif	# defined(PROG)
 
 .if !defined(_SKIP_BUILD)
-all: ${PROG}
+realbuild: ${PROG}
 .endif
+
 all: _SUBDIRUSE
 
 .if !target(clean)
@@ -197,6 +194,8 @@
 
 maninstall: afterinstall
 afterinstall: realinstall
+install_links: realinstall
+proginstall: beforeinstall
 realinstall: beforeinstall
 .endif
 
@@ -212,6 +211,10 @@
 .NOPATH:	${OBJS}
 .endif
 
+.if defined(FILES) || defined(FILESGROUPS)
+.include <files.mk>
+.endif
+
 .if ${MK_MAN} != "no"
 .include <man.mk>
 .endif
@@ -223,6 +226,20 @@
 .include <obj.mk>
 .include <dep.mk>
 .include <subdir.mk>
+
+.if !empty(PROG) && ${MK_STAGING_PROG} == "yes"
+STAGE_BINDIR ?= ${STAGE_OBJTOP}${BINDIR}
+STAGE_DIR.prog ?= ${STAGE_BINDIR}
+.if ${PROG_NAME:U${PROG}} != ${PROG}
+STAGE_AS_SETS += prog
+STAGE_AS_${PROG} = ${PROG_NAME}
+stage_as.prog: ${PROG}
+.else
+STAGE_SETS += prog
+stage_files.prog: ${PROG}
+.endif
+.endif
+
 .include <final.mk>
 
 .endif

Modified: trunk/contrib/bmake/mk/scripts.mk
===================================================================
--- trunk/contrib/bmake/mk/scripts.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/scripts.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,52 +1,91 @@
-# $Id: scripts.mk,v 1.2 2006/11/09 01:55:18 sjg Exp $
+# $Id: scripts.mk,v 1.3 2017/05/06 17:29:45 sjg Exp $
+#
+#	@(#) Copyright (c) 2006, Simon J. Gerraty
+#
+#	This file is provided in the hope that it will
+#	be of use.  There is absolutely NO WARRANTY.
+#	Permission to copy, redistribute or otherwise
+#	use this file is hereby granted provided that 
+#	the above copyright notice and this notice are
+#	left intact. 
+#      
+#	Please send copies of changes and bug-fixes to:
+#	sjg at crufty.net
+#
 
 .include <init.mk>
 
-.if defined(SCRIPTS) 
+SCRIPTSGROUPS ?= SCRIPTS
+SCRIPTSGROUPS := ${SCRIPTSGROUPS:O:u}
 
-all:	${SCRIPTS}
-
-.PHONY:		scriptsinstall
-install:	scriptsinstall
-
-.if !target(scriptsinstall)
 SCRIPTSDIR?=	${BINDIR}
 SCRIPTSOWN?=	${BINOWN}
 SCRIPTSGRP?=	${BINGRP}
 SCRIPTSMODE?=	${BINMODE}
 
+SCRIPTS_INSTALL_OWN?= -o ${SCRIPTSOWN} -g ${SCRIPTSGRP}
+SCRIPTS_COPY ?= -C
+
 # how we get script name from src
 SCRIPTSNAME_MOD?=T:R
 
-script_targets= ${SCRIPTS:@s@${DESTDIR}${SCRIPTSDIR_$s:U${SCRIPTSDIR}}/${SCRIPTSNAME_$s:U${s:${SCRIPTSNAME_MOD}}}@}
+.if !target(buildfiles)
+.for group in ${SCRIPTSGROUPS}
+buildfiles: ${${group}}
+.endfor
+.endif
+buildfiles:
+realbuild: buildfiles
 
-scriptsinstall:: ${script_targets}
-
-.PRECIOUS: ${script_targets}
-.if !defined(UPDATE)
-.PHONY: ${script_targets}
+.for group in ${SCRIPTSGROUPS}
+.if !empty(${group}) && defined(${group}DIR)
+.if ${group} != "SCRIPTS"
+${group}_INSTALL_OWN ?= ${SCRIPTS_INSTALL_OWN}
 .endif
+# incase we are staging
+STAGE_DIR.${group} ?= ${STAGE_OBJTOP}${${group}DIR}
 
-INSTALL_FLAGS?= ${RENAME} ${PRESERVE} ${COPY} ${INSTPRIV} \
-	-o ${OWN_${.TARGET:T}:U${SCRIPTSOWN}} \
-	-g ${GRP_${.TARGET:T}:U${SCRIPTSGRP}} \
-	-m ${MODE_${.TARGET:T}:U${SCRIPTSMODE}}
+.for script in ${${group}:O:u}
+${group}_INSTALL_OWN.${script:T} ?= ${${group}_INSTALL_OWN}
+${group}DIR.${script:T} ?= ${${group}DIR_${script:T}:U${${group}DIR}}
+script_mkdir_list += ${${group}DIR.${script:T}}
 
-__SCRIPTINSTALL_USE: .USE
-	${INSTALL} ${INSTALL_FLAGS_${.TARGET:T}:U${INSTALL_FLAGS}} \
-	    ${.ALLSRC} ${.TARGET}
+${group}NAME.${script} ?= ${${group}NAME_${script:T}:U${script:${SCRIPTSNAME_MOD}}}
+.if ${${group}NAME.${script}:T} != ${script:T}
+STAGE_AS_SETS += ${group}
+STAGE_AS_${script} = ${${group}NAME.${script:T}}
+stage_as.${group}: ${script}
 
-.for s in ${SCRIPTS}
-.if !defined(BUILD) && !make(all) && !make(${s})
-${DESTDIR}${SCRIPTSDIR_$s:U${SCRIPTSDIR}}/${SCRIPTSNAME_$s:U${s:${SCRIPTSNAME_MOD}}}:	.MADE
-.endif
-${DESTDIR}${SCRIPTSDIR_$s:U${SCRIPTSDIR}}/${SCRIPTSNAME_$s:U${s:${SCRIPTSNAME_MOD}}}:	${s} __SCRIPTINSTALL_USE
-.endfor
-.endif
+installscripts: installscripts.${group}.${script:T}
+installscripts.${group}.${script:T}: ${script} script_mkdirs
+	${INSTALL} ${SCRIPTS_COPY} ${${group}_INSTALL_OWN.${script:T}} \
+	-m ${SCRIPTSMODE} ${.ALLSRC:Nscript_mkdirs} ${DESTDIR}${${group}DIR}/${${group}NAME.${script:T}}
 
+.else
+STAGE_SETS += ${group}
+stage_files.${group}: ${script}
+installscripts.${group}: ${script}
+installscripts: installscripts.${group}
 .endif
 
-.if !target(scriptsinstall)
-scriptsinstall::
-.endif
+.endfor				# script
 
+installscripts.${group}: script_mkdirs
+	${INSTALL} ${SCRIPTS_COPY} ${${group}_INSTALL_OWN} -m ${SCRIPTSMODE} \
+	${.ALLSRC:Nscript_mkdirs:O:u} ${DESTDIR}${${group}DIR}
+
+.endif				# !empty
+.endfor				# group
+
+script_mkdirs:
+	@for d in ${script_mkdir_list:O:u}; do \
+		test -d ${DESTDIR}$$d || \
+		${INSTALL} -d ${SCRIPTS_INSTALL_OWN} -m 775 ${DESTDIR}$$d; \
+	done
+
+
+beforeinstall:
+installscripts:
+realinstall:	installscripts
+.ORDER: beforeinstall installscripts
+

Modified: trunk/contrib/bmake/mk/subdir.mk
===================================================================
--- trunk/contrib/bmake/mk/subdir.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/subdir.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-#	$Id: subdir.mk,v 1.14 2012/11/12 04:34:33 sjg Exp $
+#	$Id: subdir.mk,v 1.16 2017/02/08 22:16:59 sjg Exp $
 #	skip missing directories...
 
 #	$NetBSD: bsd.subdir.mk,v 1.11 1996/04/04 02:05:06 jtc Exp $
@@ -9,9 +9,7 @@
 # keep everyone happy
 _SUBDIRUSE:
 .elif !commands(_SUBDIRUSE) && !defined(NO_SUBDIR) && !defined(NOSUBDIR)
-.if exists(${.CURDIR}/Makefile.inc)
-.include "Makefile.inc"
-.endif
+.-include <${.CURDIR}/Makefile.inc>
 .if !target(.MAIN)
 .MAIN: all
 .endif
@@ -47,13 +45,18 @@
 	done
 
 ${SUBDIR}::
-	@set -e; if test -d ${.CURDIR}/${.TARGET}.${MACHINE}; then \
-		_newdir_=${.TARGET}.${MACHINE}; \
+	@set -e; _r=${.CURDIR}/; \
+	if test -z "${.TARGET:M/*}"; then \
+		if test -d ${.CURDIR}/${.TARGET}.${MACHINE}; then \
+			_newdir_=${.TARGET}.${MACHINE}; \
+		else \
+			_newdir_=${.TARGET}; \
+		fi; \
 	else \
-		_newdir_=${.TARGET}; \
+		_r= _newdir_=${.TARGET}; \
 	fi; \
 	${ECHO_DIR} "===> $${_newdir_}"; \
-	cd ${.CURDIR}/$${_newdir_}; \
+	cd $${_r}$${_newdir_}; \
 	${.MAKE} _THISDIR_="$${_newdir_}" all
 .endif
 

Modified: trunk/contrib/bmake/mk/sys/AIX.mk
===================================================================
--- trunk/contrib/bmake/mk/sys/AIX.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/sys/AIX.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -9,7 +9,7 @@
 
 NOPIC=no	# no shared libs?
 
-.SUFFIXES: .out .a .ln .o .c .cc .C .F .f .r .y .l .s .S .cl .p .h .sh .m4
+.SUFFIXES: .out .a .ln .o .c ${CXX_SUFFIXES} .F .f .r .y .l .s .S .cl .p .h .sh .m4
 
 .LIBS:		.a
 
@@ -67,8 +67,6 @@
 LINT=		lint
 LINTFLAGS=	-chapbx
 
-MAKE=		bmake
-
 PC=		pc
 PFLAGS=
 COMPILE.p=	${PC} ${PFLAGS} ${CPPFLAGS} -c
@@ -91,24 +89,15 @@
 	rm -f $*.o
 
 # C++
-.cc:
+${CXX_SUFFIXES}:
 	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.cc.o:
+${CXX_SUFFIXES:%=%.o}:
 	${COMPILE.cc} ${.IMPSRC}
-.cc.a:
+${CXX_SUFFIXES:%=%.a}:
 	${COMPILE.cc} ${.IMPSRC}
 	${AR} ${ARFLAGS} $@ $*.o
 	rm -f $*.o
 
-.C:
-	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.C.o:
-	${COMPILE.cc} ${.IMPSRC}
-.C.a:
-	${COMPILE.cc} ${.IMPSRC}
-	${AR} ${ARFLAGS} $@ $*.o
-	rm -f $*.o
-
 # Fortran/Ratfor
 .f:
 	${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}

Modified: trunk/contrib/bmake/mk/sys/Darwin.mk
===================================================================
--- trunk/contrib/bmake/mk/sys/Darwin.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/sys/Darwin.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -4,7 +4,7 @@
 OS=		Darwin
 unix?=		We run ${OS}.
 
-.SUFFIXES: .out .a .ln .o .s .S .c .cc .cpp .cxx .C .F .f .r .y .l .cl .p .h
+.SUFFIXES: .out .a .ln .o .s .S .c ${CXX_SUFFIXES} .F .f .r .y .l .cl .p .h
 .SUFFIXES: .sh .m4 .dylib
 
 .LIBS:		.a .dylib
@@ -84,8 +84,6 @@
 
 LORDER?=	lorder
 
-MAKE?=		bmake
-
 NM?=		nm
 
 PC?=		pc
@@ -114,24 +112,15 @@
 	rm -f $*.o
 
 # C++
-.cc:
+${CXX_SUFFIXES}:
 	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.cc.o:
+${CXX_SUFFIXES:%=%.o}:
 	${COMPILE.cc} ${.IMPSRC}
-.cc.a:
+${CXX_SUFFIXES:%=%.a}:
 	${COMPILE.cc} ${.IMPSRC}
 	${AR} ${ARFLAGS} $@ $*.o
 	rm -f $*.o
 
-.C:
-	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.C.o:
-	${COMPILE.cc} ${.IMPSRC}
-.C.a:
-	${COMPILE.cc} ${.IMPSRC}
-	${AR} ${ARFLAGS} $@ $*.o
-	rm -f $*.o
-
 # Fortran/Ratfor
 .f:
 	${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}

Modified: trunk/contrib/bmake/mk/sys/Generic.mk
===================================================================
--- trunk/contrib/bmake/mk/sys/Generic.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/sys/Generic.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,8 +1,8 @@
-#	$Id: Generic.mk,v 1.11 2010/09/24 05:59:53 sjg Exp $
+#	$Id: Generic.mk,v 1.13 2017/05/05 18:02:16 sjg Exp $
 #
 
 # some reasonable defaults
-.SUFFIXES: .out .a .ln .o .s .S .c .cc .cpp .cxx .C .F .f .r .y .l .cl .p .h
+.SUFFIXES: .out .a .ln .o .s .S .c ${CXX_SUFFIXES} .F .f .r .y .l .cl .p .h
 .SUFFIXES: .sh .m4
 
 .LIBS:		.a
@@ -80,8 +80,6 @@
 LINT?=		lint
 LINTFLAGS?=	-chapbxzF
 
-MAKE?=		${.MAKE}
-
 NM?=		nm
 
 PC?=		pc
@@ -110,11 +108,11 @@
 	${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC}
 
 # C++
-.cc .cpp .cxx .C:
+${CXX_SUFFIXES}:
 	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.cc.o .cpp.o .cxx.o .C.o:
+${CXX_SUFFIXES:%=%.o}:
 	${COMPILE.cc} ${.IMPSRC}
-.cc.a .cpp.a .cxx.a .C.a:
+${CXX_SUFFIXES:%=%.a}:
 	${COMPILE.cc} ${.IMPSRC}
 	${AR} ${ARFLAGS} $@ $*.o
 	rm -f $*.o

Modified: trunk/contrib/bmake/mk/sys/HP-UX.mk
===================================================================
--- trunk/contrib/bmake/mk/sys/HP-UX.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/sys/HP-UX.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-#	$Id: HP-UX.mk,v 1.9 2003/09/30 16:42:23 sjg Exp $
+#	$Id: HP-UX.mk,v 1.11 2017/05/05 18:02:16 sjg Exp $
 #	$NetBSD: sys.mk,v 1.19.2.1 1994/07/26 19:58:31 cgd Exp $
 #	@(#)sys.mk	5.11 (Berkeley) 3/13/91
 
@@ -14,7 +14,7 @@
 OSMAJOR?=10
 __HPUX_VERSION?=${OSMAJOR}
 
-.SUFFIXES: .out .a .ln .o .c .cc .C .F .f .r .y .l .s .S .cl .p .h .sh .m4
+.SUFFIXES: .out .a .ln .o .c ${CXX_SUFFIXES} .F .f .r .y .l .s .S .cl .p .h .sh .m4
 
 LIBMODE= 755
 LIBCRT0=	/lib/crt0.o
@@ -101,8 +101,6 @@
 LINT=		lint
 LINTFLAGS=	-chapbx
 
-MAKE=		bmake
-
 PC=		pc
 PFLAGS=
 COMPILE.p=	${PC} ${PFLAGS} ${CPPFLAGS} -c
@@ -131,24 +129,15 @@
 	rm -f $*.o
 
 # C++
-.cc:
+${CXX_SUFFIXES}:
 	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.cc.o:
+${CXX_SUFFIXES:%=%.o}:
 	${COMPILE.cc} ${.IMPSRC}
-.cc.a:
+${CXX_SUFFIXES:%=%.a}:
 	${COMPILE.cc} ${.IMPSRC}
 	${AR} ${ARFLAGS} $@ $*.o
 	rm -f $*.o
 
-.C:
-	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.C.o:
-	${COMPILE.cc} ${.IMPSRC}
-.C.a:
-	${COMPILE.cc} ${.IMPSRC}
-	${AR} ${ARFLAGS} $@ $*.o
-	rm -f $*.o
-
 # Fortran/Ratfor
 .f:
 	${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}

Modified: trunk/contrib/bmake/mk/sys/IRIX.mk
===================================================================
--- trunk/contrib/bmake/mk/sys/IRIX.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/sys/IRIX.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -10,7 +10,7 @@
 unix?=		We run ${OS}.
 .endif
 
-.SUFFIXES: .out .a .ln .o .s .S .c .cc .cpp .cxx .C .F .f .r .y .l .cl .p .h
+.SUFFIXES: .out .a .ln .o .s .S .c ${CXX_SUFFIXES} .F .f .r .y .l .cl .p .h
 .SUFFIXES: .sh .m4
 
 .LIBS:		.a
@@ -70,8 +70,6 @@
 
 LORDER?=	lorder
 
-MAKE?=		make
-
 NM?=		nm
 
 PC?=		pc
@@ -102,11 +100,11 @@
 	${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC}
 
 # C++
-.cc .cpp .cxx .C:
+${CXX_SUFFIXES}:
 	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.cc.o .cpp.o .cxx.o .C.o:
+${CXX_SUFFIXES:%=%.o}:
 	${COMPILE.cc} ${.IMPSRC}
-.cc.a .cpp.a .cxx.a .C.a:
+${CXX_SUFFIXES:%=%.a}:
 	${COMPILE.cc} ${.IMPSRC}
 	${AR} ${ARFLAGS} $@ $*.o
 	rm -f $*.o

Modified: trunk/contrib/bmake/mk/sys/Linux.mk
===================================================================
--- trunk/contrib/bmake/mk/sys/Linux.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/sys/Linux.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-#	$Id: Linux.mk,v 1.7 2011/03/02 05:05:21 sjg Exp $
+#	$Id: Linux.mk,v 1.9 2017/05/05 18:02:16 sjg Exp $
 #	$NetBSD: sys.mk,v 1.19.2.1 1994/07/26 19:58:31 cgd Exp $
 #	@(#)sys.mk	5.11 (Berkeley) 3/13/91
 
@@ -12,7 +12,7 @@
 
 NEED_SOLINKS=yes
 
-.SUFFIXES: .out .a .ln .o .c .cc .C .F .f .r .y .l .s .S .cl .p .h .sh .m4
+.SUFFIXES: .out .a .ln .o .c ${CXX_SUFFIXES} .F .f .r .y .l .s .S .cl .p .h .sh .m4
 
 .LIBS:		.a
 
@@ -70,8 +70,6 @@
 LINT=		lint
 LINTFLAGS=	-chapbx
 
-MAKE=		bmake
-
 PC=		pc
 PFLAGS=
 COMPILE.p=	${PC} ${PFLAGS} ${CPPFLAGS} -c
@@ -94,24 +92,15 @@
 	rm -f $*.o
 
 # C++
-.cc:
+${CXX_SUFFIXES}:
 	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.cc.o:
+${CXX_SUFFIXES:%=%.o}:
 	${COMPILE.cc} ${.IMPSRC}
-.cc.a:
+${CXX_SUFFIXES:%=%.a}:
 	${COMPILE.cc} ${.IMPSRC}
 	${AR} ${ARFLAGS} $@ $*.o
 	rm -f $*.o
 
-.C:
-	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.C.o:
-	${COMPILE.cc} ${.IMPSRC}
-.C.a:
-	${COMPILE.cc} ${.IMPSRC}
-	${AR} ${ARFLAGS} $@ $*.o
-	rm -f $*.o
-
 # Fortran/Ratfor
 .f:
 	${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}

Modified: trunk/contrib/bmake/mk/sys/NetBSD.mk
===================================================================
--- trunk/contrib/bmake/mk/sys/NetBSD.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/sys/NetBSD.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -19,7 +19,7 @@
 .endif
 .endif
 
-.SUFFIXES: .out .a .ln .o .s .S .c .cc .cpp .cxx .C .F .f .r .y .l .cl .p .h
+.SUFFIXES: .out .a .ln .o .s .S .c ${CXX_SUFFIXES} .F .f .r .y .l .cl .p .h
 .SUFFIXES: .sh .m4
 
 .LIBS:		.a
@@ -105,8 +105,6 @@
 
 LORDER?=	lorder
 
-MAKE?=		make
-
 NM?=		nm
 
 PC?=		pc
@@ -137,11 +135,11 @@
 	${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC}
 
 # C++
-.cc .cpp .cxx .C:
+${CXX_SUFFIXES}:
 	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.cc.o .cpp.o .cxx.o .C.o:
+${CXX_SUFFIXES:%=%.o}:
 	${COMPILE.cc} ${.IMPSRC}
-.cc.a .cpp.a .cxx.a .C.a:
+${CXX_SUFFIXES:%=%.a}:
 	${COMPILE.cc} ${.IMPSRC}
 	${AR} ${ARFLAGS} $@ $*.o
 	rm -f $*.o

Modified: trunk/contrib/bmake/mk/sys/OSF1.mk
===================================================================
--- trunk/contrib/bmake/mk/sys/OSF1.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/sys/OSF1.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-#	$Id: OSF1.mk,v 1.6 2003/09/30 16:42:23 sjg Exp $
+#	$Id: OSF1.mk,v 1.8 2017/05/05 18:02:16 sjg Exp $
 #	$NetBSD: sys.mk,v 1.19.2.1 1994/07/26 19:58:31 cgd Exp $
 #	@(#)sys.mk	5.11 (Berkeley) 3/13/91
 
@@ -11,7 +11,7 @@
 
 PATH=/usr/sbin:/usr/bin:/usr/ucb:/opt/gnu/bin:/usr/ccs/bin
 
-.SUFFIXES: .out .a .ln .o .c .cc .C .F .f .r .y .l .s .S .cl .p .h .sh .m4
+.SUFFIXES: .out .a .ln .o .c ${CXX_SUFFIXES} .F .f .r .y .l .s .S .cl .p .h .sh .m4
 
 .LIBS:		.a
 
@@ -77,8 +77,6 @@
 LINT=		lint
 LINTFLAGS=	-chapbx
 
-MAKE=		bmake
-
 PC=		pc
 PFLAGS=
 COMPILE.p=	${PC} ${PFLAGS} ${CPPFLAGS} -c
@@ -105,24 +103,15 @@
 	rm -f $*.o
 
 # C++
-.cc:
+${CXX_SUFFIXES}:
 	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.cc.o:
+${CXX_SUFFIXES:%=%.o}:
 	${COMPILE.cc} ${.IMPSRC}
-.cc.a:
+${CXX_SUFFIXES:%=%.a}:
 	${COMPILE.cc} ${.IMPSRC}
 	${AR} ${ARFLAGS} $@ $*.o
 	rm -f $*.o
 
-.C:
-	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.C.o:
-	${COMPILE.cc} ${.IMPSRC}
-.C.a:
-	${COMPILE.cc} ${.IMPSRC}
-	${AR} ${ARFLAGS} $@ $*.o
-	rm -f $*.o
-
 # Fortran/Ratfor
 .f:
 	${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}

Modified: trunk/contrib/bmake/mk/sys/OpenBSD.mk
===================================================================
--- trunk/contrib/bmake/mk/sys/OpenBSD.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/sys/OpenBSD.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -4,7 +4,7 @@
 OS=		OpenBSD
 unix?=		We run ${OS}.
 
-.SUFFIXES: .out .a .ln .o .s .S .c .cc .cpp .cxx .C .F .f .r .y .l .cl .p .h
+.SUFFIXES: .out .a .ln .o .s .S .c ${CXX_SUFFIXES} .F .f .r .y .l .cl .p .h
 .SUFFIXES: .sh .m4
 
 .LIBS:		.a
@@ -80,8 +80,6 @@
 
 LORDER?=	lorder
 
-MAKE?=		make
-
 NM?=		nm
 
 PC?=		pc
@@ -112,11 +110,11 @@
 	${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC}
 
 # C++
-.cc .cpp .cxx .C:
+${CXX_SUFFIXES}:
 	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.cc.o .cpp.o .cxx.o .C.o:
+${CXX_SUFFIXES:%=%.o}:
 	${COMPILE.cc} ${.IMPSRC}
-.cc.a .cpp.a .cxx.a .C.a:
+${CXX_SUFFIXES:%=%.a}:
 	${COMPILE.cc} ${.IMPSRC}
 	${AR} ${ARFLAGS} $@ $*.o
 	rm -f $*.o

Modified: trunk/contrib/bmake/mk/sys/SunOS.mk
===================================================================
--- trunk/contrib/bmake/mk/sys/SunOS.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/sys/SunOS.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-#	$Id: SunOS.mk,v 1.6 2014/04/05 22:56:54 sjg Exp $
+#	$Id: SunOS.mk,v 1.8 2017/05/05 18:02:17 sjg Exp $
 
 .if ${.PARSEFILE} == "sys.mk"
 .include <host-target.mk>
@@ -41,7 +41,7 @@
 
 # the rest is common
 
-.SUFFIXES: .out .a .ln .o .c .cc .C .F .f .r .y .l .s .S .cl .p .h .sh .m4
+.SUFFIXES: .out .a .ln .o .c ${CXX_SUFFIXES} .F .f .r .y .l .s .S .cl .p .h .sh .m4
 
 .LIBS:		.a
 
@@ -98,8 +98,6 @@
 LINT=		lint
 LINTFLAGS=	-chapbx
 
-MAKE=		bmake
-
 PC=		pc
 PFLAGS=
 COMPILE.p=	${PC} ${PFLAGS} ${CPPFLAGS} -c
@@ -126,24 +124,15 @@
 	rm -f $*.o
 
 # C++
-.cc:
+${CXX_SUFFIXES}:
 	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.cc.o:
+${CXX_SUFFIXES:%=%.o}:
 	${COMPILE.cc} ${.IMPSRC}
-.cc.a:
+${CXX_SUFFIXES:%=%.a}:
 	${COMPILE.cc} ${.IMPSRC}
 	${AR} ${ARFLAGS} $@ $*.o
 	rm -f $*.o
 
-.C:
-	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.C.o:
-	${COMPILE.cc} ${.IMPSRC}
-.C.a:
-	${COMPILE.cc} ${.IMPSRC}
-	${AR} ${ARFLAGS} $@ $*.o
-	rm -f $*.o
-
 # Fortran/Ratfor
 .f:
 	${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}

Modified: trunk/contrib/bmake/mk/sys/UnixWare.mk
===================================================================
--- trunk/contrib/bmake/mk/sys/UnixWare.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/sys/UnixWare.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-#	$Id: UnixWare.mk,v 1.1 2005/10/09 22:56:40 sjg Exp $
+#	$Id: UnixWare.mk,v 1.3 2017/05/05 18:02:17 sjg Exp $
 #	based on "Id: SunOS.5.sys.mk,v 1.6 2003/09/30 16:42:23 sjg Exp "
 #	$NetBSD: sys.mk,v 1.19.2.1 1994/07/26 19:58:31 cgd Exp $
 #	@(#)sys.mk	5.11 (Berkeley) 3/13/91
@@ -12,7 +12,7 @@
 
 PATH=/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/ccs/lib:/usr/ucb:/usr/local/bin
 
-.SUFFIXES: .out .a .ln .o .c .cc .C .F .f .r .y .l .s .S .cl .p .h .sh .m4
+.SUFFIXES: .out .a .ln .o .c ${CXX_SUFFIXES} .F .f .r .y .l .s .S .cl .p .h .sh .m4
 
 .LIBS:		.a
 
@@ -114,8 +114,6 @@
 
 LORDER?=	lorder
 
-MAKE?=		bmake
-
 NM?=		nm
 
 PC?=		pc # XXX: UDK probably does not have pc
@@ -148,24 +146,15 @@
 	rm -f $*.o
 
 # C++
-.cc:
+${CXX_SUFFIXES}:
 	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.cc.o:
+${CXX_SUFFIXES:%=%.o}:
 	${COMPILE.cc} ${.IMPSRC}
-.cc.a:
+${CXX_SUFFIXES:%=%.a}:
 	${COMPILE.cc} ${.IMPSRC}
 	${AR} ${ARFLAGS} $@ $*.o
 	rm -f $*.o
 
-.C:
-	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
-.C.o:
-	${COMPILE.cc} ${.IMPSRC}
-.C.a:
-	${COMPILE.cc} ${.IMPSRC}
-	${AR} ${ARFLAGS} $@ $*.o
-	rm -f $*.o
-
 # Fortran/Ratfor
 .f:
 	${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}

Modified: trunk/contrib/bmake/mk/sys.clean-env.mk
===================================================================
--- trunk/contrib/bmake/mk/sys.clean-env.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/sys.clean-env.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-# $Id: sys.clean-env.mk,v 1.20 2012/11/12 06:56:04 sjg Exp $
+# $Id: sys.clean-env.mk,v 1.21 2016/02/18 21:16:40 sjg Exp $
 #
 #	@(#) Copyright (c) 2009, Simon J. Gerraty
 #
@@ -94,6 +94,7 @@
 # MAKEOBJDIR='${.CURDIR:S,${SRCTOP},${OBJTOP},}'
 _srctop := ${SRCTOP:U${SB_SRC:U${SB}/src}}
 _objroot := ${OBJROOT:U${SB_OBJROOT:U${SB}/${SB_OBJPREFIX}}}
+.if ${MAKE_VERSION} < 20160218
 _objtop := ${OBJTOP:U${_objroot}${MACHINE}}
 # Take care of ${MACHINE}
 .if ${MACHINE} == "host" || ${OBJTOP} == ${HOST_OBJTOP:Uno}
@@ -113,7 +114,17 @@
 .for v in ${_tricky_env_vars}
 $v := ${$v}
 .endfor
+.else
+# we cannot use the '$$' trick, anymore
+# but we can export a literal (unexpanded) value
+SRCTOP := ${_srctop}
+OBJROOT := ${_objroot}
+OBJTOP = ${OBJROOT}${MACHINE}
+MAKEOBJDIR = ${.CURDIR:S,${SRCTOP},${OBJTOP},}
+.export-literal SRCTOP OBJROOT ${_tricky_env_vars}
+.endif
 #.info ${_tricky_env_vars:@v@${.newline}$v=${$v}@}
-
+#showenv:
+#	@env | egrep 'OBJ|SRC'
 .endif				# MAKEOBJDIR
 .endif				# level 0

Copied: trunk/contrib/bmake/mk/sys.debug.mk (from rev 11139, vendor/NetBSD/bmake/dist/mk/sys.debug.mk)
===================================================================
--- trunk/contrib/bmake/mk/sys.debug.mk	                        (rev 0)
+++ trunk/contrib/bmake/mk/sys.debug.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -0,0 +1,33 @@
+# $Id: sys.debug.mk,v 1.1 2016/10/01 19:11:55 sjg Exp $
+#
+#	@(#) Copyright (c) 2009, Simon J. Gerraty
+#
+#	This file is provided in the hope that it will
+#	be of use.  There is absolutely NO WARRANTY.
+#	Permission to copy, redistribute or otherwise
+#	use this file is hereby granted provided that 
+#	the above copyright notice and this notice are
+#	left intact. 
+#      
+#	Please send copies of changes and bug-fixes to:
+#	sjg at crufty.net
+#
+
+# Sometimes we want to turn on debugging in just one or two places
+# if .CURDIR is matched by any entry in DEBUG_MAKE_SYS_DIRS we
+# will apply DEBUG_MAKE_FLAGS now.
+# if an entry in DEBUG_MAKE_DIRS matches, we at the end of sys.mk
+# eg.  DEBUG_MAKE_FLAGS=-dv DEBUG_MAKE_SYS_DIRS="*lib/sjg"
+# use DEBUG_MAKE_FLAGS0 to apply only to .MAKE.LEVEL 0
+#
+.if ${.MAKE.LEVEL:U1} == 0
+# we use indirection, to simplify the tests below, and incase
+# DEBUG_* were given on our command line.
+_DEBUG_MAKE_FLAGS = ${DEBUG_MAKE_FLAGS0}
+_DEBUG_MAKE_SYS_DIRS = ${DEBUG_MAKE_SYS_DIRS0:U${DEBUG_MAKE_SYS_DIRS}}
+_DEBUG_MAKE_DIRS = ${DEBUG_MAKE_DIRS0:U${DEBUG_MAKE_DIRS}}
+.else
+_DEBUG_MAKE_FLAGS = ${DEBUG_MAKE_FLAGS}
+_DEBUG_MAKE_SYS_DIRS = ${DEBUG_MAKE_SYS_DIRS}
+_DEBUG_MAKE_DIRS = ${DEBUG_MAKE_DIRS}
+.endif

Modified: trunk/contrib/bmake/mk/sys.dependfile.mk
===================================================================
--- trunk/contrib/bmake/mk/sys.dependfile.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/sys.dependfile.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-# $Id: sys.dependfile.mk,v 1.6 2014/08/02 18:02:06 sjg Exp $
+# $Id: sys.dependfile.mk,v 1.8 2016/03/11 01:34:13 sjg Exp $
 #
 #	@(#) Copyright (c) 2012, Simon J. Gerraty
 #
@@ -48,8 +48,10 @@
 # MACHINE specific depend files are supported, but *not* default.
 # If any already exist, we should follow suit.
 _aml = ${ALL_MACHINE_LIST:Uarm amd64 i386 powerpc:N${MACHINE}} ${MACHINE}
-# MACHINE must be the last entry in _aml ;-)
+# make sure we restore MACHINE
+_m := ${MACHINE}
 _e := ${_aml:@MACHINE@${.MAKE.DEPENDFILE_PREFERENCE:@m@${exists($m):?$m:}@}@}
+MACHINE := ${_m}
 .if !empty(_e)
 .MAKE.DEPENDFILE ?= ${.MAKE.DEPENDFILE_PREFERENCE:M*${MACHINE}:[1]}
 .endif

Modified: trunk/contrib/bmake/mk/sys.mk
===================================================================
--- trunk/contrib/bmake/mk/sys.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/sys.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-# $Id: sys.mk,v 1.41 2015/11/14 20:20:34 sjg Exp $
+# $Id: sys.mk,v 1.45 2017/02/05 01:26:13 sjg Exp $
 #
 #	@(#) Copyright (c) 2003-2009, Simon J. Gerraty
 #
@@ -15,39 +15,9 @@
 
 # Avoid putting anything platform specific in here.
 
-# We use the following paradigm for preventing multiple inclusion.
-# It relies on the fact that conditionals and dependencies are resolved 
-# at the time they are read.
-#
-# _this ?= ${.PARSEFILE}
-# .if !target(__${_this}__)
-# __${_this}__:
-#
-.if ${MAKE_VERSION:U0} > 20100408
-_this = ${.PARSEDIR:tA}/${.PARSEFILE}
-.else
-_this = ${.PARSEDIR}/${.PARSEFILE}
-.endif
+# _DEBUG_MAKE_FLAGS etc.
+.include <sys.debug.mk>
 
-# Sometimes we want to turn on debugging in just one or two places
-# if .CURDIR is matched by any entry in DEBUG_MAKE_SYS_DIRS we
-# will apply DEBUG_MAKE_FLAGS now.
-# if an entry in DEBUG_MAKE_DIRS matches, we at the end of sys.mk
-# eg.  DEBUG_MAKE_FLAGS=-dv DEBUG_MAKE_SYS_DIRS="*lib/sjg"
-# use DEBUG_MAKE_FLAGS0 to apply only to .MAKE.LEVEL 0
-#
-.if ${.MAKE.LEVEL:U1} == 0
-# we use indirection, to simplify the tests below, and incase
-# DEBUG_* were given on our command line.
-_DEBUG_MAKE_FLAGS = ${DEBUG_MAKE_FLAGS0}
-_DEBUG_MAKE_SYS_DIRS = ${DEBUG_MAKE_SYS_DIRS0:U${DEBUG_MAKE_SYS_DIRS}}
-_DEBUG_MAKE_DIRS = ${DEBUG_MAKE_DIRS0:U${DEBUG_MAKE_DIRS}}
-.else
-_DEBUG_MAKE_FLAGS = ${DEBUG_MAKE_FLAGS}
-_DEBUG_MAKE_SYS_DIRS = ${DEBUG_MAKE_SYS_DIRS}
-_DEBUG_MAKE_DIRS = ${DEBUG_MAKE_DIRS}
-.endif
-
 .if !empty(_DEBUG_MAKE_FLAGS)
 .if ${_DEBUG_MAKE_SYS_DIRS:Uno:@x@${.CURDIR:M$x}@} != ""
 .MAKEFLAGS: ${_DEBUG_MAKE_FLAGS}
@@ -54,48 +24,9 @@
 .endif
 .endif
 
-# if this is an ancient version of bmake
-MAKE_VERSION ?= 0
-.if ${MAKE_VERSION:M*make-*}
-# turn it into what we want - just the date
-MAKE_VERSION := ${MAKE_VERSION:[1]:C,.*-,,}
-.endif
+# useful modifiers
+.include <sys.vars.mk>
 
-# some useful modifiers
-
-# A useful trick for testing multiple :M's against something
-# :L says to use the variable's name as its value - ie. literal
-# got = ${clean* destroy:${M_ListToMatch:S,V,.TARGETS,}}
-M_ListToMatch = L:@m@$${V:M$$m}@
-# match against our initial targets (see above)
-M_L_TARGETS = ${M_ListToMatch:S,V,_TARGETS,}
-
-# turn a list into a set of :N modifiers
-# NskipFoo = ${Foo:${M_ListToSkip}}
-M_ListToSkip= O:u:ts::S,:,:N,g:S,^,N,
-
-# type should be a builtin in any sh since about 1980,
-# but sadly there are exceptions!
-.if ${.MAKE.OS:Unknown:NBSD/OS} == ""
-_type_sh = which
-.endif
-# AUTOCONF := ${autoconf:L:${M_whence}}
-M_type = @x@(${_type_sh:Utype} $$x) 2> /dev/null; echo;@:sh:[0]:N* found*:[@]:C,[()],,g
-M_whence = ${M_type}:M/*:[1]
-
-# convert a path to a valid shell variable
-M_P2V = tu:C,[./-],_,g
-
-# convert path to absolute
-.if ${MAKE_VERSION:U0} > 20100408
-M_tA = tA
-.else
-M_tA = C,.*,('cd' & \&\& 'pwd') 2> /dev/null || echo &,:sh
-.endif
-
-# absoulte path to what we are reading.
-_PARSEDIR = ${.PARSEDIR:${M_tA}}
-
 # we expect a recent bmake
 .if !defined(_TARGETS)
 # some things we do only once
@@ -109,6 +40,10 @@
 # early customizations
 .-include <local.sys.env.mk>
 
+# Popular suffixes for C++
+CXX_SUFFIXES += .cc .cpp .cxx .C
+CXX_SUFFIXES := ${CXX_SUFFIXES:O:u}
+
 # find the OS specifics
 .if defined(SYS_OS_MK)
 .include <${SYS_OS_MK}>
@@ -136,14 +71,14 @@
 # some options we need to know early
 OPTIONS_DEFAULT_NO += \
 	DIRDEPS_BUILD \
-	DIRDEPS_CACHE \
-	META_MODE
+	DIRDEPS_CACHE
 
 OPTIONS_DEFAULT_DEPENDENT += \
 	AUTO_OBJ/DIRDEPS_BUILD \
+	META_MODE/DIRDEPS_BUILD \
 	STAGING/DIRDEPS_BUILD \
 
-.-include "options.mk"
+.-include <options.mk>
 
 .if ${MK_DIRDEPS_BUILD:Uno} == "yes"
 MK_META_MODE = yes
@@ -201,7 +136,7 @@
 .c.cpp-out:
 	@${COMPILE.c:N-c} -E ${.IMPSRC} | grep -v '^[ 	]*$$'
 
-.cc.cpp-out:
+${CXX_SUFFIXES:%=%.cpp-out}:
 	@${COMPILE.cc:N-c} -E ${.IMPSRC} | grep -v '^[ 	]*$$'
 
 # late customizations

Copied: trunk/contrib/bmake/mk/sys.vars.mk (from rev 11139, vendor/NetBSD/bmake/dist/mk/sys.vars.mk)
===================================================================
--- trunk/contrib/bmake/mk/sys.vars.mk	                        (rev 0)
+++ trunk/contrib/bmake/mk/sys.vars.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -0,0 +1,80 @@
+# $Id: sys.vars.mk,v 1.2 2017/01/31 07:44:45 sjg Exp $
+#
+#	@(#) Copyright (c) 2003-2009, Simon J. Gerraty
+#
+#	This file is provided in the hope that it will
+#	be of use.  There is absolutely NO WARRANTY.
+#	Permission to copy, redistribute or otherwise
+#	use this file is hereby granted provided that 
+#	the above copyright notice and this notice are
+#	left intact. 
+#      
+#	Please send copies of changes and bug-fixes to:
+#	sjg at crufty.net
+#
+
+# We use the following paradigm for preventing multiple inclusion.
+# It relies on the fact that conditionals and dependencies are resolved 
+# at the time they are read.
+#
+# _this ?= ${.PARSEFILE}
+# .if !target(__${_this}__)
+# __${_this}__:
+#
+.if ${MAKE_VERSION:U0} > 20100408
+_this = ${.PARSEDIR:tA}/${.PARSEFILE}
+.else
+_this = ${.PARSEDIR}/${.PARSEFILE}
+.endif
+
+# if this is an ancient version of bmake
+MAKE_VERSION ?= 0
+.if ${MAKE_VERSION:M*make-*}
+# turn it into what we want - just the date
+MAKE_VERSION := ${MAKE_VERSION:[1]:C,.*-,,}
+.endif
+
+# some useful modifiers
+
+# A useful trick for testing multiple :M's against something
+# :L says to use the variable's name as its value - ie. literal
+# got = ${clean* destroy:${M_ListToMatch:S,V,.TARGETS,}}
+M_ListToMatch = L:@m@$${V:M$$m}@
+# match against our initial targets (see above)
+M_L_TARGETS = ${M_ListToMatch:S,V,_TARGETS,}
+
+# turn a list into a set of :N modifiers
+# NskipFoo = ${Foo:${M_ListToSkip}}
+M_ListToSkip= O:u:ts::S,:,:N,g:S,^,N,
+
+# type should be a builtin in any sh since about 1980,
+# but sadly there are exceptions!
+.if ${.MAKE.OS:Unknown:NBSD/OS} == ""
+_type_sh = which
+.endif
+
+# AUTOCONF := ${autoconf:L:${M_whence}}
+M_type = @x@(${_type_sh:Utype} $$x) 2> /dev/null; echo;@:sh:[0]:N* found*:[@]:C,[()],,g
+M_whence = ${M_type}:M/*:[1]
+
+# convert a path to a valid shell variable
+M_P2V = tu:C,[./-],_,g
+
+# convert path to absolute
+.if ${MAKE_VERSION:U0} > 20100408
+M_tA = tA
+.else
+M_tA = C,.*,('cd' & \&\& 'pwd') 2> /dev/null || echo &,:sh
+.endif
+
+.if ${MAKE_VERSION:U0} >= 20170130
+# M_cmpv allows comparing dotted versions like 3.1.2
+# ${3.1.2:L:${M_cmpv}} -> 3001002
+# we use big jumps to handle 3 digits per dot:
+# ${123.456.789:L:${M_cmpv}} -> 123456789
+M_cmpv.units = 1 1000 1000000
+M_cmpv = S,., ,g:_:range:@i at + $${_:[-$$i]} \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh
+.endif
+
+# absoulte path to what we are reading.
+_PARSEDIR = ${.PARSEDIR:${M_tA}}

Modified: trunk/contrib/bmake/mk/warnings.mk
===================================================================
--- trunk/contrib/bmake/mk/warnings.mk	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/mk/warnings.mk	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,5 +1,5 @@
 # RCSid:
-#	$Id: warnings.mk,v 1.8 2014/04/02 19:20:23 sjg Exp $
+#	$Id: warnings.mk,v 1.14 2016/04/05 15:58:37 sjg Exp $
 #
 #	@(#) Copyright (c) 2002, Simon J. Gerraty
 #
@@ -15,9 +15,11 @@
 #
 
 .ifndef _w_cflags
+# make sure we get the behavior we expect
+.MAKE.SAVE_DOLLARS = no
 
 # Any number of warnings sets can be added.
-.-include "warnings-sets.mk"
+.-include <warnings-sets.mk>
 
 # Modest defaults - put more elaborate sets in warnings-sets.mk
 # -Wunused  etc are here so you can set
@@ -48,6 +50,11 @@
 DEFAULT_WARNINGS_SET?= MIN
 WARNINGS_SET?= ${DEFAULT_WARNINGS_SET}
 
+# There is always someone who wants more...
+.if !empty(WARNINGS_XTRAS)
+${WARNINGS_SET}_WARNINGS += ${WARNINGS_XTRAS}
+.endif
+
 # If you add sets, besure to list them (you don't have to touch this list).
 ALL_WARNINGS_SETS+= MIN LOW MEDIUM HIGH EXTRA
 
@@ -70,7 +77,7 @@
 # Without -O or if we've set -O0 somewhere - to make debugging more effective,
 # we need to turn off -Wuninitialized as otherwise we get a warning that
 # -Werror turns into an error.  To be safe, set W_uninitialized blank.
-_w_cflags:= ${CFLAGS} ${CPPFLAGS}
+_w_cflags= ${CFLAGS} ${CFLAGS_LAST} ${CPPFLAGS}
 .if ${_w_cflags:M-O*} == "" || ${_w_cflags:M-O0} != ""
 W_uninitialized=
 .endif
@@ -116,6 +123,7 @@
 
 # it is rather silly that g++ blows up on some warning flags
 NO_CXX_WARNINGS+= \
+	implicit \
 	missing-declarations \
 	missing-prototypes \
 	nested-externs \

Modified: trunk/contrib/bmake/nonints.h
===================================================================
--- trunk/contrib/bmake/nonints.h	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/nonints.h	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.69 2015/10/11 04:51:24 sjg Exp $	*/
+/*	$NetBSD: nonints.h,v 1.74 2016/09/05 00:40:29 sevan Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,6 @@
 /* main.c */
 void Main_ParseArgLine(const char *);
 void MakeMode(const char *);
-int main(int, char **);
 char *Cmd_Exec(const char *, const char **);
 void Error(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
 void Fatal(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;
@@ -120,7 +119,9 @@
 int eunlink(const char *);
 void execError(const char *, const char *);
 char *getTmpdir(void);
+Boolean s2Boolean(const char *, Boolean);
 Boolean getBoolean(const char *, Boolean);
+char *cached_realpath(const char *, char *);
 
 /* parse.c */
 void Parse_Error(int, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
@@ -142,6 +143,11 @@
 char *Str_SYSVMatch(const char *, const char *, int *len);
 void Str_SYSVSubst(Buffer *, char *, char *, int);
 
+#ifndef HAVE_STRLCPY
+/* strlcpy.c */
+size_t strlcpy(char *, const char *, size_t);
+#endif
+
 /* suff.c */
 void Suff_ClearSuffixes(void);
 Boolean Suff_IsTransform(char *);
@@ -184,8 +190,8 @@
 void Var_Append(const char *, const char *, GNode *);
 Boolean Var_Exists(const char *, GNode *);
 char *Var_Value(const char *, GNode *, char **);
-char *Var_Parse(const char *, GNode *, Boolean, Boolean, int *, void **);
-char *Var_Subst(const char *, const char *, GNode *, Boolean, Boolean);
+char *Var_Parse(const char *, GNode *, int, int *, void **);
+char *Var_Subst(const char *, const char *, GNode *, int);
 char *Var_GetTail(const char *);
 char *Var_GetHead(const char *);
 void Var_Init(void);

Modified: trunk/contrib/bmake/os.sh
===================================================================
--- trunk/contrib/bmake/os.sh	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/os.sh	2018-06-27 00:20:04 UTC (rev 11140)
@@ -17,7 +17,7 @@
 #	Simon J. Gerraty <sjg at crufty.net>
 
 # RCSid:
-#	$Id: os.sh,v 1.50 2015/12/17 17:06:29 sjg Exp $
+#	$Id: os.sh,v 1.53 2017/01/11 20:01:09 sjg Exp $
 #
 #	@(#) Copyright (c) 1994 Simon J. Gerraty
 #
@@ -139,7 +139,7 @@
 	case $OS in
 	NetBSD)
 		HOST_ARCH=$MACHINE
-		SHARE_ARCH=$OS/$HOST
+		SHARE_ARCH=$OS/$HOST_ARCH
 		;;
 	OpenBSD)
 		arch=`Which arch /usr/bin:/usr/ucb:$PATH`
@@ -206,15 +206,23 @@
 
 TMP_DIRS=${TMP_DIRS:-"/tmp /var/tmp"}
 MACHINE_ARCH=${MACHINE_ARCH:-$MACHINE}
+case "$MACHINE_ARCH" in
+x86*64|amd64) MACHINE32_ARCH=i386;;
+*64) MACHINE32_ARCH=`echo $MACHINE_ARCH | sed 's,64,32,'`;;
+*) MACHINE32_ARCH=$MACHINE_ARCH;;
+esac
 HOST_ARCH=${HOST_ARCH:-$MACHINE_ARCH}
+HOST_ARCH32=${HOST_ARCH32:-$MACHINE32_ARCH}
 # we mount server:/share/arch/$SHARE_ARCH as /usr/local
-SHARE_ARCH=${SHARE_ARCH:-$OS/$OSMAJOR.X/$HOST_ARCH}
+SHARE_ARCH_DEFAULT=$OS/$OSMAJOR.X/$HOST_ARCH
+SHARE_ARCH=${SHARE_ARCH:-$SHARE_ARCH_DEFAULT}
 LN=${LN:-ln}
 TR=${TR:-tr}
 
 # Some people like have /share/$HOST_TARGET/bin etc.
 HOST_TARGET=`echo ${OS}${OSMAJOR}-$HOST_ARCH | tr -d / | toLower`
-export HOST_TARGET
+HOST_TARGET32=`echo ${OS}${OSMAJOR}-$HOST_ARCH32 | tr -d / | toLower`
+export HOST_TARGET HOST_TARGET32
 
 case `echo -n .` in -n*) N=; C="\c";; *) N=-n; C=;; esac
 

Modified: trunk/contrib/bmake/parse.c
===================================================================
--- trunk/contrib/bmake/parse.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/parse.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.206 2015/11/26 00:23:04 sjg Exp $	*/
+/*	$NetBSD: parse.c,v 1.225 2017/04/17 13:29:07 maya Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.206 2015/11/26 00:23:04 sjg Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.225 2017/04/17 13:29:07 maya Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -76,7 +76,7 @@
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.206 2015/11/26 00:23:04 sjg Exp $");
+__RCSID("$NetBSD: parse.c,v 1.225 2017/04/17 13:29:07 maya Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -128,7 +128,6 @@
 #include <assert.h>
 #include <ctype.h>
 #include <errno.h>
-#include <fcntl.h>
 #include <stdarg.h>
 #include <stdio.h>
 
@@ -139,6 +138,10 @@
 #include "buf.h"
 #include "pathnames.h"
 
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
 #ifdef HAVE_MMAP
 #include <sys/mman.h>
 
@@ -161,6 +164,7 @@
     int             lineno;         /* current line number in file */
     int             first_lineno;   /* line number of start of text */
     int             cond_depth;     /* 'if' nesting when file opened */
+    Boolean         depending;      /* state of doing_depend on EOF */
     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 */
@@ -184,6 +188,7 @@
 typedef enum {
     Begin,  	    /* .BEGIN */
     Default,	    /* .DEFAULT */
+    DeleteOnError,  /* .DELETE_ON_ERROR */
     End,    	    /* .END */
     dotError,	    /* .ERROR */
     Ignore,	    /* .IGNORE */
@@ -301,6 +306,7 @@
 } parseKeywords[] = {
 { ".BEGIN", 	  Begin,    	0 },
 { ".DEFAULT",	  Default,  	0 },
+{ ".DELETE_ON_ERROR", DeleteOnError, 0 },
 { ".END",   	  End,	    	0 },
 { ".ERROR",   	  dotError,    	0 },
 { ".EXEC",	  Attribute,   	OP_EXEC },
@@ -537,7 +543,7 @@
 		if (lf->buf != MAP_FAILED) {
 			/* succeeded */
 			if (lf->len == lf->maplen && lf->buf[lf->len - 1] != '\n') {
-				char *b = malloc(lf->len + 1);
+				char *b = bmake_malloc(lf->len + 1);
 				b[lf->len] = '\n';
 				memcpy(b, lf->buf, lf->len++);
 				munmap(lf->buf, lf->maplen);
@@ -558,9 +564,15 @@
 	while (1) {
 		assert(bufpos <= lf->len);
 		if (bufpos == lf->len) {
+			if (lf->len > SIZE_MAX/2) {
+				errno = EFBIG;
+				Error("%s: file too large", path);
+				exit(1);
+			}
 			lf->len *= 2;
 			lf->buf = bmake_realloc(lf->buf, lf->len);
 		}
+		assert(bufpos < lf->len);
 		result = read(fd, lf->buf + bufpos, lf->len - bufpos);
 		if (result < 0) {
 			Error("%s: read error: %s", path, strerror(errno));
@@ -576,7 +588,11 @@
 
 	/* truncate malloc region to actual length (maybe not useful) */
 	if (lf->len > 0) {
+		/* as for mmap case, ensure trailing \n */
+		if (lf->buf[lf->len - 1] != '\n')
+			lf->len++;
 		lf->buf = bmake_realloc(lf->buf, lf->len);
+		lf->buf[lf->len - 1] = '\n';
 	}
 
 #ifdef HAVE_MMAP
@@ -809,14 +825,14 @@
 	return FALSE;
     }
 
-    while (isalpha((u_char)*line))
+    while (isalpha((unsigned char)*line))
 	line++;
-    if (!isspace((u_char)*line))
+    if (!isspace((unsigned char)*line))
 	return FALSE;			/* not for us */
-    while (isspace((u_char)*line))
+    while (isspace((unsigned char)*line))
 	line++;
 
-    line = Var_Subst(NULL, line, VAR_CMD, FALSE, TRUE);
+    line = Var_Subst(NULL, line, VAR_CMD, VARF_WANTRES);
     Parse_Error(mtype, "%s", line);
     free(line);
 
@@ -1093,15 +1109,15 @@
  *-----------------------------------------------------------------------
  */
 static int
-ParseFindMain(void *gnp, void *dummy)
+ParseFindMain(void *gnp, void *dummy MAKE_ATTR_UNUSED)
 {
     GNode   	  *gn = (GNode *)gnp;
     if ((gn->type & OP_NOTARGET) == 0) {
 	mainNode = gn;
 	Targ_SetMain(gn);
-	return (dummy ? 1 : 1);
+	return 1;
     } else {
-	return (dummy ? 0 : 0);
+	return 0;
     }
 }
 
@@ -1139,10 +1155,10 @@
  *-----------------------------------------------------------------------
  */
 static int
-ParseClearPath(void *path, void *dummy)
+ParseClearPath(void *path, void *dummy MAKE_ATTR_UNUSED)
 {
     Dir_ClearPath((Lst) path);
-    return(dummy ? 0 : 0);
+    return 0;
 }
 
 /*-
@@ -1233,9 +1249,9 @@
 		int 	length;
 		void    *freeIt;
 
-		(void)Var_Parse(cp, VAR_CMD, TRUE, TRUE, &length, &freeIt);
-		if (freeIt)
-		    free(freeIt);
+		(void)Var_Parse(cp, VAR_CMD, VARF_UNDEFERR|VARF_WANTRES,
+				&length, &freeIt);
+		free(freeIt);
 		cp += length-1;
 	    }
 	}
@@ -1261,6 +1277,7 @@
 		goto out;
 	    } else {
 		/* Done with this word; on to the next. */
+		cp = line;
 		continue;
 	    }
 	}
@@ -1333,6 +1350,7 @@
 		 *	.BEGIN
 		 *	.END
 		 *	.ERROR
+		 *	.DELETE_ON_ERROR
 		 *	.INTERRUPT  	Are not to be considered the
 		 *			main target.
 		 *  	.NOTPARALLEL	Make only one target at a time.
@@ -1368,6 +1386,9 @@
 		    (void)Lst_AtEnd(targets, gn);
 		    DEFAULT = gn;
 		    break;
+		case DeleteOnError:
+		    deleteOnError = TRUE;
+		    break;
 		case NotParallel:
 		    maxJobs = 1;
 		    break;
@@ -1596,7 +1617,8 @@
 	    goto out;
 	}
 	*line = '\0';
-    } else if ((specType == NotParallel) || (specType == SingleShell)) {
+    } else if ((specType == NotParallel) || (specType == SingleShell) ||
+	    (specType == DeleteOnError)) {
 	*line = '\0';
     }
 
@@ -1657,7 +1679,7 @@
 		    Suff_SetNull(line);
 		    break;
 		case ExObjdir:
-		    Main_SetObjdir(line);
+		    Main_SetObjdir("%s", line);
 		    break;
 		default:
 		    break;
@@ -1673,10 +1695,12 @@
 	}
 	if (paths) {
 	    Lst_Destroy(paths, NULL);
+	    paths = NULL;
 	}
 	if (specType == ExPath)
 	    Dir_SetPATH();
     } else {
+	assert(paths == NULL);
 	while (*line) {
 	    /*
 	     * The targets take real sources, so we must beware of archive
@@ -1735,6 +1759,7 @@
     }
 
 out:
+    assert(paths == NULL);
     if (curTargs)
 	    Lst_Destroy(curTargs, NULL);
 }
@@ -1857,7 +1882,7 @@
      * XXX Rather than counting () and {} we should look for $ and
      * then expand the variable.
      */
-    for (depth = 0, cp = line + 1; depth != 0 || *cp != '='; cp++) {
+    for (depth = 0, cp = line + 1; depth > 0 || *cp != '='; cp++) {
 	if (*cp == '(' || *cp == '{') {
 	    depth++;
 	    continue;
@@ -1948,7 +1973,7 @@
 	if (!Var_Exists(line, ctxt))
 	    Var_Set(line, "", ctxt, 0);
 
-	cp = Var_Subst(NULL, cp, ctxt, FALSE, TRUE);
+	cp = Var_Subst(NULL, cp, ctxt, VARF_WANTRES|VARF_ASSIGN);
 	oldVars = oldOldVars;
 	freeCp = TRUE;
 
@@ -1963,7 +1988,7 @@
 	     * expansion on the whole thing. The resulting string will need
 	     * freeing when we're done, so set freeCmd to TRUE.
 	     */
-	    cp = Var_Subst(NULL, cp, VAR_CMD, TRUE, TRUE);
+	    cp = Var_Subst(NULL, cp, VAR_CMD, VARF_UNDEFERR|VARF_WANTRES);
 	    freeCp = TRUE;
 	}
 
@@ -2155,7 +2180,7 @@
  */
 
 static void
-Parse_include_file(char *file, Boolean isSystem, int silent)
+Parse_include_file(char *file, Boolean isSystem, Boolean depinc, int silent)
 {
     struct loadedfile *lf;
     char          *fullname;	/* full pathname of file */
@@ -2255,6 +2280,8 @@
     /* Start reading from this file next */
     Parse_SetInput(fullname, 0, -1, loadedfile_nextbuf, lf);
     curFile->lf = lf;
+    if (depinc)
+	doing_depend = depinc;		/* only turn it on */
 }
 
 static void
@@ -2302,9 +2329,9 @@
      * Substitute for any variables in the file name before trying to
      * find the thing.
      */
-    file = Var_Subst(NULL, file, VAR_CMD, FALSE, TRUE);
+    file = Var_Subst(NULL, file, VAR_CMD, VARF_WANTRES);
 
-    Parse_include_file(file, endc == '>', silent);
+    Parse_include_file(file, endc == '>', (*line == 'd'), silent);
     free(file);
 }
 
@@ -2339,10 +2366,8 @@
 	fprintf(debug_file, "%s: ${.INCLUDEDFROMDIR} = `%s' "
 	    "${.INCLUDEDFROMFILE} = `%s'\n", __func__, pd, pf);
 
-    if (fp)
-	free(fp);
-    if (dp)
-	free(dp);
+    free(fp);
+    free(dp);
 }
 /*-
  *---------------------------------------------------------------------
@@ -2472,6 +2497,7 @@
     curFile->nextbuf = nextbuf;
     curFile->nextbuf_arg = arg;
     curFile->lf = NULL;
+    curFile->depending = doing_depend;	/* restore this on EOF */
 
     assert(nextbuf != NULL);
 
@@ -2532,12 +2558,12 @@
      * Substitute for any variables in the file name before trying to
      * find the thing.
      */
-    all_files = Var_Subst(NULL, file, VAR_CMD, FALSE, TRUE);
+    all_files = Var_Subst(NULL, file, VAR_CMD, VARF_WANTRES);
 
     if (*file == '\0') {
 	Parse_Error(PARSE_FATAL,
 		     "Filename missing from \"include\"");
-	return;
+	goto out;
     }
 
     for (file = all_files; !done; file = cp + 1) {
@@ -2550,8 +2576,9 @@
 	else
 	    done = 1;
 
-	Parse_include_file(file, FALSE, silent);
+	Parse_include_file(file, FALSE, FALSE, silent);
     }
+out:
     free(all_files);
 }
 #endif
@@ -2600,8 +2627,9 @@
     /*
      * Expand the value before putting it in the environment.
      */
-    value = Var_Subst(NULL, value, VAR_CMD, FALSE, TRUE);
+    value = Var_Subst(NULL, value, VAR_CMD, VARF_WANTRES);
     setenv(variable, value, 1);
+    free(value);
 }
 #endif
 
@@ -2628,6 +2656,7 @@
 
     assert(curFile->nextbuf != NULL);
 
+    doing_depend = curFile->depending;	/* restore this */
     /* get next input buffer, if any */
     ptr = curFile->nextbuf(curFile->nextbuf_arg, &len);
     curFile->P_ptr = ptr;
@@ -2990,7 +3019,7 @@
 		    continue;
 		}
 		if (strncmp(cp, "include", 7) == 0 ||
-			((cp[0] == 's' || cp[0] == '-') &&
+			((cp[0] == 'd' || cp[0] == 's' || cp[0] == '-') &&
 			    strncmp(&cp[1], "include", 7) == 0)) {
 		    ParseDoInclude(cp);
 		    continue;
@@ -3149,7 +3178,7 @@
 	     * variables expanded before being parsed. Tell the variable
 	     * module to complain if some variable is undefined...
 	     */
-	    line = Var_Subst(NULL, line, VAR_CMD, TRUE, TRUE);
+	    line = Var_Subst(NULL, line, VAR_CMD, VARF_UNDEFERR|VARF_WANTRES);
 
 	    /*
 	     * Need a non-circular list for the target nodes

Modified: trunk/contrib/bmake/sprite.h
===================================================================
--- trunk/contrib/bmake/sprite.h	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/sprite.h	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: sprite.h,v 1.11 2009/01/23 21:26:30 dsl Exp $	*/
+/*	$NetBSD: sprite.h,v 1.14 2017/05/31 22:02:06 maya Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -78,8 +78,8 @@
  * Common constants and type declarations for Sprite.
  */
 
-#ifndef _SPRITE
-#define _SPRITE
+#ifndef MAKE_SPRITE_H
+#define MAKE_SPRITE_H
 
 
 /*
@@ -113,4 +113,4 @@
 #define	SUCCESS			0x00000000
 #define	FAILURE			0x00000001
 
-#endif /* _SPRITE */
+#endif /* MAKE_SPRITE_H */

Modified: trunk/contrib/bmake/str.c
===================================================================
--- trunk/contrib/bmake/str.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/str.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.c,v 1.35 2014/02/12 01:35:56 sjg Exp $	*/
+/*	$NetBSD: str.c,v 1.38 2017/04/21 22:15:44 sjg Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: str.c,v 1.35 2014/02/12 01:35:56 sjg Exp $";
+static char rcsid[] = "$NetBSD: str.c,v 1.38 2017/04/21 22:15:44 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -76,7 +76,7 @@
 #if 0
 static char     sccsid[] = "@(#)str.c	5.8 (Berkeley) 6/1/90";
 #else
-__RCSID("$NetBSD: str.c,v 1.35 2014/02/12 01:35:56 sjg Exp $");
+__RCSID("$NetBSD: str.c,v 1.38 2017/04/21 22:15:44 sjg Exp $");
 #endif
 #endif				/* not lint */
 #endif
@@ -102,7 +102,7 @@
 	len2 = strlen(s2);
 
 	/* allocate length plus separator plus EOS */
-	result = bmake_malloc((u_int)(len1 + len2 + 2));
+	result = bmake_malloc((unsigned int)(len1 + len2 + 2));
 
 	/* copy first string into place */
 	memcpy(result, s1, len1);
@@ -373,16 +373,26 @@
 		 * by a range (two characters separated by "-").
 		 */
 		if (*pattern == '[') {
+			int nomatch;
+
 			++pattern;
+			if (*pattern == '^') {
+				++pattern;
+				nomatch = 1;
+			} else
+				nomatch = 0;
 			for (;;) {
-				if ((*pattern == ']') || (*pattern == 0))
+				if ((*pattern == ']') || (*pattern == 0)) {
+					if (nomatch)
+						break;
 					return(0);
+				}
 				if (*pattern == *string)
 					break;
 				if (pattern[1] == '-') {
 					c2 = pattern[2];
 					if (c2 == 0)
-						return(0);
+						return(nomatch);
 					if ((*pattern <= *string) &&
 					    (c2 >= *string))
 						break;
@@ -393,6 +403,8 @@
 				}
 				++pattern;
 			}
+			if (nomatch && (*pattern != ']') && (*pattern != 0))
+				return 0;
 			while ((*pattern != ']') && (*pattern != 0))
 				++pattern;
 			goto thisCharOK;

Modified: trunk/contrib/bmake/suff.c
===================================================================
--- trunk/contrib/bmake/suff.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/suff.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.75 2015/12/20 22:44:10 sjg Exp $	*/
+/*	$NetBSD: suff.c,v 1.86 2017/04/16 20:38:18 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.75 2015/12/20 22:44:10 sjg Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.86 2017/04/16 20:38:18 riastradh Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -76,7 +76,7 @@
 #if 0
 static char sccsid[] = "@(#)suff.c	8.4 (Berkeley) 3/21/94";
 #else
-__RCSID("$NetBSD: suff.c,v 1.75 2015/12/20 22:44:10 sjg Exp $");
+__RCSID("$NetBSD: suff.c,v 1.86 2017/04/16 20:38:18 riastradh Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -135,6 +135,7 @@
  *				order to find the node.
  */
 
+#include    	  <assert.h>
 #include    	  <stdio.h>
 #include	  "make.h"
 #include	  "hash.h"
@@ -762,7 +763,7 @@
  *-----------------------------------------------------------------------
  */
 int
-Suff_EndTransform(void *gnp, void *dummy)
+Suff_EndTransform(void *gnp, void *dummy MAKE_ATTR_UNUSED)
 {
     GNode *gn = (GNode *)gnp;
 
@@ -809,7 +810,7 @@
 	fprintf(debug_file, "transformation %s complete\n", gn->name);
     }
 
-    return(dummy ? 0 : 0);
+    return 0;
 }
 
 /*-
@@ -1215,7 +1216,7 @@
 #ifdef DEBUG_SRC
 	s2->cp = Lst_Init(FALSE);
 	Lst_AtEnd(targ->cp, s2);
-	fprintf(debug_file, "1 add %x %x to %x:", targ, s2, ls->l);
+	fprintf(debug_file, "1 add %p %p to %p:", targ, s2, ls->l);
 	Lst_ForEach(ls->l, PrintAddr, NULL);
 	fprintf(debug_file, "\n");
 #endif
@@ -1233,7 +1234,7 @@
 #ifdef DEBUG_SRC
     s2->cp = Lst_Init(FALSE);
     Lst_AtEnd(targ->cp, s2);
-    fprintf(debug_file, "2 add %x %x to %x:", targ, s2, ls->l);
+    fprintf(debug_file, "2 add %p %p to %p:", targ, s2, ls->l);
     Lst_ForEach(ls->l, PrintAddr, NULL);
     fprintf(debug_file, "\n");
 #endif
@@ -1305,14 +1306,14 @@
 		free(s->pref);
 	    else {
 #ifdef DEBUG_SRC
-		LstNode ln = Lst_Member(s->parent->cp, s);
-		if (ln != NULL)
-		    Lst_Remove(s->parent->cp, ln);
+		LstNode ln2 = Lst_Member(s->parent->cp, s);
+		if (ln2 != NULL)
+		    Lst_Remove(s->parent->cp, ln2);
 #endif
 		--s->parent->children;
 	    }
 #ifdef DEBUG_SRC
-	    fprintf(debug_file, "free: [l=%x] p=%x %d\n", l, s, s->children);
+	    fprintf(debug_file, "free: [l=%p] p=%p %d\n", l, s, s->children);
 	    Lst_Destroy(s->cp, NULL);
 #endif
 	    Lst_Remove(l, ln);
@@ -1323,7 +1324,7 @@
 	}
 #ifdef DEBUG_SRC
 	else {
-	    fprintf(debug_file, "keep: [l=%x] p=%x %d: ", l, s, s->children);
+	    fprintf(debug_file, "keep: [l=%p] p=%p %d: ", l, s, s->children);
 	    Lst_ForEach(s->cp, PrintAddr, NULL);
 	    fprintf(debug_file, "\n");
 	}
@@ -1372,7 +1373,7 @@
 	 */
 	if (Targ_FindNode(s->file, TARG_NOCREATE) != NULL) {
 #ifdef DEBUG_SRC
-	    fprintf(debug_file, "remove %x from %x\n", s, srcs);
+	    fprintf(debug_file, "remove %p from %p\n", s, srcs);
 #endif
 	    rs = s;
 	    break;
@@ -1381,7 +1382,7 @@
 	if ((ptr = Dir_FindFile(s->file, s->suff->searchPath)) != NULL) {
 	    rs = s;
 #ifdef DEBUG_SRC
-	    fprintf(debug_file, "remove %x from %x\n", s, srcs);
+	    fprintf(debug_file, "remove %p from %p\n", s, srcs);
 #endif
 	    free(ptr);
 	    break;
@@ -1497,7 +1498,7 @@
     targ->children += 1;
 #ifdef DEBUG_SRC
     ret->cp = Lst_Init(FALSE);
-    fprintf(debug_file, "3 add %x %x\n", targ, ret);
+    fprintf(debug_file, "3 add %p %p\n", targ, ret);
     Lst_AtEnd(targ->cp, ret);
 #endif
     Lst_AtEnd(slst, ret);
@@ -1556,7 +1557,7 @@
     if (DEBUG(SUFF)) {
 	fprintf(debug_file, "Expanding \"%s\"...", cgn->name);
     }
-    cp = Var_Subst(NULL, cgn->name, pgn, TRUE, TRUE);
+    cp = Var_Subst(NULL, cgn->name, pgn, VARF_UNDEFERR|VARF_WANTRES);
 
     if (cp != NULL) {
 	Lst	    members = Lst_Init(FALSE);
@@ -1609,14 +1610,14 @@
 		    int 	len;
 		    void	*freeIt;
 
-		    junk = Var_Parse(cp, pgn, TRUE, TRUE, &len, &freeIt);
+		    junk = Var_Parse(cp, pgn, VARF_UNDEFERR|VARF_WANTRES,
+			&len, &freeIt);
 		    if (junk != var_Error) {
 			cp += len - 1;
 		    }
 
-		    if (freeIt)
-			free(freeIt);
-		} else if (*cp == '\\' && *cp != '\0') {
+		    free(freeIt);
+		} else if (*cp == '\\' && cp[1] != '\0') {
 		    /*
 		     * Escaped something -- skip over it
 		     */
@@ -1894,6 +1895,7 @@
 	TARGET,	    	    /* Must be first */
 	PREFIX,	    	    /* Must be second */
     };
+    LstNode 	ln, nln;    /* Next suffix node to check */
     int	    	i;  	    /* Index into copy and vals */
     Suff    	*ms;	    /* Suffix descriptor for member */
     char    	*name;	    /* Start of member's name */
@@ -1905,6 +1907,13 @@
     eoarch = strchr(gn->name, '(');
     eoname = strchr(eoarch, ')');
 
+    /*
+     * Caller guarantees the format `libname(member)', via
+     * Arch_ParseArchive.
+     */
+    assert(eoarch != NULL);
+    assert(eoname != NULL);
+
     *eoname = '\0';	  /* Nuke parentheses during suffix search */
     *eoarch = '\0';	  /* So a suffix can be found */
 
@@ -1933,8 +1942,7 @@
     for (i = (sizeof(copy)/sizeof(copy[0]))-1; i >= 0; i--) {
 	char *p1;
 	Var_Set(copy[i], Var_Value(copy[i], mem, &p1), gn, 0);
-	if (p1)
-	    free(p1);
+	free(p1);
 
     }
 
@@ -1956,6 +1964,20 @@
     Var_Set(MEMBER, name, gn, 0);
     Var_Set(ARCHIVE, gn->name, gn, 0);
 
+    /*
+     * Set $@ for compatibility with other makes
+     */
+    Var_Set(TARGET, gn->name, gn, 0);
+
+    /*
+     * Now we've got the important local variables set, expand any sources
+     * that still contain variables or wildcards in their names.
+     */
+    for (ln = Lst_First(gn->children); ln != NULL; ln = nln) {
+	nln = Lst_Succ(ln);
+	SuffExpandChildren(ln, gn);
+    }
+
     if (ms != NULL) {
 	/*
 	 * Member has a known suffix, so look for a transformation rule from
@@ -1963,7 +1985,6 @@
 	 * through the entire list, we just look at suffixes to which the
 	 * member's suffix may be transformed...
 	 */
-	LstNode		ln;
 	SuffixCmpData	sd;		/* Search string data */
 
 	/*
@@ -2003,9 +2024,10 @@
 
     /*
      * Flag the member as such so we remember to look in the archive for
-     * its modification time.
+     * its modification time. The OP_JOIN | OP_MADE is needed because this
+     * target should never get made.
      */
-    mem->type |= OP_MEMBER;
+    mem->type |= OP_MEMBER | OP_JOIN | OP_MADE;
 }
 
 /*-
@@ -2581,14 +2603,15 @@
 
 /********************* DEBUGGING FUNCTIONS **********************/
 
-static int SuffPrintName(void *s, void *dummy)
+static int SuffPrintName(void *s, void *dummy MAKE_ATTR_UNUSED)
 {
+
     fprintf(debug_file, "%s ", ((Suff *)s)->name);
-    return (dummy ? 0 : 0);
+    return 0;
 }
 
 static int
-SuffPrintSuff(void *sp, void *dummy)
+SuffPrintSuff(void *sp, void *dummy MAKE_ATTR_UNUSED)
 {
     Suff    *s = (Suff *)sp;
     int	    flags;
@@ -2626,11 +2649,11 @@
     fprintf(debug_file, "#\tSearch Path: ");
     Dir_PrintPath(s->searchPath);
     fputc('\n', debug_file);
-    return (dummy ? 0 : 0);
+    return 0;
 }
 
 static int
-SuffPrintTrans(void *tp, void *dummy)
+SuffPrintTrans(void *tp, void *dummy MAKE_ATTR_UNUSED)
 {
     GNode   *t = (GNode *)tp;
 
@@ -2639,7 +2662,7 @@
     fputc('\n', debug_file);
     Lst_ForEach(t->commands, Targ_PrintCmd, NULL);
     fputc('\n', debug_file);
-    return(dummy ? 0 : 0);
+    return 0;
 }
 
 void

Modified: trunk/contrib/bmake/targ.c
===================================================================
--- trunk/contrib/bmake/targ.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/targ.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: targ.c,v 1.60 2015/05/25 09:01:06 manu Exp $	*/
+/*	$NetBSD: targ.c,v 1.62 2017/04/16 19:53:58 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: targ.c,v 1.60 2015/05/25 09:01:06 manu Exp $";
+static char rcsid[] = "$NetBSD: targ.c,v 1.62 2017/04/16 19:53:58 riastradh Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -76,7 +76,7 @@
 #if 0
 static char sccsid[] = "@(#)targ.c	8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: targ.c,v 1.60 2015/05/25 09:01:06 manu Exp $");
+__RCSID("$NetBSD: targ.c,v 1.62 2017/04/16 19:53:58 riastradh Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -292,10 +292,8 @@
 
 
     free(gn->name);
-    if (gn->uname)
-	free(gn->uname);
-    if (gn->path)
-	free(gn->path);
+    free(gn->uname);
+    free(gn->path);
     /* gn->fname points to name allocated when file was opened, don't free */
 
     Lst_Destroy(gn->iParents, NULL);
@@ -523,10 +521,10 @@
 
 
 int
-Targ_PrintCmd(void *cmd, void *dummy)
+Targ_PrintCmd(void *cmd, void *dummy MAKE_ATTR_UNUSED)
 {
     fprintf(debug_file, "\t%s\n", (char *)cmd);
-    return (dummy ? 0 : 0);
+    return 0;
 }
 
 /*-

Deleted: trunk/contrib/bmake/unit-tests/comment
===================================================================
--- trunk/contrib/bmake/unit-tests/comment	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/comment	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,31 +0,0 @@
-# This is a comment
-.if ${MACHINE_ARCH} == something
-FOO=bar
-.endif
-
-#\
-	Multiline comment
-
-BAR=# defined
-FOOBAR= # defined 
-
-# This is an escaped comment \
-that keeps going until the end of this line
-
-# Another escaped comment \
-that \
-goes \
-on
-
-# This is NOT an escaped comment due to the double backslashes \\
-all: hi foo bar
-	@echo comment testing done
-
-hi:
-	@echo comment testing start
-
-foo:
-	@echo this is $@
-
-bar:
-	@echo This is how a comment looks: '# comment'

Deleted: trunk/contrib/bmake/unit-tests/cond1
===================================================================
--- trunk/contrib/bmake/unit-tests/cond1	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/cond1	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,109 +0,0 @@
-# $Id: cond1,v 1.1.1.3 2011/03/06 00:04:58 sjg Exp $
-
-# hard code these!
-TEST_UNAME_S= NetBSD
-TEST_UNAME_M= sparc
-TEST_MACHINE= i386
-
-.if ${TEST_UNAME_S}
-Ok=var,
-.endif
-.if ("${TEST_UNAME_S}")
-Ok+=(\"var\"),
-.endif
-.if (${TEST_UNAME_M} != ${TEST_MACHINE})
-Ok+=(var != var),
-.endif
-.if ${TEST_UNAME_M} != ${TEST_MACHINE}
-Ok+= var != var,
-.endif
-.if !((${TEST_UNAME_M} != ${TEST_MACHINE}) && defined(X))
-Ok+= !((var != var) && defined(name)),
-.endif
-# from bsd.obj.mk
-MKOBJ?=no
-.if ${MKOBJ} == "no"
-o= no
-Ok+= var == "quoted",
-.else
-.if defined(notMAKEOBJDIRPREFIX) || defined(norMAKEOBJDIR)
-.if defined(notMAKEOBJDIRPREFIX)
-o=${MAKEOBJDIRPREFIX}${__curdir}
-.else
-o= ${MAKEOBJDIR}
-.endif
-.endif
-o= o
-.endif
-
-# repeat the above to check we get the same result
-.if ${MKOBJ} == "no"
-o2= no
-.else
-.if defined(notMAKEOBJDIRPREFIX) || defined(norMAKEOBJDIR)
-.if defined(notMAKEOBJDIRPREFIX)
-o2=${MAKEOBJDIRPREFIX}${__curdir}
-.else
-o2= ${MAKEOBJDIR}
-.endif
-.endif
-o2= o
-.endif
-
-PRIMES=2 3 5 7 11
-NUMBERS=1 2 3 4 5
-
-n=2
-.if ${PRIMES:M$n} == ""
-X=not
-.else
-X=
-.endif
-
-.if ${MACHINE_ARCH} == no-such
-A=one
-.else
-.if ${MACHINE_ARCH} == not-this
-.if ${MACHINE_ARCH} == something-else
-A=unlikely
-.else
-A=no
-.endif
-.endif
-A=other
-# We expect an extra else warning - we're not skipping here
-.else
-A=this should be an error
-.endif
-
-.if $X != ""
-.if $X == not
-B=one
-.else
-B=other
-# We expect an extra else warning - we are skipping here
-.else
-B=this should be an error
-.endif
-.else
-B=unknown
-.endif
-
-.if "quoted" == quoted
-C=clever
-.else
-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}'"
-	@echo "Passed:${.newline} ${Ok:S/,/${.newline}/}"
-	@echo "${NUMBERS:@n@$n is ${("${PRIMES:M$n}" == ""):?not:} prime${.newline}@}"
-	@echo "${"${DoNotQuoteHere:U0}" > 0:?OK:No}"
-	@echo "${${NoSuchNumber:U42} > 0:?OK:No}"

Deleted: trunk/contrib/bmake/unit-tests/doterror
===================================================================
--- trunk/contrib/bmake/unit-tests/doterror	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/doterror	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,20 +0,0 @@
-# $Id: doterror,v 1.1.1.1 2010/04/08 17:43:00 sjg Exp $
-
-
-.BEGIN:
-	@echo At first, I am
-
-.END:
-	@echo not reached
-
-.ERROR:
-	@echo "$@: Looks like '${.ERROR_TARGET}' is upset."
-
-all:	happy sad
-
-happy:
-	@echo $@
-
-sad:
-	@echo and now: $@; exit 1
-

Deleted: trunk/contrib/bmake/unit-tests/dotwait
===================================================================
--- trunk/contrib/bmake/unit-tests/dotwait	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/dotwait	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,61 +0,0 @@
-# $NetBSD: dotwait,v 1.1 2006/02/26 22:45:46 apb Exp $
-
-THISMAKEFILE:= ${.PARSEDIR}/${.PARSEFILE}
-
-TESTS= simple recursive shared cycle
-PAUSE= sleep 1
-
-# Use a .for loop rather than dependencies here, to ensure
-# that the tests are run one by one, with parallelism
-# only within tests.
-# Ignore "--- target ---" lines printed by parallel make.
-all:
-.for t in ${TESTS}
-	@${.MAKE} -f ${THISMAKEFILE} -j4 $t | grep -v "^--- "
-.endfor
-
-#
-# Within each test, the names of the sub-targets follow these
-# conventions:
-# * If it's expected that two or more targets may be made in parallel,
-#   then the target names will differ only in an alphabetic component
-#   such as ".a" or ".b".
-# * If it's expected that two or more targets should be made in sequence
-#   then the target names will differ in numeric components, such that
-#   lexical ordering of the target names matches the expected order
-#   in which the targets should be made.
-#
-# Targets may echo ${PARALLEL_TARG} to print a modified version
-# of their own name, in which alphabetic components like ".a" or ".b"
-# are converted to ".*".  Two targets that are expected to
-# be made in parallel will thus print the same strings, so that the
-# output is independent of the order in which these targets are made.
-#
-PARALLEL_TARG= ${.TARGET:C/\.[a-z]/.*/g:Q}
-.DEFAULT:
-	@echo ${PARALLEL_TARG}; ${PAUSE}; echo ${PARALLEL_TARG}
-_ECHOUSE: .USE
-	@echo ${PARALLEL_TARG}; ${PAUSE}; echo ${PARALLEL_TARG}
-
-# simple: no recursion, no cycles
-simple: simple.1 .WAIT simple.2
-
-# recursive: all children of the left hand side of the .WAIT
-# must be made before any child of the right hand side.
-recursive: recursive.1.99 .WAIT recursive.2.99
-recursive.1.99: recursive.1.1.a recursive.1.1.b _ECHOUSE
-recursive.2.99: recursive.2.1.a recursive.2.1.b _ECHOUSE
-
-# shared: both shared.1.99 and shared.2.99 depend on shared.0.
-# shared.0 must be made first, even though it is a child of
-# the right hand side of the .WAIT.
-shared: shared.1.99 .WAIT shared.2.99
-shared.1.99: shared.0 _ECHOUSE
-shared.2.99: shared.2.1 shared.0 _ECHOUSE
-
-# cycle: the cyclic dependency must not cause infinite recursion
-# leading to stack overflow and a crash.
-cycle: cycle.1.99 .WAIT cycle.2.99
-cycle.2.99: cycle.2.98 _ECHOUSE
-cycle.2.98: cycle.2.97 _ECHOUSE
-cycle.2.97: cycle.2.99 _ECHOUSE

Deleted: trunk/contrib/bmake/unit-tests/error
===================================================================
--- trunk/contrib/bmake/unit-tests/error	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/error	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,10 +0,0 @@
-# $Id: error,v 1.1.1.2 2010/05/24 23:36:03 sjg Exp $
-
-.info just FYI
-.warning this could be serious
-.error this is fatal
-
-all:
-
-.info.html:
-	@echo this should be ignored

Deleted: trunk/contrib/bmake/unit-tests/export
===================================================================
--- trunk/contrib/bmake/unit-tests/export	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/export	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,22 +0,0 @@
-# $Id: export,v 1.1.1.1 2007/10/08 20:30:12 sjg Exp $
-
-UT_TEST=export
-UT_FOO=foo${BAR}
-UT_FU=fubar
-UT_ZOO=hoopie
-UT_NO=all
-# belive it or not, we expect this one to come out with $UT_FU unexpanded.
-UT_DOLLAR= This is $$UT_FU
-
-.export UT_FU UT_FOO
-.export UT_DOLLAR
-# this one will be ignored
-.export .MAKE.PID
-
-BAR=bar is ${UT_FU}
-
-.MAKE.EXPORTED+= UT_ZOO UT_TEST
-
-all:
-	@env | grep '^UT_' | sort
-

Deleted: trunk/contrib/bmake/unit-tests/export-all
===================================================================
--- trunk/contrib/bmake/unit-tests/export-all	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/export-all	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,23 +0,0 @@
-# $Id: export-all,v 1.1.1.2 2010/04/21 04:26:14 sjg Exp $
-
-UT_OK=good
-UT_F=fine
-
-# the old way to do :tA
-M_tAbad = C,.*,cd & \&\& 'pwd',:sh
-# the new
-M_tA = tA
-
-here := ${.PARSEDIR}
-
-# this will cause trouble (recursing if we let it)
-UT_BADDIR = ${${here}/../${here:T}:L:${M_tAbad}:T}
-# this will be ok
-UT_OKDIR = ${${here}/../${here:T}:L:${M_tA}:T}
-
-.export
-
-.include "export"
-
-UT_TEST=export-all
-UT_ALL=even this gets exported

Deleted: trunk/contrib/bmake/unit-tests/export-env
===================================================================
--- trunk/contrib/bmake/unit-tests/export-env	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/export-env	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,24 +0,0 @@
-# $Id: export-env,v 1.1.1.1 2013/03/23 02:26:59 sjg Exp $
-
-# our normal .export, subsequent changes affect the environment
-UT_TEST=this
-.export UT_TEST
-UT_TEST:= ${.PARSEFILE}
-
-# not so with .export-env
-UT_ENV=exported
-.export-env UT_ENV
-UT_ENV=not-exported
-
-# gmake style export goes further; affects nothing but the environment
-UT_EXP=before-export
-export UT_EXP=exported
-UT_EXP=not-exported
-
-all:
-	@echo make:; ${UT_TEST UT_ENV UT_EXP:L:@v at echo $v=${$v};@}
-	@echo env:; ${UT_TEST UT_ENV UT_EXP:L:@v at echo $v=$${$v};@}
-
-
-
-

Deleted: trunk/contrib/bmake/unit-tests/forloop
===================================================================
--- trunk/contrib/bmake/unit-tests/forloop	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/forloop	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,45 +0,0 @@
-# $Id: forloop,v 1.1.1.1 2012/06/19 23:30:49 sjg Exp $
-
-all: for-loop
-
-LIST = one "two and three" four "five"
-
-.if make(for-fail)
-for-fail:
-
-XTRA_LIST = xtra
-.else
-
-.for x in ${LIST}
-X!= echo 'x=$x' >&2; echo
-.endfor
-
-CFL = -I/this -I"This or that" -Ithat "-DTHIS=\"this and that\""
-cfl=
-.for x in ${CFL}
-X!= echo 'x=$x' >&2; echo
-.if empty(cfl)
-cfl= $x
-.else
-cfl+= $x
-.endif
-.endfor
-X!= echo 'cfl=${cfl}' >&2; echo
-
-.if ${cfl} != ${CFL}
-.error ${.newline}'${cfl}' != ${.newline}'${CFL}'
-.endif
-
-.for a b in ${EMPTY}
-X!= echo 'a=$a b=$b' >&2; echo
-.endfor
-.endif
-
-.for a b in ${LIST} ${LIST:tu} ${XTRA_LIST}
-X!= echo 'a=$a b=$b' >&2; echo
-.endfor
-
-for-loop:
-	@echo We expect an error next:
-	@(cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} for-fail) && \
-	{ echo "Oops that should have failed!"; exit 1; } || echo OK

Deleted: trunk/contrib/bmake/unit-tests/forsubst
===================================================================
--- trunk/contrib/bmake/unit-tests/forsubst	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/forsubst	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,10 +0,0 @@
-# $Id: forsubst,v 1.1.1.1 2009/10/07 18:53:35 sjg Exp $
-
-all: for-subst
-
-here := ${.PARSEDIR}
-# this should not run foul of the parser
-.for file in ${.PARSEFILE}
-for-subst:	  ${file:S;^;${here}/;g}
-	@echo ".for with :S;... OK"
-.endfor

Deleted: trunk/contrib/bmake/unit-tests/hash
===================================================================
--- trunk/contrib/bmake/unit-tests/hash	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/hash	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,18 +0,0 @@
-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}

Deleted: trunk/contrib/bmake/unit-tests/misc
===================================================================
--- trunk/contrib/bmake/unit-tests/misc	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/misc	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,16 +0,0 @@
-# $Id: misc,v 1.1.1.1 2011/03/06 00:04:58 sjg 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

Deleted: trunk/contrib/bmake/unit-tests/moderrs
===================================================================
--- trunk/contrib/bmake/unit-tests/moderrs	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/moderrs	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,31 +0,0 @@
-# $Id: moderrs,v 1.2 2006/05/11 18:53:39 sjg Exp $
-#
-# various modifier error tests
-
-VAR=TheVariable
-# incase we have to change it ;-)
-MOD_UNKN=Z
-MOD_TERM=S,V,v
-MOD_S:= ${MOD_TERM},
-
-all:	modunkn modunknV varterm vartermV modtermV
-
-modunkn:
-	@echo "Expect: Unknown modifier 'Z'"
-	@echo "VAR:Z=${VAR:Z}"
-
-modunknV:
-	@echo "Expect: Unknown modifier 'Z'"
-	@echo "VAR:${MOD_UNKN}=${VAR:${MOD_UNKN}}"
-
-varterm:
-	@echo "Expect: Unclosed variable specification for VAR"
-	@echo VAR:S,V,v,=${VAR:S,V,v,
-
-vartermV:
-	@echo "Expect: Unclosed variable specification for VAR"
-	@echo VAR:${MOD_TERM},=${VAR:${MOD_S}
-
-modtermV:
-	@echo "Expect: Unclosed substitution for VAR (, missing)"
-	- at echo "VAR:${MOD_TERM}=${VAR:${MOD_TERM}}"

Deleted: trunk/contrib/bmake/unit-tests/modmatch
===================================================================
--- trunk/contrib/bmake/unit-tests/modmatch	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/modmatch	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,25 +0,0 @@
-
-X=a b c d e
-
-.for x in $X
-LIB${x:tu}=/tmp/lib$x.a
-.endfor
-
-X_LIBS= ${LIBA} ${LIBD} ${LIBE}
-
-LIB?=a
-
-var = head
-res = no
-.if !empty(var:M${:Uhead\:tail:C/:.*//})
-res = OK
-.endif
-
-all:
-	@for x in $X; do ${.MAKE} -f ${MAKEFILE} show LIB=$$x; done
-	@echo "Mscanner=${res}"
-
-show:
-	@echo 'LIB=${LIB} X_LIBS:M$${LIB$${LIB:tu}} is "${X_LIBS:M${LIB${LIB:tu}}}"'
-	@echo 'LIB=${LIB} X_LIBS:M*/lib$${LIB}.a is "${X_LIBS:M*/lib${LIB}.a}"'
-	@echo 'LIB=${LIB} X_LIBS:M*/lib$${LIB}.a:tu is "${X_LIBS:M*/lib${LIB}.a:tu}"'

Deleted: trunk/contrib/bmake/unit-tests/modmisc
===================================================================
--- trunk/contrib/bmake/unit-tests/modmisc	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/modmisc	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,38 +0,0 @@
-# $Id: modmisc,v 1.1.1.5 2011/04/11 15:10:32 sjg Exp $
-#
-# miscellaneous modifier tests
-
-# do not put any dirs in this list which exist on some
-# but not all target systems - an exists() check is below.
-path=:/bin:/tmp::/:.:/no/such/dir:.
-# strip cwd from path.
-MOD_NODOT=S/:/ /g:N.:ts:
-# and decorate, note that $'s need to be doubled. Also note that 
-# the modifier_variable can be used with other modifiers.
-MOD_NODOTX=S/:/ /g:N.:@d@'$$d'@
-# another mod - pretend it is more interesting
-MOD_HOMES=S,/home/,/homes/,
-MOD_OPT=@d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@
-MOD_SEP=S,:, ,g
-
-all:	modvar modvarloop modsysv
-
-modsysv:
-	@echo "The answer is ${libfoo.a:L:libfoo.a=42}"
-
-modvar:
-	@echo "path='${path}'"
-	@echo "path='${path:${MOD_NODOT}}'"
-	@echo "path='${path:S,home,homes,:${MOD_NODOT}}'"
-	@echo "path=${path:${MOD_NODOTX}:ts:}"
-	@echo "path=${path:${MOD_HOMES}:${MOD_NODOTX}:ts:}"
-
-.for d in ${path:${MOD_SEP}:N.} /usr/xbin
-path_$d?= ${d:${MOD_OPT}:${MOD_HOMES}}/
-paths+= ${d:${MOD_OPT}:${MOD_HOMES}}
-.endfor
-
-modvarloop:
-	@echo "path_/usr/xbin=${path_/usr/xbin}"
-	@echo "paths=${paths}"
-	@echo "PATHS=${paths:tu}"

Deleted: trunk/contrib/bmake/unit-tests/modorder
===================================================================
--- trunk/contrib/bmake/unit-tests/modorder	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/modorder	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,22 +0,0 @@
-# $NetBSD: modorder,v 1.2 2007/10/05 15:27:46 sjg Exp $
-
-LIST=		one two three four five six seven eight nine ten
-LISTX=		${LIST:Ox}
-LISTSX:=	${LIST:Ox}
-TEST_RESULT= && echo Ok || echo Failed
-
-# unit-tests have to produce the same results on each run
-# so we cannot actually include :Ox output.
-all:
-	@echo "LIST      = ${LIST}"
-	@echo "LIST:O    = ${LIST:O}"
-	# Note that 1 in every 10! trials two independently generated
-	# randomized orderings will be the same.  The test framework doesn't
-	# support checking probabilistic output, so we accept that the test
-	# will incorrectly fail with probability 2.8E-7.
-	@echo "LIST:Ox   = `test '${LIST:Ox}' != '${LIST:Ox}' ${TEST_RESULT}`"
-	@echo "LIST:O:Ox = `test '${LIST:O:Ox}' != '${LIST:O:Ox}' ${TEST_RESULT}`"
-	@echo "LISTX     = `test '${LISTX}' != '${LISTX}' ${TEST_RESULT}`"
-	@echo "LISTSX    = `test '${LISTSX}' = '${LISTSX}' ${TEST_RESULT}`"
-	@echo "BADMOD 1  = ${LIST:OX}"
-	@echo "BADMOD 2  = ${LIST:OxXX}"

Deleted: trunk/contrib/bmake/unit-tests/modts
===================================================================
--- trunk/contrib/bmake/unit-tests/modts	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/modts	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,43 +0,0 @@
-
-LIST= one two three
-LIST+= four five six
-
-FU_mod-ts = a / b / cool
-
-AAA= a a a
-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,}"'
-	@echo 'LIST:ts/:tu="${LIST:ts/:tu}"'
-	@echo 'LIST:ts::tu="${LIST:ts::tu}"'
-	@echo 'LIST:ts:tu="${LIST:ts:tu}"'
-	@echo 'LIST:tu:ts/="${LIST:tu:ts/}"'
-	@echo 'LIST:ts:="${LIST:ts:}"'
-	@echo 'LIST:ts="${LIST:ts}"'
-	@echo 'LIST:ts:S/two/2/="${LIST:ts:S/two/2/}"'
-	@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."
-	@${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?'

Deleted: trunk/contrib/bmake/unit-tests/modword
===================================================================
--- trunk/contrib/bmake/unit-tests/modword	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/modword	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,151 +0,0 @@
-# $Id: modword,v 1.1.1.1 2003/09/28 17:01:48 sjg Exp $
-#
-# Test behaviour of new :[] modifier
-
-all: mod-squarebrackets mod-S-W mod-C-W mod-tW-tw
-
-LIST= one two three
-LIST+= four five six
-LONGLIST= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
-
-EMPTY= # the space should be ignored
-ESCAPEDSPACE=\ # escaped space before the '#'
-REALLYSPACE:=${EMPTY:C/^/ /W}
-HASH= \#
-AT= @
-STAR= *
-ZERO= 0
-ONE= 1
-MINUSONE= -1
-
-mod-squarebrackets: mod-squarebrackets-0-star-at \
-	mod-squarebrackets-hash \
-	mod-squarebrackets-n \
-	mod-squarebrackets-start-end \
-	mod-squarebrackets-nested
-
-mod-squarebrackets-0-star-at:
-	@echo 'LIST:[]="${LIST:[]}" is an error'
-	@echo 'LIST:[0]="${LIST:[0]}"'
-	@echo 'LIST:[0x0]="${LIST:[0x0]}"'
-	@echo 'LIST:[000]="${LIST:[000]}"'
-	@echo 'LIST:[*]="${LIST:[*]}"'
-	@echo 'LIST:[@]="${LIST:[@]}"'
-	@echo 'LIST:[0]:C/ /,/="${LIST:[0]:C/ /,/}"'
-	@echo 'LIST:[0]:C/ /,/g="${LIST:[0]:C/ /,/g}"'
-	@echo 'LIST:[0]:C/ /,/1g="${LIST:[0]:C/ /,/1g}"'
-	@echo 'LIST:[*]:C/ /,/="${LIST:[*]:C/ /,/}"'
-	@echo 'LIST:[*]:C/ /,/g="${LIST:[*]:C/ /,/g}"'
-	@echo 'LIST:[*]:C/ /,/1g="${LIST:[*]:C/ /,/1g}"'
-	@echo 'LIST:[@]:C/ /,/="${LIST:[@]:C/ /,/}"'
-	@echo 'LIST:[@]:C/ /,/g="${LIST:[@]:C/ /,/g}"'
-	@echo 'LIST:[@]:C/ /,/1g="${LIST:[@]:C/ /,/1g}"'
-	@echo 'LIST:[@]:[0]:C/ /,/="${LIST:[@]:[0]:C/ /,/}"'
-	@echo 'LIST:[0]:[@]:C/ /,/="${LIST:[0]:[@]:C/ /,/}"'
-	@echo 'LIST:[@]:[*]:C/ /,/="${LIST:[@]:[*]:C/ /,/}"'
-	@echo 'LIST:[*]:[@]:C/ /,/="${LIST:[*]:[@]:C/ /,/}"'
-
-mod-squarebrackets-hash:
-	@echo 'EMPTY="${EMPTY}"'
-	@echo 'EMPTY:[#]="${EMPTY:[#]}" == 1 ?'
-	@echo 'ESCAPEDSPACE="${ESCAPEDSPACE}"'
-	@echo 'ESCAPEDSPACE:[#]="${ESCAPEDSPACE:[#]}" == 1 ?'
-	@echo 'REALLYSPACE="${REALLYSPACE}"'
-	@echo 'REALLYSPACE:[#]="${REALLYSPACE:[#]}" == 1 ?'
-	@echo 'LIST:[#]="${LIST:[#]}"'
-	@echo 'LIST:[0]:[#]="${LIST:[0]:[#]}" == 1 ?'
-	@echo 'LIST:[*]:[#]="${LIST:[*]:[#]}" == 1 ?'
-	@echo 'LIST:[@]:[#]="${LIST:[@]:[#]}"'
-	@echo 'LIST:[1]:[#]="${LIST:[1]:[#]}"'
-	@echo 'LIST:[1..3]:[#]="${LIST:[1..3]:[#]}"'
-
-mod-squarebrackets-n:
-	@echo 'EMPTY:[1]="${EMPTY:[1]}"'
-	@echo 'ESCAPEDSPACE="${ESCAPEDSPACE}"'
-	@echo 'ESCAPEDSPACE:[1]="${ESCAPEDSPACE:[1]}"'
-	@echo 'REALLYSPACE="${REALLYSPACE}"'
-	@echo 'REALLYSPACE:[1]="${REALLYSPACE:[1]}" == "" ?'
-	@echo 'REALLYSPACE:[*]:[1]="${REALLYSPACE:[*]:[1]}" == " " ?'
-	@echo 'LIST:[1]="${LIST:[1]}"'
-	@echo 'LIST:[1.]="${LIST:[1.]}" is an error'
-	@echo 'LIST:[1].="${LIST:[1].}" is an error'
-	@echo 'LIST:[2]="${LIST:[2]}"'
-	@echo 'LIST:[6]="${LIST:[6]}"'
-	@echo 'LIST:[7]="${LIST:[7]}"'
-	@echo 'LIST:[999]="${LIST:[999]}"'
-	@echo 'LIST:[-]="${LIST:[-]}" is an error'
-	@echo 'LIST:[--]="${LIST:[--]}" is an error'
-	@echo 'LIST:[-1]="${LIST:[-1]}"'
-	@echo 'LIST:[-2]="${LIST:[-2]}"'
-	@echo 'LIST:[-6]="${LIST:[-6]}"'
-	@echo 'LIST:[-7]="${LIST:[-7]}"'
-	@echo 'LIST:[-999]="${LIST:[-999]}"'
-	@echo 'LONGLIST:[17]="${LONGLIST:[17]}"'
-	@echo 'LONGLIST:[0x11]="${LONGLIST:[0x11]}"'
-	@echo 'LONGLIST:[021]="${LONGLIST:[021]}"'
-	@echo 'LIST:[0]:[1]="${LIST:[0]:[1]}"'
-	@echo 'LIST:[*]:[1]="${LIST:[*]:[1]}"'
-	@echo 'LIST:[@]:[1]="${LIST:[@]:[1]}"'
-	@echo 'LIST:[0]:[2]="${LIST:[0]:[2]}"'
-	@echo 'LIST:[*]:[2]="${LIST:[*]:[2]}"'
-	@echo 'LIST:[@]:[2]="${LIST:[@]:[2]}"'
-	@echo 'LIST:[*]:C/ /,/:[2]="${LIST:[*]:C/ /,/:[2]}"'
-	@echo 'LIST:[*]:C/ /,/:[*]:[2]="${LIST:[*]:C/ /,/:[*]:[2]}"'
-	@echo 'LIST:[*]:C/ /,/:[@]:[2]="${LIST:[*]:C/ /,/:[@]:[2]}"'
-
-mod-squarebrackets-start-end:
-	@echo 'LIST:[1.]="${LIST:[1.]}" is an error'
-	@echo 'LIST:[1..]="${LIST:[1..]}" is an error'
-	@echo 'LIST:[1..1]="${LIST:[1..1]}"'
-	@echo 'LIST:[1..1.]="${LIST:[1..1.]}" is an error'
-	@echo 'LIST:[1..2]="${LIST:[1..2]}"'
-	@echo 'LIST:[2..1]="${LIST:[2..1]}"'
-	@echo 'LIST:[3..-2]="${LIST:[3..-2]}"'
-	@echo 'LIST:[-4..4]="${LIST:[-4..4]}"'
-	@echo 'LIST:[0..1]="${LIST:[0..1]}" is an error'
-	@echo 'LIST:[-1..0]="${LIST:[-1..0]}" is an error'
-	@echo 'LIST:[-1..1]="${LIST:[-1..1]}"'
-	@echo 'LIST:[0..0]="${LIST:[0..0]}"'
-	@echo 'LIST:[3..99]="${LIST:[3..99]}"'
-	@echo 'LIST:[-3..-99]="${LIST:[-3..-99]}"'
-	@echo 'LIST:[-99..-3]="${LIST:[-99..-3]}"'
-
-mod-squarebrackets-nested:
-	@echo 'HASH="${HASH}" == "#" ?'
-	@echo 'LIST:[$${HASH}]="${LIST:[${HASH}]}"'
-	@echo 'LIST:[$${ZERO}]="${LIST:[${ZERO}]}"'
-	@echo 'LIST:[$${ZERO}x$${ONE}]="${LIST:[${ZERO}x${ONE}]}"'
-	@echo 'LIST:[$${ONE}]="${LIST:[${ONE}]}"'
-	@echo 'LIST:[$${MINUSONE}]="${LIST:[${MINUSONE}]}"'
-	@echo 'LIST:[$${STAR}]="${LIST:[${STAR}]}"'
-	@echo 'LIST:[$${AT}]="${LIST:[${AT}]}"'
-	@echo 'LIST:[$${EMPTY}]="${LIST:[${EMPTY}]}" is an error'
-	@echo 'LIST:[$${LONGLIST:[21]:S/2//}]="${LIST:[${LONGLIST:[21]:S/2//}]}"'
-	@echo 'LIST:[$${LIST:[#]}]="${LIST:[${LIST:[#]}]}"'
-	@echo 'LIST:[$${LIST:[$${HASH}]}]="${LIST:[${LIST:[${HASH}]}]}"'
-
-mod-C-W:
-	@echo 'LIST:C/ /,/="${LIST:C/ /,/}"'
-	@echo 'LIST:C/ /,/W="${LIST:C/ /,/W}"'
-	@echo 'LIST:C/ /,/gW="${LIST:C/ /,/gW}"'
-	@echo 'EMPTY:C/^/,/="${EMPTY:C/^/,/}"'
-	@echo 'EMPTY:C/^/,/W="${EMPTY:C/^/,/W}"'
-
-mod-S-W:
-	@echo 'LIST:S/ /,/="${LIST:S/ /,/}"'
-	@echo 'LIST:S/ /,/W="${LIST:S/ /,/W}"'
-	@echo 'LIST:S/ /,/gW="${LIST:S/ /,/gW}"'
-	@echo 'EMPTY:S/^/,/="${EMPTY:S/^/,/}"'
-	@echo 'EMPTY:S/^/,/W="${EMPTY:S/^/,/W}"'
-
-mod-tW-tw:
-	@echo 'LIST:tW="${LIST:tW}"'
-	@echo 'LIST:tw="${LIST:tw}"'
-	@echo 'LIST:tW:C/ /,/="${LIST:tW:C/ /,/}"'
-	@echo 'LIST:tW:C/ /,/g="${LIST:tW:C/ /,/g}"'
-	@echo 'LIST:tW:C/ /,/1g="${LIST:tW:C/ /,/1g}"'
-	@echo 'LIST:tw:C/ /,/="${LIST:tw:C/ /,/}"'
-	@echo 'LIST:tw:C/ /,/g="${LIST:tw:C/ /,/g}"'
-	@echo 'LIST:tw:C/ /,/1g="${LIST:tw:C/ /,/1g}"'
-	@echo 'LIST:tw:tW:C/ /,/="${LIST:tw:tW:C/ /,/}"'
-	@echo 'LIST:tW:tw:C/ /,/="${LIST:tW:tw:C/ /,/}"'

Deleted: trunk/contrib/bmake/unit-tests/order
===================================================================
--- trunk/contrib/bmake/unit-tests/order	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/order	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,20 +0,0 @@
-# $NetBSD: order,v 1.1 2012/11/09 19:08:28 sjg Exp $
-
-# Test that .ORDER is handled correctly.
-# The explicit dependency the.o: the.h will make us examine the.h
-# the .ORDER will prevent us building it immediately,
-# we should then examine the.c rather than stop.
-
-all: the.o
-
-.ORDER: the.c the.h
-
-the.c the.h:
-	@echo Making $@
-
-.SUFFIXES: .o .c
-
-.c.o:
-	@echo Making $@ from $?
-
-the.o: the.h

Deleted: trunk/contrib/bmake/unit-tests/phony-end
===================================================================
--- trunk/contrib/bmake/unit-tests/phony-end	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/phony-end	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,9 +0,0 @@
-# $Id: phony-end,v 1.1.1.1 2011/10/01 17:19:39 sjg Exp $
-
-all ok also.ok bug phony:
-	@echo '${.TARGET .PREFIX .IMPSRC:L:@v@$v="${$v}"@}'
-
-.END:	ok also.ok bug
-
-phony bug:	.PHONY
-all: phony

Deleted: trunk/contrib/bmake/unit-tests/posix
===================================================================
--- trunk/contrib/bmake/unit-tests/posix	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/posix	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,24 +0,0 @@
-# $Id: posix,v 1.1.1.1 2004/05/08 16:45:39 sjg Exp $
-
-all:	x plus subs err
-
-x:
-	@echo "Posix says we should execute the command as if run by system(3)"
-	@echo "Expect 'Hello,' and 'World!'"
-	@echo Hello,; false; echo "World!"
-
-plus:
-	@echo a command
-	+ at echo "a command prefixed by '+' executes even with -n"
-	@echo another command
-
-subs:
-	@echo make -n
-	@${.MAKE} -f ${MAKEFILE} -n plus
-	@echo make -n -j1
-	@${.MAKE} -f ${MAKEFILE} -n -j1 plus
-
-err:
-	@(echo Now we expect an error...; exit 1)
-	@echo "Oops! you shouldn't see this!"
-

Deleted: trunk/contrib/bmake/unit-tests/qequals
===================================================================
--- trunk/contrib/bmake/unit-tests/qequals	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/qequals	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,8 +0,0 @@
-# $Id: qequals,v 1.1.1.1 2008/03/31 00:13:05 sjg Exp $
-
-M= i386
-V.i386= OK
-V.$M ?= bug
-
-all:
-	@echo 'V.$M ?= ${V.$M}'

Deleted: trunk/contrib/bmake/unit-tests/sunshcmd
===================================================================
--- trunk/contrib/bmake/unit-tests/sunshcmd	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/sunshcmd	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,10 +0,0 @@
-BYECMD		= echo bye
-LATERCMD	= echo later
-TEST1 :sh	= echo hello
-TEST2 :sh	= ${BYECMD}
-TEST3		= ${LATERCMD:sh}
-
-all:
-	@echo "TEST1=${TEST1}"
-	@echo "TEST2=${TEST2}"
-	@echo "TEST3=${TEST3}"

Deleted: trunk/contrib/bmake/unit-tests/sysv
===================================================================
--- trunk/contrib/bmake/unit-tests/sysv	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/sysv	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,26 +0,0 @@
-# $Id: sysv,v 1.1.1.2 2011/06/05 04:23:49 sjg 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}}

Deleted: trunk/contrib/bmake/unit-tests/ternary
===================================================================
--- trunk/contrib/bmake/unit-tests/ternary	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/ternary	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,8 +0,0 @@
-
-all:
-	@for x in "" A= A=42; do ${.MAKE} -f ${MAKEFILE} show $$x; done
-
-show:
-	@echo "The answer is ${A:?known:unknown}"
-	@echo "The answer is ${A:?$A:unknown}"
-	@echo "The answer is ${empty(A):?empty:$A}"

Deleted: trunk/contrib/bmake/unit-tests/test.exp
===================================================================
--- trunk/contrib/bmake/unit-tests/test.exp	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/test.exp	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,383 +0,0 @@
-comment testing start
-this is foo
-This is how a comment looks: # comment
-comment testing done
-make: "cond1" line 75: warning: extra else
-make: "cond1" line 85: warning: extra else
-2 is  prime
-A='other' B='unknown' C='clever' o='no,no'
-Passed:
- var
- ("var")
- (var != var)
- var != var
- !((var != var) && defined(name))
- var == quoted
-
-1 is not prime
-2 is  prime
-3 is  prime
-4 is not prime
-5 is  prime
-
-make: warning: String comparison operator should be either == or !=
-make: Bad conditional expression `"0" > 0' in "0" > 0?OK:No
-
-OK
-make: "error" line 3: just FYI
-make: "error" line 4: warning: this could be serious
-make: "error" line 5: this is fatal
-UT_DOLLAR=This is $UT_FU
-UT_FOO=foobar is fubar
-UT_FU=fubar
-UT_TEST=export
-UT_ZOO=hoopie
-UT_ALL=even this gets exported
-UT_BADDIR=unit-tests
-UT_DOLLAR=This is $UT_FU
-UT_F=fine
-UT_FOO=foobar is fubar
-UT_FU=fubar
-UT_NO=all
-UT_OK=good
-UT_OKDIR=unit-tests
-UT_TEST=export-all
-UT_ZOO=hoopie
-make:
-UT_TEST=export-env
-UT_ENV=not-exported
-UT_EXP=not-exported
-env:
-UT_TEST=export-env
-UT_ENV=exported
-UT_EXP=exported
-At first, I am
-happy
-and now: sad
-.ERROR: Looks like 'sad' is upset.
-*** Error code 1
-
-Stop.
-make: stopped in unit-tests
-simple.1
-simple.1
-simple.2
-simple.2
-recursive.1.1.*
-recursive.1.1.*
-recursive.1.1.*
-recursive.1.1.*
-recursive.1.99
-recursive.1.99
-recursive.2.1.*
-recursive.2.1.*
-recursive.2.1.*
-recursive.2.1.*
-recursive.2.99
-recursive.2.99
-shared.0
-shared.0
-shared.1.99
-shared.1.99
-shared.2.1
-shared.2.1
-shared.2.99
-shared.2.99
-make: Graph cycles through `cycle.2.99'
-make: Graph cycles through `cycle.2.98'
-make: Graph cycles through `cycle.2.97'
-cycle.1.99
-cycle.1.99
-x=one
-x="two and three"
-x=four
-x="five"
-x=-I/this
-x=-I"This or that"
-x=-Ithat
-x="-DTHIS=\"this and that\""
-cfl=-I/this -I"This or that" -Ithat "-DTHIS=\"this and that\""
-a=one b="two and three"
-a=four b="five"
-a=ONE b="TWO AND THREE"
-a=FOUR b="FIVE"
-We expect an error next:
-make: "forloop" line 38: Wrong number of words (9) in .for substitution list with 2 vars
-make: Fatal errors encountered -- cannot continue
-make: stopped in unit-tests
-OK
-.for with :S;... OK
-b2af338b
-3360ac65
-7747f046
-9ca87054
-880fe816
-208fcbd3
-d5d376eb
-de41416c
-Expect: Unknown modifier 'Z'
-make: Unknown modifier 'Z'
-VAR:Z=
-Expect: Unknown modifier 'Z'
-make: Unknown modifier 'Z'
-VAR:Z=
-Expect: Unclosed variable specification for VAR
-make: Unclosed variable specification (expecting '}') for "VAR" (value "Thevariable") modifier S
-VAR:S,V,v,=Thevariable
-Expect: Unclosed variable specification for VAR
-make: Unclosed variable specification after complex modifier (expecting '}') for VAR
-VAR:S,V,v,=Thevariable
-Expect: Unclosed substitution for VAR (, missing)
-make: Unclosed substitution for VAR (, missing)
-VAR:S,V,v=
-LIB=a X_LIBS:M${LIB${LIB:tu}} is "/tmp/liba.a"
-LIB=a X_LIBS:M*/lib${LIB}.a is "/tmp/liba.a"
-LIB=a X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBA.A"
-LIB=b X_LIBS:M${LIB${LIB:tu}} is ""
-LIB=b X_LIBS:M*/lib${LIB}.a is ""
-LIB=b X_LIBS:M*/lib${LIB}.a:tu is ""
-LIB=c X_LIBS:M${LIB${LIB:tu}} is ""
-LIB=c X_LIBS:M*/lib${LIB}.a is ""
-LIB=c X_LIBS:M*/lib${LIB}.a:tu is ""
-LIB=d X_LIBS:M${LIB${LIB:tu}} is "/tmp/libd.a"
-LIB=d X_LIBS:M*/lib${LIB}.a is "/tmp/libd.a"
-LIB=d X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBD.A"
-LIB=e X_LIBS:M${LIB${LIB:tu}} is "/tmp/libe.a"
-LIB=e X_LIBS:M*/lib${LIB}.a is "/tmp/libe.a"
-LIB=e X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBE.A"
-Mscanner=OK
-path=':/bin:/tmp::/:.:/no/such/dir:.'
-path='/bin:/tmp:/:/no/such/dir'
-path='/bin:/tmp:/:/no/such/dir'
-path='/bin':'/tmp':'/':'/no/such/dir'
-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
-LIST:O:Ox = Ok
-LISTX     = Ok
-LISTSX    = Ok
-make: Bad modifier `:OX' for LIST
-BADMOD 1  = }
-make: Bad modifier `:OxXX' for LIST
-BADMOD 2  = XX}
-LIST="one two three four five six"
-LIST:ts,="one,two,three,four,five,six"
-LIST:ts/:tu="ONE/TWO/THREE/FOUR/FIVE/SIX"
-LIST:ts::tu="ONE:TWO:THREE:FOUR:FIVE:SIX"
-LIST:ts:tu="ONETWOTHREEFOURFIVESIX"
-LIST:tu:ts/="ONE/TWO/THREE/FOUR/FIVE/SIX"
-LIST:ts:="one:two:three:four:five:six"
-LIST:ts="onetwothreefourfivesix"
-LIST:ts:S/two/2/="one2threefourfivesix"
-LIST:S/two/2/:ts="one2threefourfivesix"
-LIST:ts/:S/two/2/="one/2/three/four/five/six"
-Pretend the '/' in '/n' etc. below are back-slashes.
-LIST:ts/n="one
-two
-three
-four
-five
-six"
-LIST:ts/t="one	two	three	four	five	six"
-LIST:ts/012:tu="ONE
-TWO
-THREE
-FOUR
-FIVE
-SIX"
-make: Bad modifier `:tx' for LIST
-LIST:tx="}"
-make: Bad modifier `:ts\x' for LIST
-LIST:ts/x:tu="\x:tu}"
-FU_mod-ts="a/b/cool"
-FU_mod-ts:ts:T="cool" == cool?
-B.${AAA:ts}="Baaa" == Baaa?
-make: Bad modifier `:[]' for LIST
-LIST:[]="" is an error
-LIST:[0]="one two three four five six"
-LIST:[0x0]="one two three four five six"
-LIST:[000]="one two three four five six"
-LIST:[*]="one two three four five six"
-LIST:[@]="one two three four five six"
-LIST:[0]:C/ /,/="one,two three four five six"
-LIST:[0]:C/ /,/g="one,two,three,four,five,six"
-LIST:[0]:C/ /,/1g="one,two,three,four,five,six"
-LIST:[*]:C/ /,/="one,two three four five six"
-LIST:[*]:C/ /,/g="one,two,three,four,five,six"
-LIST:[*]:C/ /,/1g="one,two,three,four,five,six"
-LIST:[@]:C/ /,/="one two three four five six"
-LIST:[@]:C/ /,/g="one two three four five six"
-LIST:[@]:C/ /,/1g="one two three four five six"
-LIST:[@]:[0]:C/ /,/="one,two three four five six"
-LIST:[0]:[@]:C/ /,/="one two three four five six"
-LIST:[@]:[*]:C/ /,/="one,two three four five six"
-LIST:[*]:[@]:C/ /,/="one two three four five six"
-EMPTY=""
-EMPTY:[#]="1" == 1 ?
-ESCAPEDSPACE="\ "
-ESCAPEDSPACE:[#]="1" == 1 ?
-REALLYSPACE=" "
-REALLYSPACE:[#]="1" == 1 ?
-LIST:[#]="6"
-LIST:[0]:[#]="1" == 1 ?
-LIST:[*]:[#]="1" == 1 ?
-LIST:[@]:[#]="6"
-LIST:[1]:[#]="1"
-LIST:[1..3]:[#]="3"
-EMPTY:[1]=""
-ESCAPEDSPACE="\ "
-ESCAPEDSPACE:[1]="\ "
-REALLYSPACE=" "
-REALLYSPACE:[1]="" == "" ?
-REALLYSPACE:[*]:[1]=" " == " " ?
-LIST:[1]="one"
-make: Bad modifier `:[1.]' for LIST
-LIST:[1.]="" is an error
-make: Bad modifier `:[1].' for LIST
-LIST:[1].="}" is an error
-LIST:[2]="two"
-LIST:[6]="six"
-LIST:[7]=""
-LIST:[999]=""
-make: Bad modifier `:[-]' for LIST
-LIST:[-]="" is an error
-make: Bad modifier `:[--]' for LIST
-LIST:[--]="" is an error
-LIST:[-1]="six"
-LIST:[-2]="five"
-LIST:[-6]="one"
-LIST:[-7]=""
-LIST:[-999]=""
-LONGLIST:[17]="17"
-LONGLIST:[0x11]="17"
-LONGLIST:[021]="17"
-LIST:[0]:[1]="one two three four five six"
-LIST:[*]:[1]="one two three four five six"
-LIST:[@]:[1]="one"
-LIST:[0]:[2]=""
-LIST:[*]:[2]=""
-LIST:[@]:[2]="two"
-LIST:[*]:C/ /,/:[2]=""
-LIST:[*]:C/ /,/:[*]:[2]=""
-LIST:[*]:C/ /,/:[@]:[2]="three"
-make: Bad modifier `:[1.]' for LIST
-LIST:[1.]="" is an error
-make: Bad modifier `:[1..]' for LIST
-LIST:[1..]="" is an error
-LIST:[1..1]="one"
-make: Bad modifier `:[1..1.]' for LIST
-LIST:[1..1.]="" is an error
-LIST:[1..2]="one two"
-LIST:[2..1]="two one"
-LIST:[3..-2]="three four five"
-LIST:[-4..4]="three four"
-make: Bad modifier `:[0..1]' for LIST
-LIST:[0..1]="" is an error
-make: Bad modifier `:[-1..0]' for LIST
-LIST:[-1..0]="" is an error
-LIST:[-1..1]="six five four three two one"
-LIST:[0..0]="one two three four five six"
-LIST:[3..99]="three four five six"
-LIST:[-3..-99]="four three two one"
-LIST:[-99..-3]="one two three four"
-HASH="#" == "#" ?
-LIST:[${HASH}]="6"
-LIST:[${ZERO}]="one two three four five six"
-LIST:[${ZERO}x${ONE}]="one"
-LIST:[${ONE}]="one"
-LIST:[${MINUSONE}]="six"
-LIST:[${STAR}]="one two three four five six"
-LIST:[${AT}]="one two three four five six"
-make: Bad modifier `:[${EMPTY' for LIST
-LIST:[${EMPTY}]="" is an error
-LIST:[${LONGLIST:[21]:S/2//}]="one"
-LIST:[${LIST:[#]}]="six"
-LIST:[${LIST:[${HASH}]}]="six"
-LIST:S/ /,/="one two three four five six"
-LIST:S/ /,/W="one,two three four five six"
-LIST:S/ /,/gW="one,two,three,four,five,six"
-EMPTY:S/^/,/=","
-EMPTY:S/^/,/W=","
-LIST:C/ /,/="one two three four five six"
-LIST:C/ /,/W="one,two three four five six"
-LIST:C/ /,/gW="one,two,three,four,five,six"
-EMPTY:C/^/,/=","
-EMPTY:C/^/,/W=","
-LIST:tW="one two three four five six"
-LIST:tw="one two three four five six"
-LIST:tW:C/ /,/="one,two three four five six"
-LIST:tW:C/ /,/g="one,two,three,four,five,six"
-LIST:tW:C/ /,/1g="one,two,three,four,five,six"
-LIST:tw:C/ /,/="one two three four five six"
-LIST:tw:C/ /,/g="one two three four five six"
-LIST:tw:C/ /,/1g="one two three four five six"
-LIST:tw:tW:C/ /,/="one,two three four five six"
-LIST:tW:tw:C/ /,/="one two three four five six"
-Making the.c
-Making the.h
-Making the.o from the.h the.c
-.TARGET="phony" .PREFIX="phony" .IMPSRC=""
-.TARGET="all" .PREFIX="all" .IMPSRC=""
-.TARGET="ok" .PREFIX="ok" .IMPSRC=""
-.TARGET="also.ok" .PREFIX="also.ok" .IMPSRC=""
-.TARGET="bug" .PREFIX="bug" .IMPSRC=""
-Posix says we should execute the command as if run by system(3)
-Expect 'Hello,' and 'World!'
-Hello,
-World!
-a command
-a command prefixed by '+' executes even with -n
-another command
-make -n
-echo a command
-echo "a command prefixed by '+' executes even with -n"
-a command prefixed by '+' executes even with -n
-echo another command
-make -n -j1
-{ echo a command 
-} || exit $?
-echo "a command prefixed by '+' executes even with -n"
-a command prefixed by '+' executes even with -n
-{ echo another command 
-} || exit $?
-Now we expect an error...
-*** Error code 1 (continuing)
-`all' not remade because of errors.
-V.i386 ?= OK
-TEST1=hello
-TEST2=bye
-TEST3=later
-FOOBAR =
-FOOBAR = foobar fubar
-fun
-fun
-fun
-In the Sun
-The answer is unknown
-The answer is unknown
-The answer is empty
-The answer is known
-The answer is 
-The answer is empty
-The answer is known
-The answer is 42
-The answer is 42
-UT_DOLLAR=This is $UT_FU
-UT_FU=fubar
-UT_TEST=unexport
-UT_TEST=unexport-env
-default FU=<v>fu</v> FOO=<v>foo</v> VAR=<v></v>
-two FU=<v>bar</v> FOO=<v>goo</v> VAR=<v></v>
-three FU=<v>bar</v> FOO=<v>goo</v> VAR=<v></v>
-four FU=<v>bar</v> FOO=<v>goo</v> VAR=<v>Internal</v>
-five FU=<v>bar</v> FOO=<v>goo</v> VAR=<v>Internal</v>
-five v=is x k=is x
-six v=is y k=is y
-show-v v=override k=override
-*** Error code 1 (ignored)
-*** Error code 1 (ignored)

Deleted: trunk/contrib/bmake/unit-tests/unexport
===================================================================
--- trunk/contrib/bmake/unit-tests/unexport	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/unexport	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,8 +0,0 @@
-# $Id: unexport,v 1.1.1.1 2009/11/19 00:31:11 sjg Exp $
-
-# pick up a bunch of exported vars
-.include "export"
-
-.unexport UT_ZOO UT_FOO
-
-UT_TEST = unexport

Deleted: trunk/contrib/bmake/unit-tests/unexport-env
===================================================================
--- trunk/contrib/bmake/unit-tests/unexport-env	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/unexport-env	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,14 +0,0 @@
-# $Id: unexport-env,v 1.1.1.1 2009/11/19 00:31:11 sjg Exp $
-
-# pick up a bunch of exported vars
-.include "export"
-
-# an example of setting up a minimal environment.
-PATH = /bin:/usr/bin:/sbin:/usr/sbin
-
-# now clobber the environment to just PATH and UT_TEST
-UT_TEST = unexport-env
-
-# this removes everything
-.unexport-env
-.export PATH UT_TEST

Deleted: trunk/contrib/bmake/unit-tests/varcmd
===================================================================
--- trunk/contrib/bmake/unit-tests/varcmd	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/unit-tests/varcmd	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,49 +0,0 @@
-# $Id: varcmd,v 1.3 2008/05/15 04:30:47 sjg Exp $
-#
-# Test behaviour of recursive make and vars set on command line.
-
-FU=fu
-FOO?=foo
-.if !empty(.TARGETS)
-TAG=${.TARGETS}
-.endif
-TAG?=default
-
-all:	one
-
-show:
-	@echo "${TAG} FU=<v>${FU}</v> FOO=<v>${FOO}</v> VAR=<v>${VAR}</v>"
-
-one:	show
-	@${.MAKE} -f ${MAKEFILE} FU=bar FOO=goo two
-
-two:	show
-	@${.MAKE} -f ${MAKEFILE} three
-
-three:	show
-	@${.MAKE} -f ${MAKEFILE} four
-
-
-.ifmake four
-VAR=Internal
-.MAKEOVERRIDES+= VAR
-.endif
-
-four:	show
-	@${.MAKE} -f ${MAKEFILE} five
-
-M = x
-V.y = is y
-V.x = is x
-V := ${V.$M}
-K := ${V}
-
-show-v:
-	@echo '${TAG} v=${V} k=${K}'
-
-five:	show show-v
-	@${.MAKE} -f ${MAKEFILE} M=y six
-
-six:	show-v
-	@${.MAKE} -f ${MAKEFILE} V=override show-v
-

Modified: trunk/contrib/bmake/var.c
===================================================================
--- trunk/contrib/bmake/var.c	2018-06-27 00:17:36 UTC (rev 11139)
+++ trunk/contrib/bmake/var.c	2018-06-27 00:20:04 UTC (rev 11140)
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.200 2015/12/01 07:26:08 sjg Exp $	*/
+/*	$NetBSD: var.c,v 1.215 2017/04/16 21:39:49 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.200 2015/12/01 07:26:08 sjg Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.215 2017/04/16 21:39:49 riastradh Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -76,7 +76,7 @@
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.200 2015/12/01 07:26:08 sjg Exp $");
+__RCSID("$NetBSD: var.c,v 1.215 2017/04/16 21:39:49 riastradh Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -154,13 +154,23 @@
 char 	var_Error[] = "";
 
 /*
- * Similar to var_Error, but returned when the 'errnum' flag for Var_Parse is
- * set false. Why not just use a constant? Well, gcc likes to condense
- * identical string instances...
+ * Similar to var_Error, but returned when the 'VARF_UNDEFERR' flag for
+ * Var_Parse is not set. Why not just use a constant? Well, gcc likes
+ * to condense identical string instances...
  */
 static char	varNoError[] = "";
 
 /*
+ * Traditionally we consume $$ during := like any other expansion.
+ * Other make's do not.
+ * This knob allows controlling the behavior.
+ * FALSE for old behavior.
+ * TRUE for new compatible.
+ */
+#define SAVE_DOLLARS ".MAKE.SAVE_DOLLARS"
+static Boolean save_dollars = FALSE;
+
+/*
  * Internally, variables are contained in four different contexts.
  *	1) the environment. They may not be changed. If an environment
  *	    variable is appended-to, the result is placed in the global
@@ -216,7 +226,11 @@
  * We pass this to Var_Export when doing the initial export
  * or after updating an exported var.
  */
-#define VAR_EXPORT_PARENT 1
+#define VAR_EXPORT_PARENT	1
+/*
+ * We pass this to Var_Export1 to tell it to leave the value alone.
+ */
+#define VAR_EXPORT_LITERAL	2
 
 /* Var*Pattern flags */
 #define VAR_SUB_GLOBAL	0x01	/* Apply substitution globally */
@@ -516,7 +530,7 @@
     h = Hash_CreateEntry(&ctxt->context, name, NULL);
     Hash_SetValue(h, v);
     v->name = h->name;
-    if (DEBUG(VAR)) {
+    if (DEBUG(VAR) && (ctxt->flags & INTERNAL) == 0) {
 	fprintf(debug_file, "%s:%s = %s\n", ctxt->name, name, val);
     }
 }
@@ -541,7 +555,7 @@
     char *cp;
     
     if (strchr(name, '$')) {
-	cp = Var_Subst(NULL, name, VAR_GLOBAL, FALSE, TRUE);
+	cp = Var_Subst(NULL, name, VAR_GLOBAL, VARF_WANTRES);
     } else {
 	cp = (char *)name;
     }
@@ -580,12 +594,13 @@
  * We only manipulate flags of vars if 'parent' is set.
  */
 static int
-Var_Export1(const char *name, int parent)
+Var_Export1(const char *name, int flags)
 {
     char tmp[BUFSIZ];
     Var *v;
     char *val = NULL;
     int n;
+    int parent = (flags & VAR_EXPORT_PARENT);
 
     if (*name == '.')
 	return 0;			/* skip internals */
@@ -613,7 +628,7 @@
 	return 0;			/* nothing to do */
     }
     val = Buf_GetAll(&v->val, NULL);
-    if (strchr(val, '$')) {
+    if ((flags & VAR_EXPORT_LITERAL) == 0 && strchr(val, '$')) {
 	if (parent) {
 	    /*
 	     * Flag this as something we need to re-export.
@@ -632,7 +647,7 @@
 	}
 	n = snprintf(tmp, sizeof(tmp), "${%s}", name);
 	if (n < (int)sizeof(tmp)) {
-	    val = Var_Subst(NULL, tmp, VAR_GLOBAL, FALSE, TRUE);
+	    val = Var_Subst(NULL, tmp, VAR_GLOBAL, VARF_WANTRES);
 	    setenv(name, val, 1);
 	    free(val);
 	}
@@ -700,7 +715,7 @@
 	int ac;
 	int i;
 
-	val = Var_Subst(NULL, tmp, VAR_GLOBAL, FALSE, TRUE);
+	val = Var_Subst(NULL, tmp, VAR_GLOBAL, VARF_WANTRES);
 	if (*val) {
 	    av = brk_string(val, &ac, FALSE, &as);
 	    for (i = 0; i < ac; i++) {
@@ -725,7 +740,7 @@
     char *val;
     char **av;
     char *as;
-    int track;
+    int flags;
     int ac;
     int i;
 
@@ -734,13 +749,16 @@
 	return;
     }
 
+    flags = 0;
     if (strncmp(str, "-env", 4) == 0) {
-	track = 0;
 	str += 4;
+    } else if (strncmp(str, "-literal", 8) == 0) {
+	str += 8;
+	flags |= VAR_EXPORT_LITERAL;
     } else {
-	track = VAR_EXPORT_PARENT;
+	flags |= VAR_EXPORT_PARENT;
     }
-    val = Var_Subst(NULL, str, VAR_GLOBAL, FALSE, TRUE);
+    val = Var_Subst(NULL, str, VAR_GLOBAL, VARF_WANTRES);
     if (*val) {
 	av = brk_string(val, &ac, FALSE, &as);
 	for (i = 0; i < ac; i++) {
@@ -760,10 +778,10 @@
 		    continue;
 		}
 	    }
-	    if (Var_Export1(name, track)) {
+	    if (Var_Export1(name, flags)) {
 		if (VAR_EXPORTED_ALL != var_exportedVars)
 		    var_exportedVars = VAR_EXPORTED_YES;
-		if (isExport && track) {
+		if (isExport && (flags & VAR_EXPORT_PARENT)) {
 		    Var_Append(MAKE_EXPORTED, name, VAR_GLOBAL);
 		}
 	    }
@@ -830,7 +848,7 @@
 	/* Using .MAKE.EXPORTED */
 	n = snprintf(tmp, sizeof(tmp), "${" MAKE_EXPORTED ":O:u}");
 	if (n < (int)sizeof(tmp)) {
-	    vlist = Var_Subst(NULL, tmp, VAR_GLOBAL, FALSE, TRUE);
+	    vlist = Var_Subst(NULL, tmp, VAR_GLOBAL, VARF_WANTRES);
 	}
     }
     if (vlist) {
@@ -860,7 +878,7 @@
 		n = snprintf(tmp, sizeof(tmp),
 			     "${" MAKE_EXPORTED ":N%s}", v->name);
 		if (n < (int)sizeof(tmp)) {
-		    cp = Var_Subst(NULL, tmp, VAR_GLOBAL, FALSE, TRUE);
+		    cp = Var_Subst(NULL, tmp, VAR_GLOBAL, VARF_WANTRES);
 		    Var_Set(MAKE_EXPORTED, cp, VAR_GLOBAL, 0);
 		    free(cp);
 		}
@@ -915,7 +933,7 @@
      * point in searching them all just to save a bit of memory...
      */
     if (strchr(name, '$') != NULL) {
-	expanded_name = Var_Subst(NULL, name, ctxt, FALSE, TRUE);
+	expanded_name = Var_Subst(NULL, name, ctxt, VARF_WANTRES);
 	if (expanded_name[0] == 0) {
 	    if (DEBUG(VAR)) {
 		fprintf(debug_file, "Var_Set(\"%s\", \"%s\", ...) "
@@ -983,8 +1001,11 @@
 
 	Var_Append(MAKEOVERRIDES, name, VAR_GLOBAL);
     }
+    if (*name == '.') {
+	if (strcmp(name, SAVE_DOLLARS) == 0)
+	    save_dollars = s2Boolean(val, save_dollars);
+    }
 
-
  out:
     free(expanded_name);
     if (v != NULL)
@@ -1026,7 +1047,7 @@
     char *expanded_name = NULL;
 
     if (strchr(name, '$') != NULL) {
-	expanded_name = Var_Subst(NULL, name, ctxt, FALSE, TRUE);
+	expanded_name = Var_Subst(NULL, name, ctxt, VARF_WANTRES);
 	if (expanded_name[0] == 0) {
 	    if (DEBUG(VAR)) {
 		fprintf(debug_file, "Var_Append(\"%s\", \"%s\", ...) "
@@ -1091,7 +1112,7 @@
     char          *cp;
 
     if ((cp = strchr(name, '$')) != NULL) {
-	cp = Var_Subst(NULL, name, ctxt, FALSE, TRUE);
+	cp = Var_Subst(NULL, name, ctxt, VARF_WANTRES);
     }
     v = VarFind(cp ? cp : name, ctxt, FIND_CMD|FIND_GLOBAL|FIND_ENV);
     free(cp);
@@ -1160,7 +1181,7 @@
 static Boolean
 VarHead(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate,
 	char *word, Boolean addSpace, Buffer *buf,
-	void *dummy)
+	void *dummy MAKE_ATTR_UNUSED)
 {
     char *slash;
 
@@ -1181,7 +1202,7 @@
 	    Buf_AddByte(buf, vpstate->varSpace);
 	Buf_AddByte(buf, '.');
     }
-    return(dummy ? TRUE : TRUE);
+    return TRUE;
 }
 
 /*-
@@ -1208,7 +1229,7 @@
 static Boolean
 VarTail(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate,
 	char *word, Boolean addSpace, Buffer *buf,
-	void *dummy)
+	void *dummy MAKE_ATTR_UNUSED)
 {
     char *slash;
 
@@ -1224,7 +1245,7 @@
     } else {
 	Buf_AddBytes(buf, strlen(word), word);
     }
-    return (dummy ? TRUE : TRUE);
+    return TRUE;
 }
 
 /*-
@@ -1250,7 +1271,7 @@
 static Boolean
 VarSuffix(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate,
 	  char *word, Boolean addSpace, Buffer *buf,
-	  void *dummy)
+	  void *dummy MAKE_ATTR_UNUSED)
 {
     char *dot;
 
@@ -1264,7 +1285,7 @@
 	dot[-1] = '.';
 	addSpace = TRUE;
     }
-    return (dummy ? addSpace : addSpace);
+    return addSpace;
 }
 
 /*-
@@ -1291,7 +1312,7 @@
 static Boolean
 VarRoot(GNode *ctx MAKE_ATTR_UNUSED, Var_Parse_State *vpstate,
 	char *word, Boolean addSpace, Buffer *buf,
-	void *dummy)
+	void *dummy MAKE_ATTR_UNUSED)
 {
     char *dot;
 
@@ -1307,7 +1328,7 @@
     } else {
 	Buf_AddBytes(buf, strlen(word), word);
     }
-    return (dummy ? TRUE : TRUE);
+    return TRUE;
 }
 
 /*-
@@ -1389,7 +1410,7 @@
     addSpace = TRUE;
 
     if ((ptr = Str_SYSVMatch(word, pat->lhs, &len)) != NULL) {
-        varexp = Var_Subst(NULL, pat->rhs, ctx, FALSE, TRUE);
+        varexp = Var_Subst(NULL, pat->rhs, ctx, VARF_WANTRES);
 	Str_SYSVSubst(buf, varexp, ptr, len);
 	free(varexp);
     } else {
@@ -1629,14 +1650,14 @@
  *-----------------------------------------------------------------------
  */
 static void
-VarREError(int errnum, regex_t *pat, const char *str)
+VarREError(int reerr, regex_t *pat, const char *str)
 {
     char *errbuf;
     int errlen;
 
-    errlen = regerror(errnum, pat, 0, 0);
+    errlen = regerror(reerr, pat, 0, 0);
     errbuf = bmake_malloc(errlen);
-    regerror(errnum, pat, errbuf, errlen);
+    regerror(reerr, pat, errbuf, errlen);
     Error("%s: %s", str, errbuf);
     free(errbuf);
 }
@@ -1809,14 +1830,14 @@
 
     if (word && *word) {
         Var_Set(loop->tvar, word, loop->ctxt, VAR_NO_EXPORT);
-        s = Var_Subst(NULL, loop->str, loop->ctxt, loop->errnum, TRUE);
+        s = Var_Subst(NULL, loop->str, loop->ctxt, loop->errnum | VARF_WANTRES);
         if (s != NULL && *s != '\0') {
             if (addSpace && *s != '\n')
                 Buf_AddByte(buf, ' ');
             Buf_AddBytes(buf, (slen = strlen(s)), s);
             addSpace = (slen > 0 && s[slen - 1] != '\n');
-            free(s);
         }
+	free(s);
     }
     return addSpace;
 }
@@ -1929,7 +1950,7 @@
 	    Buf_AddByte(buf, vpstate->varSpace);
 	}
 	addSpace = TRUE;
-	rp = realpath(word, rbuf);
+	rp = cached_realpath(word, rbuf);
 	if (rp && *rp == '/' && stat(rp, &st) == 0)
 		word = rp;
 	
@@ -2118,7 +2139,52 @@
     return Buf_Destroy(&buf, FALSE);
 }
 
+/*-
+ *-----------------------------------------------------------------------
+ * VarRange --
+ *	Return an integer sequence
+ *
+ * Input:
+ *	str		String whose words provide default range
+ *	ac		range length, if 0 use str words
+ *
+ * Side Effects:
+ *	None.
+ *
+ *-----------------------------------------------------------------------
+ */
+static char *
+VarRange(const char *str, int ac)
+{
+    Buffer	  buf;		    /* Buffer for new string */
+    char	  tmp[32];	    /* each element */
+    char 	**av;		    /* List of words to affect */
+    char 	 *as;		    /* Word list memory */
+    int 	  i, n;
 
+    Buf_Init(&buf, 0);
+    if (ac > 0) {
+	as = NULL;
+	av = NULL;
+    } else {
+	av = brk_string(str, &ac, FALSE, &as);
+    }
+    for (i = 0; i < ac; i++) {
+	n = snprintf(tmp, sizeof(tmp), "%d", 1 + i);
+	if (n >= (int)sizeof(tmp))
+	    break;
+	Buf_AddBytes(&buf, n, tmp);
+	if (i != ac - 1)
+	    Buf_AddByte(&buf, ' ');
+    }
+
+    free(as);
+    free(av);
+
+    return Buf_Destroy(&buf, FALSE);
+}
+
+
 /*-
  *-----------------------------------------------------------------------
  * VarGetPattern --
@@ -2143,7 +2209,7 @@
  */
 static char *
 VarGetPattern(GNode *ctxt, Var_Parse_State *vpstate MAKE_ATTR_UNUSED,
-	      int errnum, const char **tstr, int delim, int *flags,
+	      int flags, const char **tstr, int delim, int *vflags,
 	      int *length, VarPattern *pattern)
 {
     const char *cp;
@@ -2150,6 +2216,7 @@
     char *rstr;
     Buffer buf;
     int junk;
+    int errnum = flags & VARF_UNDEFERR;
 
     Buf_Init(&buf, 0);
     if (length == NULL)
@@ -2171,7 +2238,7 @@
 	    cp++;
 	} else if (*cp == '$') {
 	    if (cp[1] == delim) {
-		if (flags == NULL)
+		if (vflags == NULL)
 		    Buf_AddByte(&buf, *cp);
 		else
 		    /*
@@ -2178,9 +2245,9 @@
 		     * Unescaped $ at end of pattern => anchor
 		     * pattern at end.
 		     */
-		    *flags |= VAR_MATCH_END;
+		    *vflags |= VAR_MATCH_END;
 	    } else {
-		if (flags == NULL || (*flags & VAR_NOSUBST) == 0) {
+		if (vflags == NULL || (*vflags & VAR_NOSUBST) == 0) {
 		    char   *cp2;
 		    int     len;
 		    void   *freeIt;
@@ -2190,7 +2257,8 @@
 		     * delimiter, assume it's a variable
 		     * substitution and recurse.
 		     */
-		    cp2 = Var_Parse(cp, ctxt, errnum, TRUE, &len, &freeIt);
+		    cp2 = Var_Parse(cp, ctxt, errnum | VARF_WANTRES, &len,
+			&freeIt);
 		    Buf_AddBytes(&buf, strlen(cp2), cp2);
 		    free(freeIt);
 		    cp += len - 1;
@@ -2357,12 +2425,12 @@
 }
 
 static char *
-VarStrftime(const char *fmt, int zulu)
+VarStrftime(const char *fmt, int zulu, time_t utc)
 {
     char buf[BUFSIZ];
-    time_t utc;
 
-    time(&utc);
+    if (!utc)
+	time(&utc);
     if (!*fmt)
 	fmt = "%c";
     strftime(buf, sizeof(buf), fmt, zulu ? gmtime(&utc) : localtime(&utc));
@@ -2459,11 +2527,14 @@
 /* we now have some modifiers with long names */
 #define STRMOD_MATCH(s, want, n) \
     (strncmp(s, want, n) == 0 && (s[n] == endc || s[n] == ':'))
+#define STRMOD_MATCHX(s, want, n) \
+    (strncmp(s, want, n) == 0 && (s[n] == endc || s[n] == ':' || s[n] == '='))
+#define CHARMOD_MATCH(c) (c == endc || c == ':')
 
 static char *
 ApplyModifiers(char *nstr, const char *tstr,
 	       int startc, int endc,
-	       Var *v, GNode *ctxt, Boolean errnum, Boolean wantit,
+	       Var *v, GNode *ctxt, int flags,
 	       int *lengthPtr, void **freePtr)
 {
     const char 	   *start;
@@ -2470,6 +2541,7 @@
     const char     *cp;    	/* Secondary pointer into str (place marker
 				 * for tstr) */
     char	   *newStr;	/* New value to return */
+    char	   *ep;
     char	    termc;	/* Character which terminated scan */
     int             cnt;	/* Used to count brace pairs when variable in
 				 * in parens or braces */
@@ -2476,6 +2548,7 @@
     char	delim;
     int		modifier;	/* that we are processing */
     Var_Parse_State parsestate; /* Flags passed to helper functions */
+    time_t	utc;		/* for VarStrftime */
 
     delim = '\0';
     parsestate.oneBigWord = FALSE;
@@ -2494,7 +2567,7 @@
 	    int rlen;
 	    int c;
 
-	    rval = Var_Parse(tstr, ctxt, errnum, wantit, &rlen, &freeIt);
+	    rval = Var_Parse(tstr, ctxt, flags, &rlen, &freeIt);
 
 	    /*
 	     * If we have not parsed up to endc or ':',
@@ -2519,10 +2592,9 @@
 		int used;
 
 		nstr = ApplyModifiers(nstr, rval,
-				      0, 0,
-				      v, ctxt, errnum, wantit, &used, freePtr);
+				      0, 0, v, ctxt, flags, &used, freePtr);
 		if (nstr == var_Error
-		    || (nstr == varNoError && errnum == 0)
+		    || (nstr == varNoError && (flags & VARF_UNDEFERR) == 0)
 		    || strlen(rval) != (size_t) used) {
 		    free(freeIt);
 		    goto out;		/* error already reported */
@@ -2557,7 +2629,7 @@
 		    char *sv_name;
 		    VarPattern	pattern;
 		    int	how;
-		    int flags;
+		    int vflags;
 
 		    if (v->name[0] == 0)
 			goto bad_modifier;
@@ -2593,9 +2665,9 @@
 		    delim = startc == PROPEN ? PRCLOSE : BRCLOSE;
 		    pattern.flags = 0;
 
-		    flags = (wantit) ? 0 : VAR_NOSUBST;
-		    pattern.rhs = VarGetPattern(ctxt, &parsestate, errnum,
-						&cp, delim, &flags,
+		    vflags = (flags & VARF_WANTRES) ? 0 : VAR_NOSUBST;
+		    pattern.rhs = VarGetPattern(ctxt, &parsestate, flags,
+						&cp, delim, &vflags,
 						&pattern.rightLen,
 						NULL);
 		    if (v->flags & VAR_JUNK) {
@@ -2609,7 +2681,7 @@
 		    termc = *--cp;
 		    delim = '\0';
 
-		    if (wantit) {
+		    if (flags & VARF_WANTRES) {
 			switch (how) {
 			case '+':
 			    Var_Append(v->name, pattern.rhs, v_ctxt);
@@ -2640,19 +2712,19 @@
 	case '@':
 	    {
 		VarLoop_t	loop;
-		int flags = VAR_NOSUBST;
+		int vflags = VAR_NOSUBST;
 
 		cp = ++tstr;
 		delim = '@';
-		if ((loop.tvar = VarGetPattern(ctxt, &parsestate, errnum,
+		if ((loop.tvar = VarGetPattern(ctxt, &parsestate, flags,
 					       &cp, delim,
-					       &flags, &loop.tvarLen,
+					       &vflags, &loop.tvarLen,
 					       NULL)) == NULL)
 		    goto cleanup;
 
-		if ((loop.str = VarGetPattern(ctxt, &parsestate, errnum,
+		if ((loop.str = VarGetPattern(ctxt, &parsestate, flags,
 					      &cp, delim,
-					      &flags, &loop.strLen,
+					      &vflags, &loop.strLen,
 					      NULL)) == NULL)
 		    goto cleanup;
 
@@ -2659,27 +2731,54 @@
 		termc = *cp;
 		delim = '\0';
 
-		loop.errnum = errnum;
+		loop.errnum = flags & VARF_UNDEFERR;
 		loop.ctxt = ctxt;
 		newStr = VarModify(ctxt, &parsestate, nstr, VarLoopExpand,
 				   &loop);
+		Var_Delete(loop.tvar, ctxt);
 		free(loop.tvar);
 		free(loop.str);
 		break;
 	    }
+	case '_':			/* remember current value */
+	    cp = tstr + 1;	/* make sure it is set */
+	    if (STRMOD_MATCHX(tstr, "_", 1)) {
+		if (tstr[1] == '=') {
+		    char *np;
+		    int n;
+
+		    cp++;
+		    n = strcspn(cp, ":)}");
+		    np = bmake_strndup(cp, n+1);
+		    np[n] = '\0';
+		    cp = tstr + 2 + n;
+		    Var_Set(np, nstr, ctxt, 0);
+		    free(np);
+		} else {
+		    Var_Set("_", nstr, ctxt, 0);
+		}
+		newStr = nstr;
+		termc = *cp;
+		break;
+	    }
+	    goto default_case;
 	case 'D':
 	case 'U':
 	    {
 		Buffer  buf;    	/* Buffer for patterns */
-		int	    wantit_;	/* want data in buffer */
+		int	nflags;
 
-		if (wantit) {
+		if (flags & VARF_WANTRES) {
+		    int wantres;
 		    if (*tstr == 'U')
-			wantit_ = ((v->flags & VAR_JUNK) != 0);
+			wantres = ((v->flags & VAR_JUNK) != 0);
 		    else
-			wantit_ = ((v->flags & VAR_JUNK) == 0);
+			wantres = ((v->flags & VAR_JUNK) == 0);
+		    nflags = flags & ~VARF_WANTRES;
+		    if (wantres)
+			nflags |= VARF_WANTRES;
 		} else
-		    wantit_ = wantit;
+		    nflags = flags;
 		/*
 		 * Pass through tstr looking for 1) escaped delimiters,
 		 * '$'s and backslashes (place the escaped character in
@@ -2708,7 +2807,7 @@
 			    int	    len;
 			    void    *freeIt;
 
-			    cp2 = Var_Parse(cp, ctxt, errnum, wantit_, &len, &freeIt);
+			    cp2 = Var_Parse(cp, ctxt, nflags, &len, &freeIt);
 			    Buf_AddBytes(&buf, strlen(cp2), cp2);
 			    free(freeIt);
 			    cp += len - 1;
@@ -2721,7 +2820,7 @@
 
 		if ((v->flags & VAR_JUNK) != 0)
 		    v->flags |= VAR_KEEP;
-		if (wantit_) {
+		if (nflags & VARF_WANTRES) {
 		    newStr = Buf_Destroy(&buf, FALSE);
 		} else {
 		    newStr = nstr;
@@ -2768,12 +2867,12 @@
 		delim = '!';
 		emsg = NULL;
 		cp = ++tstr;
-		if ((pattern.rhs = VarGetPattern(ctxt, &parsestate, errnum,
+		if ((pattern.rhs = VarGetPattern(ctxt, &parsestate, flags,
 						 &cp, delim,
 						 NULL, &pattern.rightLen,
 						 NULL)) == NULL)
 		    goto cleanup;
-		if (wantit)
+		if (flags & VARF_WANTRES)
 		    newStr = Cmd_Exec(pattern.rhs, &emsg);
 		else
 		    newStr = varNoError;
@@ -2801,7 +2900,7 @@
 		cp = tstr+1; /* point to char after '[' */
 		delim = ']'; /* look for closing ']' */
 		estr = VarGetPattern(ctxt, &parsestate,
-				     errnum, &cp, delim,
+				     flags, &cp, delim,
 				     NULL, NULL, NULL);
 		if (estr == NULL)
 		    goto cleanup; /* report missing ']' */
@@ -2868,8 +2967,6 @@
 		     * integer for :[N], or two integers
 		     * separated by ".." for :[start..end].
 		     */
-		    char *ep;
-
 		    VarSelectWords_t seldata = { 0, 0 };
 
 		    seldata.start = strtol(estr, &ep, 0);
@@ -2928,9 +3025,15 @@
 	    }
 	case 'g':
 	    cp = tstr + 1;	/* make sure it is set */
-	    if (STRMOD_MATCH(tstr, "gmtime", 6)) {
-		newStr = VarStrftime(nstr, 1);
-		cp = tstr + 6;
+	    if (STRMOD_MATCHX(tstr, "gmtime", 6)) {
+		if (tstr[6] == '=') {
+		    utc = strtoul(&tstr[7], &ep, 10);
+		    cp = ep;
+		} else {
+		    utc = 0;
+		    cp = tstr + 6;
+		}
+		newStr = VarStrftime(nstr, 1, utc);
 		termc = *cp;
 	    } else {
 		goto default_case;
@@ -2948,9 +3051,15 @@
 	    break;
 	case 'l':
 	    cp = tstr + 1;	/* make sure it is set */
-	    if (STRMOD_MATCH(tstr, "localtime", 9)) {
-		newStr = VarStrftime(nstr, 0);
-		cp = tstr + 9;
+	    if (STRMOD_MATCHX(tstr, "localtime", 9)) {
+		if (tstr[9] == '=') {
+		    utc = strtoul(&tstr[10], &ep, 10);
+		    cp = ep;
+		} else {
+		    utc = 0;
+		    cp = tstr + 9;
+		}
+		newStr = VarStrftime(nstr, 0, utc);
 		termc = *cp;
 	    } else {
 		goto default_case;
@@ -2978,6 +3087,9 @@
 			    parsestate.varSpace = 0; /* no separator */
 			    cp = tstr + 2;
 			} else if (tstr[2] == '\\') {
+			    const char *xp = &tstr[3];
+			    int base = 8; /* assume octal */
+
 			    switch (tstr[3]) {
 			    case 'n':
 				parsestate.varSpace = '\n';
@@ -2987,12 +3099,19 @@
 				parsestate.varSpace = '\t';
 				cp = tstr + 4;
 				break;
+			    case 'x':
+				base = 16;
+				xp++;
+				goto get_numeric;
+			    case '0':
+				base = 0;
+				goto get_numeric;
 			    default:
 				if (isdigit((unsigned char)tstr[3])) {
-				    char *ep;
 
+				get_numeric:
 				    parsestate.varSpace =
-					strtoul(&tstr[3], &ep, 0);
+					strtoul(xp, &ep, base);
 				    if (*ep != ':' && *ep != endc)
 					goto bad_modifier;
 				    cp = ep;
@@ -3152,7 +3271,7 @@
 		     * expand it.
 		     */
 		    cp2 = pattern;
-		    pattern = Var_Subst(NULL, cp2, ctxt, errnum, TRUE);
+		    pattern = Var_Subst(NULL, cp2, ctxt, flags | VARF_WANTRES);
 		    free(cp2);
 		}
 		if (DEBUG(VAR))
@@ -3188,7 +3307,7 @@
 		}
 
 		cp = tstr;
-		if ((pattern.lhs = VarGetPattern(ctxt, &parsestate, errnum,
+		if ((pattern.lhs = VarGetPattern(ctxt, &parsestate, flags,
 						 &cp, delim,
 						 &pattern.flags,
 						 &pattern.leftLen,
@@ -3195,7 +3314,7 @@
 						 NULL)) == NULL)
 		    goto cleanup;
 
-		if ((pattern.rhs = VarGetPattern(ctxt, &parsestate, errnum,
+		if ((pattern.rhs = VarGetPattern(ctxt, &parsestate, flags,
 						 &cp, delim, NULL,
 						 &pattern.rightLen,
 						 &pattern)) == NULL)
@@ -3242,7 +3361,7 @@
 		int lhs_flags, rhs_flags;
 		
 		/* find ':', and then substitute accordingly */
-		if (wantit) {
+		if (flags & VARF_WANTRES) {
 		    cond_rc = Cond_EvalExpression(NULL, v->name, &value, 0, FALSE);
 		    if (cond_rc == COND_INVALID) {
 			lhs_flags = rhs_flags = VAR_NOSUBST;
@@ -3262,7 +3381,7 @@
 
 		cp = ++tstr;
 		delim = ':';
-		if ((pattern.lhs = VarGetPattern(ctxt, &parsestate, errnum,
+		if ((pattern.lhs = VarGetPattern(ctxt, &parsestate, flags,
 						 &cp, delim, &lhs_flags,
 						 &pattern.leftLen,
 						 NULL)) == NULL)
@@ -3270,7 +3389,7 @@
 
 		/* BROPEN or PROPEN */
 		delim = endc;
-		if ((pattern.rhs = VarGetPattern(ctxt, &parsestate, errnum,
+		if ((pattern.rhs = VarGetPattern(ctxt, &parsestate, flags,
 						 &cp, delim, &rhs_flags,
 						 &pattern.rightLen,
 						 NULL)) == NULL)
@@ -3311,12 +3430,12 @@
 
 		cp = tstr;
 
-		if ((re = VarGetPattern(ctxt, &parsestate, errnum, &cp, delim,
+		if ((re = VarGetPattern(ctxt, &parsestate, flags, &cp, delim,
 					NULL, NULL, NULL)) == NULL)
 		    goto cleanup;
 
 		if ((pattern.replace = VarGetPattern(ctxt, &parsestate,
-						     errnum, &cp, delim, NULL,
+						     flags, &cp, delim, NULL,
 						     NULL, NULL)) == NULL){
 		    free(re);
 		    goto cleanup;
@@ -3409,6 +3528,23 @@
 		break;
 	    }
 	    goto default_case;
+	case 'r':
+	    cp = tstr + 1;	/* make sure it is set */
+	    if (STRMOD_MATCHX(tstr, "range", 5)) {
+		int n;
+		
+		if (tstr[5] == '=') {
+		    n = strtoul(&tstr[6], &ep, 10);
+		    cp = ep;
+		} else {
+		    n = 0;
+		    cp = tstr + 5;
+		}
+		newStr = VarRange(nstr, n);
+		termc = *cp;
+		break;
+	    }
+	    goto default_case;
 	case 'O':
 	    {
 		char otype;
@@ -3440,7 +3576,7 @@
 	case 's':
 	    if (tstr[1] == 'h' && (tstr[2] == endc || tstr[2] == ':')) {
 		const char *emsg;
-		if (wantit) {
+		if (flags & VARF_WANTRES) {
 		    newStr = Cmd_Exec(nstr, &emsg);
 		    if (emsg)
 			Error(emsg, nstr);
@@ -3493,12 +3629,12 @@
 		delim='=';
 		cp = tstr;
 		if ((pattern.lhs = VarGetPattern(ctxt, &parsestate,
-						 errnum, &cp, delim, &pattern.flags,
+						 flags, &cp, delim, &pattern.flags,
 						 &pattern.leftLen, NULL)) == NULL)
 		    goto cleanup;
 		delim = endc;
 		if ((pattern.rhs = VarGetPattern(ctxt, &parsestate,
-						 errnum, &cp, delim, NULL, &pattern.rightLen,
+						 flags, &cp, delim, NULL, &pattern.rightLen,
 						 &pattern)) == NULL)
 		    goto cleanup;
 
@@ -3581,7 +3717,9 @@
  * Input:
  *	str		The string to parse
  *	ctxt		The context for the variable
- *	errnum		TRUE if undefined variables are an error
+ *	flags		VARF_UNDEFERR	if undefineds are an error
+ *			VARF_WANTRES	if we actually want the result
+ *			VARF_ASSIGN	if we are in a := assignment
  *	wantit		TRUE if we actually want the result
  *	lengthPtr	OUT: The length of the specification
  *	freePtr		OUT: Non-NULL if caller should free *freePtr
@@ -3601,9 +3739,8 @@
  */
 /* coverity[+alloc : arg-*4] */
 char *
-Var_Parse(const char *str, GNode *ctxt,
-	   Boolean errnum, Boolean wantit,
-	   int *lengthPtr, void **freePtr)
+Var_Parse(const char *str, GNode *ctxt, int flags,
+	  int *lengthPtr, void **freePtr)
 {
     const char	   *tstr;    	/* Pointer into str */
     Var		   *v;		/* Variable in invocation */
@@ -3661,17 +3798,17 @@
 		    case '@':
 			return UNCONST("$(.TARGET)");
 		    case '%':
-			return UNCONST("$(.ARCHIVE)");
+			return UNCONST("$(.MEMBER)");
 		    case '*':
 			return UNCONST("$(.PREFIX)");
 		    case '!':
-			return UNCONST("$(.MEMBER)");
+			return UNCONST("$(.ARCHIVE)");
 		}
 	    }
 	    /*
 	     * Error
 	     */
-	    return (errnum ? var_Error : varNoError);
+	    return (flags & VARF_UNDEFERR) ? var_Error : varNoError;
 	} else {
 	    haveModifier = FALSE;
 	    tstr = &str[1];
@@ -3708,7 +3845,7 @@
 	    if (*tstr == '$') {
 		int rlen;
 		void *freeIt;
-		char *rval = Var_Parse(tstr, ctxt, errnum, wantit, &rlen, &freeIt);
+		char *rval = Var_Parse(tstr, ctxt, flags,  &rlen, &freeIt);
 		if (rval != NULL) {
 		    Buf_AddBytes(&buf, strlen(rval), rval);
 		}
@@ -3821,7 +3958,7 @@
 		    return(pstr);
 		} else {
 		    Buf_Destroy(&buf, TRUE);
-		    return (errnum ? var_Error : varNoError);
+		    return (flags & VARF_UNDEFERR) ? var_Error : varNoError;
 		}
 	    } else {
 		/*
@@ -3855,7 +3992,7 @@
      */
     nstr = Buf_GetAll(&v->val, NULL);
     if (strchr(nstr, '$') != NULL) {
-	nstr = Var_Subst(NULL, nstr, ctxt, errnum, wantit);
+	nstr = Var_Subst(NULL, nstr, ctxt, flags);
 	*freePtr = nstr;
     }
 
@@ -3868,7 +4005,7 @@
 	extraFree = NULL;
 	if (extramodifiers != NULL) {
 		nstr = ApplyModifiers(nstr, extramodifiers, '(', ')',
-				      v, ctxt, errnum, wantit, &used, &extraFree);
+				      v, ctxt, flags, &used, &extraFree);
 	}
 
 	if (haveModifier) {
@@ -3876,7 +4013,7 @@
 		tstr++;
 
 		nstr = ApplyModifiers(nstr, tstr, startc, endc,
-				      v, ctxt, errnum, wantit, &used, freePtr);
+				      v, ctxt, flags, &used, freePtr);
 		tstr += used;
 		free(extraFree);
 	} else {
@@ -3917,7 +4054,7 @@
 		nstr = bmake_strndup(start, *lengthPtr);
 		*freePtr = nstr;
 	    } else {
-		nstr = errnum ? var_Error : varNoError;
+		nstr = (flags & VARF_UNDEFERR) ? var_Error : varNoError;
 	    }
 	}
 	if (nstr != Buf_GetAll(&v->val, NULL))
@@ -3932,7 +4069,7 @@
  *-----------------------------------------------------------------------
  * Var_Subst  --
  *	Substitute for all variables in the given string in the given context
- *	If undefErr is TRUE, Parse_Error will be called when an undefined
+ *	If flags & VARF_UNDEFERR, Parse_Error will be called when an undefined
  *	variable is encountered.
  *
  * Input:
@@ -3939,7 +4076,9 @@
  *	var		Named variable || NULL for all
  *	str		the string which to substitute
  *	ctxt		the context wherein to find variables
- *	undefErr	TRUE if undefineds are an error
+ *	flags		VARF_UNDEFERR	if undefineds are an error
+ *			VARF_WANTRES	if we actually want the result
+ *			VARF_ASSIGN	if we are in a := assignment
  *	wantit		TRUE if we actually want the result
  *
  * Results:
@@ -3950,8 +4089,7 @@
  *-----------------------------------------------------------------------
  */
 char *
-Var_Subst(const char *var, const char *str, GNode *ctxt,
-	   Boolean undefErr, Boolean wantit)
+Var_Subst(const char *var, const char *str, GNode *ctxt, int flags)
 {
     Buffer  	  buf;		    /* Buffer for forming things */
     char    	  *val;		    /* Value to substitute for a variable */
@@ -3975,6 +4113,8 @@
 	     * In such a case, we skip over the escape character and store the
 	     * dollar sign into the buffer directly.
 	     */
+	    if (save_dollars && (flags & VARF_ASSIGN))
+		Buf_AddByte(&buf, *str);
 	    str++;
 	    Buf_AddByte(&buf, *str);
 	    str++;
@@ -4049,7 +4189,7 @@
 		    continue;
 	    }
 
-	    val = Var_Parse(str, ctxt, undefErr, wantit, &length, &freeIt);
+	    val = Var_Parse(str, ctxt, flags, &length, &freeIt);
 
 	    /*
 	     * When we come down here, val should either point to the
@@ -4066,7 +4206,7 @@
 		 */
 		if (oldVars) {
 		    str += length;
-		} else if (undefErr || val == var_Error) {
+		} else if ((flags & VARF_UNDEFERR) || val == var_Error) {
 		    /*
 		     * If variable is undefined, complain and skip the
 		     * variable. The complaint will stop us from doing anything



More information about the Midnightbsd-cvs mailing list