aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/mk
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bmake/mk')
-rw-r--r--contrib/bmake/mk/ChangeLog644
-rw-r--r--contrib/bmake/mk/FILES60
-rw-r--r--contrib/bmake/mk/README401
-rw-r--r--contrib/bmake/mk/auto.dep.mk64
-rw-r--r--contrib/bmake/mk/auto.obj.mk56
-rw-r--r--contrib/bmake/mk/autoconf.mk78
-rw-r--r--contrib/bmake/mk/autodep.mk216
-rw-r--r--contrib/bmake/mk/dep.mk133
-rw-r--r--contrib/bmake/mk/dirdeps.mk414
-rw-r--r--contrib/bmake/mk/doc.mk63
-rw-r--r--contrib/bmake/mk/dpadd.mk196
-rw-r--r--contrib/bmake/mk/final.mk14
-rw-r--r--contrib/bmake/mk/gendirdeps.mk301
-rw-r--r--contrib/bmake/mk/host-target.mk31
-rw-r--r--contrib/bmake/mk/host.libnames.mk29
-rw-r--r--contrib/bmake/mk/inc.mk35
-rw-r--r--contrib/bmake/mk/init.mk44
-rw-r--r--contrib/bmake/mk/install-mk185
-rw-r--r--contrib/bmake/mk/install-new.mk53
-rw-r--r--contrib/bmake/mk/java.mk97
-rw-r--r--contrib/bmake/mk/lib.mk605
-rw-r--r--contrib/bmake/mk/libnames.mk22
-rw-r--r--contrib/bmake/mk/libs.mk54
-rw-r--r--contrib/bmake/mk/links.mk75
-rw-r--r--contrib/bmake/mk/man.mk137
-rw-r--r--contrib/bmake/mk/meta.autodep.mk262
-rw-r--r--contrib/bmake/mk/meta.stage.mk212
-rw-r--r--contrib/bmake/mk/meta.subdir.mk79
-rw-r--r--contrib/bmake/mk/meta.sys.mk139
-rwxr-xr-xcontrib/bmake/mk/meta2deps.py614
-rwxr-xr-xcontrib/bmake/mk/meta2deps.sh307
-rw-r--r--contrib/bmake/mk/mk-files.txt467
-rw-r--r--contrib/bmake/mk/nls.mk48
-rw-r--r--contrib/bmake/mk/obj.mk113
-rw-r--r--contrib/bmake/mk/options.mk58
-rw-r--r--contrib/bmake/mk/own.mk244
-rw-r--r--contrib/bmake/mk/prlist.mk36
-rw-r--r--contrib/bmake/mk/prog.mk219
-rw-r--r--contrib/bmake/mk/progs.mk87
-rw-r--r--contrib/bmake/mk/rst2htm.mk43
-rw-r--r--contrib/bmake/mk/scripts.mk52
-rw-r--r--contrib/bmake/mk/srctop.mk66
-rw-r--r--contrib/bmake/mk/subdir.mk99
-rw-r--r--contrib/bmake/mk/sys.clean-env.mk119
-rw-r--r--contrib/bmake/mk/sys.dependfile.mk47
-rw-r--r--contrib/bmake/mk/sys.mk199
-rw-r--r--contrib/bmake/mk/sys/AIX.mk197
-rw-r--r--contrib/bmake/mk/sys/Darwin.mk220
-rw-r--r--contrib/bmake/mk/sys/Generic.mk208
-rw-r--r--contrib/bmake/mk/sys/HP-UX.mk237
-rw-r--r--contrib/bmake/mk/sys/IRIX.mk199
-rw-r--r--contrib/bmake/mk/sys/Linux.mk200
-rw-r--r--contrib/bmake/mk/sys/NetBSD.mk234
-rw-r--r--contrib/bmake/mk/sys/OSF1.mk211
-rw-r--r--contrib/bmake/mk/sys/OpenBSD.mk209
-rw-r--r--contrib/bmake/mk/sys/SunOS.mk232
-rw-r--r--contrib/bmake/mk/sys/UnixWare.mk254
-rw-r--r--contrib/bmake/mk/target-flags.mk62
-rw-r--r--contrib/bmake/mk/warnings.mk148
-rw-r--r--contrib/bmake/mk/yacc.mk57
60 files changed, 10185 insertions, 0 deletions
diff --git a/contrib/bmake/mk/ChangeLog b/contrib/bmake/mk/ChangeLog
new file mode 100644
index 000000000000..fee1c905c444
--- /dev/null
+++ b/contrib/bmake/mk/ChangeLog
@@ -0,0 +1,644 @@
+2013-01-23 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20130123
+ * meta.stage.mk: add stage_links (hard links).
+ if doing hard links, we add dest to link as well.
+ Default the stage dir for [sym]links to STAGE_OBJTOP since
+ these are typically specified as absolute paths.
+ Add -m "mode" flag to StageFiles and StageAs.
+
+2012-11-11 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20121111
+ * autoconf.mk: avoid meta mode seeing changed commands for config.status
+ * meta.autodep.mk: pass resolved MAKESYSPATH to gendirdeps
+ in case we were found via .../mk
+ * sys.clean-env.mk: move it from examples, we and others use it
+ "as is".
+ * FILES: add srctop.mk and options.mk
+ * own.mk: convert to using options.mk
+ which is modeled after FreeBSD's handling of MK_*
+ but more flexible.
+ This allows MK_* for boolean knobs to not be confused
+ with MK* which can be commands.
+
+ * examples/sys.clean-env.mk: add WITH[OUT]_ to
+ MAKE_ENV_SAVE_PREFIX_LIST.
+ Mention that HOME=/var/empty might be a good idea.
+
+2012-11-08 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * sys.dependfile.mk: if not depend file exists, $MACHINE
+ specific ones are supported but not the default,
+ check if any exist and follow suit.
+
+2012-11-06 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20121106
+
+2012-11-05 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * import latest dirdeps.mk and meta2deps.py from Juniper.
+ * progs.mk: add MAN and CXXFLAGS to PROG_VARS
+ also add PROGS_TARGETS and pass on PROG_CXX if it seems
+ appropriate.
+
+2012-11-04 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * meta.stage.mk: update CLEANFILES
+ remove redundant cp of .dirdep from STAGE_AS_SCRIPT.
+ * progs.mk: Add LDADD to PROG_VARS
+
+2012-10-12 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * meta.stage.mk (STAGE_DIR_FILTER): track dirs we stage to in
+ _STAGED_DIRS so that these can be turned into filters for
+ GENDIRDEPS_FILTER.
+
+2012-10-10 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20121010
+ * meta.stage.mk (STAGE_DIRDEP_SCRIPT): check that an existing
+ target.dirdep matches .dirdep
+
+2012-08-08 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20120808
+ * import latest meta2deps.py from Juniper.
+
+2012-07-11 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20120711
+ * dep.mk: add explicit dependencies on SRCS after applying
+ SRCS_DEP_FILTER
+ * meta.autodep.mk: add explicit dependencies on SRCS after
+ applying SRCS_DEP_FILTER
+ * meta.autodep.mk: ensure GENDIRDEPS_FILTER is exported if needed.
+
+2012-06-26 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20120626
+ * meta.sys.mk: ignore PYTHON if it does not exist
+ compare ${.MAKE.DEPENDFILE:E} against ${MACHINE} is more reliable.
+ * meta.stage.mk: examine .MAKE.DEPENDFILE_PREFERENCE for any
+ entries ending in .${MACHINE} to decide if qualified _dirdep is
+ needed.
+ * gendirdeps.mk: only produce unqualified deps if no
+ .MAKE.DEPENDFILE_PREFERENCE ends in .${MACHINE}
+ * meta.subdir.mk: apply SUBDIREPS_FILTER
+
+2012-04-20 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20120420
+ * add sys.dependfile.mk so we can experiment with
+ .MAKE.DEPENDFILE_PREFERENCE
+ * meta.autodep.mk: _DEPENDFILE is precious!
+
+2012-03-15 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20120315
+ * install-new.mk: avoid being interrupted
+
+2012-02-26 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * man.mk: MAN might have multiple values so be careful with exists().
+
+2012-01-19 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20120112
+ * fix examples/sys.clean-env.mk so that MAKEOBJDIR is handled
+ as: MAKEOBJDIR='${.CURDIR:S,${SRCTOP},${OBJTOP},}'
+
+2011-12-03 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20111201
+ * import dirdeps.mk from Juniper sjg@
+ o more consistent handling of DEP_MACHINE, especially when
+ dealing with an odd Makefile.depend, when normally using
+ Makefile.depend.${MACHINE}
+
+2011-11-22 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20111122
+ * meta.autodep.mk: add some debug output, be more crisp about
+ updating. Use ${.ALLTARGETS:M*.o} as a clue for .depend
+
+2011-11-13 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20111111
+ it's too cool to miss
+ * import meta* updates from Juniper sjg@
+ o dirdeps.mk set DEP_MACHINE for Makefile.depend (when we are
+ normally using Makefile.depend.${MACHINE}), handy for
+ read-only manually maintained dependencies.
+ o meta2deps.py add a clear 'ERROR:' token if an exception is raised.
+ o gendirdeps.mk if ERROR: from meta2deps.py do not update
+ anything.
+
+2011-10-30 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-new.mk separate the cmp and copy logic to its own function.
+
+2011-10-28 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20111028
+ * sys.mk: include auto.obj.mk if MKOBJDIRS is set to auto
+ * subdir.mk: ensure _SUBDIRUSE is provided
+ * meta.autodep.mk: remove dependency of gendirdeps.mk on auto.obj.mk
+ * meta.subdir.mk: always allow for Makefile.depend
+
+2011-10-10 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20111010
+ o minor tweak to *dirdeps.mk from Juniper sjg@
+
+2011-10-01 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20111001
+ o add meta2deps.py from Juniper sjg@
+ o tweak gendirdeps.mk to work with meta2deps.py when not
+ cross-building
+ * autoconf.mk: add autoconf-input as a hook for regenerating
+ AUTOCONF_INPUTS (configure).
+
+2011-08-24 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * meta.autodep.mk: if we do not have OBJS, .depend isn't a useful
+ trigger for updating Makefile.depend*
+
+2011-08-08 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20110808
+ * obj.mk: minor cleanup
+ * auto.obj.mk: improve description of Mkdirs and honor NO_OBJ too.
+
+2011-08-01 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * auto.obj.mk (.OBJDIR): throw an error if we cannot use the
+ specified dir.
+
+2011-06-28 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * meta.autodep.mk: if XMAKE_META_FILE is set
+ the makefile uses a foreign make, and so dependencies
+ can only be gathered from a clean tree build.
+
+2011-06-24 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20110622
+ * meta.autodep.mk: improve bootstraping
+
+2011-06-10 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * yacc.mk: handle the corner case of .c being removed
+ while .h remains.
+
+2011-06-08 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * yacc.mk: do .y.h and .y.c separately
+
+2011-06-04 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20110606
+ * don't store SRC_DIRDEPS in Makefile.depend* by default
+ not everyone needs it.
+
+2011-05-04 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20110505
+ first release including meta mode makefiles
+
+2011-05-02 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * meta.stage.mk: add STAGE_AS_SETS and stage_as
+ for things that need to be staged with different names.
+
+2011-05-01 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * meta.stage.mk: add notion of STAGE_SETS
+ so a makefile can stage to multiple dirs
+
+2011-04-03 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * rst2htm.mk: convert rst to s5 (slides) or plain html depending
+ on target name.
+
+2011-03-30 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20110330
+
+2011-03-29 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * sys.mk (_DEBUG_MAKE_FLAGS): use indirection so that DEBUG_MAKE_FLAGS0
+ can be used to debug level 0 only and DEBUG_MAKE_FLAGS for the rest.
+ * sys.mk: re-define M_whence in terms of M_type.
+ M_type is useful for checking if something is a builtin.
+
+2011-03-16 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * meta.stage.mk: add stage_symlinks and leverage StageLinks for
+ stage_libs
+
+2011-03-10 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * dirdeps.mk: correct value for _depdir_files depends on
+ .MAKE.DEPENDFILE
+ Add our copyright - just to make it clear we have frobbed this
+ quite a bit.
+ DEP_MACHINE needs to be set to MACHINE each time, if using only
+ Makefile.depend (cf. Makefile.depend.${MACHINE})
+
+ * meta.stage.mk: meta mode version of staging
+
+ * init.mk, final.mk: include local.*.mk to simplify customization
+
+2011-03-03 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * auto.obj.mk: just because we are doing mk destroy, we should
+ still set .OBJDIR correctly if it exists.
+
+ * install-mk (mksrc): do not exclude meta.sys.mk
+
+2011-03-01 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * host-target.mk: set/export _HOST_ARCH etc separately,
+ catch junk resulting from uname -p, so we can find sys/Linux.mk
+ correctly.
+
+2011-02-18 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * meta.sys.mk: throw an error if /dev/filemon is missing and we
+ expected to be updating Makefile.depend*
+
+2011-02-14 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20110214
+ * meta.subdir.mk: add support for -DBOOTSTRAP_DEPENDFILES
+
+2010-09-25 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * meta.sys.mk: not valid for older bmake
+
+2010-09-24 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20100919
+ include dirdeps.mk et al from Juniper Networks,
+ for meta mode - requires filemon(9).
+ * sys.mk, subdir.mk: Add hooks for meta mode.
+ we do this as meta.sys.mk, meta.autodep.mk and meta.subdir.mk
+ to make turning it on/off simple.
+
+2010-06-16 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20100616
+ * fix typo in sys.mk
+
+2010-06-12 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20100612
+ * lib.mk: remove duplicate addition to SOBJS
+
+2010-06-10 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * sys.mk: Add a means of selectively turning on debug flags.
+ Eg. DEBUG_MAKE_FLAGS=-dv DEBUG_MAKE_DIRS="*lib/sjg"
+ will act as if we did make -dv if .CURDIR ends in lib/sjg
+ DEBUG_MAKE_SYS_DIRS does the same thing, but we set the flags at
+ the start of sys.mk rather than the end.
+ This only makes sense for leaf dirs, so we check that
+ .MAKE.LEVEL > 0
+
+2010-06-09 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20100608
+ * sys.mk: include sys.env.mk later so it can use M_ListToSkip et al.
+ * examples/sys.clean-env.mk: require MAKE_VERIONS >= 20100606
+ also make it easier for folk to tweak
+
+2010-06-08 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20100606
+ do not install examples/*
+ * FILES: add examples/sys.clean-env.mk
+ * examples/sys.clean-env.mk: use .export-env to handle MAKEOBJDIR
+ this requires bmake-20100606 or later to work.
+
+2010-05-13 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * sys.mk (M_tA): better simulate the result of :tA if not available.
+
+2010-05-04 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * sys.mk: canonicalize MAKE_VERSION
+ old versions reported bmake-<src-date> build-<build-date>
+ whereas we only care about <src-date>
+
+2010-04-25 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk: just warn about FORCE_{BSD,SYS}_MK being ignored
+ * lib.mk: we only build the shared lib if SHLIB_FULLVERSION
+ is !empty
+
+2010-04-22 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * dpadd.mk: use LDADD_* if defined.
+
+2010-04-21 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20100420
+ * sys/NetBSD.mk: add MACHINE_CPU to keep netbsd makefiles happy
+ * autoconf.mk allow AUTO_AUTOCONF
+
+2010-04-19 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * obj.mk: add objwarn to keep freebsd makefiles happy
+ * auto.obj.mk: ensure Mkdirs is available.
+ * FILES: add auto.dep.mk - a simpler version of autodep.mk
+ * dep.mk: auto.dep.mk does not do 'make depend' so ignore it if
+ asked to do that.
+ fix/simplify the tests for when to run mkdep.
+ * auto.dep.mk: add some explaination of how/what we do.
+ * autodep.mk: skip the .OPTIONAL frobbing of .depend
+ bmake's FROM_DEPEND flag makes it redundant.
+
+2010-04-13 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20100404
+ * subdir.mk: protect from multiple inclusion using _SUBDIRUSE.
+ * obj.mk: protect from multiple inclusion even as bsd.obj.mk
+ Also create a target _SUBDIRUSE so that we can be used without
+ subdir.mk
+
+2010-04-12 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * dep.mk: use <> when .including so can override.
+
+2010-01-11 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * lib.mk (SHLIB_LINKS): ensure a string comparison.
+
+2010-01-04 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20100102
+ * own.mk: ensure PRINTOBJDIR works
+ * autoconf.mk: pass on CONFIGURE_ARGS
+ * init.mk: handle COPTS.${.IMPSRC:T} etc.
+ * lib.mk: allow sys.mk to control SHLIB_FULLVERSION
+ fix handling of symlinks for darwin
+ * libnames.mk: add DSHLIBEXT for libs which only exist as shared.
+ * man.mk: suppress chown when not root.
+ * rst2htm.mk: allow srcs from multiple locations.
+ * sys.mk: M_whence, stop after 1st line of output.
+ * sys/Darwin.mk: Use .dylib for DSHLIBEXT and HOST_LIBEXT
+ * sys/SunOS.mk: we need to export PATH
+
+2009-12-23 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version
+ include rst2htm.mk
+
+2009-12-17 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * sys.mk,libnames.mk add .-include <local.*>
+ this allows local customization without the need to edit the
+ distributed files.
+
+2009-12-14 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * dpadd.mk (__dpadd_libdirs): order -L's to avoid picking up
+ older versions already installed.
+
+2009-12-13 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * stage.mk (.stage-install): generalize lib.mk's .libinstall
+ * rules.mk rules for generic Makefile.
+ * inc.mk install for includes.
+
+2009-12-11 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * sys/NetBSD.mk (MAKE_VERSION): some of our *.mk want to check
+ this, so provide it if using native make.
+
+2009-12-10 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * FILES: move all the platform *.sys.mk files to sys/*.mk
+ * Rename Generic.sys.mk to sys.mk - we always want it.
+
+2009-11-17 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version
+ * host-target.mk: only export the expensive stuff
+ * Generic.sys.mk (sys_mk): for SunOS we need to look for
+ ${HOST_OS}.${HOST_OSMAJOR} too!
+
+2009-11-07 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version
+ * lib.mk: if sys.mk doesn't give us an lorder, don't use it.
+ based on patch from Greg Olszewski.
+ * Generic.sys.mk: if we have nothing to work with
+ set LORDER etc only if we can find it.
+
+2009-09-08 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version
+ * man.mk: cleanman: remove CLEANMAN if defined.
+
+2009-09-04 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * SunOS.5.sys.mk (CC): Use ?= like the other *sys.mk
+
+2009-07-17 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version
+ include auto.obj.mk
+
+
+2009-03-26 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * prog.mk,lib.mk: ensure test of USE_DPADD_MK doesn't fail.
+
+2008-11-11 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version
+ man.mk: ensure we generate *.cat1 etc in .
+
+2008-07-16 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version
+ add prlist.mk
+
+2007-11-25 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * Generic.sys.mk: Allow os specific sys.mk to be in a
+ subdir of ${.PARSEDIR}
+
+2007-11-22 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version
+ * general cleanup
+ * dpadd.mk introduce DPMAGIC_LIBS_*
+
+2007-04-30 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version
+
+ * libs.mk, progs.mk, autodep.mk: allow for per lib/prog
+ depend files and ensure clean is called for each lib/prog.
+
+2007-03-27 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * autodep.mk (.depend): delete lines that do not start with
+ space and do not contain ':'
+
+2007-02-16 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * autodep.mk (.depend): gcc may wrap lines if pathnames are long
+ so make sure the transform for .OPTIONAL copes.
+
+2007-02-03 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version
+
+ * own.mk: make sure RM and LN are defined.
+
+ * obj.mk: fix a typo, and objlink target.
+
+2006-12-30 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version
+ * added libs.mk - analagous to progs.mk
+ make both of them always inlcude {lib,prog}.mk
+
+2006-12-28 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * progs.mk: add a means of building multiple apps in one dir.
+
+2006-11-26 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20061126
+
+ * warnings.mk: detect invalid WARNINGS_SET
+
+ * warnings.mk: use ${.TARGET:T:R}.o when looking for target
+ specific warnings.
+
+ * For .cc sources, turn off warnings that g++ vomits on.
+
+2006-11-08 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * own.mk: if __initialized__ target doesn't exist and we are
+ FreeBSD we got here directly from sys.mk
+
+2006-11-06 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20061106
+ add scripts.mk
+
+2006-03-18 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20060318
+
+ * autodep.mk: avoid := when modifying OBJS into __dependsrcs
+
+2006-03-02 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20060302
+ * autodep.mk: use -MF et al to help gcc+ccache DTRT.
+
+2006-03-01 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20060301
+ * autodep.mk (.depend):
+ if MAKE_VERSION is newer than 20050530 we can make .END depend on
+ .depend and make .depend depend on __depsrcs that exist.
+ * dpadd.mk: add SRC_PATHADD
+
+2005-11-04 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20051104
+ * prog.mk: remove all the LIBC?= junk, use
+ .-include libnames.mk instead (none by default).
+ also if USE_DPADD_MK is set, include that.
+
+2005-10-09 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20051001
+ Add UnixWare.sys.mk from Klaus Heinz.
+
+2005-04-05 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk: always install *.sys.mk and if need be symlink one
+ to sys.mk
+
+2005-03-22 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * subdir.mk, own.mk: use .MAKE rather than MAKE
+
+2004-02-15 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * own.mk: don't use NetBSD's _SRC_TOP_ it can
+ cause confusion. Also don't take just 'mk' as a
+ srctop indicator.
+
+2004-02-14 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * warnings.mk: overhauled, now very powerful.
+
+2004-02-03 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * Generic.sys.mk: need to use ${.PARSEDIR} with exists().
+
+2004-02-01 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): bump version to 20040201
+ * extract HOST_TARGET stuff to host-target.mk so own.mk and
+ Generic.sys.mk can share.
+ * fix typo in autodep.mk _SUBDIRUSE not _SUBDIR.
+
+2003-09-30 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): 20030930
+ * rename generic.sys.mk to Generic.sys.mk
+ so that it does not get installed (unless being used as sys.mk)
+ * set OS and ROOT_GROUP for those that we know the value.
+ for others (eg. Generic.sys.mk) wrap the != in an .ifndef so
+ we don't do it again for each sub-make.
+
+2003-09-28 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk (MK_VERSION): 20030928
+ Add some extra *.sys.mk from bootstrap-pkgsrc
+ some of these likely still need work.
+ Make everything default to root:wheel ownership,
+ sys.mk can set ROOT_GROUP accordingly.
+
+2003-08-07 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk: if FORCE_BSD_MK={cp,ln} use the ones in SYS_MK_DIR
+ not the portable ones.
+
+2003-07-31 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk: add ability to use cp -f when updating
+ destination .mk files. Also now possible to play games with
+ FORCE_SYS_MK=ln etc on *BSD machines to link /usr/share/mk/sys.mk
+ into dest - not recommended unless you seriously want to.
+
+2003-07-28 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * own.mk (IMPFLAGS): add support for COPTS.${IMPSRC:T} etc
+ for semi-compatability with NetBSD.
+
+2003-07-23 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * install-mk: add a version indicator
+
+2003-07-22 Simon J. Gerraty <sjg@void.crufty.net>
+
+ * prog.mk: don't try and use ${LIBCRT0} if its /dev/null
+
+ * install-mk: Allow FORCE_SYS_MK to come from env
+
+
+
diff --git a/contrib/bmake/mk/FILES b/contrib/bmake/mk/FILES
new file mode 100644
index 000000000000..7a2bf294e43f
--- /dev/null
+++ b/contrib/bmake/mk/FILES
@@ -0,0 +1,60 @@
+ChangeLog
+FILES
+README
+auto.obj.mk
+autoconf.mk
+autodep.mk
+auto.dep.mk
+dep.mk
+doc.mk
+dpadd.mk
+final.mk
+host-target.mk
+host.libnames.mk
+inc.mk
+init.mk
+install-mk
+java.mk
+lib.mk
+libnames.mk
+libs.mk
+links.mk
+man.mk
+mk-files.txt
+nls.mk
+obj.mk
+options.mk
+own.mk
+prlist.mk
+prog.mk
+progs.mk
+rst2htm.mk
+scripts.mk
+srctop.mk
+subdir.mk
+sys.mk
+sys.clean-env.mk
+sys.dependfile.mk
+sys/AIX.mk
+sys/Darwin.mk
+sys/Generic.mk
+sys/HP-UX.mk
+sys/IRIX.mk
+sys/Linux.mk
+sys/NetBSD.mk
+sys/OSF1.mk
+sys/OpenBSD.mk
+sys/SunOS.mk
+sys/UnixWare.mk
+target-flags.mk
+warnings.mk
+yacc.mk
+dirdeps.mk
+gendirdeps.mk
+install-new.mk
+meta2deps.py
+meta2deps.sh
+meta.sys.mk
+meta.autodep.mk
+meta.stage.mk
+meta.subdir.mk
diff --git a/contrib/bmake/mk/README b/contrib/bmake/mk/README
new file mode 100644
index 000000000000..3d79b6a2de7d
--- /dev/null
+++ b/contrib/bmake/mk/README
@@ -0,0 +1,401 @@
+# $Id: README,v 1.1 1997/03/11 07:27:15 sjg Exp $
+
+This directory contains some macro's derrived from the NetBSD bsd.*.mk
+macros. They have the same names but without the bsd., separate macro
+files are needed to ensure we can make them do what we want for
+builing things outside of /usr/src. Nearly all the comments below
+apply.
+
+# $NetBSD: bsd.README,v 1.18 1997/01/13 00:54:23 mark Exp $
+# @(#)bsd.README 5.1 (Berkeley) 5/11/90
+
+This is the README file for the new make "include" files for the BSD
+source tree. The files are installed in /usr/share/mk, and are, by
+convention, named with the suffix ".mk".
+
+Note, this file is not intended to replace reading through the .mk
+files for anything tricky.
+
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+RANDOM THINGS WORTH KNOWING:
+
+The files are simply C-style #include files, and pretty much behave like
+you'd expect. The syntax is slightly different in that a single '.' is
+used instead of the hash mark, i.e. ".include <bsd.prog.mk>".
+
+One difference that will save you lots of debugging time is that inclusion
+of the file is normally done at the *end* of the Makefile. The reason for
+this is because .mk files often modify variables and behavior based on the
+values of variables set in the Makefile. To make this work, remember that
+the FIRST target found is the target that is used, i.e. if the Makefile has:
+
+ a:
+ echo a
+ a:
+ echo a number two
+
+the command "make a" will echo "a". To make things confusing, the SECOND
+variable assignment is the overriding one, i.e. if the Makefile has:
+
+ a= foo
+ a= bar
+
+ b:
+ echo ${a}
+
+the command "make b" will echo "bar". This is for compatibility with the
+way the V7 make behaved.
+
+It's fairly difficult to make the BSD .mk files work when you're building
+multiple programs in a single directory. It's a lot easier split up the
+programs than to deal with the problem. Most of the agony comes from making
+the "obj" directory stuff work right, not because we switch to a new version
+of make. So, don't get mad at us, figure out a better way to handle multiple
+architectures so we can quit using the symbolic link stuff. (Imake doesn't
+count.)
+
+The file .depend in the source directory is expected to contain dependencies
+for the source files. This file is read automatically by make after reading
+the Makefile.
+
+The variable DESTDIR works as before. It's not set anywhere but will change
+the tree where the file gets installed.
+
+The profiled libraries are no longer built in a different directory than
+the regular libraries. A new suffix, ".po", is used to denote a profiled
+object.
+
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+The include file <sys.mk> has the default rules for all makes, in the BSD
+environment or otherwise. You probably don't want to touch this file.
+
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+The include file <bsd.man.mk> handles installing manual pages and their
+links.
+
+It has a single target:
+
+ maninstall:
+ Install the manual pages and their links.
+
+It sets/uses the following variables:
+
+MANDIR Base path for manual installation.
+
+MANGRP Manual group.
+
+MANOWN Manual owner.
+
+MANMODE Manual mode.
+
+MANSUBDIR Subdirectory under the manual page section, i.e. "/vax"
+ or "/tahoe" for machine specific manual pages.
+
+MAN The manual pages to be installed (use a .1 - .9 suffix).
+
+MLINKS List of manual page links (using a .1 - .9 suffix). The
+ linked-to file must come first, the linked file second,
+ and there may be multiple pairs. The files are soft-linked.
+
+The include file <bsd.man.mk> includes a file named "../Makefile.inc" if
+it exists.
+
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+The include file <bsd.own.mk> contains source tree configuration parameters,
+such as the owners, groups, etc. for both manual pages and binaries, and
+a few global "feature configuration" parameters.
+
+It has no targets.
+
+To get system-specific configuration parameters, bsd.own.mk will try to
+include the file specified by the "MAKECONF" variable. If MAKECONF is not
+set, or no such file exists, the system make configuration file, /etc/mk.conf
+is included. These files may define any of the variables described below.
+
+bsd.own.mk sets the following variables, if they are not already defined
+(defaults are in brackets):
+
+BSDSRCDIR The real path to the system sources, so that 'make obj'
+ will work correctly. [/usr/src]
+
+BSDOBJDIR The real path to the system 'obj' tree, so that 'make obj'
+ will work correctly. [/usr/obj]
+
+BINGRP Binary group. [bin]
+
+BINOWN Binary owner. [bin]
+
+BINMODE Binary mode. [555]
+
+NONBINMODE Mode for non-executable files. [444]
+
+MANDIR Base path for manual installation. [/usr/share/man/cat]
+
+MANGRP Manual group. [bin]
+
+MANOWN Manual owner. [bin]
+
+MANMODE Manual mode. [${NONBINMODE}]
+
+LIBDIR Base path for library installation. [/usr/lib]
+
+LINTLIBDIR Base path for lint(1) library installation. [/usr/libdata/lint]
+
+LIBGRP Library group. [${BINGRP}]
+
+LIBOWN Library owner. [${BINOWN}]
+
+LIBMODE Library mode. [${NONBINMODE}]
+
+DOCDIR Base path for system documentation (e.g. PSD, USD, etc.)
+ installation. [/usr/share/doc]
+
+DOCGRP Documentation group. [bin]
+
+DOCOWN Documentation owner. [bin]
+
+DOCMODE Documentation mode. [${NONBINMODE}]
+
+NLSDIR Base path for National Language Support files installation.
+ [/usr/share/nls]
+
+NLSGRP National Language Support files group. [bin]
+
+NLSOWN National Language Support files owner. [bin]
+
+NLSMODE National Language Support files mode. [${NONBINMODE}]
+
+STRIP The flag passed to the install program to cause the binary
+ to be stripped. This is to be used when building your
+ own install script so that the entire system can be made
+ stripped/not-stripped using a single knob. [-s]
+
+COPY The flag passed to the install program to cause the binary
+ to be copied rather than moved. This is to be used when
+ building our own install script so that the entire system
+ can either be installed with copies, or with moves using
+ a single knob. [-c]
+
+Additionally, the following variables may be set by bsd.own.mk or in a
+make configuration file to modify the behaviour of the system build
+process (default values are in brackets along with comments, if set by
+bsd.own.mk):
+
+EXPORTABLE_SYSTEM
+ Do not build /usr/src/domestic, even if it is present.
+
+SKEY Compile in support for S/key authentication. [yes, set
+ unconditionally]
+
+KERBEROS Compile in support for Kerberos 4 authentication.
+
+KERBEROS5 Compile in support for Kerberos 5 authentication.
+
+MANZ Compress manual pages at installation time.
+
+SYS_INCLUDE Copy or symlink kernel include files into /usr/include.
+ Possible values are "symlinks" or "copies" (which is
+ the same as the variable being unset).
+
+NOPROFILE Do not build profiled versions of system libraries
+
+NOPIC Do not build PIC versions of system libraries, and
+ do not build shared libraries. [set if ${MACHINE_ARCH}
+ is "mips", "vax", "alpha" or "arm32", unset otherwise.]
+
+NOLINT Do not build lint libraries. [set, set unconditionally]
+
+bsd.own.mk is generally useful when building your own Makefiles so that
+they use the same default owners etc. as the rest of the tree.
+
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+The include file <bsd.prog.mk> handles building programs from one or
+more source files, along with their manual pages. It has a limited number
+of suffixes, consistent with the current needs of the BSD tree.
+
+It has eight targets:
+
+ all:
+ build the program and its manual page
+ clean:
+ remove the program, any object files and the files a.out,
+ Errs, errs, mklog, and core.
+ cleandir:
+ remove all of the files removed by the target clean, as
+ well as .depend, tags, and any manual pages.
+ depend:
+ make the dependencies for the source files, and store
+ them in the file .depend.
+ includes:
+ install any header files.
+ install:
+ install the program and its manual pages; if the Makefile
+ does not itself define the target install, the targets
+ beforeinstall and afterinstall may also be used to cause
+ actions immediately before and after the install target
+ is executed.
+ lint:
+ run lint on the source files
+ tags:
+ create a tags file for the source files.
+
+It sets/uses the following variables:
+
+BINGRP Binary group.
+
+BINOWN Binary owner.
+
+BINMODE Binary mode.
+
+CLEANFILES Additional files to remove for the clean and cleandir targets.
+
+COPTS Additional flags to the compiler when creating C objects.
+
+HIDEGAME If HIDEGAME is defined, the binary is installed in
+ /usr/games/hide, and a symbolic link is created to
+ /usr/games/dm.
+
+LDADD Additional loader objects. Usually used for libraries.
+ For example, to load with the compatibility and utility
+ libraries, use:
+
+ LDADD+=-lutil -lcompat
+
+LDFLAGS Additional loader flags.
+
+LINKS The list of binary links; should be full pathnames, the
+ linked-to file coming first, followed by the linked
+ file. The files are hard-linked. For example, to link
+ /bin/test and /bin/[, use:
+
+ LINKS= ${DESTDIR}/bin/test ${DESTDIR}/bin/[
+
+MAN Manual pages (should end in .1 - .9). If no MAN variable is
+ defined, "MAN=${PROG}.1" is assumed.
+
+PROG The name of the program to build. If not supplied, nothing
+ is built.
+
+SRCS List of source files to build the program. If PROG is not
+ defined, it's assumed to be ${PROG}.c.
+
+DPADD Additional dependencies for the program. Usually used for
+ libraries. For example, to depend on the compatibility and
+ utility libraries use:
+
+ DPADD+=${LIBCOMPAT} ${LIBUTIL}
+
+ The following libraries are predefined for DPADD:
+
+ LIBC /lib/libc.a
+ LIBCOMPAT /usr/lib/libcompat.a
+ LIBCRYPT /usr/lib/libcrypt.a
+ LIBCURSES /usr/lib/libcurses.a
+ LIBDBM /usr/lib/libdbm.a
+ LIBDES /usr/lib/libdes.a
+ LIBL /usr/lib/libl.a
+ LIBKDB /usr/lib/libkdb.a
+ LIBKRB /usr/lib/libkrb.a
+ LIBKVM /usr/lib/libkvm.a
+ LIBM /usr/lib/libm.a
+ LIBMP /usr/lib/libmp.a
+ LIBPC /usr/lib/libpc.a
+ LIBPLOT /usr/lib/libplot.a
+ LIBRPC /usr/lib/sunrpc.a
+ LIBTERM /usr/lib/libterm.a
+ LIBUTIL /usr/lib/libutil.a
+
+SHAREDSTRINGS If defined, a new .c.o rule is used that results in shared
+ strings, using xstr(1). Note that this will not work with
+ parallel makes.
+
+STRIP The flag passed to the install program to cause the binary
+ to be stripped.
+
+SUBDIR A list of subdirectories that should be built as well.
+ Each of the targets will execute the same target in the
+ subdirectories.
+
+The include file <bsd.prog.mk> includes the file named "../Makefile.inc"
+if it exists, as well as the include file <bsd.man.mk>.
+
+Some simple examples:
+
+To build foo from foo.c with a manual page foo.1, use:
+
+ PROG= foo
+
+ .include <bsd.prog.mk>
+
+To build foo from foo.c with a manual page foo.2, add the line:
+
+ MAN= foo.2
+
+If foo does not have a manual page at all, add the line:
+
+ NOMAN= noman
+
+If foo has multiple source files, add the line:
+
+ SRCS= a.c b.c c.c d.c
+
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+The include file <bsd.subdir.mk> contains the default targets for building
+subdirectories. It has the same eight targets as <bsd.prog.mk>: all,
+clean, cleandir, depend, includes, install, lint, and tags. For all of
+the directories listed in the variable SUBDIRS, the specified directory
+will be visited and the target made. There is also a default target which
+allows the command "make subdir" where subdir is any directory listed in
+the variable SUBDIRS.
+
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+The include file <bsd.sys.mk> is used by <bsd.prog.mk> and
+<bsd.lib.mk>. It contains overrides that are used when building
+the NetBSD source tree. For instance, if "PARALLEL" is defined by
+the program/library Makefile, it includes a set of rules for lex and
+yacc that allow multiple lex and yacc targets to be built in parallel.
+
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+The include file <bsd.lib.mk> has support for building libraries. It has
+the same eight targets as <bsd.prog.mk>: all, clean, cleandir, depend,
+includes, install, lint, and tags. It has a limited number of suffixes,
+consistent with the current needs of the BSD tree.
+
+It sets/uses the following variables:
+
+LIB The name of the library to build.
+
+LIBDIR Target directory for libraries.
+
+LINTLIBDIR Target directory for lint libraries.
+
+LIBGRP Library group.
+
+LIBOWN Library owner.
+
+LIBMODE Library mode.
+
+LDADD Additional loader objects.
+
+MAN The manual pages to be installed (use a .1 - .9 suffix).
+
+SRCS List of source files to build the library. Suffix types
+ .s, .c, and .f are supported. Note, .s files are preferred
+ to .c files of the same name. (This is not the default for
+ versions of make.)
+
+The include file <bsd.lib.mk> includes the file named "../Makefile.inc"
+if it exists, as well as the include file <bsd.man.mk>.
+
+It has rules for building profiled objects; profiled libraries are
+built by default.
+
+Libraries are ranlib'd when made.
diff --git a/contrib/bmake/mk/auto.dep.mk b/contrib/bmake/mk/auto.dep.mk
new file mode 100644
index 000000000000..bb2d4c195a77
--- /dev/null
+++ b/contrib/bmake/mk/auto.dep.mk
@@ -0,0 +1,64 @@
+#
+# RCSid:
+# $Id: auto.dep.mk,v 1.2 2010/04/19 17:37:19 sjg Exp $
+#
+# @(#) Copyright (c) 2010, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+# This module provides automagic dependency generation along the
+# lines suggested in the GNU make.info
+
+# set MKDEP=auto.dep and dep.mk will include us
+
+# This version differs from autodep.mk, in that
+# we use ${.TARGET:T}.d rather than ${.TARGET:T:R}.d
+# this makes it simpler to get the args to -MF and -MT right
+# and ensure we can simply include all the .d files.
+#
+# However suffix rules do not work with something like .o.d so we
+# don't even try to handle 'make depend' gracefully.
+# dep.mk will handle that itself.
+#
+.if !target(__${.PARSEFILE}__)
+__${.PARSEFILE}__:
+
+# this what bmake > 20100401 will look for
+.MAKE.DEPENDFILE ?= .depend
+
+# set this to -MMD to ignore /usr/include
+# actually it ignores <> so may not be a great idea
+CFLAGS_MD ?= -MD
+# -MF etc not available on all gcc versions.
+CFLAGS_MF ?= -MF ${.TARGET:T}.d -MT ${.TARGET:T}
+CFLAGS += ${CFLAGS_MD} ${CFLAGS_MF}
+CXXFLAGS += ${CFLAGS_MD} ${CFLAGS_MF}
+
+CLEANFILES += .depend ${.MAKE.DEPENDFILE} *.d
+
+# skip generating dependfile for misc targets
+.if ${.TARGETS:Uall:M*all} != ""
+.END: ${.MAKE.DEPENDFILE}
+.endif
+
+# doing 'make depend' isn't a big win with this model
+.if !target(depend)
+depend: ${.MAKE.DEPENDFILE}
+.endif
+
+# this is trivial
+${.MAKE.DEPENDFILE}: ${OBJS} ${POBJS} ${SOBJS}
+ -@for f in ${.ALLSRC:M*o:T:O:u:%=%.d}; do \
+ echo ".-include \"$$f\""; \
+ done > $@
+
+.endif
diff --git a/contrib/bmake/mk/auto.obj.mk b/contrib/bmake/mk/auto.obj.mk
new file mode 100644
index 000000000000..adccd4b87c8c
--- /dev/null
+++ b/contrib/bmake/mk/auto.obj.mk
@@ -0,0 +1,56 @@
+# $Id: auto.obj.mk,v 1.8 2011/08/08 17:35:20 sjg Exp $
+#
+# @(#) Copyright (c) 2004, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+ECHO_TRACE ?= echo
+
+.ifndef Mkdirs
+# A race condition in some versions of mkdir, means that it can bail
+# if another process made a dir that mkdir expected to.
+# We repeat the mkdir -p a number of times to try and work around this.
+# We stop looping as soon as the dir exists.
+# If we get to the end of the loop, a plain mkdir will issue an error.
+Mkdirs= Mkdirs() { \
+ for d in $$*; do \
+ for i in 1 2 3 4 5 6; do \
+ mkdir -p $$d; \
+ test -d $$d && return 0; \
+ done > /dev/null 2>&1; \
+ mkdir $$d || exit $$?; \
+ done; }
+.endif
+
+# if MKOBJDIRS is set to auto (and NOOBJ isn't defined) do some magic...
+# This will automatically create objdirs as needed.
+# Skip it if we are just doing 'clean'.
+.if !defined(NOOBJ) && !defined(NO_OBJ) && ${MKOBJDIRS:Uno} == auto
+# Use __objdir here so it is easier to tweak without impacting
+# the logic.
+__objdir?= ${MAKEOBJDIR}
+.if ${.OBJDIR} != ${__objdir}
+# We need to chdir, make the directory if needed
+.if !exists(${__objdir}/) && \
+ (${.TARGETS} == "" || ${.TARGETS:Nclean*:N*clean:Ndestroy*} != "")
+# This will actually make it...
+__objdir_made != echo ${__objdir}/; umask ${OBJDIR_UMASK:U002}; \
+ ${ECHO_TRACE} "[Creating objdir ${__objdir}...]" >&2; \
+ ${Mkdirs}; Mkdirs ${__objdir}
+.endif
+# This causes make to use the specified directory as .OBJDIR
+.OBJDIR: ${__objdir}
+.if ${.OBJDIR} != ${__objdir} && ${__objdir_made:Uno:M${__objdir}/*} != ""
+.error could not use ${__objdir}
+.endif
+.endif
+.endif
diff --git a/contrib/bmake/mk/autoconf.mk b/contrib/bmake/mk/autoconf.mk
new file mode 100644
index 000000000000..573a7159957b
--- /dev/null
+++ b/contrib/bmake/mk/autoconf.mk
@@ -0,0 +1,78 @@
+# $Id: autoconf.mk,v 1.8 2012/11/19 05:37:48 sjg Exp $
+#
+# @(#) Copyright (c) 1996-2009, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+.NOPATH: config.h config.status
+
+.if !target(config.h)
+config.h: ${.CURDIR}/config.h.in config.status
+ ./config.status
+.endif
+
+.if !target(config.status)
+# avoid the targets behaving differently
+.if exists(${.OBJDIR}/config.status)
+config.status: config.recheck
+.else
+config.status: config.gen
+.endif
+
+config.recheck: config.h.in ${.CURDIR}/configure
+ ./config.status --recheck
+ @touch $@
+
+config.gen: config.h.in ${.CURDIR}/configure
+ CC="${CC} ${CCMODE}" ${.CURDIR}/configure --no-create ${CONFIGURE_ARGS}
+ @touch $@ config.recheck
+
+CLEANFILES+= config.recheck config.gen config.status *.meta
+.endif
+
+# avoid things blowing up if these are not here...
+# this is not quite per the autoconf manual,
+# and is extremely convoluted - but all utterly necessary!
+
+.if make(autoconf-in) || make(configure) || make(config.h.in) || ${AUTO_AUTOCONF:Uno:tl} == "yes"
+AUTOCONF ?= autoconf
+AUTOHEADER ?= autoheader
+
+# expand it to a full path
+AUTOCONF := ${AUTOCONF:${M_whence}}
+
+.if exists(${AUTOCONF})
+
+.PRECIOUS: configure config.h.in config.status
+
+ACLOCAL =
+ACCONFIG =
+
+.if exists(${.CURDIR}/aclocal.m4)
+ACLOCAL += aclocal.m4
+.endif
+# use of acconfig.h is deprecated!
+.if exists(${.CURDIR}/acconfig.h)
+ACCONFIG += acconfig.h
+.endif
+
+config.h.in: ${.CURDIR}/configure.in ${ACCONFIG}
+ (cd ${.CURDIR} && ${AUTOHEADER})
+
+configure: ${.CURDIR}/configure.in ${ACLOCAL}
+ (cd ${.CURDIR} && ${AUTOCONF})
+
+AUTOCONF_INPUTS += configure
+autoconf-input: ${AUTOCONF_INPUTS}
+
+.endif
+.endif
diff --git a/contrib/bmake/mk/autodep.mk b/contrib/bmake/mk/autodep.mk
new file mode 100644
index 000000000000..744770fe5a3c
--- /dev/null
+++ b/contrib/bmake/mk/autodep.mk
@@ -0,0 +1,216 @@
+#
+# RCSid:
+# $Id: autodep.mk,v 1.32 2010/04/19 17:37:56 sjg Exp $
+#
+# @(#) Copyright (c) 1999-2010, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+
+# This module provides automagic dependency generation along the
+# lines suggested in the GNU make.info
+# The depend target is mainly for backwards compatability,
+# dependencies are normally updated as part of compilation.
+
+# set MKDEP=autodep and dep.mk will include us
+.if !target(__${.PARSEFILE}__)
+__${.PARSEFILE}__:
+
+# different versions of bsd.dep.mk use these
+MKDEP=autodep
+MKDEPCMD=autodep
+
+DEPENDFILE?= .depend
+.for d in ${DEPENDFILE:N.depend}
+# bmake only groks .depend
+.-include "$d"
+.endfor
+
+# it does nothing if SRCS is not defined or is empty
+.if defined(SRCS) && !empty(SRCS)
+DEPSRCS?=${SRCS}
+__depsrcs=${DEPSRCS:M*.c}
+__depsrcs+=${DEPSRCS:M*.y}
+__depsrcs+=${DEPSRCS:M*.l}
+__depsrcs+=${DEPSRCS:M*.s}
+__depsrcs+=${DEPSRCS:M*.S}
+__depsrcs+=${DEPSRCS:M*.cc}
+__depsrcs+=${DEPSRCS:M*.cpp}
+__depsrcs+=${DEPSRCS:M*.C}
+__depsrcs+=${DEPSRCS:M*.cxx}
+__depsrcs+=${DEPSRCS:M*.pc}
+
+.for s in ${__depsrcs}
+${s:T:R}.d: $s
+.endfor
+
+__depsrcs:=${__depsrcs:T:R:S/$/.d/g}
+# we also need to handle makefiles where the .d's from __depsrcs
+# don't match those from OBJS
+# we avoid using := here, since the modifier applied to OBJS
+# can cause trouble if there are any undefined vars in OBJS.
+__dependsrcsx?= ${__depsrcs} ${OBJS:S/.o/.d/}
+__dependsrcs= ${__dependsrcsx:O:u}
+
+# clean up any .c files we may have generated
+#__gensrcs:= ${DEPSRCS:M*.y} ${DEPSRCS:M*.l}
+#CLEANFILES+= ${__gensrcs:T:R:S/$/.c/g}
+
+# set this to -MMD to ignore /usr/include
+# actually it ignores <> so may not be a great idea
+CFLAGS_MD?=-MD
+# -MF etc not available on all gcc versions.
+# we "fix" the .o later
+CFLAGS_MF?=-MF ${.TARGET:T:R}.d -MT ${.TARGET:T:R}.o
+CFLAGS+= ${CFLAGS_MD} ${CFLAGS_MF}
+RM?= rm
+
+# watch out for people who don't use CPPFLAGS
+CPPFLAGS_MD=${CFLAGS:M-[IUD]*} ${CPPFLAGS}
+CXXFLAGS_MD=${CXXFLAGS:M-[IUD]*} ${CPPFLAGS}
+
+# just in case these need to be different
+CC_MD?=${CC}
+CXX_MD?=${CXX}
+
+# so we can do an explicit make depend, but not otherwise
+.if make(depend)
+.SUFFIXES: .d
+
+.if empty(CFLAGS_MD)
+.y.d:
+ @echo updating dependencies for $<
+ @${YACC} ${YFLAGS} $<
+ @${SHELL} -ec "${CC_MD} -M ${CPPFLAGS_MD} y.tab.c | sed '/:/s/^/$@ /' > $@" || { ${RM} -f y.tab.c $@; false; }
+ @${RM} -f y.tab.c
+
+.l.d:
+ @echo updating dependencies for $<
+ ${LEX} ${LFLAGS} $<
+ @${SHELL} -ec "${CC_MD} -M ${CPPFLAGS_MD} lex.yy.c | sed '/:/s/^/$@ /' > $@" || { ${RM} -f lex.yy.c $@; false; }
+ @${RM} -f lex.yy.c
+
+.c.d:
+ @echo updating dependencies for $<
+ @${SHELL} -ec "${CC_MD} -M ${CPPFLAGS_MD} $< | sed '/:/s/^/$@ /' > $@" || { ${RM} -f $@; false; }
+
+.s.d .S.d:
+ @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:
+ @echo updating dependencies for $<
+ @${SHELL} -ec "${CXX_MD} -M ${CXXFLAGS_MD} $< | sed '/:/s/^/$@ /' > $@" || { ${RM} -f $@; false; }
+.else
+.y.d:
+ ${YACC} ${YFLAGS} $<
+ ${CC_MD} ${CFLAGS_MD:S/D//} ${CPPFLAGS_MD} y.tab.c > $@ || { ${RM} -f y.tab.c $@; false; }
+ ${RM} -f y.tab.c
+
+.l.d:
+ ${LEX} ${LFLAGS} $<
+ ${CC_MD} ${CFLAGS_MD:S/D//} ${CPPFLAGS_MD} lex.yy.c > $@ || { ${RM} -f lex.yy.c $@; false; }
+ ${RM} -f lex.yy.c
+
+.c.d:
+ ${CC_MD} ${CFLAGS_MD:S/D//} ${CPPFLAGS_MD} $< > $@ || { ${RM} -f $@; false; }
+
+.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_MD} ${CFLAGS_MD:S/D//} ${CXXFLAGS_MD} $< > $@ || { ${RM} -f $@; false; }
+.endif
+
+.if !target(depend)
+depend: beforedepend ${DEPENDFILE} afterdepend _SUBDIRUSE
+
+${DEPENDFILE}: ${DEPSRCS} ${__dependsrcs}
+.NOPATH: ${__dependsrcs}
+.OPTIONAL: ${__dependsrcs}
+.endif
+.endif # make(depend)
+
+.if empty(CFLAGS_MD)
+# make sure the .d's are generated/updated
+${PROG} ${_LIBS}: ${DEPENDFILE}
+.endif
+
+.ORDER: beforedepend ${DEPENDFILE} afterdepend
+
+.if ${.OBJDIR} != ${.CURDIR}
+__depfiles= *.d
+.else
+__depfiles= ${__dependsrcs}
+.endif
+
+DEPCLEANFILES= ${DEPENDFILE} ${__depfiles} y.tab.d *.tmp.d
+
+cleandir: cleanautodepend
+cleanautodepend:
+ ${RM} -f ${DEPCLEANFILES}
+
+CLEANFILES+= ${DEPCLEANFILES}
+
+.if defined(__dependsrcs) && !empty(__dependsrcs)
+.if make(depend) || !(make(clean*) || make(destroy*) || make(obj) || make(*install) || make(install-*))
+# this ensures we do the right thing if only building a shared or
+# profiled lib
+OBJ_EXTENSIONS?=.o .po .so .So
+MDLIB_SED= -e '/:/s,^\([^\.:]*\)\.[psS]*o,${OBJ_EXTENSIONS:S,^,\1,},'
+.ifdef NOMD_SED
+.ifdef LIB
+MD_SED=sed ${MDLIB_SED}
+.else
+MD_SED=cat
+.endif
+.else
+# arrange to put some variable names into ${DEPENDFILE}
+.ifdef LIB
+MD_SED=sed ${MDLIB_SED}
+.else
+MD_SED=sed
+.endif
+SUBST_DEPVARS+= SB TOP BACKING SRC SRCDIR BASE BASEDIR
+.for v in ${SUBST_DEPVARS}
+.if defined(${v}) && !empty(${v})
+MD_SED+= -e 's,${$v},$${$v},'
+.endif
+.endfor
+.endif
+.if (${MD_SED} == "sed")
+MD_SED=cat
+.endif
+
+# this will be done whenever make finishes successfully
+.if ${MAKE_VERSION:U0:[1]:C/.*-//} < 20050530
+.END:
+.else
+.END: ${DEPENDFILE}
+# we do not want to trigger building .d's just use them if they exist
+${DEPENDFILE}: ${__dependsrcs:@d@${exists($d):?$d:}@}
+.endif
+ -@${MD_SED} ${__depfiles} > ${DEPENDFILE}.new 2> /dev/null && \
+ test -s ${DEPENDFILE}.new && mv ${DEPENDFILE}.new ${DEPENDFILE}; \
+ ${RM} -f ${DEPENDFILE}.new
+.endif
+.endif
+.else
+depend: beforedepend afterdepend _SUBDIRUSE
+.endif
+
+.if !target(beforedepend)
+beforedepend:
+.endif
+.if !target(afterdepend)
+afterdepend:
+.endif
+
+.endif
diff --git a/contrib/bmake/mk/dep.mk b/contrib/bmake/mk/dep.mk
new file mode 100644
index 000000000000..b75450097277
--- /dev/null
+++ b/contrib/bmake/mk/dep.mk
@@ -0,0 +1,133 @@
+# $Id: dep.mk,v 1.16 2012/11/11 22:37:02 sjg Exp $
+
+.if !target(__${.PARSEFILE}__)
+__${.PARSEFILE}__:
+
+# handle Proc*C as well...
+.if defined(SRCS)
+.if !empty(SRCS:M*.pc)
+.include <proc.mk>
+.endif
+
+# it would be nice to be able to query .SUFFIXES
+OBJ_EXTENSIONS+= .o .po .lo .So
+
+# explicit dependencies help short-circuit .SUFFIX searches
+SRCS_DEP_FILTER+= N*.[hly]
+.for s in ${SRCS:${SRCS_DEP_FILTER:O:u:ts:}}
+.for e in ${OBJ_EXTENSIONS:O:u}
+.if !target(${s:T:R}$e)
+${s:T:R}$e: $s
+.endif
+.endfor
+.endfor
+.endif
+
+.if exists(/usr/bin/mkdep)
+MKDEP_CMD?= mkdep
+.elif exists(/usr/local/share/bin/mkdeps.sh)
+MKDEP_CMD?= /usr/local/share/bin/mkdeps.sh -N
+.endif
+MKDEP_CMD?= mkdep
+
+MKDEP ?= ${MKDEP_CMD}
+
+.NOPATH: .depend
+
+.if ${MKDEP} == "auto.dep" && make(depend)
+# auto.dep.mk does not "do" depend
+MK_AUTODEP= no
+.endif
+
+.if ${MK_AUTODEP} == yes
+.if ${MKDEP:T:S,auto,,} != ${MKDEP:T}
+.include <${MKDEP}.mk>
+.else
+.include <autodep.mk>
+.endif
+.else
+.if ${MKDEP:T:S,auto,,} != ${MKDEP:T}
+MKDEP = ${MKDEP_CMD}
+.endif
+MKDEP_ENV_VARS += CC CXX
+.for v in ${MKDEP_ENV_VARS:O:u}
+.if !empty($v)
+MKDEP_ENV += $v='${$v}'
+.endif
+.endfor
+
+_MKDEP = ${MKDEP_ENV} ${MKDEP}
+
+# some of the rules involve .h sources, so remove them from mkdep line
+.if !target(depend)
+depend: beforedepend .depend _SUBDIRUSE afterdepend
+
+.if defined(SRCS)
+# libs can have too many SRCS for a single command line
+# so do them one at a time.
+.depend: ${SRCS} ${.PARSEDIR}/${.PASEFILE}
+ @rm -f .depend
+.ifdef LIB
+ @files="${.ALLSRC:M*.[sS]}"; \
+ set -x; for f in $$files; do ${_MKDEP} -a ${MKDEPFLAGS} \
+ ${CFLAGS:M-[ID]*} ${CPPFLAGS} ${AINC} $$f; done
+ @files="${.ALLSRC:M*.c} ${.ALLSRC:M*.pc:T:.pc=.c}"; \
+ set -x; for f in $$files; do ${_MKDEP} -a ${MKDEPFLAGS} \
+ ${CFLAGS:M-[ID]*} ${CPPFLAGS} $$f; done
+ @files="${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cxx}"; \
+ set -x; for f in $$files; do ${_MKDEP} -a ${MKDEPFLAGS} \
+ ${CXXFLAGS:M-[ID]*} ${CPPFLAGS} $$f; done
+.else
+ @files="${.ALLSRC:M*.[Ss]}"; \
+ case "$$files" in *.[Ss]*) \
+ echo ${_MKDEP} -a ${MKDEPFLAGS} \
+ ${CFLAGS:M-[ID]*} ${CPPFLAGS} ${AINC} $$files; \
+ ${_MKDEP} -a ${MKDEPFLAGS} \
+ ${CFLAGS:M-[ID]*} ${CPPFLAGS} ${AINC} $$files;; \
+ esac
+ @files="${.ALLSRC:M*.c} ${.ALLSRC:M*.pc:T:.pc=.c}"; \
+ case "$$files" in *.c*) \
+ echo ${_MKDEP} -a ${MKDEPFLAGS} \
+ ${CFLAGS:M-[ID]*} ${CPPFLAGS} $$files; \
+ ${_MKDEP} -a ${MKDEPFLAGS} \
+ ${CFLAGS:M-[ID]*} ${CPPFLAGS} $$files;; \
+ esac
+ @files="${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cxx}"; \
+ case "$$files" in *.[Cc]*) \
+ echo ${_MKDEP} -a ${MKDEPFLAGS} \
+ ${CXXFLAGS:M-[ID]*} ${CPPFLAGS} $$files; \
+ ${_MKDEP} -a ${MKDEPFLAGS} \
+ ${CXXFLAGS:M-[ID]*} ${CPPFLAGS} $$files;; \
+ esac
+.endif
+.else
+.depend:
+.endif
+.if !target(beforedepend)
+beforedepend:
+.endif
+.if !target(afterdepend)
+afterdepend:
+.endif
+.endif
+.endif
+
+.if !target(tags)
+.if defined(SRCS)
+tags: ${SRCS} _SUBDIRUSE
+ -cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC:N*.h} | \
+ sed "s;\${.CURDIR}/;;" > tags
+.else
+tags:
+.endif
+.endif
+
+.if defined(SRCS)
+cleandir: cleandepend
+.if !target(cleandepend)
+cleandepend:
+ rm -f .depend ${.CURDIR}/tags
+.endif
+.endif
+
+.endif
diff --git a/contrib/bmake/mk/dirdeps.mk b/contrib/bmake/mk/dirdeps.mk
new file mode 100644
index 000000000000..9f051e9203e7
--- /dev/null
+++ b/contrib/bmake/mk/dirdeps.mk
@@ -0,0 +1,414 @@
+# $Id: dirdeps.mk,v 1.23 2012/11/06 05:44:03 sjg Exp $
+
+# Copyright (c) 2010-2012, Juniper Networks, Inc.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Much of the complexity here is for supporting cross-building.
+# If a tree does not support that, simply using plain Makefile.depend
+# should provide sufficient clue.
+# Otherwise the recommendation is to use Makefile.depend.${MACHINE}
+# as expected below.
+
+# Note: this file gets multiply included.
+# This is what we do with DIRDEPS
+
+# DIRDEPS:
+# This is a list of directories - relative to SRCTOP, it is only
+# of interest to .MAKE.LEVEL 0.
+# In some cases the entry may be qualified with a .<machine>
+# suffix, for example to force building something for the pseudo
+# machines "host" or "common" regardless of current ${MACHINE}.
+# All unqualified entries end up being qualified with .${MACHINE}
+# and _DIRDEPS_USE below, uses the suffix to set MACHINE
+# correctly when visiting each entry.
+#
+# Each entry is also converted into a set of paths to look for
+# Makefile.depend.<machine> to learn the dependencies of each.
+# Each Makefile.depend.<machine> sets DEP_RELDIR to be the
+# the RELDIR (path relative to SRCTOP) for its directory, and
+# DEP_MACHINE to its suffix (<machine>), further since
+# each Makefile.depend.<machine> 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).
+#
+# BUILD_AT_LEVEL0
+# Indicates whether .MAKE.LEVEL 0 builds anything:
+# if "no" sub-makes are used to build everything,
+# if "yes" sub-makes are only used to build for other machines.
+#
+# TARGET_SPEC_VARS
+# All the description above (and below) assumes <machine> is the
+# only data needed to control the build.
+# This is not always the case. So in addition to setting
+# MACHINE in the build environment we set TARGET_SPEC which is
+# composed of the values of TARGET_SPEC_VARS separated by
+# commas. The default is just MACHINE.
+#
+# If more that MACHINE is needed then sys.mk needs to decompose
+# TARGET_SPEC and set the relevant variables accordingly.
+# It is important that MACHINE be included in TARGET_SPEC_VARS
+# since if there is more the value passed as MACHINE will infact
+# be the TARGET_SPEC.
+# Note: TARGET_SPEC cannot contain any '.'s so the target
+# tripple used by compiler folk won't work (directly anyway).
+#
+# For example:
+#
+# # variables other than MACHINE might be optional
+# TARGET_SPEC_VARS = MACHINE TARGET_OS
+# .if ${TARGET_SPEC:Uno:M*,*} != ""
+# _tspec := ${TARGET_SPEC:S/,/ /g}
+# MACHINE := ${_tspec:[1]}
+# TARGET_OS := ${_tspec:[2]}
+# # etc.
+# .for v in ${TARGET_SPEC_VARS:O:u}
+# .if empty($v)
+# .undef $v
+# .endif
+# .endfor
+# .endif
+#
+
+.if ${.MAKE.LEVEL} == 0
+# 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)
+# do some setup we only need once
+_CURDIR ?= ${.CURDIR}
+
+# If TARGET_SPEC_VARS is other than just MACHINE
+# it should be set by sys.mk or similar by now.
+# TARGET_SPEC must not contain any '.'s.
+TARGET_SPEC_VARS ?= MACHINE
+TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,}
+
+.if !defined(.MAKE.DEPENDFILE_PREFERENCE)
+# this makes the logic below neater?
+.MAKE.DEPENDFILE_PREFERENCE = ${_CURDIR}/${.MAKE.DEPENDFILE:T}
+.if ${.MAKE.DEPENDFILE:E} == "${TARGET_SPEC}"
+.if ${TARGET_SPEC} != ${MACHINE}
+.MAKE.DEPENDFILE_PREFERENCE += ${_CURDIR}/${.MAKE.DEPENDFILE:T:R}.$${MACHINE}
+.endif
+.MAKE.DEPENDFILE_PREFERENCE += ${_CURDIR}/${.MAKE.DEPENDFILE:T:R}
+.endif
+.endif
+
+_default_dependfile := ${.MAKE.DEPENDFILE_PREFERENCE:[1]:T}
+_machine_dependfiles := ${.MAKE.DEPENDFILE_PREFERENCE:M*.${TARGET_SPEC}} \
+ ${.MAKE.DEPENDFILE_PREFERENCE:M*.${MACHINE}}
+
+# for machine specific dependfiles we require ${MACHINE} to be at the end
+# also for the sake of sanity we require a common prefix
+.if !defined(.MAKE.DEPENDFILE_PREFIX)
+.if !empty(_machine_dependfiles)
+.MAKE.DEPENDFILE_PREFIX := ${_machine_dependfiles:[1]:T:R}
+.else
+.MAKE.DEPENDFILE_PREFIX := ${_default_dependfile:T}
+.endif
+.endif
+
+
+# this is how we identify non-machine specific dependfiles
+N_notmachine := ${.MAKE.DEPENDFILE_PREFERENCE:E:N${TARGET_SPEC}:N${MACHINE}:${M_ListToSkip}}
+
+.endif # !target(_DIRDEP_USE)
+
+_last_dependfile := ${.MAKE.MAKEFILES:M*/${.MAKE.DEPENDFILE_PREFIX}*:[-1]}
+
+# Note: if a makefile is read many times, the above
+# will not work, so we also test for DEP_MACHINE==depend below.
+.if empty(_last_dependfile)
+# we haven't included one yet
+DEP_MACHINE ?= ${TARGET_MACHINE:U${TARGET_SPEC}}
+# else it should be correctly set by ${.MAKE.DEPENDFILE}
+.elif ${_last_dependfile:E:${N_notmachine}} == "" || ${DEP_MACHINE:Uno:${N_notmachine}} == ""
+# don't rely on manually maintained files to be correct
+DEP_MACHINE := ${_DEP_MACHINE:U${TARGET_SPEC}}
+.else
+# just in case
+DEP_MACHINE ?= ${_last_dependfile:E}
+.endif
+
+# 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)
+# make sure this target exists
+dirdeps:
+
+# We normally expect to be included by Makefile.depend.*
+# which sets the DEP_* macros below.
+DEP_RELDIR ?= ${RELDIR}
+
+# this can cause lots of output!
+# set to a set of glob expressions that might match RELDIR
+DEBUG_DIRDEPS ?= no
+
+# remember the initial value of DEP_RELDIR - we test for it below.
+_DEP_RELDIR := ${DEP_RELDIR}
+
+# things we skip for host tools
+SKIP_HOSTDIR ?=
+
+NSkipHostDir = ${SKIP_HOSTDIR:N*.host:S,$,.host,:N.host:${M_ListToSkip}}
+NSkipHostDep = ${SKIP_HOSTDIR:R:@d@*/$d*.host@:${M_ListToSkip}}
+
+# things we always skip
+# SKIP_DIRDEPS allows for adding entries on command line.
+SKIP_DIR += .host *.WAIT ${SKIP_DIRDEPS}
+
+.ifdef HOSTPROG
+SKIP_DIR += ${SKIP_HOSTDIR}
+.endif
+
+NSkipDir = ${SKIP_DIR:${M_ListToSkip}}
+
+.if defined(NO_DIRDEPS) || defined(NODIRDEPS)
+# confine ourselves to the original dir
+DIRDEPS_FILTER += M${_DEP_RELDIR}*
+.endif
+
+# we supress SUBDIR when visiting the leaves
+# we assume sys.mk will set MACHINE_ARCH
+_DIRDEP_USE: .USE .MAKE
+ @for m in ${.MAKE.MAKEFILE_PREFERENCE}; do \
+ test -s ${.TARGET:R}/$$m || continue; \
+ echo "${TRACER}Checking ${.TARGET:R} for ${.TARGET:E} ..."; \
+ TARGET_SPEC=${.TARGET:E} \
+ MACHINE=${.TARGET:E} MACHINE_ARCH= NO_SUBDIR=1 \
+ ${.MAKE} -C ${.TARGET:R} || exit 1; \
+ break; \
+ done
+
+.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(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
+.else
+_machine_list != 'ls' -1 ${_CURDIR}/${.MAKE.DEPENDFILE_PREFIX}.* 2> /dev/null; echo
+.endif
+_only_machines := ${_machine_list:${NIgnoreFiles:UN*.bak}:E:O:u}
+.else
+_only_machines := ${ONLY_MACHINE_LIST}
+.endif
+
+.if empty(_only_machines)
+# we must be boot-strapping
+_only_machines := ${TARGET_MACHINE:U${ALL_MACHINE_LIST:U${DEP_MACHINE}}}
+.endif
+
+.else # ! ALL_MACHINES
+# if ONLY_MACHINE_LIST is set, we are limited to that
+# 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_MACHINE_LIST:U${TARGET_MACHINE:U${DEP_MACHINE}}:M${DEP_MACHINE}}
+.endif
+
+.if !empty(NOT_MACHINE_LIST)
+_only_machines := ${_only_machines:${NOT_MACHINE_LIST:${M_ListToSkip}}}
+.endif
+
+# make sure we have a starting place?
+DIRDEPS ?= ${RELDIR}
+.endif # target
+
+_debug_reldir := ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.${DEP_MACHINE}:L:M$x}@}
+_debug_search := ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.depend:L:M$x}@}
+
+# the rest is done repeatedly for every Makefile.depend we read.
+# if we are anything but the original dir we care only about the
+# machine type we were included for..
+
+.if ${DEP_RELDIR} == "."
+_this_dir := ${SRCTOP}
+.else
+_this_dir := ${SRCTOP}/${DEP_RELDIR}
+.endif
+
+# on rare occasions, there can be a need for extra help
+_dep_hack := ${_this_dir}/${.MAKE.DEPENDFILE_PREFIX}.inc
+.-include "${_dep_hack}"
+
+.if ${DEP_RELDIR} != ${_DEP_RELDIR} || ${DEP_MACHINE} != ${TARGET_SPEC}
+# this should be all
+_machines := ${DEP_MACHINE}
+.else
+# this is the machine list we actually use below
+_machines := ${_only_machines}
+
+.if defined(HOSTPROG) || ${DEP_MACHINE} == "host"
+# we need to build this guy's dependencies for host as well.
+_machines += host
+.endif
+
+_machines := ${_machines:O:u}
+.endif
+
+# reset these each time through
+_build_dirs =
+_depdir_files =
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# pickup other machines for this dir if necessary
+.if ${BUILD_AT_LEVEL0:Uyes} == "no"
+_build_dirs += ${_machines:@m@${_CURDIR}.$m@}
+.else
+_build_dirs += ${_machines:N${DEP_MACHINE}:@m@${_CURDIR}.$m@}
+.if ${DEP_MACHINE} == ${TARGET_SPEC}
+# pickup local dependencies now
+.-include <.depend>
+.endif
+.endif
+.endif
+
+.if !empty(_debug_reldir)
+.info ${DEP_RELDIR}.${DEP_MACHINE}: _last_dependfile='${_last_dependfile}'
+.info ${DEP_RELDIR}.${DEP_MACHINE}: DIRDEPS='${DIRDEPS}'
+.info ${DEP_RELDIR}.${DEP_MACHINE}: _machines='${_machines}'
+.endif
+
+.if !empty(DIRDEPS)
+
+# this is what we start with
+__depdirs := ${DIRDEPS:${NSkipDir}:${DIRDEPS_FILTER:ts:}:O:u:@d@${SRCTOP}/$d@}
+
+# some entries may be qualified with .<machine>
+# the :M*/*/*.* just tries to limit the dirs we check to likely ones.
+# the ${d:E:M*/*} ensures we don't consider junos/usr.sbin/mgd
+__qual_depdirs := ${__depdirs:M*/*/*.*:@d@${exists($d):?:${"${d:E:M*/*}":?:${exists(${d:R}):?$d:}}}@}
+__unqual_depdirs := ${__depdirs:${__qual_depdirs:Uno:${M_ListToSkip}}}
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# if it was called out - we likely need it.
+__hostdpadd := ${DPADD:U.:M${HOST_OBJTOP}/*:S,${HOST_OBJTOP}/,,:H:${NSkipDir}:${DIRDEPS_FILTER:ts:}:S,$,.host,:N.*:@d@${SRCTOP}/$d@}
+__qual_depdirs += ${__hostdpadd}
+.endif
+
+.if !empty(_debug_reldir)
+.info depdirs=${__depdirs}
+.info qualified=${__qual_depdirs}
+.info unqualified=${__unqual_depdirs}
+.endif
+
+# _build_dirs is what we will feed to _DIRDEP_USE
+_build_dirs += \
+ ${__qual_depdirs:M*.host:${NSkipHostDir}:N.host} \
+ ${__qual_depdirs:N*.host} \
+ ${_machines:@m@${__unqual_depdirs:@d@$d.$m@}@}
+
+_build_dirs := ${_build_dirs:O:u}
+
+# this is where we will pick up more dependencies from
+# the inner inline loops look complex, but save a significant
+# amount of memory compared to a .for loop.
+_depdir_files =
+.for d in ${_build_dirs}
+.if exists($d)
+# easy, we're building for ${MACHINE}
+_depdir_files += ${.MAKE.DEPENDFILE_PREFERENCE:T:@m@${exists($d/$m):?$d/$m:}@:[1]}
+.elif exists(${d:R}) && ${d:R:T} == ${d:T:R}
+# a little more complex - building for another machine
+# we will ensure the file is qualified with a machine
+# so that if necessary _DEP_MACHINE can be set below
+_depdir_files += ${.MAKE.DEPENDFILE_PREFERENCE:T:S,.${TARGET_SPEC}$,.${d:E},:S,.${MACHINE}$,.${d:E},:@m@${exists(${d:R}/$m):?${d:R}/$m:}@:[1]:@m@${"${m:M*.${d:E}}":?$m:$m.${d:E}}@}
+.endif
+.endfor
+
+# clean up
+_depdir_files := ${_depdir_files:O:u}
+
+.endif # empty DIRDEPS
+
+# 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)
+# this makes it all happen
+dirdeps: ${_build_dirs}
+${_build_dirs}: _DIRDEP_USE
+
+.if !empty(_debug_reldir)
+.info ${DEP_RELDIR}.${DEP_MACHINE}: ${_build_dirs}
+.endif
+
+.for m in ${_machines}
+# it would be nice to do :N${.TARGET}
+.if !empty(__qual_depdirs)
+.for q in ${__qual_depdirs:E:O:u:N$m}
+.if !empty(_debug_reldir) || ${DEBUG_DIRDEPS:@x@${${DEP_RELDIR}.$m:L:M$x}${${DEP_RELDIR}.$q:L:M$x}@} != ""
+.info ${DEP_RELDIR}.$m: ${_build_dirs:M*.$q}
+.endif
+${_this_dir}.$m: ${_build_dirs:M*.$q}
+.endfor
+.endif
+.if !empty(_debug_reldir)
+.info ${DEP_RELDIR}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m}
+.endif
+${_this_dir}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m}
+.endfor
+
+.endif
+
+.for d in ${_depdir_files}
+.if ${.MAKE.MAKEFILES:M${d}} == ""
+.if !empty(_debug_search)
+.info Looking for $d
+.endif
+.if exists($d)
+.include <$d>
+.elif exists(${d:R})
+# an unqualified file exists, we qualified it above so we can set _DEP_MACHINE
+# it might be manually maintained and shared by all machine types
+# tell it the machine we are interested in.
+_DEP_MACHINE := ${d:E}
+.if !empty(_debug_reldir)
+.info loading ${d:R} for ${_DEP_MACHINE}
+.endif
+# pretend we read $d, so we don't come by here again.
+.MAKE.MAKEFILES += $d
+.include <${d:R}>
+.endif
+.endif
+.endfor
+.endif # -V
+
+.elif ${.MAKE.LEVEL} > 42
+.error You should have stopped recursing by now.
+.else
+_DEP_RELDIR := ${DEP_RELDIR}
+# pickup local dependencies
+.-include <.depend>
+.endif
+
diff --git a/contrib/bmake/mk/doc.mk b/contrib/bmake/mk/doc.mk
new file mode 100644
index 000000000000..d496c42aeefb
--- /dev/null
+++ b/contrib/bmake/mk/doc.mk
@@ -0,0 +1,63 @@
+# $Id: doc.mk,v 1.4 2012/11/11 22:37:02 sjg Exp $
+
+.if !target(__${.PARSEFILE}__)
+__${.PARSEFILE}__:
+
+BIB?= bib
+EQN?= eqn
+GREMLIN?= grn
+GRIND?= vgrind -f
+INDXBIB?= indxbib
+PIC?= pic
+REFER?= refer
+ROFF?= groff -M/usr/share/tmac ${MACROS} ${PAGES}
+SOELIM?= soelim
+TBL?= tbl
+
+.PATH: ${.CURDIR}
+
+.if !target(all)
+.MAIN: all
+all: paper.ps
+.endif
+
+.if !target(paper.ps)
+paper.ps: ${SRCS}
+ ${ROFF} ${SRCS} > ${.TARGET}
+.endif
+
+.if !target(print)
+print: paper.ps
+ lpr -P${PRINTER} paper.ps
+.endif
+
+.if !target(manpages)
+manpages:
+.endif
+
+.if !target(obj)
+obj:
+.endif
+
+clean cleandir:
+ rm -f paper.* [eE]rrs mklog ${CLEANFILES}
+
+.if ${MK_DOC} == "no"
+install:
+.else
+FILES?= ${SRCS}
+install:
+ ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 444 \
+ Makefile ${FILES} ${EXTRA} ${DESTDIR}${BINDIR}/${DIR}
+.endif
+
+spell: ${SRCS}
+ spell ${SRCS} | sort | comm -23 - spell.ok > paper.spell
+
+BINDIR?= /usr/share/doc
+BINGRP?= bin
+BINOWN?= bin
+BINMODE?= 444
+
+.include <own.mk>
+.endif
diff --git a/contrib/bmake/mk/dpadd.mk b/contrib/bmake/mk/dpadd.mk
new file mode 100644
index 000000000000..a940b61c144c
--- /dev/null
+++ b/contrib/bmake/mk/dpadd.mk
@@ -0,0 +1,196 @@
+# $Id: dpadd.mk,v 1.18 2011/11/10 05:13:37 sjg Exp $
+#
+# @(#) Copyright (c) 2004, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+.if !target(__${.PARSEFILE}__)
+__${.PARSEFILE}__:
+
+# sometimes we play games with .CURDIR etc
+# _* hold the original values of .*
+_OBJDIR?= ${.OBJDIR}
+_CURDIR?= ${.CURDIR}
+
+# 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.*//}}
+.endfor
+
+# DPADD can contain things other than libs
+__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}}@}
+.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}
+
+# 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.
+
+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 seach 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}/,,}
+.endif
+RELTOP?= ${RELDIR:C,[^/]+,..,g}
+.endif
+RELOBJTOP?= ${OBJTOP}
+RELSRCTOP?= ${SRCTOP}
+
+.if !make(dpadd)
+.ifdef LIB
+# Each lib is its own src_lib, we want to include it in SRC_LIBS
+# so that the correct INCLUDES_* will be picked up automatically.
+SRC_LIBS+= ${_OBJDIR}/lib${LIB}.a
+.endif
+.endif
+
+#
+# This little bit of magic, assumes that SRC_libfoo will be
+# set if it cannot be correctly derrived from ${LIBFOO}
+# Note that SRC_libfoo and INCLUDES_libfoo should be named for the
+# actual libary name not the variable name that might refer to it.
+# 99% of the time the two are the same, but the DPADD logic
+# only has the libary name available, so stick to that.
+#
+
+SRC_LIBS?=
+__dpadd_libs += ${SRC_LIBS}
+DPMAGIC_LIBS += ${__dpadd_libs} \
+ ${__dpadd_libs:@d@${DPMAGIC_LIBS_${d:T:R}}@}
+
+.for __lib in ${DPMAGIC_LIBS:O:u}
+#
+# if SRC_libfoo is not set, then we assume that the srcdir corresponding
+# to where we found the library is correct.
+#
+SRC_${__lib:T:R} ?= ${__lib:H:S,${OBJTOP},${RELSRCTOP},}
+#
+# This is a no-brainer but just to be complete...
+#
+OBJ_${__lib:T:R} ?= ${__lib:H:S,${OBJTOP},${RELOBJTOP},}
+#
+# If INCLUDES_libfoo is not set, then we'll use ${SRC_libfoo}/h if it exists,
+# else just ${SRC_libfoo}.
+#
+INCLUDES_${__lib:T:R}?= -I${exists(${SRC_${__lib:T:R}}/h):?${SRC_${__lib:T:R}}/h:${SRC_${__lib:T:R}}}
+
+.endfor
+
+# Now for the bits we actually need
+__dpadd_incs=
+.for __lib in ${__dpadd_libs:u}
+.if (make(${PROG}_p) || defined(NEED_GPROF)) && exists(${__lib:R}_p.a)
+__ldadd=-l${__lib:T:R:S,lib,,}
+LDADD := ${LDADD:S,^${__ldadd}$,${__ldadd}_p,g}
+.endif
+
+#
+# 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
+
+#
+# eliminate any duplicates - but don't mess with the order
+# force evaluation now - to avoid giving make a headache
+#
+.for t in CFLAGS CXXFLAGS
+# avoid duplicates
+__$t_incs:=${$t:M-I*:O:u}
+.for i in ${__dpadd_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} != ""
+ @echo "${RELDIR}: ${DPADD:S,${OBJTOP}/,,}"
+.endif
+.endif
+.endif
+
+.ifdef SRC_PATHADD
+# We don't want to assume that we need to .PATH every element of
+# SRC_LIBS, but the Makefile cannot do
+# .PATH: ${SRC_libfoo}
+# since the value of SRC_libfoo must be available at the time .PATH:
+# is read - and we only just worked it out.
+# Further, they can't wait until after include of {lib,prog}.mk as
+# the .PATH is needed before then.
+# So we let the Makefile do
+# SRC_PATHADD+= ${SRC_libfoo}
+# and we defer the .PATH: until now so that SRC_libfoo will be available.
+.PATH: ${SRC_PATHADD}
+.endif
+
+.endif
diff --git a/contrib/bmake/mk/final.mk b/contrib/bmake/mk/final.mk
new file mode 100644
index 000000000000..5f4118993814
--- /dev/null
+++ b/contrib/bmake/mk/final.mk
@@ -0,0 +1,14 @@
+# $Id: final.mk,v 1.5 2011/03/11 05:22:38 sjg Exp $
+
+.if !target(__${.PARSEFILE}__)
+__${.PARSEFILE}__:
+
+# provide a hook for folk who want to do scary stuff
+.-include "${.CURDIR}/../Makefile-final.inc"
+
+.if !empty(STAGE)
+.-include <stage.mk>
+.endif
+
+.-include <local.final.mk>
+.endif
diff --git a/contrib/bmake/mk/gendirdeps.mk b/contrib/bmake/mk/gendirdeps.mk
new file mode 100644
index 000000000000..890f4956f38e
--- /dev/null
+++ b/contrib/bmake/mk/gendirdeps.mk
@@ -0,0 +1,301 @@
+# $Id: gendirdeps.mk,v 1.10 2012/06/30 00:37:50 sjg Exp $
+
+# Copyright (c) 2010, Juniper Networks, Inc.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#
+# This makefile [re]generates ${.MAKE.DEPENDFILE}
+#
+
+.include <install-new.mk>
+
+# Assumptions:
+# RELDIR is the relative path from ${SRCTOP} to ${_CURDIR}
+# (SRCTOP is ${SB}/src)
+# _CURDIR is the absolute version of ${.CURDIR}
+# _OBJDIR is the absolute version of ${.OBJDIR}
+# _objroot is realpath of ${_OBJTOP} without ${MACHINE}
+# this may be different from _OBJROOT if $SB/obj is a
+# symlink to another filesystem.
+# _objroot must be a prefix match for _objtop
+
+.MAIN: all
+
+# keep this simple
+.MAKE.MODE = compat
+
+all:
+
+_CURDIR ?= ${.CURDIR}
+_OBJDIR ?= ${.OBJDIR}
+_OBJTOP ?= ${OBJTOP}
+_OBJROOT ?= ${OBJROOT:U${_OBJTOP}}
+_objroot ?= ${_OBJROOT:tA}
+
+_this = ${.PARSEDIR}/${.PARSEFILE}
+
+# remember what to make
+_DEPENDFILE := ${_CURDIR}/${.MAKE.DEPENDFILE:T}
+
+# We do _not_ want to read our own output!
+.MAKE.DEPENDFILE = /dev/null
+
+# caller should have set this
+META_FILES ?= ${.MAKE.META.FILES}
+
+.if !empty(META_FILES)
+
+.if ${.MAKE.LEVEL} > 0 && !empty(GENDIRDEPS_FILTER)
+# so we can compare below
+.-include <${_DEPENDFILE}>
+# yes, I mean :U with no value
+_DIRDEPS := ${DIRDEPS:U:O:u}
+.endif
+
+META_FILES := ${META_FILES:T:O:u}
+.export META_FILES
+
+# pickup customizations
+.-include "local.gendirdeps.mk"
+
+# these are actually prefixes that we'll skip
+# they should all be absolute paths
+SKIP_GENDIRDEPS ?=
+.if !empty(SKIP_GENDIRDEPS)
+_skip_gendirdeps = egrep -v '^(${SKIP_GENDIRDEPS:O:u:ts|})' |
+.else
+_skip_gendirdeps =
+.endif
+
+# this (*should* be set in meta.sys.mk)
+# is the script that extracts what we want.
+META2DEPS ?= ${.PARSEDIR}/meta2deps.sh
+META2DEPS := ${META2DEPS}
+
+.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" && ${DEBUG_GENDIRDEPS:Uno:Mmeta2d*} != ""
+_time = time
+_sh_x = sh -x
+_py_d = -ddd
+.else
+_time =
+_sh_x =
+_py_d =
+.endif
+
+.if ${META2DEPS:E} == "py"
+# we can afford to do this all the time.
+DPDEPS ?= no
+META2DEPS_CMD = ${_time} ${PYTHON} ${META2DEPS} ${_py_d} \
+ -R ${RELDIR} -H ${HOST_TARGET} -O ${M2D_OBJROOT}
+.if ${DPDEPS:tl} != "no"
+META2DEPS_CMD += -D ${DPDEPS}
+.endif
+.if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} == ""
+# meta2deps.py only groks objroot
+# so we need to give it what it expects
+M2D_OBJROOT = ${OBJTOP}/
+# and tell it not to add machine qualifiers
+META2DEPS_ARGS += MACHINE=none
+.else
+.if defined(SB_OBJROOT)
+M2D_OBJROOT ?= ${SB_OBJROOT}
+.else
+M2D_OBJROOT = ${OBJTOP}/
+.endif
+.endif
+.if defined(SB_BACKING_SB)
+META2DEPS_CMD += -S ${SB_BACKING_SB}/src -O ${SB_BACKING_SB}/${SB_OBJPREFIX}
+.endif
+META2DEPS_FILTER = sed 's,^src:,${SRCTOP}/,;s,^\([^/]\),${OBJTOP}/\1,' |
+.elif ${META2DEPS:E} == "sh"
+META2DEPS_CMD = ${_time} ${_sh_x} ${META2DEPS} \
+ OBJTOP=${_objtop} SB_OBJROOT=${_objroot}
+.else
+META2DEPS_CMD ?= ${META2DEPS}
+.endif
+
+# we are only interested in the dirs
+# sepecifically those we read something from.
+# we canonicalize them to keep things simple
+# if we are using a split-fs sandbox, it gets a little messier.
+_objtop := ${_OBJTOP:tA}
+dir_list != cd ${_OBJDIR} && \
+ ${META2DEPS_CMD} MACHINE=${MACHINE} \
+ SRCTOP=${SRCTOP} RELDIR=${RELDIR} CURDIR=${_CURDIR} \
+ ${META2DEPS_ARGS} \
+ ${META_FILES:O:u} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \
+ sed 's,//*$$,,;s,\.${HOST_TARGET}$$,.host,'
+
+.if ${dir_list:M*ERROR\:*} != ""
+.warning ${dir_list:tW:C,.*(ERROR),\1,}
+.warning Skipping ${_DEPENDFILE:S,${SRCTOP}/,,}
+# we are not going to update anything
+.else
+
+.if !empty(DPADD)
+_nonlibs := ${DPADD:T:Nlib*:N*include}
+.if !empty(_nonlibs)
+dir_list += ${_nonlibs:@x@${DPADD:M*/$x}@:H:tA}
+.endif
+.endif
+
+# DIRDEPS represent things that had to have been built first
+# so they should all be undir OBJTOP.
+# Note that ${_OBJTOP}/bsd/include/machine will get reported
+# to us as $SRCTOP/bsd/sys/$MACHINE_ARCH/include meaning we
+# will want to visit bsd/include
+# so we add
+# ${"${dir_list:M*bsd/sys/${MACHINE_ARCH}/include}":?bsd/include:}
+# to GENDIRDEPS_DIR_LIST_XTRAS
+dirdep_list = \
+ ${dir_list:M${_objtop}*/*:C,${_objtop}[^/]*/,,} \
+ ${GENDIRDEPS_DIR_LIST_XTRAS}
+
+# anything we use from an object dir other than ours
+# needs to be qualified with its .<machine> suffix
+# (we used the pseudo machine "host" for the HOST_TARGET).
+qualdir_list = \
+ ${dir_list:M${_objroot}*/*/*:N${SRCTOP}*:N${_objtop}*:C,${_objroot}([^/]+)/(.*),\2.\1,:S,.${HOST_TARGET},.host,}
+
+.if ${_OBJROOT} != ${_objroot}
+dirdep_list += \
+ ${dir_list:M${_OBJTOP}*/*:C,${_OBJTOP}[^/]*/,,}
+
+qualdir_list += \
+ ${dir_list:M${_OBJROOT}*/*/*:N${SRCTOP}*:N${_OBJTOP}*:C,${_OBJROOT}([^/]+)/(.*),\2.\1,:S,.${HOST_TARGET},.host,}
+.endif
+
+dirdep_list := ${dirdep_list:O:u}
+qualdir_list := ${qualdir_list:O:u}
+
+DIRDEPS = \
+ ${dirdep_list:N${RELDIR}:N${RELDIR}/*} \
+ ${qualdir_list:N${RELDIR}.*:N${RELDIR}/*}
+
+# We only consider things below $RELDIR/ if they have a makefile.
+# This is the same test that _DIRDEPS_USE applies.
+# We have do a double test with dirdep_list as it _may_ contain
+# qualified dirs - if we got anything from a stage dir.
+# qualdir_list we know are all qualified.
+# It would be nice do peform this check for all of DIRDEPS,
+# but we cannot assume that all of the tree is present,
+# in fact we can only assume that RELDIR is.
+DIRDEPS += \
+ ${dirdep_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/$d/$m):?$d:${exists(${SRCTOP}/${d:R}/$m):?$d:}}@}@} \
+ ${qualdir_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/${d:R}/$m):?$d:}@}@}
+
+DIRDEPS := ${DIRDEPS:${GENDIRDEPS_FILTER:UNno:ts:}:O:u}
+
+.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != ""
+.info ${RELDIR}: dir_list='${dir_list}'
+.info ${RELDIR}: dirdep_list='${dirdep_list}'
+.info ${RELDIR}: qualdir_list='${qualdir_list}'
+.info ${RELDIR}: SKIP_GENDIRDEPS='${SKIP_GENDIRDEPS}'
+.info ${RELDIR}: GENDIRDEPS_FILTER='${GENDIRDEPS_FILTER}'
+.info ${RELDIR}: FORCE_DPADD='${DPADD}'
+.info ${RELDIR}: DIRDEPS='${DIRDEPS}'
+.endif
+
+# SRC_DIRDEPS is for checkout logic
+src_dirdep_list = \
+ ${dir_list:M${SRCTOP}/*:S,${SRCTOP}/,,}
+
+SRC_DIRDEPS = \
+ ${src_dirdep_list:N${RELDIR}:N${RELDIR}/*:C,(/h)/.*,,}
+
+SRC_DIRDEPS := ${SRC_DIRDEPS:${GENDIRDEPS_SRC_FILTER:UN/*:ts:}:O:u}
+
+# if you want to capture SRC_DIRDEPS in .MAKE.DEPENDFILE put
+# SRC_DIRDEPS_FILE = ${_DEPENDFILE}
+# in local.gendirdeps.mk
+.if ${SRC_DIRDEPS_FILE:Uno:tl} != "no"
+ECHO_SRC_DIRDEPS = echo 'SRC_DIRDEPS = \'; echo '${SRC_DIRDEPS:@d@ $d \\${.newline}@}'; echo;
+
+.if ${SRC_DIRDEPS_FILE:T} == ${_DEPENDFILE:T}
+_include_src_dirdeps = ${ECHO_SRC_DIRDEPS}
+.else
+all: ${SRC_DIRDEPS_FILE}
+.if !target(${SRC_DIRDEPS_FILE})
+${SRC_DIRDEPS_FILE}: ${META_FILES} ${_this} ${META2DEPS}
+ @(${ECHO_SRC_DIRDEPS}) > $@
+.endif
+.endif
+.endif
+_include_src_dirdeps ?=
+
+all: ${_DEPENDFILE}
+
+# if this is going to exist it would be there by now
+.if !exists(.depend)
+CAT_DEPEND = /dev/null
+.endif
+CAT_DEPEND ?= .depend
+
+.if !empty(_DIRDEPS) && ${DIRDEPS} != ${_DIRDEPS}
+# we may have changed a filter
+.PHONY: ${_DEPENDFILE}
+.endif
+
+# 'cat .depend' should suffice, but if we are mixing build modes
+# .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}
+ @(echo '# Autogenerated - do NOT edit!'; echo; \
+ echo 'DEP_RELDIR := $${_PARSEDIR:S,$${SRCTOP}/,,}'; echo; \
+ echo 'DEP_MACHINE := $${.PARSEFILE:E}'; echo; \
+ echo 'DIRDEPS = \'; \
+ echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \
+ ${_include_src_dirdeps} \
+ echo '.include <dirdeps.mk>'; \
+ echo; \
+ echo '.if $${DEP_RELDIR} == $${_DEP_RELDIR}'; \
+ echo '# local dependencies - needed for -jN in clean tree'; \
+ [ -s ${CAT_DEPEND} ] && { grep : ${CAT_DEPEND} | grep -v '[/\\]'; }; \
+ echo '.endif' ) | sed 's,_\([{(]\),$$\1,g' > $@.new${.MAKE.PID}
+ @${InstallNew}; InstallNew -s $@.new${.MAKE.PID}
+
+.endif # meta2deps failed
+.elif !empty(SUBDIR)
+
+DIRDEPS := ${SUBDIR:S,^,${RELDIR}/,:O:u}
+
+all: ${_DEPENDFILE}
+
+${_DEPENDFILE}: ${MAKEFILE} ${_this}
+ @(echo '# Autogenerated - do NOT edit!'; echo; \
+ echo 'DEP_RELDIR := $${_PARSEDIR:S,$${SRCTOP}/,,}'; echo; \
+ echo 'DEP_MACHINE := $${.PARSEFILE:E}'; echo; \
+ echo 'DIRDEPS = \'; \
+ echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \
+ echo '.include <dirdeps.mk>'; \
+ echo ) | sed 's,_\([{(]\),$$\1,g' > $@.new
+ @${InstallNew}; InstallNew $@.new
+
+.else
+
+# nothing to do
+all ${_DEPENDFILE}:
+
+.endif
+${_DEPENDFILE}: .PRECIOUS
diff --git a/contrib/bmake/mk/host-target.mk b/contrib/bmake/mk/host-target.mk
new file mode 100644
index 000000000000..c6d4562bf15a
--- /dev/null
+++ b/contrib/bmake/mk/host-target.mk
@@ -0,0 +1,31 @@
+# RCSid:
+# $Id: host-target.mk,v 1.6 2011/03/02 05:05:21 sjg Exp $
+
+# Host platform information; may be overridden
+.if !defined(_HOST_OSNAME)
+_HOST_OSNAME != uname -s
+.export _HOST_OSNAME
+.endif
+.if !defined(_HOST_OSREL)
+_HOST_OSREL != uname -r
+.export _HOST_OSREL
+.endif
+.if !defined(_HOST_ARCH)
+_HOST_ARCH != uname -p 2>/dev/null || uname -m
+# uname -p may produce garbage on linux
+.if ${_HOST_ARCH:[\#]} > 1
+_HOST_ARCH != uname -m
+.endif
+.export _HOST_ARCH
+.endif
+
+HOST_OSMAJOR := ${_HOST_OSREL:C/[^0-9].*//}
+HOST_OSTYPE := ${_HOST_OSNAME}-${_HOST_OSREL:C/\([^\)]*\)//}-${_HOST_ARCH}
+HOST_OS := ${_HOST_OSNAME}
+host_os := ${_HOST_OSNAME:tl}
+HOST_TARGET := ${host_os}${HOST_OSMAJOR}-${_HOST_ARCH}
+
+# tr is insanely non-portable, accommodate the lowest common denominator
+TR ?= tr
+toLower = ${TR} 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'
+toUpper = ${TR} 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
diff --git a/contrib/bmake/mk/host.libnames.mk b/contrib/bmake/mk/host.libnames.mk
new file mode 100644
index 000000000000..c0a13d756d16
--- /dev/null
+++ b/contrib/bmake/mk/host.libnames.mk
@@ -0,0 +1,29 @@
+# $Id: host.libnames.mk,v 1.4 2010/01/11 23:01:31 sjg Exp $
+#
+# @(#) Copyright (c) 2007-2009, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+
+DLIBEXT ?= .a
+DSHLIBEXT ?= ${DLIBEXT}
+HOST_LIBEXT ?= ${DSHLIBEXT}
+HOST_LIBDIRS ?= /usr/lib /lib
+HOST_LIBS ?=
+
+.for x in ${HOST_LIBS:O:u}
+.for d in ${HOST_LIBDIRS}
+.if exists($d/lib$x${HOST_LIBEXT})
+LIB${x:tu} ?= $d/lib$x${HOST_LIBEXT}
+.endif
+.endfor
+.endfor
diff --git a/contrib/bmake/mk/inc.mk b/contrib/bmake/mk/inc.mk
new file mode 100644
index 000000000000..5d57f527167d
--- /dev/null
+++ b/contrib/bmake/mk/inc.mk
@@ -0,0 +1,35 @@
+# $Id: inc.mk,v 1.3 2011/03/11 05:23:05 sjg Exp $
+#
+# @(#) Copyright (c) 2008, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+.include <init.mk>
+
+includes: ${INCS}
+
+.if !empty(LIBOWN)
+INC_INSTALL_OWN ?= -o ${LIBOWN} -g ${LIBGRP}
+.endif
+INCMODE ?= 444
+INC_COPY ?= -C
+INCSDIR ?= ${INCDIR}
+
+realinstall: incinstall
+.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}
+.endif
+.endif
diff --git a/contrib/bmake/mk/init.mk b/contrib/bmake/mk/init.mk
new file mode 100644
index 000000000000..ed63fe6f1a5f
--- /dev/null
+++ b/contrib/bmake/mk/init.mk
@@ -0,0 +1,44 @@
+# $Id: init.mk,v 1.8 2012/11/11 22:37:02 sjg Exp $
+#
+# @(#) Copyright (c) 2002, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+.if !target(__${.PARSEFILE}__)
+__${.PARSEFILE}__:
+
+.if ${MAKE_VERSION:U0} > 20100408
+_this_mk_dir := ${.PARSEDIR:tA}
+.else
+_this_mk_dir := ${.PARSEDIR}
+.endif
+
+.-include <local.init.mk>
+.-include "${.CURDIR:H}/Makefile.inc"
+.include <own.mk>
+
+.MAIN: all
+
+.if !empty(WARNINGS_SET) || !empty(WARNINGS_SET_${MACHINE_ARCH})
+.include <warnings.mk>
+.endif
+
+COPTS += ${COPTS.${.IMPSRC:T}}
+CPPFLAGS += ${CPPFLAGS.${.IMPSRC:T}}
+CPUFLAGS += ${CPUFLAGS.${.IMPSRC:T}}
+
+.if ${.MAKE.LEVEL:U1} == 0 && ${BUILD_AT_LEVEL0:Uyes:tl} == "no"
+# this tells lib.mk and prog.mk to not actually build anything
+_SKIP_BUILD = not building at level 0
+.endif
+
+.endif
diff --git a/contrib/bmake/mk/install-mk b/contrib/bmake/mk/install-mk
new file mode 100644
index 000000000000..7dea1fc33df3
--- /dev/null
+++ b/contrib/bmake/mk/install-mk
@@ -0,0 +1,185 @@
+:
+# NAME:
+# install-mk - install mk files
+#
+# SYNOPSIS:
+# install-mk [options] [var=val] [dest]
+#
+# DESCRIPTION:
+# This tool installs mk files in a semi-intelligent manner into
+# "dest".
+#
+# Options:
+#
+# -n just say what we want to do, but don't touch anything.
+#
+# -f use -f when copying sys,mk.
+#
+# -v be verbose
+#
+# -q be quiet
+#
+# -m "mode"
+# Use "mode" for installed files (444).
+#
+# -o "owner"
+# Use "owner" for installed files.
+#
+# -g "group"
+# Use "group" for installed files.
+#
+# var=val
+# Set "var" to "val". See below.
+#
+# All our *.mk files are copied to "dest" with appropriate
+# ownership and permissions.
+#
+# By default if a sys.mk can be found in a standard location
+# (that bmake will find) then no sys.mk will be put in "dest".
+#
+# SKIP_SYS_MK:
+# If set, we will avoid installing our 'sys.mk'
+# This is probably a bad idea.
+#
+# SKIP_BSD_MK:
+# If set, we will skip making bsd.*.mk links to *.mk
+#
+# sys.mk:
+#
+# By default (and provided we are not installing to the system
+# mk dir - '/usr/share/mk') we install our own 'sys.mk' which
+# includes a sys specific file, or a generic one.
+#
+#
+# AUTHOR:
+# Simon J. Gerraty <sjg@crufty.net>
+
+# RCSid:
+# $Id: install-mk,v 1.83 2013/01/24 01:02:23 sjg Exp $
+#
+# @(#) Copyright (c) 1994 Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+MK_VERSION=20130123
+OWNER=
+GROUP=
+MODE=444
+BINMODE=555
+ECHO=:
+SKIP=
+cp_f=-f
+
+while :
+do
+ case "$1" in
+ *=*) eval "$1"; shift;;
+ +f) cp_f=; shift;;
+ -f) cp_f=-f; shift;;
+ -m) MODE=$2; shift 2;;
+ -o) OWNER=$2; shift 2;;
+ -g) GROUP=$2; shift 2;;
+ -v) ECHO=echo; shift;;
+ -q) ECHO=:; shift;;
+ -n) ECHO=echo SKIP=:; shift;;
+ --) shift; break;;
+ *) break;;
+ esac
+done
+
+case $# in
+0) echo "$0 [options] <destination> [<os>]"
+ echo "eg."
+ echo "$0 -o bin -g bin -m 444 /usr/local/share/mk"
+ exit 1
+ ;;
+esac
+dest=$1
+os=${2:-`uname`}
+osrel=${3:-`uname -r`}
+
+Do() {
+ $ECHO "$@"
+ $SKIP "$@"
+}
+
+Error() {
+ echo "ERROR: $@" >&2
+ exit 1
+}
+
+Warning() {
+ echo "WARNING: $@" >&2
+}
+
+[ "$FORCE_SYS_MK" ] && Warning "ignoring: FORCE_{BSD,SYS}_MK (no longer supported)"
+
+SYS_MK_DIR=${SYS_MK_DIR:-/usr/share/mk}
+SYS_MK=${SYS_MK:-$SYS_MK_DIR/sys.mk}
+
+realpath() {
+ [ -d $1 ] && cd $1 && 'pwd' && return
+ echo $1
+}
+
+if [ -s $SYS_MK -a -d $dest ]; then
+ # if this is a BSD system we don't want to touch $SYS_MK
+ dest=`realpath $dest`
+ sys_mk_dir=`realpath $SYS_MK_DIR`
+ if [ $dest = $sys_mk_dir ]; then
+ case "$os" in
+ *BSD*) SKIP_SYS_MK=:
+ SKIP_BSD_MK=:
+ ;;
+ *) # could be fake?
+ if [ ! -d $dest/sys -a ! -s $dest/Generic.sys.mk ]; then
+ SKIP_SYS_MK=: # play safe
+ SKIP_BSD_MK=:
+ fi
+ ;;
+ esac
+ fi
+fi
+
+[ -d $dest/sys ] || Do mkdir -p $dest/sys
+[ -d $dest/sys ] || Do mkdir $dest/sys || exit 1
+[ -z "$SKIP" ] && dest=`realpath $dest`
+
+cd `dirname $0`
+mksrc=`'pwd'`
+if [ $mksrc = $dest ]; then
+ SKIP_MKFILES=:
+else
+ # we do not install the examples
+ mk_files=`grep '^[a-z].*\.mk' FILES | egrep -v '(examples/|^sys\.mk|sys/)'`
+ mk_scripts=`egrep '^[a-z].*\.(sh|py)' FILES | egrep -v '/'`
+ sys_mk_files=`grep 'sys/.*\.mk' FILES`
+ SKIP_MKFILES=
+ [ -z "$SKIP_SYS_MK" ] && mk_files="sys.mk $mk_files"
+fi
+$SKIP_MKFILES Do cp $cp_f $mk_files $dest
+$SKIP_MKFILES Do cp $cp_f $sys_mk_files $dest/sys
+$SKIP_MKFILES Do cp $cp_f $mk_scripts $dest
+$SKIP cd $dest
+$SKIP_MKFILES Do chmod $MODE $mk_files $sys_mk_files
+$SKIP_MKFILES Do chmod $BINMODE $mk_scripts
+[ "$GROUP" ] && $SKIP_MKFILES Do chgrp $GROUP $mk_files $sys_mk_files
+[ "$OWNER" ] && $SKIP_MKFILES Do chown $OWNER $mk_files $sys_mk_files
+# if this is a BSD system the bsd.*.mk should exist and be used.
+if [ -z "$SKIP_BSD_MK" ]; then
+ for f in dep doc init lib links man nls obj own prog subdir
+ do
+ b=bsd.$f.mk
+ [ -s $b ] || Do ln -s $f.mk $b
+ done
+fi
+exit 0
diff --git a/contrib/bmake/mk/install-new.mk b/contrib/bmake/mk/install-new.mk
new file mode 100644
index 000000000000..ddfff20e3b85
--- /dev/null
+++ b/contrib/bmake/mk/install-new.mk
@@ -0,0 +1,53 @@
+# $Id: install-new.mk,v 1.3 2012/03/24 18:25:49 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@crufty.net
+#
+
+.if !defined(InstallNew)
+
+# copy if src and target are different making a backup if desired
+CmpCp= CmpCp() { \
+ src=$$1 target=$$2 _bak=$$3; \
+ if ! test -s $$target || ! cmp -s $$target $$src; then \
+ trap "" 1 2 3 15; \
+ if test -s $$target; then \
+ if test "x$$_bak" != x; then \
+ rm -f $$target$$_bak; \
+ mv $$target $$target$$_bak; \
+ else \
+ rm -f $$target; \
+ fi; \
+ fi; \
+ cp $$src $$target; \
+ fi; }
+
+# If the .new file is different, we want it.
+# Note: this function will work as is for *.new$RANDOM"
+InstallNew= ${CmpCp}; InstallNew() { \
+ _t=-e; _bak=; \
+ while :; do \
+ case "$$1" in \
+ -?) _t=$$1; shift;; \
+ --bak) _bak=$$2; shift 2;; \
+ *) break;; \
+ esac; \
+ done; \
+ for new in "$$@"; do \
+ if test $$_t $$new; then \
+ target=`expr $$new : '\(.*\).new'`; \
+ CmpCp $$new $$target $$_bak; \
+ fi; \
+ rm -f $$new; \
+ done; :; }
+
+.endif
diff --git a/contrib/bmake/mk/java.mk b/contrib/bmake/mk/java.mk
new file mode 100644
index 000000000000..ef4a5ea0ba10
--- /dev/null
+++ b/contrib/bmake/mk/java.mk
@@ -0,0 +1,97 @@
+#
+# RCSid:
+# $Id: java.mk,v 1.14 2007/11/22 08:16:25 sjg Exp $
+
+# @(#) Copyright (c) 1998-2001, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+.if !target(__${.PARSEFILE}__)
+__${.PARSEFILE}__:
+
+.include <init.mk>
+
+CLASSPATH?=.
+
+.if defined(PROG)
+SRCS?= ${PROG:.class=.java}
+.endif
+.if !defined(SRCS) || empty(SRCS)
+SRCS!=cd ${.CURDIR} && echo *.java
+.endif
+.SUFFIXES: .class .java
+
+CLEANFILES+= *.class
+
+JAVAC?= javac
+JAVADOC?= javadoc
+
+.if !target(docs)
+docs:
+ ${JAVADOC} ${JAVADOC_FLAGS} ${SRCS}
+.endif
+
+.if defined(JAVADESTDIR) && !empty(JAVADESTDIR)
+JAVASRCDIR?=${JAVADESTDIR:H}/src
+__classdest:=${JAVADESTDIR}${.CURDIR:S,${JAVASRCDIR},,}/
+CLASSPATH:=${CLASSPATH}:${JAVADESTDIR}
+JAVAC_FLAGS+= -d ${JAVADESTDIR}
+.else
+__classdest=
+.endif
+
+JAVAC_FLAGS+= ${JAVAC_DBG}
+
+.if defined(MAKE_VERSION) && !defined(NO_CLASSES_COOKIE)
+# java works best by compiling a bunch of classes at once.
+# this lot does that but needs a recent netbsd make or
+# or its portable cousin bmake.
+.for __s in ${SRCS}
+__c:= ${__classdest}${__s:.java=.class}
+.if !target(${__c})
+# We need to do something to force __c's parent to be made.
+${__c}: ${__s}
+ @rm -f ${.TARGET}
+.endif
+SRCS_${__c}=${__s}
+__classes:= ${__classes} ${__c}
+.endfor
+__classes_cookie=${__classdest}.classes.done
+CLEANFILES+= ${__classes} ${__classes_cookie}
+
+${__classes_cookie}: ${__classes}
+ CLASSPATH=${CLASSPATH} ${JAVAC} ${JAVAC_FLAGS} ${.OODATE:@c@${SRCS_$c}@}
+ @touch ${.TARGET}
+
+all: ${__classes_cookie}
+
+.else
+# this will work with other BSD make's
+.for __s in ${SRCS}
+__c:= ${__classdest}${__s:.java=.class}
+${__c}: ${__s}
+ CLASSPATH=${CLASSPATH} ${JAVAC} ${JAVAC_FLAGS} ${.OODATE}
+.endfor
+
+all: ${SRCS:%.java=${__classdest}%.class}
+
+.endif
+
+.if !target(cleanjava)
+cleanjava:
+ rm -f [Ee]rrs mklog core *.core ${PROG} ${CLEANFILES}
+
+clean: cleanjava
+cleandir: cleanjava
+.endif
+
+.endif
diff --git a/contrib/bmake/mk/lib.mk b/contrib/bmake/mk/lib.mk
new file mode 100644
index 000000000000..24f9527f003f
--- /dev/null
+++ b/contrib/bmake/mk/lib.mk
@@ -0,0 +1,605 @@
+# $Id: lib.mk,v 1.48 2012/11/12 04:08:18 sjg Exp $
+
+.if !target(__${.PARSEFILE}__)
+__${.PARSEFILE}__:
+
+.include <init.mk>
+
+.if ${OBJECT_FMT} == "ELF"
+NEED_SOLINKS?= yes
+.endif
+
+.if exists(${.CURDIR}/shlib_version)
+SHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major
+SHLIB_MINOR != . ${.CURDIR}/shlib_version ; echo $$minor
+.endif
+
+print-shlib-major:
+.if defined(SHLIB_MAJOR) && ${MK_PIC} != "no"
+ @echo ${SHLIB_MAJOR}
+.else
+ @false
+.endif
+
+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
+.SUFFIXES: .sh .m4 .m
+
+CFLAGS+= ${COPTS}
+
+# Derrived from NetBSD-1.6
+
+# Set PICFLAGS to cc flags for producing position-independent code,
+# if not already set. Includes -DPIC, if required.
+
+# Data-driven table using make variables to control how shared libraries
+# are built for different platforms and object formats.
+# OBJECT_FMT: currently either "ELF" or "a.out", from <bsd.own.mk>
+# SHLIB_SOVERSION: version number to be compiled into a shared library
+# via -soname. Usualy ${SHLIB_MAJOR} on ELF.
+# NetBSD/pmax used to use ${SHLIB_MAJOR}[.${SHLIB_MINOR}
+# [.${SHLIB_TEENY}]]
+# SHLIB_SHFLAGS: Flags to tell ${LD} to emit shared library.
+# 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.
+# CPPICFLAGS: flags for ${CPP} to preprocess .[sS] files for ${AS}
+# CPICFLAGS: flags for ${CC} to compile .[cC] files to .so objects.
+# CAPICFLAGS flags for {$CC} to compiling .[Ss] files
+# (usually just ${CPPPICFLAGS} ${CPICFLAGS})
+# APICFLAGS: flags for ${AS} to assemble .[sS] to .so objects.
+
+.if ${TARGET_OSNAME} == "NetBSD"
+.if ${MACHINE_ARCH} == "alpha"
+ # Alpha-specific shared library flags
+FPICFLAGS ?= -fPIC
+CPICFLAGS ?= -fPIC -DPIC
+CPPPICFLAGS?= -DPIC
+CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
+APICFLAGS ?=
+.elif ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb"
+ # mips-specific shared library flags
+
+# On mips, all libs are compiled with ABIcalls, not just sharedlibs.
+MKPICLIB= no
+
+# so turn shlib PIC flags on for ${AS}.
+AINC+=-DABICALLS
+AFLAGS+= -fPIC
+AS+= -KPIC
+
+.elif ${MACHINE_ARCH} == "vax" && ${OBJECT_FMT} == "ELF"
+# On the VAX, all object are PIC by default, not just sharedlibs.
+MKPICLIB= no
+
+.elif (${MACHINE_ARCH} == "sparc" || ${MACHINE_ARCH} == "sparc64") && \
+ ${OBJECT_FMT} == "ELF"
+# If you use -fPIC you need to define BIGPIC to turn on 32-bit
+# relocations in asm code
+FPICFLAGS ?= -fPIC
+CPICFLAGS ?= -fPIC -DPIC
+CPPPICFLAGS?= -DPIC -DBIGPIC
+CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
+APICFLAGS ?= -KPIC
+
+.else
+
+# Platform-independent flags for NetBSD a.out shared libraries
+SHLIB_SOVERSION=${SHLIB_FULLVERSION}
+SHLIB_SHFLAGS=
+FPICFLAGS ?= -fPIC
+CPICFLAGS?= -fPIC -DPIC
+CPPPICFLAGS?= -DPIC
+CAPICFLAGS?= ${CPPPICFLAGS} ${CPICFLAGS}
+APICFLAGS?= -k
+
+.endif
+
+# Platform-independent linker flags for ELF shared libraries
+.if ${OBJECT_FMT} == "ELF"
+SHLIB_SOVERSION= ${SHLIB_MAJOR}
+SHLIB_SHFLAGS= -soname lib${LIB}.so.${SHLIB_SOVERSION}
+SHLIB_LDSTARTFILE?= /usr/lib/crtbeginS.o
+SHLIB_LDENDFILE?= /usr/lib/crtendS.o
+.endif
+
+# for compatability with the following
+CC_PIC?= ${CPICFLAGS}
+LD_shared=${SHLIB_SHFLAGS}
+
+.endif # NetBSD
+
+.if ${TARGET_OSNAME} == "FreeBSD"
+.if ${OBJECT_FMT} == "ELF"
+SHLIB_SOVERSION= ${SHLIB_MAJOR}
+SHLIB_SHFLAGS= -soname lib${LIB}.so.${SHLIB_SOVERSION}
+.else
+SHLIB_SHFLAGS= -assert pure-text
+.endif
+SHLIB_LDSTARTFILE=
+SHLIB_LDENDFILE=
+CC_PIC?= -fpic
+LD_shared=${SHLIB_SHFLAGS}
+
+.endif # FreeBSD
+
+MKPICLIB?= yes
+
+# sys.mk can override these
+CC_PG?=-pg
+CC_PIC?=-DPIC
+
+LD_X?=-X
+LD_x?=-x
+LD_r?=-r
+
+# Non BSD machines will be using bmake.
+.if ${TARGET_OSNAME} == "SunOS"
+LD_shared=-assert pure-text
+.if ${OBJECT_FMT} == "ELF" || ${MACHINE} == "solaris"
+# Solaris
+LD_shared=-h lib${LIB}.so.${SHLIB_MAJOR} -G
+.endif
+.elif ${TARGET_OSNAME} == "HP-UX"
+LD_shared=-b
+LD_so=sl
+DLLIB=
+# HPsUX lorder does not grok anything but .o
+LD_sobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.so,'`
+LD_pobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.po,'`
+.elif ${TARGET_OSNAME} == "OSF1"
+LD_shared= -msym -shared -expect_unresolved '*'
+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_pobjs=`${LORDER} ${OBJS} | ${TSORT} | sed 's,\.o,.po,'`
+AR_cq= -cqs
+.elif ${TARGET_OSNAME} == "FreeBSD"
+LD_solib= lib${LIB}_pic.a
+.elif ${TARGET_OSNAME} == "Linux"
+# this is ambiguous of course
+LD_shared=-shared -h lib${LIB}.so.${SHLIB_MAJOR}
+LD_solib= --whole-archive lib${LIB}_pic.a
+# Linux uses GNU ld, which is a multi-pass linker
+# so we don't need to use lorder or tsort
+LD_objs = ${OBJS}
+LD_pobjs = ${POBJS}
+LD_sobjs = ${SOBJS}
+.elif ${TARGET_OSNAME} == "Darwin"
+SHLIB_LD = ${CC}
+SHLIB_INSTALL_VERSION ?= ${SHLIB_MAJOR}
+SHLIB_COMPATABILITY_VERSION ?= ${SHLIB_MAJOR}.${SHLIB_MINOR:U0}
+SHLIB_COMPATABILITY ?= \
+ -compatibility_version ${SHLIB_COMPATABILITY_VERSION} \
+ -current_version ${SHLIB_FULLVERSION}
+LD_shared = -dynamiclib \
+ -flat_namespace -undefined suppress \
+ -install_name ${LIBDIR}/lib${LIB}.${SHLIB_INSTALL_VERSION}.${LD_solink} \
+ ${SHLIB_COMPATABILITY}
+SHLIB_LINKS =
+.for v in ${SHLIB_COMPATABILITY_VERSION} ${SHLIB_INSTALL_VERSION}
+.if "$v" != "${SHLIB_FULLVERSION}"
+SHLIB_LINKS += lib${LIB}.$v.${LD_solink}
+.endif
+.endfor
+.if ${MK_LINKLIB} != "no"
+SHLIB_LINKS += lib${LIB}.${LD_solink}
+.endif
+
+LD_so = ${SHLIB_FULLVERSION}.dylib
+LD_sobjs = ${SOBJS:O:u}
+LD_solib = ${LD_sobjs}
+SOLIB = ${LD_sobjs}
+LD_solink = dylib
+.if ${MACHINE_ARCH} == "i386"
+PICFLAG ?= -fPIC
+.else
+PICFLAG ?= -fPIC -fno-common
+.endif
+RANLIB = :
+.endif
+
+SHLIB_LD ?= ${LD}
+
+.if !empty(SHLIB_MAJOR)
+.if ${NEED_SOLINKS} && empty(SHLIB_LINKS)
+.if ${MK_LINKLIB} != "no"
+SHLIB_LINKS = lib${LIB}.${LD_solink}
+.endif
+.if "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
+SHLIB_LINKS += lib${LIB}.${LD_solink}.${SHLIB_MAJOR}
+.endif
+.endif
+.endif
+
+LIBTOOL?=libtool
+LD_shared ?= -Bshareable -Bforcearchive
+LD_so ?= so.${SHLIB_FULLVERSION}
+LD_solink ?= so
+.if empty(LORDER)
+LD_objs ?= ${OBJS}
+LD_pobjs ?= ${POBJS}
+LD_sobjs ?= ${SOBJS}
+.else
+LD_objs ?= `${LORDER} ${OBJS} | ${TSORT}`
+LD_sobjs ?= `${LORDER} ${SOBJS} | ${TSORT}`
+LD_pobjs ?= `${LORDER} ${POBJS} | ${TSORT}`
+.endif
+LD_solib ?= ${LD_sobjs}
+AR_cq ?= cq
+.if exists(/netbsd) && exists(${DESTDIR}/usr/lib/libdl.so)
+DLLIB ?= -ldl
+.endif
+
+# some libs have lots of objects, and scanning all .o, .po and .So meta files
+# is a waste of time, this tells meta.autodep.mk to just pick one
+# (typically .So)
+# yes, 42 is a random number.
+.if ${MK_META_MODE} == "yes" && ${SRCS:Uno:[\#]} > 42
+OPTIMIZE_OBJECT_META_FILES ?= yes
+.endif
+
+
+.if ${MK_LIBTOOL} == "yes"
+# because libtool is so facist about naming the object files,
+# we cannot (yet) build profiled libs
+MK_PROFILE=no
+_LIBS=lib${LIB}.a
+.if exists(${.CURDIR}/shlib_version)
+SHLIB_AGE != . ${.CURDIR}/shlib_version ; echo $$age
+.endif
+.else
+# for the normal .a we do not want to strip symbols
+.c.o:
+ ${COMPILE.c} ${.IMPSRC}
+
+# for the normal .a we do not want to strip symbols
+.cc.o .C.o:
+ ${COMPILE.cc} ${.IMPSRC}
+
+.S.o .s.o:
+ @echo ${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
+ @${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
+
+.if (${LD_X} == "")
+.c.po:
+ ${COMPILE.c} ${CC_PG} ${.IMPSRC} -o ${.TARGET}
+
+.cc.po .C.po:
+ ${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}
+
+.S.so .s.so:
+ ${COMPILE.S} ${PICFLAG} ${CC_PIC} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
+.else
+.c.po:
+ @echo ${COMPILE.c} ${CC_PG} ${.IMPSRC} -o ${.TARGET}
+ @${COMPILE.c} ${CC_PG} ${.IMPSRC} -o ${.TARGET}.o
+ @${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
+ @rm -f ${.TARGET}.o
+
+.cc.po .C.po:
+ @echo ${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}
+ @${COMPILE.cc} -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}
+ @rm -f ${.TARGET}.o
+.endif
+
+.if (${LD_x} == "")
+.c.so:
+ ${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
+
+.cc.so .C.so:
+ ${COMPILE.cc} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
+
+.S.po .s.po:
+ ${COMPILE.S} -DGPROF -DPROF ${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}
+ @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}
+ @rm -f ${.TARGET}.o
+
+.S.po .s.po:
+ @echo ${COMPILE.S} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
+ @${COMPILE.S} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
+ @${LD} ${LD_X} ${LD_r} ${.TARGET}.o -o ${.TARGET}
+ @rm -f ${.TARGET}.o
+
+.endif
+.endif
+
+.c.ln:
+ ${LINT} ${LINTFLAGS} ${CFLAGS:M-[IDU]*} -i ${.IMPSRC}
+
+.if ${MK_LIBTOOL} != "yes"
+
+.if !defined(PICFLAG)
+PICFLAG=-fpic
+.endif
+
+_LIBS=
+
+.if ${MK_ARCHIVE} != "no"
+_LIBS += lib${LIB}.a
+.endif
+
+.if ${MK_PROFILE} != "no"
+_LIBS+=lib${LIB}_p.a
+POBJS+=${OBJS:.o=.po}
+.endif
+
+.if ${MK_PIC} != "no"
+.if ${MK_PICLIB} == "no"
+SOLIB ?= lib${LIB}.a
+.else
+SOLIB=lib${LIB}_pic.a
+_LIBS+=${SOLIB}
+.endif
+.if !empty(SHLIB_FULLVERSION)
+_LIBS+=lib${LIB}.${LD_so}
+.endif
+.endif
+
+.if ${MK_LINT} != "no"
+_LIBS+=llib-l${LIB}.ln
+.endif
+
+# here is where you can define what LIB* are
+.-include <libnames.mk>
+.if ${MK_DPADD_MK} == "yes"
+# lots of cool magic, but might not suit everyone.
+.include <dpadd.mk>
+.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:
+.endif
+.endif
+all: _SUBDIRUSE
+
+.for s in ${SRCS:N*.h:M*/*}
+${.o .so .po .lo:L:@o@${s:T:R}$o@}: $s
+.endfor
+
+OBJS+= ${SRCS:T:N*.h:R:S/$/.o/g}
+.NOPATH: ${OBJS}
+
+.if ${MK_LIBTOOL} == "yes"
+.if ${MK_PIC} == "no"
+LT_STATIC=-static
+.else
+LT_STATIC=
+.endif
+SHLIB_AGE?=0
+
+# .lo's are created as a side effect
+.s.o .S.o .c.o:
+ ${LIBTOOL} --mode=compile ${CC} ${LT_STATIC} ${CFLAGS} ${CPPFLAGS} ${IMPFLAGS} -c ${.IMPSRC}
+
+# can't really do profiled libs with libtool - its too facist about
+# naming the output...
+lib${LIB}.a:: ${OBJS}
+ @rm -f ${.TARGET}
+ ${LIBTOOL} --mode=link ${CC} ${LT_STATIC} -o ${.TARGET:.a=.la} ${OBJS:.o=.lo} -rpath ${SHLIBDIR}:/usr/lib -version-info ${SHLIB_MAJOR}:${SHLIB_MINOR}:${SHLIB_AGE}
+ @ln .libs/${.TARGET} .
+
+lib${LIB}.${LD_so}:: lib${LIB}.a
+ @[ -s ${.TARGET}.${SHLIB_AGE} ] || { ln -s .libs/lib${LIB}.${LD_so}* . 2>/dev/null; : }
+ @[ -s ${.TARGET} ] || ln -s ${.TARGET}.${SHLIB_AGE} ${.TARGET}
+
+.else # MK_LIBTOOL=yes
+
+lib${LIB}.a:: ${OBJS}
+ @echo building standard ${LIB} library
+ @rm -f ${.TARGET}
+ @${AR} ${AR_cq} ${.TARGET} ${LD_objs}
+ ${RANLIB} ${.TARGET}
+
+POBJS+= ${OBJS:.o=.po}
+.NOPATH: ${POBJS}
+lib${LIB}_p.a:: ${POBJS}
+ @echo building profiled ${LIB} library
+ @rm -f ${.TARGET}
+ @${AR} ${AR_cq} ${.TARGET} ${LD_pobjs}
+ ${RANLIB} ${.TARGET}
+
+SOBJS+= ${OBJS:.o=.so}
+.NOPATH: ${SOBJS}
+lib${LIB}_pic.a:: ${SOBJS}
+ @echo building shared object ${LIB} library
+ @rm -f ${.TARGET}
+ @${AR} ${AR_cq} ${.TARGET} ${LD_sobjs}
+ ${RANLIB} ${.TARGET}
+
+#SHLIB_LDADD?= ${LDADD}
+
+# 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}\)
+ @rm -f ${.TARGET}
+.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD"
+.if ${OBJECT_FMT} == "ELF"
+ ${SHLIB_LD} -x -shared ${SHLIB_SHFLAGS} -o ${.TARGET} \
+ ${SHLIB_LDSTARTFILE} \
+ --whole-archive ${SOLIB} --no-whole-archive ${SHLIB_LDADD} \
+ ${SHLIB_LDENDFILE}
+.else
+ ${SHLIB_LD} ${LD_x} ${LD_shared} \
+ -o ${.TARGET} ${SOLIB} ${SHLIB_LDADD}
+.endif
+.else
+ ${SHLIB_LD} -o ${.TARGET} ${LD_shared} ${LD_solib} ${DLLIB} ${SHLIB_LDADD}
+.endif
+.endif
+.if !empty(SHLIB_LINKS)
+ rm -f ${SHLIB_LINKS}; ${SHLIB_LINKS:O:u:@x@ln -s ${.TARGET} $x;@}
+.endif
+
+LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
+.NOPATH: ${LOBJS}
+LLIBS?= -lc
+llib-l${LIB}.ln: ${LOBJS}
+ @echo building llib-l${LIB}.ln
+ @rm -f llib-l${LIB}.ln
+ @${LINT} -C${LIB} ${LOBJS} ${LLIBS}
+
+.if !target(clean)
+cleanlib: .PHONY
+ rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
+ rm -f lib${LIB}.a ${OBJS}
+ rm -f lib${LIB}_p.a ${POBJS}
+ rm -f lib${LIB}_pic.a lib${LIB}.so.*.* ${SOBJS}
+ rm -f llib-l${LIB}.ln ${LOBJS}
+.if !empty(SHLIB_LINKS)
+ rm -f ${SHLIB_LINKS}
+.endif
+
+clean: _SUBDIRUSE cleanlib
+cleandir: _SUBDIRUSE cleanlib
+.else
+cleandir: _SUBDIRUSE clean
+.endif
+
+.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
+afterdepend: .depend
+ @(TMP=/tmp/_depend$$$$; \
+ sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \
+ < .depend > $$TMP; \
+ mv $$TMP .depend)
+.endif
+
+.if !target(install)
+.if !target(beforeinstall)
+beforeinstall:
+.endif
+
+.if !empty(LIBOWN)
+LIB_INSTALL_OWN ?= -o ${LIBOWN} -g ${LIBGRP}
+.endif
+
+.include <links.mk>
+
+.if !target(realinstall)
+realinstall: libinstall
+.endif
+.if !target(libinstall)
+libinstall:
+ [ -d ${DESTDIR}/${LIBDIR} ] || \
+ ${INSTALL} -d ${LIB_INSTALL_OWN} -m 775 ${DESTDIR}${LIBDIR}
+.if ${MK_ARCHIVE} != "no"
+ ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 lib${LIB}.a \
+ ${DESTDIR}${LIBDIR}
+ ${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}.a
+ chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}.a
+.endif
+.if ${MK_PROFILE} != "no"
+ ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 \
+ lib${LIB}_p.a ${DESTDIR}${LIBDIR}
+ ${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
+ chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
+.endif
+.if ${MK_PIC} != "no"
+.if ${MK_PICLIB} != "no"
+ ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m 600 \
+ lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
+ ${RANLIB} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
+ chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
+.endif
+.if !empty(SHLIB_MAJOR)
+ ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m ${LIBMODE} \
+ lib${LIB}.${LD_so} ${DESTDIR}${LIBDIR}
+.if !empty(SHLIB_LINKS)
+ (cd ${DESTDIR}${LIBDIR} && { rm -f ${SHLIB_LINKS}; ${SHLIB_LINKS:O:u:@x@ln -s lib${LIB}.${LD_so} $x;@} })
+.endif
+.endif
+.endif
+.if ${MK_LINT} != "no" && ${MK_LINKLIB} != "no" && !empty(LOBJS)
+ ${INSTALL} ${COPY} ${LIB_INSTALL_OWN} -m ${LIBMODE} \
+ llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
+.endif
+.if defined(LINKS) && !empty(LINKS)
+ @set ${LINKS}; ${_LINKS_SCRIPT}
+.endif
+.endif
+
+install: maninstall _SUBDIRUSE
+maninstall: afterinstall
+afterinstall: realinstall
+realinstall: beforeinstall
+.endif
+
+.if ${MK_MAN} != "no"
+.include <man.mk>
+.endif
+
+.if ${MK_NLS} != "no"
+.include <nls.mk>
+.endif
+
+.include <obj.mk>
+.include <inc.mk>
+.include <dep.mk>
+.include <subdir.mk>
+.endif
+
+# during building we usually need/want to install libs somewhere central
+# note that we do NOT ch{own,grp} as that would likely fail at this point.
+# otherwise it is the same as realinstall
+# Note that we don't need this when using dpadd.mk
+.libinstall: ${_LIBS}
+ test -d ${DESTDIR}${LIBDIR} || ${INSTALL} -d -m775 ${DESTDIR}${LIBDIR}
+.for _lib in ${_LIBS:M*.a}
+ ${INSTALL} ${COPY} -m 644 ${_lib} ${DESTDIR}${LIBDIR}
+ ${RANLIB} ${DESTDIR}${LIBDIR}/${_lib}
+.endfor
+.for _lib in ${_LIBS:M*.${LD_solink}*:O:u}
+ ${INSTALL} ${COPY} -m ${LIBMODE} ${_lib} ${DESTDIR}${LIBDIR}
+.if !empty(SHLIB_LINKS)
+ (cd ${DESTDIR}${LIBDIR} && { ${SHLIB_LINKS:O:u:@x@ln -sf ${_lib} $x;@}; })
+.endif
+.endfor
+ @touch ${.TARGET}
+
+.include <final.mk>
+.endif
diff --git a/contrib/bmake/mk/libnames.mk b/contrib/bmake/mk/libnames.mk
new file mode 100644
index 000000000000..60e12eb5109a
--- /dev/null
+++ b/contrib/bmake/mk/libnames.mk
@@ -0,0 +1,22 @@
+# $Id: libnames.mk,v 1.7 2009/12/25 07:34:03 sjg Exp $
+#
+# @(#) Copyright (c) 2007-2009, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+DLIBEXT ?= .a
+DSHLIBEXT ?= .so
+
+.-include "local.libnames.mk"
+.-include "sjg.libnames.mk"
+.-include "fwall.libnames.mk"
+.-include "host.libnames.mk"
diff --git a/contrib/bmake/mk/libs.mk b/contrib/bmake/mk/libs.mk
new file mode 100644
index 000000000000..05b450689b11
--- /dev/null
+++ b/contrib/bmake/mk/libs.mk
@@ -0,0 +1,54 @@
+# $Id: libs.mk,v 1.2 2007/04/30 17:39:27 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@crufty.net
+#
+
+.MAIN: all
+
+.if defined(LIBS)
+
+.ifndef LIB
+.for t in ${LIBS:R:T:S,^lib,,}
+.if make(lib$t)
+LIB?= $t
+lib$t: all
+.endif
+.endfor
+.endif
+
+.if defined(LIB)
+# just one of many
+.for v in DPADD SRCS CFLAGS ${LIB_VARS}
+$v += ${${v}_lib${LIB}}
+.endfor
+# ensure that we don't clobber each other's dependencies
+DEPENDFILE?= .depend.${LIB}
+# lib.mk will do the rest
+.else
+all: ${LIBS:S,^lib,,:@t@lib$t.a@} .MAKE
+.endif
+.endif
+
+# handle being called [bsd.]libs.mk
+.include <${.PARSEFILE:S,libs,lib,}>
+
+.ifndef LIB
+.for t in ${LIBS:R:T:S,^lib,,}
+lib$t.a: ${SRCS} ${DPADD} ${SRCS_lib$t} ${DPADD_lib$t}
+ (cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} LIB=$t)
+
+clean: $t.clean
+$t.clean:
+ (cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} LIB=$t ${@:E})
+.endfor
+.endif
diff --git a/contrib/bmake/mk/links.mk b/contrib/bmake/mk/links.mk
new file mode 100644
index 000000000000..4ec8a01c415c
--- /dev/null
+++ b/contrib/bmake/mk/links.mk
@@ -0,0 +1,75 @@
+# $Id: links.mk,v 1.5 2005/07/11 18:01:05 sjg Exp $
+#
+# @(#) Copyright (c) 2005, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+# some platforms need something special
+LN?= ln
+ECHO?= echo
+
+LINKS?=
+SYMLINKS?=
+
+__SYMLINK_SCRIPT= \
+ ${ECHO} "$$t -> $$l"; \
+ mkdir -p `dirname $$t`; \
+ rm -f $$t; \
+ ${LN} -s $$l $$t
+
+__LINK_SCRIPT= \
+ ${ECHO} "$$t -> $$l"; \
+ mkdir -p `dirname $$t`; \
+ rm -f $$t; \
+ ${LN} $$l $$t
+
+_SYMLINKS_SCRIPT= \
+ while test $$\# -ge 2; do \
+ l=$$1; shift; \
+ t=${DESTDIR}$$1; shift; \
+ ${__SYMLINK_SCRIPT}; \
+ done; :;
+
+_LINKS_SCRIPT= \
+ while test $$\# -ge 2; do \
+ l=${DESTDIR}$$1; shift; \
+ t=${DESTDIR}$$1; shift; \
+ ${__LINK_SCRIPT}; \
+ done; :;
+
+_SYMLINKS_USE: .USE
+ @set ${$@_SYMLINKS:U${SYMLINKS}}; ${_SYMLINKS_SCRIPT}
+
+_LINKS_USE: .USE
+ @set ${$@_LINKS:U${LINKS}}; ${_LINKS_SCRIPT}
+
+
+# sometimes we want to ensure DESTDIR is ignored
+_BUILD_SYMLINKS_SCRIPT= \
+ while test $$\# -ge 2; do \
+ l=$$1; shift; \
+ t=$$1; shift; \
+ ${__SYMLINK_SCRIPT}; \
+ done; :;
+
+_BUILD_LINKS_SCRIPT= \
+ while test $$\# -ge 2; do \
+ l=$$1; shift; \
+ t=$$1; shift; \
+ ${__LINK_SCRIPT}; \
+ done; :;
+
+_BUILD_SYMLINKS_USE: .USE
+ @set ${$@_SYMLINKS:U${SYMLINKS}}; ${_BUILD_SYMLINKS_SCRIPT}
+
+_BUILD_LINKS_USE: .USE
+ @set ${$@_LINKS:U${LINKS}}; ${_BUILD_LINKS_SCRIPT}
diff --git a/contrib/bmake/mk/man.mk b/contrib/bmake/mk/man.mk
new file mode 100644
index 000000000000..391b08afe491
--- /dev/null
+++ b/contrib/bmake/mk/man.mk
@@ -0,0 +1,137 @@
+# $Id: man.mk,v 1.20 2012/12/13 01:51:01 sjg Exp $
+
+.if !target(__${.PARSEFILE}__)
+__${.PARSEFILE}__:
+
+.include <init.mk>
+
+# unlike bsd.man.mk we handle 3 approaches
+# 1. install unformated nroff (default)
+# 2. install formatted pages
+# 3. install formatted pages but with extension of .0
+# sadly we cannot rely on a shell that supports ${foo#...} and ${foo%...}
+# so we have to use sed(1).
+
+# set MANTARGET=cat for formatted pages
+MANTARGET?= man
+# set this to .0 for same behavior as bsd.man.mk
+MCATEXT?=
+
+NROFF?= nroff
+MANDIR?= /usr/share/man
+MANDOC?= man
+
+.SUFFIXES: .1 .2 .3 .4 .5 .6 .7 .8 .9 .cat1 .cat2 .cat3 .cat4 .cat5 .cat6 \
+ .cat7 .cat8 .cat9
+
+.9.cat9 .8.cat8 .7.cat7 .6.cat6 .5.cat5 .4.cat4 .3.cat3 .2.cat2 .1.cat1:
+ @echo "${NROFF} -${MANDOC} ${.IMPSRC} > ${.TARGET:T}"
+ @${NROFF} -${MANDOC} ${.IMPSRC} > ${.TARGET:T} || ( rm -f ${.TARGET:T} ; false )
+
+.if defined(MAN) && !empty(MAN)
+
+# we use cmt2doc.pl to extract manpages from source
+# this is triggered by the setting of EXTRACT_MAN or MAN being set but
+# not existsing.
+
+.if !exists(${MAN:[1]}) && !target(${MAN:[1]})
+.if defined(EXTRACT_MAN) && ${EXTRACT_MAN} == "no"
+MAN=
+.else
+.if exists(/usr/local/share/bin/cmt2doc.pl)
+CMT2DOC?= cmt2doc.pl
+CMT2DOC_OPTS?= ${CMT2DOC_ORGOPT} -pmS${.TARGET:E}
+.endif
+.ifdef CMT2DOC
+.c.8 .c.5 .c.3 .c.4 .c.1 \
+ .cc.8 .cc.5 .cc.3 .cc.4 .cc.1 \
+ .h.8 .h.5 .h.3 .h.4 .h.1 \
+ .sh.8 .sh.5 .sh.3 .sh.4 .sh.1 \
+ .pl.8 .pl.5 .pl.3 .pl.4 .pl.1:
+ @echo "${CMT2DOC} ${.IMPSRC} > ${.TARGET:T}"
+ @${CMT2DOC} ${CMT2DOC_OPTS} ${.IMPSRC} > ${.TARGET:T} || ( rm -f ${.TARGET:T} ; false )
+.else
+MAN=
+.endif
+.endif
+.endif
+
+_mandir=${DESTDIR}${MANDIR}/${MANTARGET}`echo $$page | sed -e 's/.*\.cat/./' -e 's/.*\.//'`
+.if ${MANTARGET} == "cat"
+_mfromdir?=.
+MANALL= ${MAN:S/.1$/.cat1/g:S/.2$/.cat2/g:S/.3$/.cat3/g:S/.4$/.cat4/g:S/.5$/.cat5/g:S/.6$/.cat6/g:S/.7$/.cat7/g:S/.8$/.cat8/g:S/.9$/.cat9/g}
+.if ${MCATEXT} == ""
+_minstpage=`echo $$page | sed 's/\.cat/./'`
+.else
+_minstpage=`echo $$page | sed 's/\.cat.*//'`${MCATEXT}
+.endif
+.endif
+.if target(${MAN:[1]})
+_mfromdir?=.
+.endif
+_mfromdir?=${.CURDIR}
+MANALL?= ${MAN}
+_minstpage?=$${page}
+.endif
+
+.if !empty(MANOWN)
+MAN_INSTALL_OWN ?= -o ${MANOWN} -g ${MANGRP}
+MAN_CHOWN ?= chown
+.else
+MAN_CHOWN = :
+.endif
+
+MINSTALL= ${INSTALL} ${COPY} ${MAN_INSTALL_OWN} -m ${MANMODE}
+.if defined(MANZ)
+# chown and chmod are done afterward automatically
+MCOMPRESS= gzip -cf
+MCOMPRESSSUFFIX= .gz
+.endif
+
+maninstall:
+.if defined(MANALL) && !empty(MANALL)
+ @for page in ${MANALL:T}; do \
+ test -s ${_mfromdir}/$$page || continue; \
+ dir=${_mandir}; \
+ test -d $$dir || ${INSTALL} -d ${MAN_INSTALL_OWN} -m 775 $$dir; \
+ instpage=$${dir}${MANSUBDIR}/${_minstpage}${MCOMPRESSSUFFIX}; \
+ if [ X"${MCOMPRESS}" = X ]; then \
+ echo ${MINSTALL} ${_mfromdir}/$$page $$instpage; \
+ ${MINSTALL} ${_mfromdir}/$$page $$instpage; \
+ else \
+ rm -f $$instpage; \
+ echo ${MCOMPRESS} ${_mfromdir}/$$page \> $$instpage; \
+ ${MCOMPRESS} ${_mfromdir}/$$page > $$instpage; \
+ ${MAN_CHOWN} ${MANOWN}:${MANGRP} $$instpage; \
+ chmod ${MANMODE} $$instpage; \
+ fi \
+ done
+.if defined(MLINKS) && !empty(MLINKS)
+ @set ${MLINKS}; \
+ while test $$# -ge 2; do \
+ page=$$1; \
+ shift; \
+ dir=${_mandir}; \
+ l=${_minstpage}${MCOMPRESSSUFFIX}; \
+ page=$$1; \
+ shift; \
+ dir=${_mandir}; \
+ t=$${dir}${MANSUBDIR}/${_minstpage}${MCOMPRESSSUFFIX}; \
+ echo $$t -\> $$l; \
+ rm -f $$t; \
+ ln -s $$l $$t; \
+ done
+.endif
+.endif
+
+.if defined(MANALL) && !empty(MANALL)
+manall: ${MANALL}
+all: manall
+.endif
+
+.if defined(CLEANMAN) && !empty(CLEANMAN)
+cleandir: cleanman
+cleanman:
+ rm -f ${CLEANMAN}
+.endif
+.endif
diff --git a/contrib/bmake/mk/meta.autodep.mk b/contrib/bmake/mk/meta.autodep.mk
new file mode 100644
index 000000000000..c29c26e85e24
--- /dev/null
+++ b/contrib/bmake/mk/meta.autodep.mk
@@ -0,0 +1,262 @@
+# $Id: meta.autodep.mk,v 1.32 2012/11/13 00:44:26 sjg Exp $
+
+#
+# @(#) Copyright (c) 2010, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+_this ?= ${.PARSEFILE}
+.if !target(__${_this}__)
+__${_this}__: .NOTMAIN
+
+.-include "local.autodep.mk"
+
+.if defined(SRCS)
+# it would be nice to be able to query .SUFFIXES
+OBJ_EXTENSIONS+= .o .po .lo .So
+
+# explicit dependencies help short-circuit .SUFFIX searches
+SRCS_DEP_FILTER+= N*.[hly]
+.for s in ${SRCS:${SRCS_DEP_FILTER:O:u:ts:}}
+.for e in ${OBJ_EXTENSIONS:O:u}
+.if !target(${s:T:R}$e)
+${s:T:R}$e: $s
+.endif
+.endfor
+.endfor
+.endif
+
+.if make(gendirdeps)
+# you are supposed to know what you are doing!
+UPDATE_DEPENDFILE = yes
+.elif !empty(.TARGETS) && !make(all)
+# do not update the *depend* files
+# unless we are building the entire directory or the default target.
+# NO means don't update .depend - or Makefile.depend*
+# no means update .depend but not Makefile.depend*
+UPDATE_DEPENDFILE = NO
+.elif ${.MAKEFLAGS:M-k} != ""
+# it is a bad idea to update anything
+UPDATE_DEPENDFILE = NO
+.endif
+
+_CURDIR ?= ${.CURDIR}
+_DEPENDFILE := ${_CURDIR}/${.MAKE.DEPENDFILE:T}
+
+.if ${.MAKE.LEVEL} == 0
+.if ${BUILD_AT_LEVEL0:Uyes:tl} == "no"
+UPDATE_DEPENDFILE = NO
+.endif
+.endif
+.if !exists(${_DEPENDFILE})
+_bootstrap_dirdeps = yes
+.endif
+_bootstrap_dirdeps ?= no
+UPDATE_DEPENDFILE ?= yes
+
+.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != ""
+.info ${_DEPENDFILE:S,${SRCTOP}/,,} update=${UPDATE_DEPENDFILE}
+.endif
+
+.if !empty(XMAKE_META_FILE)
+.if exists(${.OBJDIR}/${XMAKE_META_FILE})
+# we cannot get accurate dependencies from an update build
+UPDATE_DEPENDFILE = NO
+.else
+META_XTRAS += ${XMAKE_META_FILE}
+.endif
+.endif
+
+.if ${_bootstrap_dirdeps} == "yes" || exists(${_DEPENDFILE})
+# if it isn't supposed to be touched by us the Makefile should have
+# UPDATE_DEPENDFILE = no
+WANT_UPDATE_DEPENDFILE ?= yes
+.endif
+
+.if ${WANT_UPDATE_DEPENDFILE:Uno:tl} != "no"
+.if ${.MAKE.MODE:Mmeta*} == "" || ${.MAKE.MODE:M*read*} != ""
+UPDATE_DEPENDFILE = no
+.endif
+
+.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != ""
+.info ${_DEPENDFILE:S,${SRCTOP}/,,} update=${UPDATE_DEPENDFILE}
+.endif
+
+.if ${UPDATE_DEPENDFILE:tl} == "yes"
+# sometimes we want .meta files generated to aid debugging/error detection
+# but do not want to consider them for dependencies
+# for example the result of running configure
+# just make sure this is not empty
+META_FILE_FILTER ?= N.meta
+
+.if !empty(DPADD)
+# if we have any non-libs in DPADD,
+# they probably need to be paid attention to
+.if !empty(DPLIBS)
+FORCE_DPADD = ${DPADD:${DPLIBS:${M_ListToSkip}}:${DPADD_LAST:${M_ListToSkip}}}
+.else
+_nonlibs := ${DPADD:T:Nlib*:N*include}
+.if !empty(_nonlibs)
+FORCE_DPADD += ${_nonlibs:@x@${DPADD:M*/$x}@}
+.endif
+.endif
+.endif
+
+.if !make(gendirdeps)
+.END: gendirdeps
+.endif
+
+# if we don't have OBJS, then .depend isn't useful
+.if !target(.depend) && (!empty(OBJS) || ${.ALLTARGETS:M*.o} != "")
+# some makefiles and/or targets contain
+# circular dependencies if you dig too deep
+# (as meta mode is apt to do)
+# so we provide a means of supressing them.
+# the input to the loop below is target: dependency
+# with just one dependency per line.
+# Also some targets are not really local, or use random names.
+# Use local.autodep.mk to provide local additions!
+SUPPRESS_DEPEND += \
+ ${SB:S,/,_,g}* \
+ *:y.tab.c \
+ *.c:*.c \
+ *.h:*.h
+
+.NOPATH: .depend
+# we use ${.MAKE.META.CREATED} to trigger an update but
+# we process using ${.MAKE.META.FILES}
+# the double $$ defers initial evaluation
+# if necessary, we fake .po dependencies, just so the result
+# in Makefile.depend* is stable
+# The current objdir may be refered to in various ways
+OBJDIR_REFS += ${.OBJDIR} ${.OBJDIR:tA} ${_OBJDIR} ${RELOBJTOP}/${RELDIR}
+_depend = .depend
+# it would be nice to be able to get .SUFFIXES as ${.SUFFIXES}
+# we actually only care about the .SUFFIXES of files that might be
+# generated by tools like yacc.
+DEPEND_SUFFIXES += .c .h .cpp .hpp .cxx .hxx .cc .hh
+.depend: .NOMETA $${.MAKE.META.CREATED} ${_this}
+ @echo "Updating $@: ${.OODATE:T:[1..8]}"
+ @egrep -i '^R .*\.(${DEPEND_SUFFIXES:tl:O:u:S,^.,,:ts|})$$' /dev/null ${.MAKE.META.FILES:T:O:u:${META_FILE_FILTER:ts:}:M*o.meta} | \
+ sed -e 's, \./, ,${OBJDIR_REFS:O:u:@d@;s, $d/, ,@};/\//d' \
+ -e 's,^\([^/][^/]*\).meta...[0-9]* ,\1: ,' | \
+ sort -u | \
+ while read t d; do \
+ case "$$d:" in $$t) continue;; esac; \
+ case "$$t$$d" in ${SUPPRESS_DEPEND:U.:O:u:ts|}) continue;; esac; \
+ echo $$t $$d; \
+ done > $@.${.MAKE.PID}
+ @case "${.MAKE.META.FILES:T:M*.po.*}" in \
+ *.po.*) mv $@.${.MAKE.PID} $@;; \
+ *) { cat $@.${.MAKE.PID}; \
+ sed 's,\.So:,.o:,;s,\.o:,.po:,' $@.${.MAKE.PID}; } | sort -u > $@; \
+ rm -f $@.${.MAKE.PID};; \
+ esac
+.else
+# make sure this exists
+.depend:
+# do _not_ assume that .depend is in any fit state for us to use
+CAT_DEPEND = /dev/null
+.if ${.MAKE.LEVEL} > 0
+.export CAT_DEPEND
+.endif
+_depend =
+.endif
+
+.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != ""
+.info ${_DEPENDFILE:S,${SRCTOP}/,,} _depend=${_depend}
+.endif
+
+gendirdeps: ${_DEPENDFILE}
+
+.if !target(${_DEPENDFILE})
+.if ${_bootstrap_dirdeps} == "yes"
+# We are boot-strapping a new directory
+# Use DPADD to seed DIRDEPS
+.if !empty(DPADD)
+# anything which matches ${_OBJROOT}* but not ${_OBJTOP}*
+# needs to be qualified in DIRDEPS
+# The pseudo machine "host" is used for HOST_TARGET
+DIRDEPS = \
+ ${DPADD:M${_OBJTOP}*:H:C,${_OBJTOP}[^/]*/,,:N.:O:u} \
+ ${DPADD:M${_OBJROOT}*:N${_OBJTOP}*:H:S,${_OBJROOT},,:C,^([^/]+)/(.*),\2.\1,:S,${HOST_TARGET}$,host,:N.*:O:u}
+
+.endif
+.endif
+
+_gendirdeps_mutex =
+.if defined(NEED_GENDIRDEPS_MUTEX)
+# If a src dir gets built with multiple object dirs,
+# we need a mutex. Obviously, this is best avoided.
+# Note if .MAKE.DEPENDFILE is common for all ${MACHINE}
+# you either need to mutex, or ensure only one machine builds at a time!
+# lockf is an example of a suitable tool
+LOCKF ?= /usr/bin/lockf
+.if exists(${LOCKF})
+GENDIRDEPS_MUTEXER ?= ${LOCKF} -k
+.endif
+.if empty(GENDIRDEPS_MUTEXER)
+.error NEED_GENDIRDEPS_MUTEX defined, but GENDIRDEPS_MUTEXER not set
+.else
+_gendirdeps_mutex = ${GENDIRDEPS_MUTEXER} ${GENDIRDEPS_MUTEX:U${_CURDIR}/Makefile}
+.endif
+.endif
+
+# If we have META_XTRAS we most likely did not create them
+# but we need to behave as if we did.
+# Avoid adding glob patterns to .MAKE.META.CREATED though.
+.MAKE.META.CREATED += ${META_XTRAS:N*\**:O:u}
+
+.if make(gendirdeps)
+META_FILES = *.meta
+.elif ${OPTIMIZE_OBJECT_META_FILES:Uno:tl} == "no"
+META_FILES = ${.MAKE.META.FILES:T:N.depend*:O:u}
+.else
+# if we have 1000's of .o.meta, .So.meta etc we need only look at one set
+# it is left as an exercise for the reader to work out what this does
+META_FILES = ${.MAKE.META.FILES:T:N.depend*:N*o.meta:O:u} \
+ ${.MAKE.META.FILES:T:M*.${.MAKE.META.FILES:M*o.meta:R:E:O:u:[1]}.meta:O:u}
+.endif
+
+.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != ""
+.info ${_DEPENDFILE:S,${SRCTOP}/,,}: ${_depend} ${.PARSEDIR}/gendirdeps.mk ${META2DEPS} xtras=${META_XTRAS}
+.endif
+
+.if ${.MAKE.LEVEL} > 0 && !empty(GENDIRDEPS_FILTER)
+.export GENDIRDEPS_FILTER
+.endif
+
+# we might have .../ in MAKESYSPATH
+_makesyspath:= ${_PARSEDIR}
+${_DEPENDFILE}: ${_depend} ${.PARSEDIR}/gendirdeps.mk ${META2DEPS} $${.MAKE.META.CREATED}
+ @echo Checking $@: ${.OODATE:T:[1..8]}
+ @(cd . && \
+ SKIP_GENDIRDEPS='${SKIP_GENDIRDEPS:O:u}' \
+ 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:}}')
+ @test -s $@ && touch $@; :
+.endif
+
+.endif
+.endif
+
+.if ${_bootstrap_dirdeps} == "yes"
+# make sure this is included at least once
+.include <dirdeps.mk>
+.else
+${_DEPENDFILE}: .PRECIOUS
+.endif
+
+CLEANFILES += *.meta filemon.* *.db
+.endif
diff --git a/contrib/bmake/mk/meta.stage.mk b/contrib/bmake/mk/meta.stage.mk
new file mode 100644
index 000000000000..cf62db4311e1
--- /dev/null
+++ b/contrib/bmake/mk/meta.stage.mk
@@ -0,0 +1,212 @@
+# $Id: meta.stage.mk,v 1.17 2013/01/24 01:02:23 sjg Exp $
+#
+# @(#) Copyright (c) 2011, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+.if !target(__${.PARSEFILE}__)
+__${.PARSEFILE}__:
+
+.if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} != ""
+# this is generally safer anyway
+_dirdep = ${RELDIR}.${MACHINE}
+.else
+_dirdep = ${RELDIR}
+.endif
+
+# this allows us to trace dependencies back to their src dir
+.dirdep:
+ @echo '${_dirdep}' > $@
+
+.if defined(NO_POSIX_SHELL) || ${type printf:L:sh:Mbuiltin} == ""
+_stage_file_basename = `basename $$f`
+_stage_target_dirname = `dirname $$t`
+.else
+_stage_file_basename = $${f\#\#*/}
+_stage_target_dirname = $${t%/*}
+.endif
+
+_objroot ?= ${_OBJROOT:tA}
+# make sure this is global
+_STAGED_DIRS ?=
+.export _STAGED_DIRS
+# add each dir we stage to to _STAGED_DIRS
+# and make sure we have absolute paths so that bmake
+# will match against .MAKE.META.BAILIWICK
+STAGE_DIR_FILTER = tA:@d@$${_STAGED_DIRS::+=$$d}$$d@
+# convert _STAGED_DIRS into suitable filters
+GENDIRDEPS_FILTER += Nnot-empty-is-important \
+ ${_STAGED_DIRS:O:u:M${OBJTOP}*:S,${OBJTOP}/,N,} \
+ ${_STAGED_DIRS:O:u:N${OBJTOP}*:S,${_objroot},,:C,^([^/]+)/(.*),N\2.\1,:S,${HOST_TARGET},.host,}
+
+# it is an error for more than one src dir to try and stage
+# the same file
+STAGE_DIRDEP_SCRIPT = StageDirdep() { \
+ t=$$1; \
+ if [ -s $$t.dirdep ]; then \
+ cmp -s .dirdep $$t.dirdep && return; \
+ echo "ERROR: $$t installed by `cat $$t.dirdep` not ${_dirdep}" >&2; \
+ exit 1; \
+ fi; \
+ ln .dirdep $$t.dirdep 2> /dev/null || \
+ cp .dirdep $$t.dirdep; }
+
+# common logic for staging files
+# this all relies on RELDIR being set to a subdir of SRCTOP
+# we use ln(1) if we can, else cp(1)
+STAGE_FILE_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageFiles() { \
+ case "$$1" in -m) mode=$$2; shift 2;; *) mode=;; esac; \
+ dest=$$1; shift; \
+ mkdir -p $$dest; \
+ [ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \
+ for f in "$$@"; do \
+ case "$$f" in */*) t=$$dest/${_stage_file_basename};; *) t=$$dest/$$f;; esac; \
+ StageDirdep $$t; \
+ rm -f $$t; \
+ { ln $$f $$t 2> /dev/null || \
+ cp -p $$f $$t; }; \
+ $${mode:+chmod $$mode $$t}; \
+ done; :; }
+
+STAGE_LINKS_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageLinks() { \
+ case "$$1" in --) shift;; -*) ldest= lnf=$$1; shift;; /*) ldest=$$1/;; esac; \
+ dest=$$1; shift; \
+ mkdir -p $$dest; \
+ [ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \
+ while test $$\# -ge 2; do \
+ l=$$ldest$$1; shift; \
+ t=$$dest/$$1; \
+ case "$$1" in */*) mkdir -p ${_stage_target_dirname};; esac; \
+ shift; \
+ StageDirdep $$t; \
+ rm -f $$t 2>/dev/null; \
+ ln $$lnf $$l $$t; \
+ done; :; }
+
+STAGE_AS_SCRIPT = ${STAGE_DIRDEP_SCRIPT}; StageAs() { \
+ case "$$1" in -m) mode=$$2; shift 2;; *) mode=;; esac; \
+ dest=$$1; shift; \
+ mkdir -p $$dest; \
+ [ -s .dirdep ] || echo '${_dirdep}' > .dirdep; \
+ while test $$\# -ge 2; do \
+ s=$$1; shift; \
+ t=$$dest/$$1; \
+ case "$$1" in */*) mkdir -p ${_stage_target_dirname};; esac; \
+ shift; \
+ StageDirdep $$t; \
+ rm -f $$t; \
+ { ln $$s $$t 2> /dev/null || \
+ cp -p $$s $$t; }; \
+ $${mode:+chmod $$mode $$t}; \
+ done; :; }
+
+# this is simple, a list of the "staged" files depends on this,
+_STAGE_BASENAME_USE: .USE ${.TARGET:T}
+ @${STAGE_FILE_SCRIPT}; StageFiles ${.TARGET:H:${STAGE_DIR_FILTER}} ${.TARGET:T}
+
+.if !empty(STAGE_INCSDIR)
+CLEANFILES += stage_incs
+
+STAGE_INCS ?= ${.ALLSRC:N.dirdep}
+
+stage_incs: .dirdep
+ @${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_INCSDIR:${STAGE_DIR_FILTER}} ${STAGE_INCS}
+ @touch $@
+.endif
+
+.if !empty(STAGE_LIBDIR)
+CLEANFILES += stage_libs
+
+STAGE_LIBS ?= ${.ALLSRC:N.dirdep}
+
+stage_libs: .dirdep
+ @${STAGE_FILE_SCRIPT}; StageFiles ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} ${STAGE_LIBS}
+.if !empty(SHLIB_LINKS)
+ @${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} \
+ ${SHLIB_LINKS:@t@${STAGE_LIBS:T:M$t.*} $t@}
+.elif !empty(SHLIB_LINK) && !empty(SHLIB_NAME)
+ @${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_LIBDIR:${STAGE_DIR_FILTER}} ${SHLIB_NAME} ${SHLIB_LINK} ${SYMLINKS:T}
+.endif
+ @touch $@
+.endif
+
+.if !empty(STAGE_DIR)
+STAGE_SETS += _default
+STAGE_DIR._default = ${STAGE_DIR}
+STAGE_LINKS_DIR._default = ${STAGE_LINKS_DIR:U${STAGE_OBJTOP}}
+STAGE_SYMLINKS_DIR._default = ${STAGE_SYMLINKS_DIR:U${STAGE_OBJTOP}}
+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)
+
+CLEANFILES += ${STAGE_SETS:@s@stage*$s@}
+
+# some makefiles need to populate multiple directories
+.for s in ${STAGE_SETS:O:u}
+STAGE_FILES.$s ?= ${.ALLSRC:N.dirdep}
+STAGE_SYMLINKS.$s ?= ${.ALLSRC:N.dirdep}
+STAGE_LINKS_DIR.$s ?= ${STAGE_OBJTOP}
+STAGE_SYMLINKS_DIR.$s ?= ${STAGE_OBJTOP}
+
+.if $s != "_default"
+stage_files: stage_files.$s
+stage_files.$s: .dirdep
+.else
+stage_files: .dirdep
+.endif
+ @${STAGE_FILE_SCRIPT}; StageFiles ${FLAGS.$@} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_FILES.$s}
+ @touch $@
+
+.if $s != "_default"
+stage_links: stage_links.$s
+stage_links.$s: .dirdep
+.else
+stage_links: .dirdep
+.endif
+ @${STAGE_LINKS_SCRIPT}; StageLinks ${STAGE_LINKS_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_LINKS.$s}
+ @touch $@
+
+.if $s != "_default"
+stage_symlinks: stage_symlinks.$s
+stage_symlinks.$s: .dirdep
+.else
+stage_symlinks: .dirdep
+.endif
+ @${STAGE_LINKS_SCRIPT}; StageLinks -s ${STAGE_SYMLINKS_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_SYMLINKS.$s}
+ @touch $@
+
+.endfor
+.endif
+
+.if !empty(STAGE_AS_SETS)
+CLEANFILES += ${STAGE_AS_SETS:@s@stage*$s@}
+
+# 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
+.for s in ${STAGE_AS_SETS:O:u}
+STAGE_AS.$s ?= ${.ALLSRC:N.dirdep}
+
+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:T}:U${f:T}}@}
+ @touch $@
+
+.endfor
+.endif
+
+.endif
diff --git a/contrib/bmake/mk/meta.subdir.mk b/contrib/bmake/mk/meta.subdir.mk
new file mode 100644
index 000000000000..2b739ee9ae9c
--- /dev/null
+++ b/contrib/bmake/mk/meta.subdir.mk
@@ -0,0 +1,79 @@
+# $Id: meta.subdir.mk,v 1.10 2012/07/03 05:26:46 sjg Exp $
+
+#
+# @(#) Copyright (c) 2010, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+.if !defined(NO_SUBDIR) && !empty(SUBDIR)
+.if make(destroy*) || make(clean*)
+.MAKE.MODE = compat
+.if !commands(destroy)
+.-include <bsd.obj.mk>
+.endif
+.elif ${.MAKE.LEVEL} == 0
+
+.MAIN: all
+
+.if !exists(${.CURDIR}/${.MAKE.DEPENDFILE:T}) || make(gendirdeps)
+# start with this
+DIRDEPS = ${SUBDIR:N.WAIT:O:u:@d@${RELDIR}/$d@}
+
+.if make(gendirdeps)
+.include <meta.autodep.mk>
+.else
+# this is the cunning bit
+# actually it is probably a bit risky
+# since we may pickup subdirs which are not relevant
+# the alternative is a walk through the tree though
+# which is difficult without a sub-make.
+
+.if defined(BOOTSTRAP_DEPENDFILES)
+_find_name = ${.MAKE.MAKEFILE_PREFERENCE:@m@-o -name $m@:S,^-o,,1}
+DIRDEPS = ${_subdeps:H:O:u:@d@${RELDIR}/$d@}
+.elif ${.MAKE.DEPENDFILE:E} == ${MACHINE} && defined(ALL_MACHINES)
+# we want to find Makefile.depend.* ie for all machines
+# and turn the dirs into dir.<machine>
+_find_name = -name '${.MAKE.DEPENDFILE:T:R}*'
+DIRDEPS = ${_subdeps:O:u:${NIgnoreFiles}:@d@${RELDIR}/${d:H}.${d:E}@:S,.${MACHINE}$,,:S,.depend$,,}
+.else
+# much simpler
+_find_name = -name ${.MAKE.DEPENDFILE:T}
+.if ${.MAKE.DEPENDFILE:E} == ${MACHINE}
+_find_name += -o -name ${.MAKE.DEPENDFILE:T:R}
+.endif
+DIRDEPS = ${_subdeps:H:O:u:@d@${RELDIR}/$d@}
+.endif
+
+_subdeps != cd ${.CURDIR} && \
+ find ${SUBDIR:N.WAIT} -type f \( ${_find_name} \) -print -o \
+ -name .svn -prune 2> /dev/null; echo
+
+.if empty(_subdeps)
+DIRDEPS =
+.else
+# clean up if needed
+DIRDEPS := ${DIRDEPS:S,^./,,:S,/./,/,g:${SUBDIREPS_FILTER:Uu}}
+.endif
+# we just dealt with it, if we leave it defined,
+# dirdeps.mk will compute some interesting combinations.
+.undef ALL_MACHINES
+
+DEP_RELDIR = ${RELDIR}
+.include <dirdeps.mk>
+.endif
+.endif
+.else
+all: .PHONY
+.endif
+
+.endif
diff --git a/contrib/bmake/mk/meta.sys.mk b/contrib/bmake/mk/meta.sys.mk
new file mode 100644
index 000000000000..1707a6670bb5
--- /dev/null
+++ b/contrib/bmake/mk/meta.sys.mk
@@ -0,0 +1,139 @@
+# $Id: meta.sys.mk,v 1.16 2012/07/03 05:26:00 sjg Exp $
+
+#
+# @(#) Copyright (c) 2010, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+# include this if you want to enable meta mode
+# for maximum benefit, requires filemon(4) driver.
+
+.if ${MAKE_VERSION:U0} > 20100901
+.if !target(.ERROR)
+
+
+META_MODE += meta verbose
+.MAKE.MODE ?= ${META_MODE}
+
+.if ${.MAKE.LEVEL} == 0
+_make_mode := ${.MAKE.MODE} ${META_MODE}
+.if ${_make_mode:M*read*} != "" || ${_make_mode:M*nofilemon*} != ""
+# tell everyone we are not updating Makefile.depend*
+UPDATE_DEPENDFILE = NO
+.export UPDATE_DEPENDFILE
+.endif
+.if ${UPDATE_DEPENDFILE:Uyes:tl} == "no" && !exists(/dev/filemon)
+# we should not get upset
+META_MODE += nofilemon
+.export META_MODE
+.endif
+.endif
+
+.if !defined(NO_SILENT)
+.if ${MAKE_VERSION} > 20110818
+# only be silent when we have a .meta file
+META_MODE += silent=yes
+.else
+.SILENT:
+.endif
+.endif
+
+# make defaults .MAKE.DEPENDFILE to .depend
+# that won't work for us.
+.if ${.MAKE.DEPENDFILE} == ".depend"
+.undef .MAKE.DEPENDFILE
+.endif
+
+# if you don't cross build for multiple MACHINEs concurrently, then
+# .MAKE.DEPENDFILE = Makefile.depend
+# probably makes sense - you can set that in local.sys.mk
+.MAKE.DEPENDFILE ?= Makefile.depend.${MACHINE}
+
+# we use the pseudo machine "host" for the build host.
+# this should be taken care of before we get here
+.if ${OBJTOP:Ua} == ${HOST_OBJTOP:Ub}
+MACHINE = host
+.endif
+
+.if ${.MAKE.LEVEL} == 0
+# it can be handy to know which MACHINE kicked off the build
+# for example, if using Makefild.depend for multiple machines,
+# allowing only MACHINE0 to update can keep things simple.
+MACHINE0 := ${MACHINE}
+
+.if defined(PYTHON) && exists(${PYTHON})
+# we prefer the python version of this - it is much faster
+META2DEPS ?= ${.PARSEDIR}/meta2deps.py
+.else
+META2DEPS ?= ${.PARSEDIR}/meta2deps.sh
+.endif
+META2DEPS := ${META2DEPS}
+.export META2DEPS
+.endif
+
+MAKE_PRINT_VAR_ON_ERROR += \
+ .ERROR_TARGET \
+ .ERROR_META_FILE \
+ .MAKE.LEVEL \
+ MAKEFILE \
+ .MAKE.MODE
+
+.if !defined(SB) && defined(SRCTOP)
+SB = ${SRCTOP:H}
+.endif
+ERROR_LOGDIR ?= ${SB}/error
+meta_error_log = ${ERROR_LOGDIR}/meta-${.MAKE.PID}.log
+
+# we are not interested in make telling us a failure happened elsewhere
+.ERROR: _metaError
+_metaError: .NOMETA .NOTMAIN
+ -@[ "${.ERROR_META_FILE}" ] && { \
+ grep -q 'failure has been detected in another branch' ${.ERROR_META_FILE} && exit 0; \
+ mkdir -p ${meta_error_log:H}; \
+ cp ${.ERROR_META_FILE} ${meta_error_log}; \
+ echo "ERROR: log ${meta_error_log}" >&2; }; :
+
+.endif
+
+# Are we, after all, in meta mode?
+.if ${.MAKE.MODE:Mmeta*} != ""
+MKDEP = meta.autodep
+
+.if ${.MAKE.LEVEL} == 0
+# make sure dirdeps target exists and do it first
+all: dirdeps .WAIT
+dirdeps:
+.NOPATH: dirdeps
+
+.if defined(ALL_MACHINES)
+# the first .MAIN: is what counts
+# by default dirdeps is all we want at level0
+.MAIN: dirdeps
+# tell dirdeps.mk what we want
+BUILD_AT_LEVEL0 = no
+.endif
+
+.if ${.MAKE.DEPENDFILE:E} == ${MACHINE}
+# it works best if we do everything via sub-makes
+BUILD_AT_LEVEL0 ?= no
+.endif
+BUILD_AT_LEVEL0 ?= yes
+.endif
+
+# if we think we are updating dependencies,
+# then filemon had better be present
+.if ${UPDATE_DEPENDFILE:Uyes:tl} != "no" && !exists(/dev/filemon)
+.error ${.newline}ERROR: The filemon module (/dev/filemon) is not loaded.
+.endif
+
+.endif
+.endif
diff --git a/contrib/bmake/mk/meta2deps.py b/contrib/bmake/mk/meta2deps.py
new file mode 100755
index 000000000000..cb6d3213b221
--- /dev/null
+++ b/contrib/bmake/mk/meta2deps.py
@@ -0,0 +1,614 @@
+#!/usr/bin/env python
+
+"""
+This script parses each "meta" file and extracts the
+information needed to deduce build and src dependencies.
+
+It works much the same as the original shell script, but is
+*much* more efficient.
+
+The parsing work is handled by the class MetaFile.
+We only pay attention to a subset of the information in the
+"meta" files. Specifically:
+
+'CWD' to initialize our notion.
+
+'C' to track chdir(2) on a per process basis
+
+'R' files read are what we really care about.
+ directories read, provide a clue to resolving
+ subsequent relative paths. That is if we cannot find
+ them relative to 'cwd', we check relative to the last
+ dir read.
+
+'W' files opened for write or read-write,
+ for filemon V3 and earlier.
+
+'E' files executed.
+
+'L' files linked
+
+'V' the filemon version, this record is used as a clue
+ that we have reached the interesting bit.
+
+"""
+
+"""
+RCSid:
+ $Id: meta2deps.py,v 1.7 2012/11/06 05:44:03 sjg Exp $
+
+ Copyright (c) 2011, Juniper Networks, Inc.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""
+
+import os, re, sys
+
+def getv(dict, key, d=None):
+ """Lookup key in dict and return value or the supplied default."""
+ if key in dict:
+ return dict[key]
+ return d
+
+def resolve(path, cwd, last_dir=None, debug=0, debug_out=sys.stderr):
+ """
+ Return an absolute path, resolving via cwd or last_dir if needed.
+ """
+ if path.endswith('/.'):
+ path = path[0:-2]
+ if path[0] == '/':
+ return path
+ if path == '.':
+ return cwd
+ if path.startswith('./'):
+ return cwd + path[1:]
+ if last_dir == cwd:
+ last_dir = None
+ for d in [last_dir, cwd]:
+ if not d:
+ continue
+ p = '/'.join([d,path])
+ if debug > 2:
+ print >> debug_out, "looking for:", p,
+ if not os.path.exists(p):
+ if debug > 2:
+ print >> debug_out, "nope"
+ p = None
+ continue
+ if debug > 2:
+ print >> debug_out, "found:", p
+ return p
+ return None
+
+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.
+ """
+ path = resolve(path, cwd, last_dir, debug, debug_out)
+ if path and (path.find('./') > 0 or
+ path.endswith('/..') or
+ os.path.islink(path)):
+ return os.path.realpath(path)
+ return path
+
+def sort_unique(list, cmp=None, key=None, reverse=False):
+ list.sort(cmp, key, reverse)
+ nl = []
+ le = None
+ for e in list:
+ if e == le:
+ continue
+ nl.append(e)
+ return nl
+
+class MetaFile:
+ """class to parse meta files generated by bmake."""
+
+ conf = None
+ dirdep_re = None
+ host_target = None
+ srctops = []
+ objroots = []
+
+ seen = {}
+ obj_deps = []
+ src_deps = []
+ file_deps = []
+
+ def __init__(self, name, conf={}):
+ """if name is set we will parse it now.
+ conf can have the follwing keys:
+
+ SRCTOPS list of tops of the src tree(s).
+
+ CURDIR the src directory 'bmake' was run from.
+
+ RELDIR the relative path from SRCTOP to CURDIR
+
+ MACHINE the machine we built for.
+ set to 'none' if we are not cross-building.
+
+ HOST_TARGET
+ when we build for the psuedo 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 '-'.
+
+ 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'
+
+ debug desired debug level
+
+ debug_out open file to send debug output to (sys.stderr)
+
+ """
+
+ self.name = name
+ self.debug = getv(conf, 'debug', 0)
+ self.debug_out = getv(conf, 'debug_out', sys.stderr)
+
+ if not self.conf:
+ # some of the steps below we want to do only once
+ self.conf = conf
+ self.host_target = getv(conf, 'HOST_TARGET')
+ for srctop in getv(conf, 'SRCTOPS', []):
+ if srctop[-1] != '/':
+ srctop += '/'
+ if not srctop in self.srctops:
+ self.srctops.append(srctop)
+ _srctop = os.path.realpath(srctop)
+ if _srctop[-1] != '/':
+ _srctop += '/'
+ if not _srctop in self.srctops:
+ self.srctops.append(_srctop)
+
+ for objroot in getv(conf, 'OBJROOTS', []):
+ if not objroot in self.objroots:
+ self.objroots.append(objroot)
+ _objroot = os.path.realpath(objroot)
+ if objroot[-1] == '/':
+ _objroot += '/'
+ if not _objroot in self.objroots:
+ self.objroots.append(_objroot)
+
+ if self.debug:
+ print >> self.debug_out, "host_target=", self.host_target
+ print >> self.debug_out, "srctops=", self.srctops
+ print >> self.debug_out, "objroots=", self.objroots
+
+ self.dirdep_re = re.compile(r'([^/]+)/(.+)')
+
+ self.curdir = getv(conf, 'CURDIR')
+ self.machine = getv(conf, 'MACHINE', '')
+ self.reldir = getv(conf, 'RELDIR')
+ self.dpdeps = getv(conf, 'DPDEPS')
+ if self.dpdeps and not self.reldir:
+ if self.debug:
+ print >> self.debug_out, "need reldir:",
+ if self.curdir:
+ srctop = self.find_top(self.curdir, self.srctops)
+ if srctop:
+ self.reldir = self.curdir.replace(srctop,'')
+ if self.debug:
+ print >> self.debug_out, self.reldir
+ if not self.reldir:
+ self.dpdeps = None # we cannot do it?
+
+ if name:
+ self.parse()
+
+ def reset(self):
+ """reset state if we are being passed meta files from multiple directories."""
+ self.seen = {}
+ self.obj_deps = []
+ self.src_deps = []
+ self.file_deps = []
+
+ def dirdeps(self, sep='\n'):
+ """return DIRDEPS"""
+ return sep.strip() + sep.join(self.obj_deps)
+
+ def src_dirdeps(self, sep='\n'):
+ """return SRC_DIRDEPS"""
+ return sep.strip() + sep.join(self.src_deps)
+
+ def file_depends(self, out=None):
+ """Append DPDEPS_${file} += ${RELDIR}
+ for each file we saw, to the output file."""
+ if not self.reldir:
+ return None
+ for f in sort_unique(self.file_deps):
+ print >> out, 'DPDEPS_%s += %s' % (f, self.reldir)
+
+ def seenit(self, dir):
+ """rememer that we have seen dir."""
+ self.seen[dir] = 1
+
+ def add(self, list, data, clue=''):
+ """add data to list if it isn't already there."""
+ if data not in list:
+ list.append(data)
+ if self.debug:
+ print >> self.debug_out, "%s: %sAdd: %s" % (self.name, clue, data)
+
+ def find_top(self, path, list):
+ """the logical tree may be split accross multiple trees"""
+ for top in list:
+ if path.startswith(top):
+ if self.debug > 2:
+ print >> self.debug_out, "found in", top
+ return top
+ return None
+
+ def find_obj(self, objroot, dir, path, input):
+ """return path within objroot, taking care of .dirdep files"""
+ ddep = None
+ for ddepf in [path + '.dirdep', dir + '/.dirdep']:
+ if not ddep and os.path.exists(ddepf):
+ ddep = open(ddepf, 'rb').readline().strip('# \n')
+ if self.debug > 1:
+ print >> self.debug_out, "found %s: %s\n" % (ddepf, ddep)
+ if ddep.endswith(self.machine):
+ ddep = ddep[0:-(1+len(self.machine))]
+
+ if not ddep:
+ # no .dirdeps, so remember that we've seen the raw input
+ self.seenit(input)
+ self.seenit(dir)
+ if self.machine == 'none':
+ if dir.startswith(objroot):
+ return dir.replace(objroot,'')
+ return None
+ m = self.dirdep_re.match(dir.replace(objroot,''))
+ if m:
+ ddep = m.group(2)
+ dmachine = m.group(1)
+ if dmachine != self.machine:
+ if not (self.machine == 'host' and
+ dmachine == self.host_target):
+ if self.debug > 2:
+ print >> self.debug_out, "adding .%s to %s" % (dmachine, ddep)
+ ddep += '.' + dmachine
+
+ return ddep
+
+ 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"
+ F "pid" "child"
+ R "pid" "path"
+ W "pid" "path"
+ X "pid" "status"
+ D "pid" "path"
+ L "pid" "src" "target"
+ M "pid" "old" "new"
+ S "pid" "path"
+ # Bye bye
+
+ We go to some effort to avoid processing a dependency more than once.
+ Of the above record types only C,E,F,L,R,V and W are of interest.
+ """
+
+ version = 0 # unknown
+ if name:
+ self.name = name;
+ if file:
+ f = file
+ cwd = last_dir = self.cwd
+ else:
+ f = open(self.name, 'rb')
+ skip = True
+ pid_cwd = {}
+ pid_last_dir = {}
+ last_pid = 0
+
+ if self.curdir:
+ self.seenit(self.curdir) # we ignore this
+
+ interesting = 'CEFLRV'
+ for line in f:
+ # ignore anything we don't care about
+ if not line[0] in interesting:
+ continue
+ if self.debug > 2:
+ print >> self.debug_out, "input:", line,
+ w = line.split()
+
+ if skip:
+ if w[0] == 'V':
+ skip = False
+ version = int(w[1])
+ """
+ if version < 4:
+ # we cannot ignore 'W' records
+ # as they may be 'rw'
+ interesting += 'W'
+ """
+ elif w[0] == 'CWD':
+ self.cwd = cwd = last_dir = w[1]
+ self.seenit(cwd) # ignore this
+ if self.debug:
+ print >> self.debug_out, "%s: CWD=%s" % (self.name, cwd)
+ continue
+
+ pid = int(w[1])
+ if pid != last_pid:
+ if last_pid:
+ pid_cwd[last_pid] = cwd
+ pid_last_dir[last_pid] = last_dir
+ cwd = getv(pid_cwd, pid, self.cwd)
+ last_dir = getv(pid_last_dir, pid, self.cwd)
+ last_pid = pid
+
+ # process operations
+ if w[0] == 'F':
+ npid = int(w[2])
+ pid_cwd[npid] = cwd
+ pid_last_dir[npid] = cwd
+ last_pid = npid
+ continue
+ elif w[0] == 'C':
+ cwd = abspath(w[2], cwd, None, self.debug, self.debug_out)
+ if cwd.endswith('/.'):
+ cwd = cwd[0:-2]
+ last_dir = cwd
+ if self.debug > 1:
+ print >> self.debug_out, "cwd=", cwd
+ continue
+
+ if w[2] in self.seen:
+ if self.debug > 2:
+ print >> self.debug_out, "seen:", w[2]
+ continue
+ # file operations
+ if w[0] in 'ML':
+ path = w[2].strip("'")
+ else:
+ path = w[2]
+ # we are never interested in .dirdep files as dependencies
+ if path.endswith('.dirdep'):
+ continue
+ # we don't want to resolve the last component if it is
+ # a symlink
+ path = resolve(path, cwd, last_dir, self.debug, self.debug_out)
+ if not path:
+ continue
+ dir,base = os.path.split(path)
+ if dir in self.seen:
+ if self.debug > 2:
+ print >> self.debug_out, "seen:", dir
+ continue
+ # we can have a path in an objdir which is a link
+ # to the src dir, we may need to add dependencies for each
+ rdir = dir
+ dir = abspath(dir, cwd, last_dir, self.debug, self.debug_out)
+ if rdir == dir or rdir.find('./') > 0:
+ rdir = None
+ # now put path back together
+ path = '/'.join([dir,base])
+ if self.debug > 1:
+ print >> self.debug_out, "raw=%s rdir=%s dir=%s path=%s" % (w[2], rdir, dir, path)
+ if w[0] in 'SRWL':
+ if w[0] == 'W' and path.endswith('.dirdep'):
+ continue
+ if path in [last_dir, cwd, self.cwd, self.curdir]:
+ if self.debug > 1:
+ print >> self.debug_out, "skipping:", path
+ continue
+ if os.path.isdir(path):
+ if w[0] in 'RW':
+ last_dir = path;
+ if self.debug > 1:
+ print >> self.debug_out, "ldir=", last_dir
+ continue
+
+ if w[0] in 'REWML':
+ # finally, we get down to it
+ if dir == self.cwd or dir == self.curdir:
+ continue
+ 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(w[2])
+ self.seenit(dir)
+ if rdir and not rdir.startswith(srctop):
+ dir = rdir # for below
+ rdir = None
+ else:
+ continue
+
+ objroot = None
+ for dir in [dir,rdir]:
+ if not dir:
+ continue
+ objroot = self.find_top(dir, self.objroots)
+ if objroot:
+ break
+ if objroot:
+ ddep = self.find_obj(objroot, dir, path, w[2])
+ if ddep:
+ self.add(self.obj_deps, ddep, 'obj')
+ else:
+ # don't waste time looking again
+ self.seenit(w[2])
+ self.seenit(dir)
+ if not file:
+ f.close()
+
+
+def main(argv, klass=MetaFile, xopts='', xoptf=None):
+ """Simple driver for class MetaFile.
+
+ Usage:
+ script [options] [key=value ...] "meta" ...
+
+ Options and key=value pairs contribute to the
+ dictionary passed to MetaFile.
+
+ -S "SRCTOP"
+ add "SRCTOP" to the "SRCTOPS" list.
+
+ -C "CURDIR"
+
+ -O "OBJROOT"
+ add "OBJROOT" to the "OBJROOTS" list.
+
+ -m "MACHINE"
+
+ -H "HOST_TARGET"
+
+ -D "DPDEPS"
+
+ -d bumps debug level
+
+ """
+ import getopt
+
+ # import Psyco if we can
+ # it can speed things up quite a bit
+ have_psyco = 0
+ try:
+ import psyco
+ psyco.full()
+ have_psyco = 1
+ except:
+ pass
+
+ conf = {
+ 'SRCTOPS': [],
+ 'OBJROOTS': [],
+ }
+
+ try:
+ machine = os.environ['MACHINE']
+ if machine:
+ conf['MACHINE'] = machine
+ srctop = os.environ['SB_SRC']
+ if srctop:
+ conf['SRCTOPS'].append(srctop)
+ objroot = os.environ['SB_OBJROOT']
+ if objroot:
+ conf['OBJROOTS'].append(objroot)
+ except:
+ pass
+
+ debug = 0
+ output = True
+
+ opts, args = getopt.getopt(argv[1:], 'dS:C:O:R:m:D:H:q' + xopts)
+ for o, a in opts:
+ if o == '-d':
+ debug += 1
+ elif o == '-q':
+ output = False
+ elif o == '-H':
+ conf['HOST_TARGET'] = a
+ elif o == '-S':
+ if a not in conf['SRCTOPS']:
+ conf['SRCTOPS'].append(a)
+ elif o == '-C':
+ conf['CURDIR'] = a
+ elif o == '-O':
+ if a not in conf['OBJROOTS']:
+ conf['OBJROOTS'].append(a)
+ elif o == '-R':
+ conf['RELDIR'] = a
+ elif o == '-D':
+ conf['DPDEPS'] = a
+ elif o == '-m':
+ conf['MACHINE'] = a
+ elif xoptf:
+ xoptf(o, a, conf)
+
+ conf['debug'] = debug
+
+ # get any var=val assignments
+ eaten = []
+ for a in args:
+ if a.find('=') > 0:
+ k,v = a.split('=')
+ if k in ['SRCTOP','OBJROOT','SRCTOPS','OBJROOTS']:
+ if k == 'SRCTOP':
+ k = 'SRCTOPS'
+ elif k == 'OBJROOT':
+ k = 'OBJROOTS'
+ if v not in conf[k]:
+ conf[k].append(v)
+ else:
+ conf[k] = v
+ eaten.append(a)
+ continue
+ break
+
+ for a in eaten:
+ args.remove(a)
+
+ debug_out = getv(conf, 'debug_out', sys.stderr)
+
+ if debug:
+ print >> debug_out, "config:"
+ print >> debug_out, "psyco=", have_psyco
+ for k,v in conf.items():
+ print >> debug_out, "%s=%s" % (k,v)
+
+ for a in args:
+ m = klass(a, conf)
+
+ if output:
+ print m.dirdeps()
+
+ print m.src_dirdeps('\nsrc:')
+
+ dpdeps = getv(conf, 'DPDEPS')
+ if dpdeps:
+ m.file_depends(open(dpdeps, 'wb'))
+
+ return m
+
+if __name__ == '__main__':
+ try:
+ main(sys.argv)
+ except:
+ # yes, this goes to stdout
+ print "ERROR: ", sys.exc_info()[1]
+ raise
+
diff --git a/contrib/bmake/mk/meta2deps.sh b/contrib/bmake/mk/meta2deps.sh
new file mode 100755
index 000000000000..e7ddd829aed4
--- /dev/null
+++ b/contrib/bmake/mk/meta2deps.sh
@@ -0,0 +1,307 @@
+#!/bin/sh
+
+# NAME:
+# meta2deps.sh - extract useful info from .meta files
+#
+# SYNOPSIS:
+# meta2deps.sh SB="SB" "meta" ...
+#
+# DESCRIPTION:
+# This script looks each "meta" file and extracts the
+# information needed to deduce build and src dependencies.
+#
+# To do this, we extract the 'CWD' record as well as all the
+# syscall traces which describe 'R'ead, 'C'hdir and 'E'xec
+# syscalls.
+#
+# The typical meta file looks like::
+#.nf
+#
+# # Meta data file "path"
+# CMD "command-line"
+# CWD "cwd"
+# TARGET "target"
+# -- command output --
+# -- filemon acquired metadata --
+# # buildmon version 2
+# V 2
+# E "pid" "path"
+# R "pid" "path"
+# C "pid" "cwd"
+# R "pid" "path"
+# X "pid" "status"
+#.fi
+#
+# The fact that all the syscall entry lines start with a single
+# character make these files quite easy to process using sed(1).
+#
+# To simplify the logic the 'CWD' line is made to look like a
+# normal 'C'hdir entry, and "cwd" is remembered so that it can
+# be prefixed to any "path" which is not absolute.
+#
+# If the "path" being read ends in '.srcrel' it is the content
+# of (actually the first line of) that file that we are
+# interested in.
+#
+# Any "path" which lies outside of the sandbox "SB" is generally
+# not of interest and is ignored.
+#
+# The output, is a set of absolute paths with "SB" like:
+#.nf
+#
+# $SB/obj-i386/junos/gnu/lib/csu
+# $SB/obj-i386/junos/gnu/lib/libgcc
+# $SB/obj-i386/bsd/include
+# $SB/obj-i386/bsd/lib/csu/i386-elf
+# $SB/obj-i386/bsd/lib/libc
+# $SB/src/bsd/include
+# $SB/src/bsd/sys/i386/include
+# $SB/src/bsd/sys/sys
+# $SB/src/pan-release/rtsock
+# $SB/src/pfe-shared/include/jnx
+#.fi
+#
+# Which can then be further processed by 'gendirdeps.mk'
+#
+# If we are passed 'DPDEPS='"dpdeps", then for each src file
+# outside of "CURDIR" we read, we output a line like:
+#.nf
+#
+# DPDEPS_$path += $RELDIR
+#.fi
+#
+# with "$path" geting turned into reldir's, so that we can end
+# up with a list of all the directories which depend on each src
+# file in another directory. This can allow for efficient yet
+# complete testing of changes.
+
+
+# RCSid:
+# $Id: meta2deps.sh,v 1.4 2012/11/07 06:55:21 sjg Exp $
+
+# Copyright (c) 2010, Juniper Networks, Inc.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+meta2src() {
+ cat /dev/null "$@" |
+ sed -n '/^R .*\.[chyl]$/s,^..[0-9]* ,,p' |
+ sort -u
+}
+
+meta2dirs() {
+ cat /dev/null "$@" |
+ sed -n '/^R .*\/.*\.[a-z0-9][^\/]*$/s,^..[0-9]* \(.*\)/[^/]*$,\1,p' |
+ sort -u
+}
+
+meta2deps() {
+ DPDEPS=
+ while :
+ do
+ case "$1" in
+ *=*) eval export "$1"; shift;;
+ *) break;;
+ esac
+ done
+
+ [ -z "$RELDIR" ] && unset DPDEPS
+ tf=/tmp/m2d$$-$USER
+ rm -f $tf.*
+ trap 'rm -f $tf.*; trap 0' 0
+
+ > $tf.dirdep
+ > $tf.qual
+ > $tf.srcdep
+ > $tf.srcrel
+ > $tf.dpdeps
+
+ seenit=
+ seensrc=
+ lpid=
+ cat /dev/null "$@" |
+ sed -e 's,^CWD,C C,;/^[CREFL] /!d' -e "s,',,g" |
+ while read op pid path junk
+ do
+ : op=$op pid=$pid path=$path
+ # we track cwd and ldir (of interest) per pid
+ # CWD is bmake's cwd
+ case "$lpid,$pid" in
+ ,C) CWD=$path cwd=$path ldir=$path
+ if [ -z "$SB" ]; then
+ SB=`echo $CWD | sed 's,/obj.*,,'`
+ fi
+ SRCTOP=${SRCTOP:-$SB/src}
+ continue
+ ;;
+ $pid,$pid) ;;
+ *)
+ case "$lpid" in
+ "") ;;
+ *) eval ldir_$lpid=$ldir cwd_$lpid=$cwd;;
+ esac
+ eval ldir=\${ldir_$pid:-$CWD} cwd=\${cwd_$pid:-$CWD}
+ lpid=$pid
+ ;;
+ esac
+
+ case "$op,$path" in
+ *.dirdep) continue;;
+ W,*srcrel) continue;;
+ C,*)
+ case "$path" in
+ /*) cwd=$path;;
+ *) cwd=`cd $cwd/$path 2> /dev/null && /bin/pwd`;;
+ esac
+ # watch out for temp dirs that no longer exist
+ test -d ${cwd:-/dev/null/no/such} || cwd=$CWD
+ continue
+ ;;
+ F,*) eval cwd_$path=$cwd ldir_$path=$ldir
+ continue
+ ;;
+ *) dir=${path%/*}
+ case "$path" in
+ $SB/*|${SB_BACKING_SB:-$SB}/*) ;;
+ $SB_OBJROOT*) ;;
+ /*/stage/*) ;;
+ /*) continue;;
+ *) for path in $ldir/$path $cwd/$path
+ do
+ test -e $path && break
+ done
+ dir=${path%/*}
+ ;;
+ esac
+ ;;
+ esac
+ # avoid repeating ourselves...
+ case "$DPDEPS,$seensrc," in
+ ,*)
+ case ",$seenit," in
+ *,$dir,*) continue;;
+ esac
+ ;;
+ *,$path,*) continue;;
+ esac
+ # canonicalize if needed
+ case "/$dir/" in
+ */../*|*/./*)
+ rdir=$dir
+ dir=`cd $dir 2> /dev/null && /bin/pwd`
+ seen="$rdir,$dir"
+ ;;
+ *) seen=$dir;;
+ esac
+ case "$dir" in
+ ${CURDIR:-.}|${CURDIR:-.}/*|"") continue;;
+ $SRCTOP/*|${SB_BACKING_SB:-$SB}/src/*)
+ # avoid repeating ourselves...
+ case "$DPDEPS,$seensrc," in
+ ,*)
+ case ",$seenit," in
+ *,$dir,*) continue;;
+ esac
+ ;;
+ esac
+ ;;
+ *)
+ case ",$seenit," in
+ *,$dir,*) continue;;
+ esac
+ ;;
+ esac
+ if [ -d $path ]; then
+ case "$path" in
+ */..) ldir=${dir%/*};;
+ *) ldir=$path;;
+ esac
+ continue
+ fi
+ [ -f $path ] || continue
+ case "$dir" in
+ $CWD) continue;; # ignore
+ $SRCTOP/*|${SB_BACKING_SB:-$SB}/src/*)
+ seenit="$seenit,$seen"
+ echo $dir >> $tf.srcdep
+ case "$DPDEPS,$reldir,$seensrc," in
+ ,*) ;;
+ *) seensrc="$seensrc,$path"
+ echo "DPDEPS_$dir/${path##*/} += $RELDIR" >> $tf.dpdeps
+ ;;
+ esac
+ continue
+ ;;
+ esac
+ # if there is a .dirdep we cannot skip
+ # just because we've seen the dir before.
+ if [ -s $path.dirdep ]; then
+ # this file contains:
+ # '# ${RELDIR}.<machine>'
+ echo $path.dirdep >> $tf.qual
+ continue
+ elif [ -s $dir.dirdep ]; then
+ echo $dir.dirdep >> $tf.qual
+ seenit="$seenit,$seen"
+ continue
+ fi
+ seenit="$seenit,$seen"
+ case "$dir" in
+ $SB/*|${SB_OBJROOT:-$SB/}*|${SB_BACKING_SB:-$SB}/*)
+ echo $dir;;
+ esac
+ done > $tf.dirdep
+ _nl=echo
+ for f in $tf.dirdep $tf.qual $tf.srcdep
+ do
+ [ -s $f ] || continue
+ case $f in
+ *qual) # a list of .dirdep files
+ # we can prefix everthing with $OBJTOP to
+ # tell gendirdeps.mk that these are
+ # DIRDEP entries, since they are already
+ # qualified with .<machine> as needed.
+ # We strip .$MACHINE though
+ xargs cat < $f | sort -u |
+ sed "s,^# ,,;s,^,$OBJTOP/,;s,\.$MACHINE\$,,"
+ ;;
+ *) sort -u $f;;
+ esac
+ _nl=:
+ done
+ if [ -s $tf.dpdeps ]; then
+ case "$DPDEPS" in
+ */*) ;;
+ *) echo > $DPDEPS;; # the echo is needed!
+ esac
+ sort -u $tf.dpdeps |
+ sed "s,${SRCTOP}/,,;s,${SB_BACKING_SB:-$SB}/src/,," >> $DPDEPS
+ fi
+ # ensure we produce _something_ else egrep -v gets upset
+ $_nl
+}
+
+case /$0 in
+*/meta2dep*) meta2deps "$@";;
+*/meta2dirs*) meta2dirs "$@";;
+*/meta2src*) meta2src "$@";;
+esac
diff --git a/contrib/bmake/mk/mk-files.txt b/contrib/bmake/mk/mk-files.txt
new file mode 100644
index 000000000000..78826417b859
--- /dev/null
+++ b/contrib/bmake/mk/mk-files.txt
@@ -0,0 +1,467 @@
+mk-files
+********
+
+The term ``mk-files`` refers to a collection of ``*.mk`` files.
+
+You need bmake_ or a *recent* NetBSD_ make.
+If in doubt use bmake_.
+
+Introduction
+============
+
+Many years ago, when building large software projects, I used GNU make
+(or my own patched version of it), and had developed a set of macros
+to simplify developing complex build trees.
+
+Since the early 90's my main development machines, run BSD
+(NetBSD_ to be precise), and the BSD source tree is good example of a
+large software project. It quickly became clear that
+``/usr/share/mk/*.mk`` were a great model, but were quite tightly
+linked to building the BSD tree.
+
+Much as I liked using NetBSD, my customers were more likely to be
+using SunOS, HP-UX etc, so I started on bmake_ and a portable collection
+of mk-files (mk.tar.gz_). NetBSD provided much of the original structure.
+
+Since then I've added a lot of features to NetBSD's make and hence to
+bmake which is kept closely in sync. The mk-files however have
+diverged quite a bit, though ideas are still picked up from NetBSD.
+
+Basics
+------
+
+The BSD build model is very simple. A directory produces one
+component, which is generally either a library or a program.
+Library makefiles include ``lib.mk`` and programs include ``prog.mk``
+and they *do the right thing*.
+
+A simple library makefile might look like::
+
+ LIB = sig
+
+ SRCS = \
+ sigaction.c \
+ sigcompat.c \
+ sighdl.c
+
+ .include <lib.mk>
+
+a simple program makefile::
+
+ PROG = cat
+
+ SRCS = cat.c
+
+ .include <prog.mk>
+
+in such cases even the ``SRCS`` line is unnecessary as ``prog.mk``
+will default it to ``${PROG}.c``.
+
+It is the sensible use of defaults and the plethora of macro modifiers
+provided by bmake_ that allow simple makefiles such as the above
+*just work* on many different systems.
+
+
+mk-files
+========
+
+This section provides a brief description of some of the ``*.mk``
+files.
+
+sys.mk
+------
+
+When bmake starts, it looks for ``sys.mk`` and reads it before doing
+anything else. Thus, this is the place to setup the environment for
+everyone else.
+
+In this distribution, sys.mk avoids doing anything platform dependent.
+It is quite short, and includes a number of other files (which may or
+may not exists)
+
+sys.env.mk
+ If it exists, is expected to do things like conditioning the
+ environment. Since it will only be included by the initial
+ instance of bmake, it should ``.export`` anything that
+ sub-makes might need.
+
+examples/sys.clean-env.mk
+ An example of how to clean the environment.
+ See the file for all the details::
+
+ .if ${MAKE_VERSION} >= 20100606 && ${.MAKE.LEVEL} == 0
+ # we save any env var that starts with these
+ MAKE_SAVE_ENV_PREFIX += SB MK MAKE MACHINE NEED_ CCACHE DISTCC USE_ SSH
+ MAKE_SAVE_ENV_VARS += \
+ PATH HOME USER LOGNAME \
+ SRCTOP OBJTOP OBJROOT \
+ ${_env_vars}
+
+ _env_vars != env | egrep '^(${MAKE_SAVE_ENV_PREFIX:ts|})' | sed 's,=.*,,'; echo
+ _export_list =
+ .for v in ${MAKE_SAVE_ENV_VARS:O:u}
+ .if !empty($v)
+ _export_list += $v
+ $v := ${$v}
+ .endif
+ .endfor
+ # now clobber the environment
+ .unexport-env
+
+ # list of vars that we handle specially below
+ _tricky_env_vars = MAKEOBJDIR
+ # export our selection - sans tricky ones
+ .export ${_export_list:${_tricky_env_vars:${M_ListToSkip}}}
+
+ # this next bit may need tweaking
+ .if defined(MAKEOBJDIR)
+ srctop := ${SRCTOP:U${SB_SRC:U${SB}/src}}
+ objroot := ${OBJROOT:U${SB_OBJROOT:U${SB}/${SB_OBJPREFIX}}}
+ # we'll take care of MACHINE below
+ objtop := ${OBJTOP:U${objroot}${MACHINE}}
+ .if !empty(objtop)
+ # we would normally want something like (/bin/sh):
+ # MAKEOBJDIR="\${.CURDIR:S,${SRCTOP},${OBJROOT}\${MACHINE},}"
+ # the $$ below is how we achieve the same result here.
+ # since everything saved from the environment above
+ # has run through := we need to compensate for ${MACHINE}
+ MAKEOBJDIR = $${.CURDIR:S,${srctop},${objtop:S,${MACHINE},\${MACHINE},},}
+
+ # export these as-is, and do not track...
+ .export-env ${_tricky_env_vars}
+ # now evaluate for ourselves
+ .for v in ${_tricky_env_vars}
+ $v := ${$v}
+ .endfor
+
+ .endif
+ .endif
+ .endif
+
+
+host-target.mk
+ Is used to set macros like ``HOST_TARGET``, ``HOST_OS`` and
+ ``host_os`` which are used to find the next step.
+
+sys/\*.mk
+ Platform specific additions, such as ``Darwin.mk`` or ``SunOS.mk``
+ set things like ``HOST_LIBEXT = .dylib`` for Darwin or
+ ``SHLIB_FULLVERSION = ${SHLIB_MAJOR}`` for SunOS 5.
+ If there is no OS specific file, ``sys/Generic.mk`` is used.
+
+local.sys.mk
+ Any ``local.*.mk`` file is not part of the distribution.
+ This provides a hook for sites to do extra setup without
+ having to edit the distributed files.
+
+
+The above arrangement makes it easy for the mk files to be part of a
+src tree on an NFS volume and to allow building on multiple platforms.
+
+lib.mk
+------
+
+This file is used to build a number of different libraries from the
+same SRCS.
+
+lib${LIB}.a
+ An archive lib of ``.o`` files, this is the default
+
+lib${LIB}_p.a
+ A profiled lib of ``.po`` files.
+ Still an archive lib, but all the objects are built with
+ profiling in mind - hence the different extension.
+ It is skipped if ``MKPROFILE`` is "no".
+
+lib${LIB}_pic.a
+ An archive of ``.so`` objects compiled for relocation.
+ On NetBSD this is the input to ``lib${LIB}.${LD_so}``, it is
+ skipped if ``MKPICLIB`` is "no".
+
+lib${LIB}.${LD_so}
+ A shared library. The value of ``LD_so`` is very platform
+ specific. For example::
+
+ # SunOS 5 and most other ELF systems
+ libsslfd.so.1
+
+ # Darwin
+ libsslfd.1.dylib
+
+ This library will only be built if ``SHLIB_MAJOR`` has
+ a value, and ``MKPIC`` is not set to "no".
+
+There is a lot of platform specific tweaking in ``lib.mk``, largely the
+result of the original distributions trying to avoid interfering with
+the system's ``sys.mk``.
+
+libnames.mk
+-----------
+
+This is included by both ``prog.mk`` and ``lib.mk`` and tries to
+include ``*.libnames.mk`` of which:
+
+local.libnames.mk
+ does not exist unless you create it. It is a handy way for you
+ to customize without touching the distributed files.
+ For example, on a test machine I needed to build openssl but
+ not install it, so put the following in ``local.libnames.mk``::
+
+ .if ${host_os} == "sunos"
+ LIBCRYPTO = ${OBJTOP}/openssl/lib/crypto/libcrypto${DLIBEXT}
+ LIBSSL = ${OBJTOP}/openssl/lib/ssl/libssl${DLIBEXT}
+ INCLUDES_libcrypto = -I${OBJ_libcrypto}
+ .endif
+
+ The makefile created an openssl dir in ``${OBJ_libcrypto}`` to
+ gather all the headers. dpadd.mk_ did the rest.
+
+sjg.libnames.mk
+ not part of the mk-files distribution.
+
+host.libnames.mk
+ contains logic to find any libs named in ``HOST_LIBS`` in
+ ``HOST_LIBDIRS``.
+
+Each file above gets an opportunity to define things like::
+
+ LIBSSLFD ?= ${OBJTOP}/ssl/lib/sslfd/libsslfd${DLIBEXT}
+ INCLUDES_libsslfd = -I${SRC_libsslfd}/h -I${OBJ_libslfd}
+
+these are used by dpadd.mk_ and will be explained below.
+
+dpadd.mk
+--------
+
+This file looks like line noise, and is best considered read-only.
+However it provides some very useful functionality, which simplifies the build.
+
+Makefiles can use the LIB* macros defined via libnames.mk_ or anywhere
+else in various ways::
+
+ # indicate that we need to include headers from LIBCRYPTO
+ # this would result in ${INCLUDES_libcrypto} being added to CFLAGS.
+ SRC_LIBS += ${LIBCRYPTO}
+
+ # indicate that libsslfd must be built already.
+ # it also has the same effect as SRC_LIBS
+ DPADD += ${LIBSSLFD}
+
+ # indicate that not only must libsslfd be built,
+ # but that we need to link with it.
+ # this is almost exactly equivalent to
+ # DPADD += ${LIBSSLFD}
+ # LDADD += -L${LIBSSLFD:H} -lsslfd
+ # and mostly serves to ensure that DPADD and LDADD are in sync.
+ DPLIBS += ${LIBSSLFD}
+
+Any library (referenced by its full path) in any of the above, is
+added to ``DPMAGIC_LIBS`` with the following results, for each lib *foo*.
+
+SRC_libfoo
+ Is set to indicate where the src for libfoo is.
+ By default it is derived from ``LIBFOO`` by replacing
+ ``${OBJTOP}`` with ``${SRCTOP}``.
+
+OBJ_libfoo
+ Not very exciting, is just the dir where libfoo lives.
+
+INCLUDES_libfoo
+ What to add to ``CFLAGS`` to find the public headers.
+ The default varies. If ``${SRC_libfoo}/h`` exists, it is assumed
+ to be the home of all public headers and thus the default is
+ ``-I${SRC_libfoo}/h``
+
+ Otherwise we make no assumptions and the default is
+ ``-I${SRC_libfoo} -I${OBJ_libfoo}``
+
+LDADD_libfoo
+ This only applies to libs reference via ``DPLIBS``.
+ The default is ``-lfoo``, ``LDADD_*`` provides a hook to
+ instantiate other linker flags at the appropriate point
+ without losing the benfits of ``DPLIBS``.
+
+prog.mk
+-------
+
+Compiles the specified SRCS and links them and the nominated libraries
+into a program. Prog makefiles usually need to list the libraries
+that need to be linked. We prefer use of ``DPLIBS`` but the more
+traditional ``DPADD`` and ``LDADD`` work just as well.
+That is::
+
+ DPLIBS += ${LIBCRYPTO}
+
+is equivalent to::
+
+ DPADD += ${LIBCRYPTO}
+ LDADD += -lcrypto
+
+obj.mk
+------
+
+One of the cool aspects of BSD make, is its support for separating
+object files from the src tree. This is also the source of much
+confusion to some.
+
+Traditionally one had to do a separate ``make obj`` pass through the
+tree. If ``MKOBJDIRS`` is "auto", we include auto.obj.mk_.
+
+auto.obj.mk
+-----------
+
+This leverages the ``.OBJDIR`` target introduced some years ago to
+NetBSD make, to automatically create the desired object dir.
+
+subdir.mk
+---------
+
+This is the traditional means of walking the tree. A makefile sets
+``SUBDIR`` to the list of sub-dirs to visit.
+
+If ``SUBDIR_MUST_EXIST`` is set, missing directories cause an error,
+otherwise a warning is issued. If you don't even want the warning,
+set ``MISSING_DIR=continue``.
+
+Traditionally, ``subdir.mk`` prints clue as it visits each subdir::
+
+ ===> ssl
+ ===> ssl/lib
+ ===> ssl/lib/sslfd
+
+you can suppress that - or enhance it by setting ``ECHO_DIR``::
+
+ # suppress subdir noise
+ ECHO_DIR=:
+ # print time stamps
+ ECHO_DIR=echo @ `date "+%s [%Y-%m-%d %T] "`
+
+links.mk
+--------
+
+Provides rules for processing lists of ``LINKS`` and ``SYMLINKS``.
+Each is expected to be a list of ``link`` and ``target`` pairs
+(``link`` -> ``target``).
+
+The logic is generally in a ``_*_SCRIPT`` which is referenced in a
+``_*_USE`` (``.USE``) target.
+
+The ``_BUILD_*`` forms are identical, but do not use ``${DESTDIR}``
+and so are useful for creating symlinks during the build phase.
+For example::
+
+ SYMLINKS += ${.CURDIR}/${MACHINE_ARCH}/include machine
+ header_links: _BUILD_SYMLINKS_USE
+
+ md.o: header_links
+
+would create a symlink called ``machine`` in ``${.OBJDIR}`` pointing to
+``${.CURDIR}/${MACHINE_ARCH}/include`` before compiling ``md.o``
+
+
+autoconf.mk
+-----------
+
+Deals with running (or generating) GNU autoconf ``configure`` scripts.
+
+dep.mk
+------
+
+Deals with collecting dependencies. Another useful feature of BSD
+make is the separation of this sort of information into a ``.depend``
+file. ``MKDEP`` needs to point to a suitable tool (like mkdeps.sh_)
+
+If ``USE_AUTODEP_MK`` is "yes" includes autodep.mk_
+
+autodep.mk
+----------
+
+Leverages the ``-MD`` feature of recent GCC to collect dependency
+information as a side effect of compilation. With this GCC puts
+dependency info into a ``.d`` file.
+
+Unfortunately GCC bases the name of the ``.d`` file on the name of the
+input rather than the output file, which causes problems when the same
+source is compiled different ways. The latest GCC supports ``-MF`` to
+name the ``.d`` file and ``-MT`` to control the name to put as the
+dependent.
+
+Recent bmake allows dependencies for the ``.END`` target (run at the
+end if everything was successful), and ``autodep.mk`` uses this to
+post process the ``.d`` files into ``.depend``.
+
+auto.dep.mk
+-----------
+
+A much simpler implementation than autodep.mk_ it uses
+``-MF ${.TARGET:T}.d``
+to avoid possible conflicts during parallel builds.
+This precludes the use of suffix rules to drive ``make depend``, so
+dep.mk_ handles that if specifically requested.
+
+own.mk
+------
+
+Normally included by ``init.mk`` (included by ``lib.mk`` and
+``prog.mk`` etc), sets macros for default ownership etc.
+
+It includes ``${MAKECONF}`` if it is defined and exists.
+
+man.mk
+------
+
+Deals with man pages.
+
+warnings.mk
+-----------
+
+This provides a means of fine grained control over warnings on a per
+``${MACHINE}`` or even file basis.
+
+A makefile sets ``WARNINGS_SET`` to name a list of warnings
+and individual ``W_*`` macros can be used to tweak them.
+For example::
+
+ WARNINGS_SET = HIGH
+ W_unused_sparc = -Wno-unused
+
+would add all the warnings in ``${HIGH_WARNINGS}`` to CFLAGS, but
+on sparc, ``-Wno-unused`` would replace ``-Wunused``.
+
+You should never need to edit ``warnings.mk``, it will include
+``warnings-sets.mk`` if it exists and you use that to make any local
+customizations.
+
+Meta mode
+=========
+
+The 20110505 and later versions of ``mk-files`` include a number of
+makefile contributed by Juniper Networks, Inc.
+These allow the latest version of bmake_ to run in `meta mode`_.
+
+.. _`meta mode`: bmake-meta-mode.htm
+
+Install
+=======
+
+You can use the content of mk.tar.gz_ without installing at all.
+
+The script ``install-mk`` takes care of copying ``*.mk`` into a
+destination directory, and unless told not to, create ``bsd.*.mk`` links
+for ``lib.mk`` etc.
+
+If you just want to create the ``bsd.*.mk`` links in the directory
+where you unpacked the tar file, you can::
+
+ ./mk/install-mk ./mk
+
+------
+
+.. _bmake: bmake.htm
+.. _NetBSD: http://www.netbsd.org/
+.. _mkdeps.sh: http://www.crufty.net/ftp/pub/sjg/mkdeps.sh
+.. _mk.tar.gz: http://www.crufty.net/ftp/pub/sjg/mk.tar.gz
+
+:Author: sjg@crufty.net
+:Revision: $Id: mk-files.txt,v 1.15 2011/06/08 07:06:18 sjg Exp $
+:Copyright: Crufty.NET
diff --git a/contrib/bmake/mk/nls.mk b/contrib/bmake/mk/nls.mk
new file mode 100644
index 000000000000..e302c8dc88cb
--- /dev/null
+++ b/contrib/bmake/mk/nls.mk
@@ -0,0 +1,48 @@
+# $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
+
+.MAIN: all
+.endif
+
+.SUFFIXES: .cat .msg
+
+.msg.cat:
+ @rm -f ${.TARGET}
+ gencat ${.TARGET} ${.IMPSRC}
+
+.if defined(NLS) && !empty(NLS)
+NLSALL= ${NLS:.msg=.cat}
+.NOPATH: ${NLSALL}
+.endif
+
+.if !defined(NLSNAME)
+.if defined(PROG)
+NLSNAME=${PROG}
+.else
+NLSNAME=lib${LIB}
+.endif
+.endif
+
+nlsinstall:
+.if defined(NLSALL)
+ @for msg in ${NLSALL}; do \
+ NLSLANG=`basename $$msg .cat`; \
+ dir=${DESTDIR}${NLSDIR}/$${NLSLANG}; \
+ ${INSTALL} -d $$dir; \
+ ${INSTALL} ${COPY} -o ${NLSOWN} -g ${NLSGRP} -m ${NLSMODE} $$msg $$dir/${NLSNAME}.cat; \
+ done
+.endif
+
+.if defined(NLSALL)
+all: ${NLSALL}
+
+install: nlsinstall
+
+cleandir: cleannls
+cleannls:
+ rm -f ${NLSALL}
+.endif
diff --git a/contrib/bmake/mk/obj.mk b/contrib/bmake/mk/obj.mk
new file mode 100644
index 000000000000..b936379d4f6b
--- /dev/null
+++ b/contrib/bmake/mk/obj.mk
@@ -0,0 +1,113 @@
+# $Id: obj.mk,v 1.15 2012/11/11 22:37:02 sjg Exp $
+#
+# @(#) Copyright (c) 1999-2010, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+.if !target(__${.PARSEFILE:S,bsd.,,}__)
+__${.PARSEFILE:S,bsd.,,}__:
+
+.include <init.mk>
+
+ECHO_TRACE ?= echo
+
+.if ${MK_OBJDIRS} == "no"
+obj:
+objlink:
+objwarn:
+.else
+
+# this has to match how make behaves
+.if defined(MAKEOBJDIRPREFIX) || defined(MAKEOBJDIR)
+.if defined(MAKEOBJDIRPREFIX)
+__objdir:= ${MAKEOBJDIRPREFIX}${.CURDIR}
+.else
+__objdir:= ${MAKEOBJDIR}
+.endif
+.else
+__objdir= ${__objlink}
+.endif
+
+.if defined(OBJMACHINE)
+__objlink= obj.${MACHINE}
+.else
+__objlink= obj
+.endif
+
+.if ${MK_AUTO_OBJ} == "yes"
+.-include "auto.obj.mk"
+.endif
+
+.NOPATH: ${__objdir}
+.PHONY: obj
+
+obj: _SUBDIRUSE
+ @if test ! -d ${__objdir}/.; then \
+ mkdir -p ${__objdir}; \
+ if test ! -d ${__objdir}; then \
+ mkdir ${__objdir}; exit 1; \
+ fi; \
+ ${ECHO_TRACE} "[Creating objdir ${__objdir}...]" >&2; \
+ fi
+
+.if !target(_SUBDIRUSE)
+# this just allows us to be included by ourselves
+_SUBDIRUSE:
+.endif
+
+# so we can interact with freebsd makefiles
+.if !target(objwarn)
+objwarn:
+.if ${.OBJDIR} == ${.CURDIR}
+ @echo "Warning Object directory is ${.CURDIR}"
+.elif ${.OBJDIR} != ${__objdir}
+ @echo "Warning Object directory is ${.OBJDIR} vs. ${__objdir}"
+.endif
+.endif
+
+.if !target(objlink)
+objlink:
+.if ${__objdir:T} != ${__objlink}
+ @if test -d ${__objdir}/.; then \
+ ${RM} -f ${.CURDIR}/${__objlink}; \
+ ${LN} -s ${__objdir} ${.CURDIR}/${__objlink}; \
+ echo "${__objlink} -> ${__objdir}"; \
+ else \
+ echo "No ${__objdir} to link to - do a 'make obj'"; \
+ fi
+.endif
+.endif
+.endif
+
+_CURDIR?= ${.CURDIR}
+_OBJDIR?= ${.OBJDIR}
+
+.if !target(print-objdir)
+print-objdir:
+ @echo ${_OBJDIR}
+.endif
+
+.if !target(whereobj)
+whereobj:
+ @echo ${_OBJDIR}
+.endif
+
+.if !target(destroy)
+.if ${.CURDIR} != ${.OBJDIR}
+destroy:
+ (cd ${_CURDIR} && rm -rf ${_OBJDIR})
+.else
+destroy: clean
+.endif
+.endif
+
+.endif
diff --git a/contrib/bmake/mk/options.mk b/contrib/bmake/mk/options.mk
new file mode 100644
index 000000000000..7d1bf67915a0
--- /dev/null
+++ b/contrib/bmake/mk/options.mk
@@ -0,0 +1,58 @@
+# $Id: options.mk,v 1.6 2013/01/28 19:28:52 sjg Exp $
+#
+# @(#) Copyright (c) 2012, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+# Inspired by FreeBSD bsd.own.mk, but intentionally simpler.
+
+# Options are normally listed in either OPTIONS_DEFAULT_{YES,NO}
+# We convert these to ${OPTION}/{yes,no} in OPTIONS_DEFAULT_VALUES.
+# We add the OPTIONS_DEFAULT_NO first so they take precedence.
+# This allows override of an OPTIONS_DEFAULT_YES by adding it to
+# OPTIONS_DEFAULT_NO or adding ${OPTION}/no to OPTIONS_DEFAULT_VALUES.
+# An OPTIONS_DEFAULT_NO option can only be overridden by putting
+# ${OPTION}/yes in OPTIONS_DEFAULT_VALUES.
+# A makefile may set NO_* (or NO*) to indicate it cannot do something.
+# User sets WITH_* and WITHOUT_* to indicate what they want.
+# We set MK_* which is then all we need care about.
+OPTIONS_DEFAULT_VALUES += \
+ ${OPTIONS_DEFAULT_NO:O:u:S,$,/no,} \
+ ${OPTIONS_DEFAULT_YES:O:u:S,$,/yes,}
+
+.for o in ${OPTIONS_DEFAULT_VALUES:M*/*}
+.if ${o:T:tl} == "no"
+.if defined(WITH_${o:H}) && !defined(NO_${o:H}) && !defined(NO${o:H})
+MK_${o:H} ?= yes
+.else
+MK_${o:H} ?= no
+.endif
+.else
+.if defined(WITHOUT_${o:H}) || defined(NO_${o:H}) || defined(NO${o:H})
+MK_${o:H} ?= no
+.else
+MK_${o:H} ?= yes
+.endif
+.endif
+.endfor
+
+# OPTIONS_DEFAULT_DEPENDENT += FOO_UTILS/FOO
+# if neither WITH[OUT]_FOO_UTILS is set, use value of MK_FOO
+.for o in ${OPTIONS_DEFAULT_DEPENDENT:M*/*:O:u}
+.if defined(WITH_${o:H}) && !defined(NO_${o:H}) && !defined(NO${o:H})
+MK_${o:H} ?= yes
+.elif defined(WITHOUT_${o:H}) || defined(NO_${o:H}) || defined(NO${o:H})
+MK_${o:H} ?= no
+.else
+MK_${o:H} ?= ${MK_${o:T}}
+.endif
+.endfor
diff --git a/contrib/bmake/mk/own.mk b/contrib/bmake/mk/own.mk
new file mode 100644
index 000000000000..85ea66b80094
--- /dev/null
+++ b/contrib/bmake/mk/own.mk
@@ -0,0 +1,244 @@
+# $Id: own.mk,v 1.26 2012/12/11 23:40:19 sjg Exp $
+
+.if !target(__${.PARSEFILE}__)
+__${.PARSEFILE}__:
+
+.if !target(__init.mk__)
+.include "init.mk"
+.endif
+
+.ifndef NOMAKECONF
+MAKECONF?= /etc/mk.conf
+.-include "${MAKECONF}"
+.endif
+
+.include <host-target.mk>
+
+TARGET_OSNAME?= ${_HOST_OSNAME}
+TARGET_OSREL?= ${_HOST_OSREL}
+TARGET_OSTYPE?= ${HOST_OSTYPE}
+TARGET_HOST?= ${HOST_TARGET}
+
+# these may or may not exist
+.-include "${TARGET_HOST}.mk"
+.-include "config.mk"
+
+RM?= rm
+LN?= ln
+INSTALL?= install
+
+prefix?= /usr
+.if exists(${prefix}/lib)
+libprefix?= ${prefix}
+.else
+libprefix?= /usr
+.endif
+
+# FreeBSD at least does not set this
+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}
+COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp
+LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS}
+COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c
+LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
+CXXFLAGS?= ${CFLAGS}
+COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c
+LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS}
+COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c
+LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS}
+COMPILE.f?= ${FC} ${FFLAGS} -c
+LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS}
+COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c
+LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS}
+COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c
+LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS}
+LEX.l?= ${LEX} ${LFLAGS}
+COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c
+LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS}
+YACC.y?= ${YACC} ${YFLAGS}
+
+# for suffix rules
+IMPFLAGS?= ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}}
+.for s in .c .cc
+COMPILE.$s += ${IMPFLAGS}
+LINK.$s += ${IMPFLAGS}
+.endfor
+
+PRINT.VAR.MAKE = MAKESYSPATH=${MAKESYSPATH:U${.PARSEDIR}} ${.MAKE}
+.if empty(.MAKEFLAGS:M-V*)
+.if defined(MAKEOBJDIRPREFIX) || defined(MAKEOBJDIR)
+PRINTOBJDIR= ${PRINT.VAR.MAKE} -r -V .OBJDIR -f /dev/null xxx
+.else
+PRINTOBJDIR= ${PRINT.VAR.MAKE} -V .OBJDIR
+.endif
+.else
+PRINTOBJDIR= echo # prevent infinite recursion
+.endif
+
+# we really like to have SRCTOP and OBJTOP defined...
+.if !defined(SRCTOP) || !defined(OBJTOP)
+.-include "srctop.mk"
+.endif
+
+.if !defined(SRCTOP) || !defined(OBJTOP)
+# dpadd.mk is rather pointless without these
+OPTIONS_DEFAULT_NO+= DPADD_MK
+.endif
+
+# process options
+OPTIONS_DEFAULT_NO+= \
+ INSTALL_AS_USER \
+ LIBTOOL \
+ LINT \
+ META_MODE \
+
+OPTIONS_DEFAULT_YES+= \
+ ARCHIVE \
+ AUTODEP \
+ AUTO_OBJ \
+ CRYPTO \
+ DOC \
+ DPADD_MK \
+ GDB \
+ KERBEROS \
+ LINKLIB \
+ MAN \
+ NLS \
+ OBJ \
+ PIC \
+ SHARE \
+ SKEY \
+ YP \
+
+OPTIONS_DEFAULT_DEPENDENT+= \
+ CATPAGES/MAN \
+ OBJDIRS/OBJ \
+ PICINSTALL/LINKLIB \
+ PICLIB/PIC \
+ PROFILE/LINKLIB \
+
+.include <options.mk>
+
+.if ${MK_INSTALL_AS_USER} == "yes"
+# We ignore this if user is root.
+_uid!= id -u
+.if ${_uid} != 0
+.if !defined(USERGRP)
+USERGRP!= id -g
+.export USERGRP
+.endif
+.for x in BIN CONF DOC INFO KMOD LIB MAN NLS SHARE
+$xOWN= ${USER}
+$xGRP= ${USERGRP}
+.endfor
+.endif
+.endif
+
+# override this in sys.mk
+ROOT_GROUP?= wheel
+BINGRP?= ${ROOT_GROUP}
+BINOWN?= root
+BINMODE?= 555
+NONBINMODE?= 444
+
+# Define MANZ to have the man pages compressed (gzip)
+#MANZ= 1
+
+MANTARGET?= cat
+MANDIR?= ${prefix}/share/man/${MANTARGET}
+MANGRP?= ${BINGRP}
+MANOWN?= ${BINOWN}
+MANMODE?= ${NONBINMODE}
+
+LIBDIR?= ${libprefix}/lib
+SHLIBDIR?= ${libprefix}/lib
+.if ${USE_SHLIBDIR:Uno} == "yes"
+_LIBSODIR?= ${SHLIBDIR}
+.else
+_LIBSODIR?= ${LIBDIR}
+.endif
+# this is where ld.*so lives
+SHLINKDIR?= /usr/libexec
+LINTLIBDIR?= ${libprefix}/libdata/lint
+LIBGRP?= ${BINGRP}
+LIBOWN?= ${BINOWN}
+LIBMODE?= ${NONBINMODE}
+
+DOCDIR?= ${prefix}/share/doc
+DOCGRP?= ${BINGRP}
+DOCOWN?= ${BINOWN}
+DOCMODE?= ${NONBINMODE}
+
+NLSDIR?= ${prefix}/share/nls
+NLSGRP?= ${BINGRP}
+NLSOWN?= ${BINOWN}
+NLSMODE?= ${NONBINMODE}
+
+KMODDIR?= ${prefix}/lkm
+KMODGRP?= ${BINGRP}
+KMODOWN?= ${BINOWN}
+KMODMODE?= ${NONBINMODE}
+
+COPY?= -c
+STRIP_FLAG?= -s
+
+.if ${TARGET_OSNAME} == "NetBSD"
+.if exists(/usr/libexec/ld.elf_so)
+OBJECT_FMT=ELF
+.endif
+OBJECT_FMT?=a.out
+.endif
+# sys.mk should set something appropriate if need be.
+OBJECT_FMT?=ELF
+
+.if (${_HOST_OSNAME} == "FreeBSD")
+CFLAGS+= ${CPPFLAGS}
+.endif
+
+# allow for per target flags
+# apply the :T:R first, so the more specific :T can override if needed
+CPPFLAGS += ${CPPFLAGS_${.TARGET:T:R}} ${CPPFLAGS_${.TARGET:T}}
+CFLAGS += ${CFLAGS_${.TARGET:T:R}} ${CFLAGS_${.TARGET:T}}
+
+# Define SYS_INCLUDE to indicate whether you want symbolic links to the system
+# source (``symlinks''), or a separate copy (``copies''); (latter useful
+# in environments where it's not possible to keep /sys publicly readable)
+#SYS_INCLUDE= symlinks
+
+# don't try to generate PIC versions of libraries on machines
+# which don't support PIC.
+.if (${MACHINE_ARCH} == "vax") || \
+ ((${MACHINE_ARCH} == "mips") && defined(STATIC_TOOLCHAIN)) || \
+ ((${MACHINE_ARCH} == "alpha") && defined(ECOFF_TOOLCHAIN))
+MK_PIC=no
+.endif
+
+# No lint, for now.
+NOLINT=
+
+
+.if ${MK_LINKLIB} == "no"
+MK_PICINSTALL= no
+MK_PROFILE= no
+.endif
+
+.if ${MK_MAN} == "no"
+MK_CATPAGES= no
+.endif
+
+.if ${MK_OBJ} == "no"
+MK_OBJDIRS= no
+MK_AUTO_OBJ= no
+.endif
+
+.if ${MK_SHARE} == "no"
+MK_CATPAGES= no
+MK_DOC= no
+MK_INFO= no
+MK_MAN= no
+MK_NLS= no
+.endif
+
+.endif
diff --git a/contrib/bmake/mk/prlist.mk b/contrib/bmake/mk/prlist.mk
new file mode 100644
index 000000000000..09d7dfdacc97
--- /dev/null
+++ b/contrib/bmake/mk/prlist.mk
@@ -0,0 +1,36 @@
+# $Id: prlist.mk,v 1.3 2008/07/17 16:24:57 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@crufty.net
+#
+
+.if !target(__${.PARSEFILE}__)
+__${.PARSEFILE}__:
+
+# this needs to be included after all the lists it will process
+# are defined - which is why it is a separate file.
+# Usage looks like:
+# MAKEFLAGS= ${.MAKE} -f ${MAKEFILE} prlist.SOMETHING_HUGE | xargs whatever
+#
+.if make(prlist.*)
+.for t in ${.TARGETS:Mprlist.*:E}
+.if empty($t)
+prlist.$t:
+.else
+prlist.$t: ${$t:O:u:S,^,prlist-,}
+${$t:O:u:S,^,prlist-,}: .PHONY
+ @echo "${.TARGET:S,prlist-,,}"
+.endif
+.endfor
+.endif
+
+.endif
diff --git a/contrib/bmake/mk/prog.mk b/contrib/bmake/mk/prog.mk
new file mode 100644
index 000000000000..99fd7e81f50e
--- /dev/null
+++ b/contrib/bmake/mk/prog.mk
@@ -0,0 +1,219 @@
+# $Id: prog.mk,v 1.24 2012/12/13 23:04:14 sjg Exp $
+
+.if !target(__${.PARSEFILE}__)
+__${.PARSEFILE}__:
+
+.include <init.mk>
+
+# FreeBSD at least expects MAN8 etc.
+.if defined(MAN) && !empty(MAN)
+_sect:=${MAN:E}
+MAN${_sect}=${MAN}
+.endif
+
+.SUFFIXES: .out .o .c .cc .C .y .l .s .8 .7 .6 .5 .4 .3 .2 .1 .0
+
+CFLAGS+= ${COPTS}
+
+.if ${TARGET_OSNAME} == "NetBSD"
+.if ${MACHINE_ARCH} == "sparc64"
+CFLAGS+= -mcmodel=medlow
+.endif
+
+# ELF platforms depend on crtbegin.o and crtend.o
+.if ${OBJECT_FMT} == "ELF"
+.ifndef LIBCRTBEGIN
+LIBCRTBEGIN= ${DESTDIR}/usr/lib/crtbegin.o
+.MADE: ${LIBCRTBEGIN}
+.endif
+.ifndef LIBCRTEND
+LIBCRTEND= ${DESTDIR}/usr/lib/crtend.o
+.MADE: ${LIBCRTEND}
+.endif
+_SHLINKER= ${SHLINKDIR}/ld.elf_so
+.else
+LIBCRTBEGIN?=
+LIBCRTEND?=
+_SHLINKER= ${SHLINKDIR}/ld.so
+.endif
+
+.ifndef LIBCRT0
+LIBCRT0= ${DESTDIR}/usr/lib/crt0.o
+.MADE: ${LIBCRT0}
+.endif
+.endif # NetBSD
+
+# here is where you can define what LIB* are
+.-include <libnames.mk>
+.if ${MK_DPADD_MK} == "yes"
+# lots of cool magic, but might not suit everyone.
+.include <dpadd.mk>
+.endif
+
+.if defined(SHAREDSTRINGS)
+CLEANFILES+=strings
+.c.o:
+ ${CC} -E ${CFLAGS} ${.IMPSRC} | xstr -c -
+ @${CC} ${CFLAGS} -c x.c -o ${.TARGET}
+ @rm -f x.c
+
+.cc.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)
+SRCS?= ${PROG}.c
+.for s in ${SRCS:N*.h:N*.sh:M*/*}
+${.o .po .lo:L:@o@${s:T:R}$o@}: $s
+.endfor
+.if !empty(SRCS:N*.h:N*.sh)
+OBJS+= ${SRCS:T:N*.h:N*.sh:R:S/$/.o/g}
+LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
+.endif
+
+.if defined(OBJS) && !empty(OBJS)
+.NOPATH: ${OBJS} ${PROG} ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
+
+# this is known to work for NetBSD 1.6 and FreeBSD 4.2
+.if ${TARGET_OSNAME} == "NetBSD" || ${TARGET_OSNAME} == "FreeBSD"
+_PROGLDOPTS=
+.if ${SHLINKDIR} != "/usr/libexec" # XXX: change or remove if ld.so moves
+_PROGLDOPTS+= -Wl,-dynamic-linker=${_SHLINKER}
+.endif
+.if defined(LIBDIR) && ${SHLIBDIR} != ${LIBDIR}
+_PROGLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib \
+ -L${DESTDIR}${SHLIBDIR}
+.endif
+_PROGLDOPTS+= -Wl,-rpath,${SHLIBDIR}:/usr/lib
+
+.if defined(PROG_CXX)
+_CCLINK= ${CXX}
+_SUPCXX= -lstdc++ -lm
+.endif
+.endif # NetBSD
+
+_CCLINK?= ${CC}
+
+.if defined(DESTDIR) && exists(${LIBCRT0}) && ${LIBCRT0} != "/dev/null"
+
+${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
+ ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} -L${DESTDIR}/usr/lib ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND}
+
+.else
+
+${PROG}: ${LIBCRT0} ${OBJS} ${LIBC} ${DPADD}
+ ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD}
+
+.endif # defined(DESTDIR)
+.endif # defined(OBJS) && !empty(OBJS)
+
+.if !defined(MAN)
+MAN= ${PROG}.1
+.endif # !defined(MAN)
+.endif # defined(PROG)
+
+.if !defined(_SKIP_BUILD)
+all: ${PROG}
+.endif
+all: _SUBDIRUSE
+
+.if !target(clean)
+cleanprog:
+ rm -f a.out [Ee]rrs mklog core *.core \
+ ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
+
+clean: _SUBDIRUSE cleanprog
+cleandir: _SUBDIRUSE cleanprog
+.else
+cleandir: _SUBDIRUSE clean
+.endif
+
+.if defined(SRCS) && (!defined(MKDEP) || ${MKDEP} != autodep)
+afterdepend: .depend
+ @(TMP=/tmp/_depend$$$$; \
+ sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.ln:/' \
+ < .depend > $$TMP; \
+ mv $$TMP .depend)
+.endif
+
+.if !target(install)
+.if !target(beforeinstall)
+beforeinstall:
+.endif
+.if !target(afterinstall)
+afterinstall:
+.endif
+
+.if !empty(BINOWN)
+PROG_INSTALL_OWN ?= -o ${BINOWN} -g ${BINGRP}
+.endif
+
+.if !target(realinstall)
+realinstall: proginstall
+.endif
+.if !target(proginstall)
+proginstall:
+.if defined(PROG)
+ [ -d ${DESTDIR}${BINDIR} ] || \
+ ${INSTALL} -d ${PROG_INSTALL_OWN} -m 775 ${DESTDIR}${BINDIR}
+ ${INSTALL} ${COPY} ${STRIP_FLAG} ${PROG_INSTALL_OWN} -m ${BINMODE} \
+ ${PROG} ${DESTDIR}${BINDIR}/${PROG_NAME}
+.endif
+.if defined(HIDEGAME)
+ (cd ${DESTDIR}/usr/games; rm -f ${PROG}; ln -s dm ${PROG})
+.endif
+.endif
+
+.include <links.mk>
+
+install: maninstall install_links _SUBDIRUSE
+
+install_links:
+.if !empty(SYMLINKS)
+ @set ${SYMLINKS}; ${_SYMLINKS_SCRIPT}
+.endif
+.if !empty(LINKS)
+ @set ${LINKS}; ${_LINKS_SCRIPT}
+.endif
+
+maninstall: afterinstall
+afterinstall: realinstall
+realinstall: beforeinstall
+.endif
+
+.if !target(lint)
+lint: ${LOBJS}
+.if defined(LOBJS) && !empty(LOBJS)
+ @${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD}
+.endif
+.endif
+
+.NOPATH: ${PROG}
+.if defined(OBJS) && !empty(OBJS)
+.NOPATH: ${OBJS}
+.endif
+
+.if ${MK_MAN} != "no"
+.include <man.mk>
+.endif
+
+.if ${MK_NLS} != "no"
+.include <nls.mk>
+.endif
+
+.include <obj.mk>
+.include <dep.mk>
+.include <subdir.mk>
+.include <final.mk>
+
+.endif
diff --git a/contrib/bmake/mk/progs.mk b/contrib/bmake/mk/progs.mk
new file mode 100644
index 000000000000..0fd23120b620
--- /dev/null
+++ b/contrib/bmake/mk/progs.mk
@@ -0,0 +1,87 @@
+# $Id: progs.mk,v 1.11 2012/11/06 17:18:54 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@crufty.net
+#
+
+.MAIN: all
+
+.if defined(PROGS)
+
+# In meta mode, we can capture dependenices for _one_ of the progs.
+# if makefile doesn't nominate one, we use the first.
+.ifndef UPDATE_DEPENDFILE_PROG
+UPDATE_DEPENDFILE_PROG = ${PROGS:[1]}
+.export UPDATE_DEPENDFILE_PROG
+.endif
+
+.ifndef PROG
+# They may have asked us to build just one
+.for t in ${PROGS}
+.if make($t)
+PROG ?= $t
+.endif
+.endfor
+.endif
+
+.if defined(PROG)
+# just one of many
+PROG_VARS += CFLAGS CPPFLAGS CXXFLAGS DPADD DPLIBS LDADD MAN SRCS
+.for v in ${PROG_VARS:O:u}
+$v += ${${v}_${PROG}:U${${v}.${PROG}}}
+.endfor
+
+# for meta mode, there can be only one!
+.if ${PROG} == ${UPDATE_DEPENDFILE_PROG:Uno}
+UPDATE_DEPENDFILE ?= yes
+.endif
+UPDATE_DEPENDFILE ?= NO
+
+# ensure that we don't clobber each other's dependencies
+DEPENDFILE?= .depend.${PROG}
+# prog.mk will do the rest
+.else
+all: ${PROGS}
+
+# We cannot capture dependencies for meta mode here
+UPDATE_DEPENDFILE = NO
+# nor can we safely run in parallel.
+.NOTPARALLEL:
+.endif
+.endif
+
+# handle being called [bsd.]progs.mk
+.include <${.PARSEFILE:S,progs,prog,}>
+
+.ifndef PROG
+PROGS_TARGETS += clean
+
+.for p in ${PROGS}
+.if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p)
+# bsd.prog.mk may need to know this
+x.$p= PROG_CXX=$p
+.endif
+
+$p ${p}_p: .PHONY .MAKE
+ (cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} PROG=$p ${x.$p})
+
+.for t in ${PROGS_TARGETS:O:u}
+$p.$t: .PHONY .MAKE
+ (cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} PROG=$p ${x.$p} ${@:E})
+.endfor
+.endfor
+
+.for t in ${PROGS_TARGETS:O:u}
+$t: ${PROGS:%=%.$t}
+.endfor
+
+.endif
diff --git a/contrib/bmake/mk/rst2htm.mk b/contrib/bmake/mk/rst2htm.mk
new file mode 100644
index 000000000000..8bd66dab48d6
--- /dev/null
+++ b/contrib/bmake/mk/rst2htm.mk
@@ -0,0 +1,43 @@
+# $Id: rst2htm.mk,v 1.8 2011/04/03 21:39:25 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@crufty.net
+#
+
+# convert reStructuredText to HTML, using rst2html.py from
+# docutils - http://docutils.sourceforge.net/
+
+.if empty(TXTSRCS)
+TXTSRCS != 'ls' -1t ${.CURDIR}/*.txt ${.CURDIR}/*.rst 2>/dev/null; echo
+.endif
+RSTSRCS ?= ${TXTSRCS}
+HTMFILES ?= ${RSTSRCS:R:T:O:u:%=%.htm}
+RST2HTML ?= rst2html.py
+RST2S5 ?= rst2s5.py
+# the following will run RST2S5 if the target name contains the word 'slides'
+# otherwise it uses RST2HTML
+RST2HTM = ${"${.TARGET:T:M*slides*}":?${RST2S5} ${RST2S5_FLAGS}:${RST2HTML} ${RST2HTML_FLAGS}}
+
+RST_SUFFIXES ?= .rst .txt
+
+CLEANFILES += ${HTMFILES}
+
+html: ${HTMFILES}
+
+.SUFFIXES: ${RST_SUFFIXES} .htm
+
+${RST_SUFFIXES:@s@$s.htm@}:
+ ${RST2HTM} ${.IMPSRC} ${.TARGET}
+
+.for s in ${RSTSRCS:O:u}
+${s:R:T}.htm: $s
+.endfor
diff --git a/contrib/bmake/mk/scripts.mk b/contrib/bmake/mk/scripts.mk
new file mode 100644
index 000000000000..efd65f94ccd7
--- /dev/null
+++ b/contrib/bmake/mk/scripts.mk
@@ -0,0 +1,52 @@
+# $Id: scripts.mk,v 1.2 2006/11/09 01:55:18 sjg Exp $
+
+.include <init.mk>
+
+.if defined(SCRIPTS)
+
+all: ${SCRIPTS}
+
+.PHONY: scriptsinstall
+install: scriptsinstall
+
+.if !target(scriptsinstall)
+SCRIPTSDIR?= ${BINDIR}
+SCRIPTSOWN?= ${BINOWN}
+SCRIPTSGRP?= ${BINGRP}
+SCRIPTSMODE?= ${BINMODE}
+
+# 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}}}@}
+
+scriptsinstall:: ${script_targets}
+
+.PRECIOUS: ${script_targets}
+.if !defined(UPDATE)
+.PHONY: ${script_targets}
+.endif
+
+INSTALL_FLAGS?= ${RENAME} ${PRESERVE} ${COPY} ${INSTPRIV} \
+ -o ${OWN_${.TARGET:T}:U${SCRIPTSOWN}} \
+ -g ${GRP_${.TARGET:T}:U${SCRIPTSGRP}} \
+ -m ${MODE_${.TARGET:T}:U${SCRIPTSMODE}}
+
+__SCRIPTINSTALL_USE: .USE
+ ${INSTALL} ${INSTALL_FLAGS_${.TARGET:T}:U${INSTALL_FLAGS}} \
+ ${.ALLSRC} ${.TARGET}
+
+.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
+
+.endif
+
+.if !target(scriptsinstall)
+scriptsinstall::
+.endif
+
diff --git a/contrib/bmake/mk/srctop.mk b/contrib/bmake/mk/srctop.mk
new file mode 100644
index 000000000000..fab090c80d39
--- /dev/null
+++ b/contrib/bmake/mk/srctop.mk
@@ -0,0 +1,66 @@
+# $Id: srctop.mk,v 1.3 2012/11/11 23:20:18 sjg Exp $
+#
+# @(#) Copyright (c) 2012, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+.if !defined(SRCTOP)
+# if using mk(1) SB will be set.
+.ifdef SB
+.if ${.CURDIR:S,${SB},,} != ${.CURDIR}
+# we are actually within SB
+.ifdef SB_SRC
+SRCTOP:= ${SB_SRC}
+.elif exists(${SB}/src)
+SRCTOP:= ${SB}/src
+.else
+SRCTOP:= ${SB}
+.endif
+.endif
+.endif
+
+.if !defined(SRCTOP)
+.for rd in share/mk build/mk mk
+.if ${_this_mk_dir:M*${rd}} != ""
+.if ${.CURDIR:S,${_this_mk_dir:${rd:C,[^/]+,H,g:S,/, ,g:ts:}},,} != ${.CURDIR}
+SRCTOP:= ${_this_mk_dir:${rd:C,[^/]+,H,g:S,/, ,g:ts:}}
+.endif
+.endif
+.endfor
+.endif
+
+.if !defined(SRCTOP)
+_SRCTOP_TEST_?= [ -f ../.sandbox-env -o -d share/mk ]
+# Linux at least has a bug where attempting to check an automounter
+# directory will hang. So avoid looking above /a/b
+SRCTOP!= cd ${.CURDIR}; while :; do \
+ here=`pwd`; \
+ ${_SRCTOP_TEST_} && { echo $$here; break; }; \
+ case $$here in /*/*/*) cd ..;; *) echo ""; break;; esac; \
+ done
+.endif
+.if defined(SRCTOP) && exists(${SRCTOP}/.)
+.export SRCTOP
+.endif
+.endif
+
+.if !defined(OBJTOP) && !empty(SRCTOP)
+.if defined(MAKEOBJDIRPREFIX) && exists(${MAKEOBJDIRPREFIX}${SRCTOP})
+OBJTOP= ${MAKEOBJDIRPREFIX}${SRCTOP}
+.elif (exists(${SRCTOP}/Makefile) || exists(${SRCTOP}/makefile))
+OBJTOP!= cd ${SRCTOP} && ${PRINTOBJDIR}
+.endif
+.if empty(OBJTOP)
+OBJTOP= ${SRCTOP}
+.endif
+.export OBJTOP
+.endif
diff --git a/contrib/bmake/mk/subdir.mk b/contrib/bmake/mk/subdir.mk
new file mode 100644
index 000000000000..313b7d7a3b2b
--- /dev/null
+++ b/contrib/bmake/mk/subdir.mk
@@ -0,0 +1,99 @@
+# $Id: subdir.mk,v 1.14 2012/11/12 04:34:33 sjg Exp $
+# skip missing directories...
+
+# $NetBSD: bsd.subdir.mk,v 1.11 1996/04/04 02:05:06 jtc Exp $
+# @(#)bsd.subdir.mk 5.9 (Berkeley) 2/1/91
+
+.if ${.MAKE.LEVEL} == 0 && ${.MAKE.MODE:Uno:Mmeta*} != ""
+.include <meta.subdir.mk>
+# keep everyone happy
+_SUBDIRUSE:
+.elif !commands(_SUBDIRUSE) && !defined(NO_SUBDIR) && !defined(NOSUBDIR)
+.if exists(${.CURDIR}/Makefile.inc)
+.include "Makefile.inc"
+.endif
+.if !target(.MAIN)
+.MAIN: all
+.endif
+
+ECHO_DIR ?= echo
+.ifdef SUBDIR_MUST_EXIST
+MISSING_DIR=echo "Missing ===> ${.CURDIR}/$${entry}"; exit 1
+.else
+MISSING_DIR=echo "Skipping ===> ${.CURDIR}/$${entry}"; continue
+.endif
+
+_SUBDIRUSE: .USE
+.if defined(SUBDIR)
+ @Exists() { test -f $$1; }; \
+ for entry in ${SUBDIR}; do \
+ (set -e; \
+ if Exists ${.CURDIR}/$${entry}.${MACHINE}/[mM]akefile; then \
+ _newdir_="$${entry}.${MACHINE}"; \
+ elif Exists ${.CURDIR}/$${entry}/[mM]akefile; then \
+ _newdir_="$${entry}"; \
+ else \
+ ${MISSING_DIR}; \
+ fi; \
+ if test X"${_THISDIR_}" = X""; then \
+ _nextdir_="$${_newdir_}"; \
+ else \
+ _nextdir_="$${_THISDIR_}/$${_newdir_}"; \
+ fi; \
+ ${ECHO_DIR} "===> $${_nextdir_}"; \
+ cd ${.CURDIR}/$${_newdir_}; \
+ ${.MAKE} _THISDIR_="$${_nextdir_}" \
+ ${.TARGET:S/realinstall/install/:S/.depend/depend/}) || exit 1; \
+ done
+
+${SUBDIR}::
+ @set -e; if test -d ${.CURDIR}/${.TARGET}.${MACHINE}; then \
+ _newdir_=${.TARGET}.${MACHINE}; \
+ else \
+ _newdir_=${.TARGET}; \
+ fi; \
+ ${ECHO_DIR} "===> $${_newdir_}"; \
+ cd ${.CURDIR}/$${_newdir_}; \
+ ${.MAKE} _THISDIR_="$${_newdir_}" all
+.endif
+
+.if !target(install)
+.if !target(beforeinstall)
+beforeinstall:
+.endif
+.if !target(afterinstall)
+afterinstall:
+.endif
+install: maninstall
+maninstall: afterinstall
+afterinstall: realinstall
+realinstall: beforeinstall _SUBDIRUSE
+.endif
+
+.if defined(SRCS)
+etags: ${SRCS}
+ -cd ${.CURDIR}; etags `echo ${.ALLSRC:N*.h} | sed 's;${.CURDIR}/;;'`
+.endif
+
+SUBDIR_TARGETS += \
+ all \
+ clean \
+ cleandir \
+ includes \
+ depend \
+ lint \
+ obj \
+ tags \
+ etags
+
+.for t in ${SUBDIR_TARGETS:O:u}
+$t: _SUBDIRUSE
+.endfor
+
+.include <own.mk>
+.if make(destroy*)
+.include <obj.mk>
+.endif
+.endif
+# make sure this exists
+all:
diff --git a/contrib/bmake/mk/sys.clean-env.mk b/contrib/bmake/mk/sys.clean-env.mk
new file mode 100644
index 000000000000..b1867c3804bc
--- /dev/null
+++ b/contrib/bmake/mk/sys.clean-env.mk
@@ -0,0 +1,119 @@
+# $Id: sys.clean-env.mk,v 1.20 2012/11/12 06:56:04 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@crufty.net
+#
+
+# This makefile would normally be included by sys.env.mk
+
+# The variables used by this makefile include:
+#
+# MAKE_ENV_SAVE_VAR_LIST
+# The actuall list of variables from the environment that will be
+# preserved.
+# MAKE_ENV_SAVE_PREFIX_LIST
+# A list of prefixes to match against the environment - the results
+# are added to MAKE_ENV_SAVE_VAR_LIST after being filtered by...
+# MAKE_ENV_SAVE_EXCLUDE_LIST
+# A list of words or patterns which is turned into a list of :N
+# modifiers.
+
+.if ${.MAKE.LEVEL} == 0 && ${MAKE_VERSION} >= 20100606
+# We save any env var that starts with the words in MAKE_ENV_SAVE_PREFIX_LIST.
+# This gets expanded to an egrep expression like '^(A|B|C...)'
+# and added to MAKE_ENV_SAVE_VAR_LIST below.
+# If any of these end up being too greedy, MAKE_ENV_SAVE_EXCLUDE_LIST
+# can be used to filter.
+MAKE_ENV_SAVE_PREFIX_LIST += \
+ CCACHE \
+ CVS \
+ DEBUG \
+ DISTCC \
+ HOST \
+ MACHINE \
+ MAKE \
+ MK \
+ NEED_ \
+ SB_ \
+ SSH \
+ SVN \
+ USE_ \
+ WITH_ \
+ WITHOUT_ \
+
+
+# This could be a list of vars or patterns to explicitly exclude.
+MAKE_ENV_SAVE_EXCLUDE_LIST ?= _
+
+# This is the actual list that we will save
+# HOME is probably something worth clobbering eg.
+# HOME=/var/empty
+MAKE_ENV_SAVE_VAR_LIST += \
+ HOME \
+ LOGNAME \
+ OBJROOT \
+ OBJTOP \
+ PATH \
+ SB \
+ SRCTOP \
+ USER \
+ ${_env_vars:${MAKE_ENV_SAVE_EXCLUDE_LIST:${M_ListToSkip}}}
+
+_env_vars != env | egrep '^(${MAKE_ENV_SAVE_PREFIX_LIST:ts|})' | sed 's,=.*,,'; echo
+
+_export_list =
+.for v in ${MAKE_ENV_SAVE_VAR_LIST:O:u}
+.if defined($v)
+_export_list += $v
+# Save current value
+$v := ${$v}
+.endif
+.endfor
+
+# Now, clobber the environment
+.unexport-env
+
+# This is a list of vars that we handle specially below
+_tricky_env_vars = MAKEOBJDIR OBJTOP
+# Export our selection - sans tricky ones
+.export ${_export_list:${_tricky_env_vars:${M_ListToSkip}}}
+
+# This next bit may need tweaking
+# if you don't happen to like the way I set it.
+.if defined(MAKEOBJDIR)
+# We are going to set this to the equivalent of the shell's
+# MAKEOBJDIR='${.CURDIR:S,${SRCTOP},${OBJTOP},}'
+_srctop := ${SRCTOP:U${SB_SRC:U${SB}/src}}
+_objroot := ${OBJROOT:U${SB_OBJROOT:U${SB}/${SB_OBJPREFIX}}}
+_objtop := ${OBJTOP:U${_objroot}${MACHINE}}
+# Take care of ${MACHINE}
+.if ${MACHINE} == "host" || ${OBJTOP} == ${HOST_OBJTOP:Uno}
+OBJTOP = ${_objtop:S,${HOST_TARGET}$,\${MACHINE},}
+.else
+OBJTOP = ${_objtop:S,${MACHINE}$,\${MACHINE},}
+.endif
+# Export like this
+MAKEOBJDIR = $${.CURDIR:S,${_srctop},$${OBJTOP},}
+#.info ${MAKE_SAVE_ENV_VARS _srctop _objroot _objtop OBJTOP MAKEOBJDIR:L:@v@${.newline}$v=${$v}@}
+
+# Export these as-is, and do not track...
+# otherwise the environment will be ruined when we evaluate them below.
+.export-env ${_tricky_env_vars}
+
+# Now evaluate for ourselves
+.for v in ${_tricky_env_vars}
+$v := ${$v}
+.endfor
+#.info ${_tricky_env_vars:@v@${.newline}$v=${$v}@}
+
+.endif # MAKEOBJDIR
+.endif # level 0
diff --git a/contrib/bmake/mk/sys.dependfile.mk b/contrib/bmake/mk/sys.dependfile.mk
new file mode 100644
index 000000000000..752a46fe8ce1
--- /dev/null
+++ b/contrib/bmake/mk/sys.dependfile.mk
@@ -0,0 +1,47 @@
+# $Id: sys.dependfile.mk,v 1.4 2012/11/08 18:31:42 sjg Exp $
+#
+# @(#) Copyright (c) 2012, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+# This only makes sense in meta mode.
+# This allows a mixture of auto generated as well as manually edited
+# dependency files, which can be differentiated by their names.
+# As per dirdeps.mk we only require:
+# 1. a common prefix
+# 2. that machine specific files end in .${MACHINE}
+#
+# The .MAKE.DEPENDFILE_PREFERENCE below is an example.
+
+# All depend file names should start with this
+.MAKE.DEPENDFILE_PREFIX ?= Makefile.depend
+
+# The order of preference: we will use the first one of these we find
+# otherwise the 1st entry will be used by default.
+.MAKE.DEPENDFILE_PREFERENCE ?= \
+ ${.CURDIR}/${.MAKE.DEPENDFILE_PREFIX}.${MACHINE} \
+ ${.CURDIR}/${.MAKE.DEPENDFILE_PREFIX}
+
+_e := ${.MAKE.DEPENDFILE_PREFERENCE:@m@${exists($m):?$m:}@}
+.if !empty(_e)
+.MAKE.DEPENDFILE := ${_e:[1]}
+.elif ${.MAKE.DEPENDFILE_PREFERENCE:M*${MACHINE}} != "" && ${.MAKE.DEPENDFILE_PREFERENCE:[1]:E} != ${MACHINE}
+# MACHINE specific depend files are supported, but *not* default.
+# If any already exist, we should follow suit.
+_aml = ${ALL_MACHINE_LIST:Uarm amd64 i386 powerpc:N${MACHINE}} ${MACHINE}
+# MACHINE must be the last entry in _aml ;-)
+_e := ${_aml:@MACHINE@${.MAKE.DEPENDFILE_PREFERENCE:@m@${exists($m):?$m:}@}@}
+.if !empty(_e)
+.MAKE.DEPENDFILE ?= ${.MAKE.DEPENDFILE_PREFERENCE:M*${MACHINE}:[1]}
+.endif
+.endif
+.MAKE.DEPENDFILE ?= ${.MAKE.DEPENDFILE_PREFERENCE:[1]}
diff --git a/contrib/bmake/mk/sys.mk b/contrib/bmake/mk/sys.mk
new file mode 100644
index 000000000000..30eca9b84508
--- /dev/null
+++ b/contrib/bmake/mk/sys.mk
@@ -0,0 +1,199 @@
+# $Id: sys.mk,v 1.35 2012/11/12 06:27:51 sjg Exp $
+#
+# @(#) Copyright (c) 2003-2009, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+# Avoid putting anything platform specific in here.
+
+# 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
+
+# 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}
+.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
+
+# 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,
+# AUTOCONF := ${autoconf:L:${M_whence}}
+M_type = @x@(type $$x 2> /dev/null); echo;@:sh:[0]:N* found*:[@]:C,[()],,g
+M_whence = ${M_type}:M/*
+
+# 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
+_TARGETS := ${.TARGETS}
+.-include <sys.env.mk>
+.endif
+
+# we need HOST_TARGET etc below.
+.include <host-target.mk>
+
+# find the OS specifics
+.if defined(SYS_OS_MK)
+.include <${SYS_OS_MK}>
+.else
+_sys_mk =
+.for x in ${HOST_OSTYPE} ${HOST_TARGET} ${HOST_OS} ${MACHINE} Generic
+.if empty(_sys_mk)
+.-include <sys/$x.mk>
+_sys_mk := ${.MAKE.MAKEFILES:M*/$x.mk}
+.if !empty(_sys_mk)
+_sys_mk := sys/${_sys_mk:T}
+.endif
+.endif
+.if empty(_sys_mk)
+# might be an old style
+.-include <$x.sys.mk>
+_sys_mk := ${.MAKE.MAKEFILES:M*/$x.sys.mk:T}
+.endif
+.endfor
+
+SYS_OS_MK := ${_sys_mk}
+.export SYS_OS_MK
+.endif
+
+# allow customization without editing.
+.-include <local.sys.mk>
+
+# if you want objdirs make them automatic
+.if ${MKOBJDIRS:Uno} == "auto"
+.include <auto.obj.mk>
+.endif
+
+.if !empty(SRCTOP)
+.if ${.CURDIR} == ${SRCTOP}
+RELDIR = .
+.elif ${.CURDIR:M${SRCTOP}/*}
+RELDIR := ${.CURDIR:S,${SRCTOP}/,,}
+.endif
+.endif
+
+MACHINE_ARCH.host ?= ${_HOST_ARCH}
+MACHINE_ARCH.${MACHINE} ?= ${MACHINE}
+.if empty(MACHINE_ARCH)
+MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}}
+.endif
+
+.ifndef ROOT_GROUP
+ROOT_GROUP != sed -n /:0:/s/:.*//p /etc/group
+.export ROOT_GROUP
+.endif
+
+unix ?= We run ${_HOST_OSNAME}.
+
+# A race condition in mkdir, means that it can bail if another
+# process made a dir that mkdir expected to.
+# We repeat the mkdir -p a number of times to try and work around this.
+# We stop looping as soon as the dir exists.
+# If we get to the end of the loop, a plain mkdir will issue an error.
+Mkdirs= Mkdirs() { \
+ for d in $$*; do \
+ for i in 1 2 3 4 5 6; do \
+ mkdir -p $$d; \
+ test -d $$d && return 0; \
+ done; \
+ mkdir $$d || exit $$?; \
+ done; }
+
+# this often helps with debugging
+.SUFFIXES: .cpp-out
+
+.c.cpp-out:
+ @${COMPILE.c:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$'
+
+.cc.cpp-out:
+ @${COMPILE.cc:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$'
+
+# we don't include own.mk but user can expect -DWITH_META_MODE to work
+.if defined(WITHOUT_META_MODE)
+USE_META= no
+.elif defined(WITH_META_MODE)
+USE_META= yes
+.endif
+.if ${USE_META:Uno} == "yes"
+.-include <meta.sys.mk>
+.endif
+# make sure we have a harmless value
+.MAKE.MODE ?= normal
+
+# if .CURDIR is matched by any entry in DEBUG_MAKE_DIRS we
+# will apply DEBUG_MAKE_FLAGS, now.
+.if !empty(_DEBUG_MAKE_FLAGS)
+.if ${_DEBUG_MAKE_DIRS:Uno:@x@${.CURDIR:M$x}@} != ""
+.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS}
+.endif
+.endif
diff --git a/contrib/bmake/mk/sys/AIX.mk b/contrib/bmake/mk/sys/AIX.mk
new file mode 100644
index 000000000000..18adfa6befda
--- /dev/null
+++ b/contrib/bmake/mk/sys/AIX.mk
@@ -0,0 +1,197 @@
+# $NetBSD: sys.mk,v 1.19.2.1 1994/07/26 19:58:31 cgd Exp $
+# @(#)sys.mk 5.11 (Berkeley) 3/13/91
+
+OS= AIX
+unix= We run ${OS}.
+ROOT_GROUP= system
+
+# This needs a lot of work yet...
+
+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
+
+.LIBS: .a
+
+AR= ar
+ARFLAGS= rl
+RANLIB= ranlib
+
+AS= as
+AFLAGS=
+COMPILE.s= ${AS} ${AFLAGS}
+LINK.s= ${CC} ${AFLAGS} ${LDFLAGS}
+COMPILE.S= ${CC} ${AFLAGS} ${CPPFLAGS} -c
+LINK.S= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS}
+.if exists(/usr/local/bin/gcc)
+CC= gcc
+DBG= -O -g
+STATIC?= -static
+.else
+CC= cc
+DBG= -g
+STATIC=
+.endif
+CFLAGS= ${DBG}
+COMPILE.c= ${CC} ${CFLAGS} ${CPPFLAGS} -c
+LINK.c= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CXX= g++
+CXXFLAGS= ${CFLAGS}
+COMPILE.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c
+LINK.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CPP= cpp
+.if defined(DESTDIR)
+CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include
+.endif
+
+MK_DEP= mkdeps.sh -N
+FC= f77
+FFLAGS= -O
+RFLAGS=
+COMPILE.f= ${FC} ${FFLAGS} -c
+LINK.f= ${FC} ${FFLAGS} ${LDFLAGS}
+COMPILE.F= ${FC} ${FFLAGS} ${CPPFLAGS} -c
+LINK.F= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS}
+COMPILE.r= ${FC} ${FFLAGS} ${RFLAGS} -c
+LINK.r= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS}
+
+LEX= lex
+LFLAGS=
+LEX.l= ${LEX} ${LFLAGS}
+
+LD= ld
+LDFLAGS=
+
+LINT= lint
+LINTFLAGS= -chapbx
+
+MAKE= bmake
+
+PC= pc
+PFLAGS=
+COMPILE.p= ${PC} ${PFLAGS} ${CPPFLAGS} -c
+LINK.p= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+SHELL= sh
+
+YACC= yacc
+YFLAGS= -d
+YACC.y= ${YACC} ${YFLAGS}
+
+# C
+.c:
+ ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.c.o:
+ ${COMPILE.c} ${.IMPSRC}
+.c.a:
+ ${COMPILE.c} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# C++
+.cc:
+ ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.cc.o:
+ ${COMPILE.cc} ${.IMPSRC}
+.cc.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}
+.f.o:
+ ${COMPILE.f} ${.IMPSRC}
+.f.a:
+ ${COMPILE.f} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.F:
+ ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.F.o:
+ ${COMPILE.F} ${.IMPSRC}
+.F.a:
+ ${COMPILE.F} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.r:
+ ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.r.o:
+ ${COMPILE.r} ${.IMPSRC}
+.r.a:
+ ${COMPILE.r} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Pascal
+.p:
+ ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.p.o:
+ ${COMPILE.p} ${.IMPSRC}
+.p.a:
+ ${COMPILE.p} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Assembly
+.s:
+ ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.s.o:
+ ${COMPILE.s} -o ${.TARGET} ${.IMPSRC}
+.s.a:
+ ${COMPILE.s} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+.S:
+ ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.S.o:
+ ${COMPILE.S} ${.IMPSRC}
+.S.a:
+ ${COMPILE.S} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Lex
+.l:
+ ${LEX.l} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll
+ rm -f lex.yy.c
+.l.c:
+ ${LEX.l} ${.IMPSRC}
+ mv lex.yy.c ${.TARGET}
+.l.o:
+ ${LEX.l} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} lex.yy.c
+ rm -f lex.yy.c
+
+# Yacc
+.y:
+ ${YACC.y} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS}
+ rm -f y.tab.c
+.y.c:
+ ${YACC.y} ${.IMPSRC}
+ mv y.tab.c ${.TARGET}
+.y.o:
+ ${YACC.y} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} y.tab.c
+ rm -f y.tab.c
+
+# Shell
+.sh:
+ rm -f ${.TARGET}
+ cp ${.IMPSRC} ${.TARGET}
diff --git a/contrib/bmake/mk/sys/Darwin.mk b/contrib/bmake/mk/sys/Darwin.mk
new file mode 100644
index 000000000000..d05e32ae895e
--- /dev/null
+++ b/contrib/bmake/mk/sys/Darwin.mk
@@ -0,0 +1,220 @@
+# $NetBSD: Darwin.sys.mk,v 1.3 2003/02/16 09:44:41 grant Exp $
+# @(#)sys.mk 8.2 (Berkeley) 3/21/94
+
+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: .sh .m4 .dylib
+
+.LIBS: .a .dylib
+
+SHLIBEXT = .dylib
+HOST_LIBEXT = .dylib
+DSHLIBEXT = .dylib
+
+AR?= ar
+ARFLAGS?= rl
+RANLIB =
+
+AS?= as
+AFLAGS?=
+COMPILE.s?= ${AS} ${AFLAGS}
+LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS}
+COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c
+LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+.if exists(/usr/bin/gcc)
+CC?= gcc -pipe
+.else
+CC?= cc -pipe
+.endif
+DBG?= -O2
+CFLAGS?= ${DBG}
+COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c
+LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+.if exists(/usr/bin/g++)
+CXX?= g++
+.else
+CXX?= c++
+.endif
+CXXFLAGS?= ${CFLAGS}
+COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c
+LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+OBJC?= ${CC}
+OBJCFLAGS?= ${CFLAGS}
+COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c
+LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CPP?= cpp
+NOLINT= 1
+CPPFLAGS?=
+
+MK_DEP?= mkdeps.sh -N
+
+FC?= f77
+FFLAGS?= -O
+RFLAGS?=
+COMPILE.f?= ${FC} ${FFLAGS} -c
+LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS}
+COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c
+LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS}
+COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c
+LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS}
+
+INSTALL?= install
+
+LEX?= lex
+LFLAGS?=
+LEX.l?= ${LEX} ${LFLAGS}
+
+LD?= ld
+LDFLAGS?=
+
+SHLIB_TEENY = 0
+SHLIB_MINOR = 0
+
+MKPICLIB = no
+LIBEXT = .dylib
+
+LINT?= lint
+LINTFLAGS?= -chapbx
+
+LORDER?= lorder
+
+MAKE?= bmake
+
+NM?= nm
+
+PC?= pc
+PFLAGS?=
+COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c
+LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+SHELL?= sh
+
+SIZE?= size
+
+TSORT?= tsort -q
+
+YACC?= bison -y
+YFLAGS?= -d
+YACC.y?= ${YACC} ${YFLAGS}
+
+# C
+.c:
+ ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.c.o:
+ ${COMPILE.c} ${.IMPSRC}
+.c.a:
+ ${COMPILE.c} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# C++
+.cc:
+ ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.cc.o:
+ ${COMPILE.cc} ${.IMPSRC}
+.cc.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}
+.f.o:
+ ${COMPILE.f} ${.IMPSRC}
+.f.a:
+ ${COMPILE.f} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.F:
+ ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.F.o:
+ ${COMPILE.F} ${.IMPSRC}
+.F.a:
+ ${COMPILE.F} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.r:
+ ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.r.o:
+ ${COMPILE.r} ${.IMPSRC}
+.r.a:
+ ${COMPILE.r} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Pascal
+.p:
+ ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.p.o:
+ ${COMPILE.p} ${.IMPSRC}
+.p.a:
+ ${COMPILE.p} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Assembly
+.s:
+ ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.s.o:
+ ${COMPILE.s} -o ${.TARGET} ${.IMPSRC}
+.s.a:
+ ${COMPILE.s} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+.S:
+ ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.S.o:
+ ${COMPILE.S} ${.IMPSRC}
+.S.a:
+ ${COMPILE.S} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Lex
+.l:
+ ${LEX.l} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll
+ rm -f lex.yy.c
+.l.c:
+ ${LEX.l} ${.IMPSRC}
+ mv lex.yy.c ${.TARGET}
+.l.o:
+ ${LEX.l} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} lex.yy.c
+ rm -f lex.yy.c
+
+# Yacc
+.y:
+ ${YACC.y} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS}
+ rm -f y.tab.c
+.y.c:
+ ${YACC.y} ${.IMPSRC}
+ mv y.tab.c ${.TARGET}
+.y.o:
+ ${YACC.y} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} y.tab.c
+ rm -f y.tab.c
+
+# Shell
+.sh:
+ rm -f ${.TARGET}
+ cp ${.IMPSRC} ${.TARGET}
diff --git a/contrib/bmake/mk/sys/Generic.mk b/contrib/bmake/mk/sys/Generic.mk
new file mode 100644
index 000000000000..179da9743598
--- /dev/null
+++ b/contrib/bmake/mk/sys/Generic.mk
@@ -0,0 +1,208 @@
+# $Id: Generic.mk,v 1.11 2010/09/24 05:59:53 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: .sh .m4
+
+.LIBS: .a
+
+tools = \
+ ar \
+ lorder \
+ ranlib \
+ tsort
+
+.for t in ${tools}
+${t:tu} := ${t:${M_whence}}
+.endfor
+
+# need to make sure this is set
+MACHINE_ARCH.${MACHINE} ?= ${MACHINE}
+.if empty(MACHINE_ARCH)
+MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}}
+.endif
+
+.if !empty(TSORT)
+TSORT += -q
+.endif
+
+ARFLAGS?= rl
+
+AS?= as
+AFLAGS?=
+.if ${MACHINE_ARCH} == "sparc64"
+AFLAGS+= -Wa,-Av9a
+.endif
+COMPILE.s?= ${CC} ${AFLAGS} -c
+LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS}
+COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp
+LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CC?= cc
+DBG?= -O2
+CFLAGS?= ${DBG}
+COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c
+LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CXX?= c++
+CXXFLAGS?= ${CFLAGS}
+COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c
+LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+OBJC?= ${CC}
+OBJCFLAGS?= ${CFLAGS}
+COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c
+LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CPP?= cpp
+CPPFLAGS?=
+
+FC?= f77
+FFLAGS?= -O
+RFLAGS?=
+COMPILE.f?= ${FC} ${FFLAGS} -c
+LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS}
+COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c
+LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS}
+COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c
+LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS}
+
+INSTALL?= install
+
+LEX?= lex
+LFLAGS?=
+LEX.l?= ${LEX} ${LFLAGS}
+
+LD?= ld
+LDFLAGS?=
+
+LINT?= lint
+LINTFLAGS?= -chapbxzF
+
+MAKE?= ${.MAKE}
+
+NM?= nm
+
+PC?= pc
+PFLAGS?=
+COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c
+LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+SHELL?= sh
+
+SIZE?= size
+
+YACC?= yacc
+YFLAGS?=
+YACC.y?= ${YACC} ${YFLAGS}
+
+# C
+.c:
+ ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.c.o:
+ ${COMPILE.c} ${.IMPSRC}
+.c.a:
+ ${COMPILE.c} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+.c.ln:
+ ${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC}
+
+# C++
+.cc .cpp .cxx .C:
+ ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.cc.o .cpp.o .cxx.o .C.o:
+ ${COMPILE.cc} ${.IMPSRC}
+.cc.a .cpp.a .cxx.a .C.a:
+ ${COMPILE.cc} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Fortran/Ratfor
+.f:
+ ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.f.o:
+ ${COMPILE.f} ${.IMPSRC}
+.f.a:
+ ${COMPILE.f} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.F:
+ ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.F.o:
+ ${COMPILE.F} ${.IMPSRC}
+.F.a:
+ ${COMPILE.F} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.r:
+ ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.r.o:
+ ${COMPILE.r} ${.IMPSRC}
+.r.a:
+ ${COMPILE.r} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Pascal
+.p:
+ ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.p.o:
+ ${COMPILE.p} ${.IMPSRC}
+.p.a:
+ ${COMPILE.p} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Assembly
+.s:
+ ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.s.o:
+ ${COMPILE.s} ${.IMPSRC}
+.s.a:
+ ${COMPILE.s} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+.S:
+ ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.S.o:
+ ${COMPILE.S} ${.IMPSRC}
+.S.a:
+ ${COMPILE.S} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Lex
+.l:
+ ${LEX.l} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll
+ rm -f lex.yy.c
+.l.c:
+ ${LEX.l} ${.IMPSRC}
+ mv lex.yy.c ${.TARGET}
+.l.o:
+ ${LEX.l} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} lex.yy.c
+ rm -f lex.yy.c
+
+# Yacc
+.y:
+ ${YACC.y} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS}
+ rm -f y.tab.c
+.y.c:
+ ${YACC.y} ${.IMPSRC}
+ mv y.tab.c ${.TARGET}
+.y.o:
+ ${YACC.y} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} y.tab.c
+ rm -f y.tab.c
+
+# Shell
+.sh:
+ rm -f ${.TARGET}
+ cp ${.IMPSRC} ${.TARGET}
+
diff --git a/contrib/bmake/mk/sys/HP-UX.mk b/contrib/bmake/mk/sys/HP-UX.mk
new file mode 100644
index 000000000000..f6e3e2c81377
--- /dev/null
+++ b/contrib/bmake/mk/sys/HP-UX.mk
@@ -0,0 +1,237 @@
+# $Id: HP-UX.mk,v 1.9 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
+
+OS= HP-UX
+ROOT_GROUP= root
+unix?= We run ${OS}.
+
+# HP-UX's cc does not provide any clues as to wether this is 9.x or 10.x
+# nor does sys/param.h, so we'll use the existence of /hp-ux
+.if exists("/hp-ux")
+OSMAJOR?=9
+.endif
+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
+
+LIBMODE= 755
+LIBCRT0= /lib/crt0.o
+
+.LIBS: .a
+
+# +b<path> is needed to stop the binaries from insisting on having
+# the build tree available :-)
+# +s tells the dynamic loader to use SHLIB_PATH if set
+LD_bpath?=-Wl,+b/lib:/usr/lib:/usr/local/lib
+LD_spath?=-Wl,+s
+LDADD+= ${LD_bpath} ${LD_spath}
+
+.if exists(/usr/lib/end.o)
+LDADD+= /usr/lib/end.o
+.endif
+
+AR= ar
+ARFLAGS= rl
+RANLIB= :
+
+AFLAGS=
+COMPILE.s= ${AS} ${AFLAGS}
+LINK.s= ${CC} ${AFLAGS} ${LDFLAGS}
+COMPILE.S= ${CC} ${AFLAGS} ${CPPFLAGS} -c
+LINK.S= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS}
+.if exists(/usr/local/bin/gcc)
+PIPE?= -pipe
+CC?= gcc ${PIPE}
+AS= gas
+DBG?= -O -g
+STATIC?= -static
+.if defined(DESTDIR)
+CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include
+.endif
+.else
+# HP's bundled compiler knows not -g or -O
+AS= as
+CC= cc
+.if exists(/opt/ansic/bin/cc)
+CCMODE?=-Ae +ESlit
+PICFLAG?= +z
+LD_x=
+DBG?=-g -O
+.endif
+DBG?=
+STATIC?= -Wl,-a,archive
+.endif
+.if (${__HPUX_VERSION} == "10")
+CCSOURCE_FLAGS?= -D_HPUX_SOURCE
+.else
+CCSOURCE_FLAGS?= -D_HPUX_SOURCE -D_INCLUDE_POSIX_SOURCE -D_INCLUDE_XOPEN_SOURCE -D_INCLUDE_XOPEN_SOURCE_EXTENDED
+.endif
+CFLAGS= ${DBG}
+CFLAGS+= ${CCMODE} -D__hpux__ -D__HPUX_VERSION=${__HPUX_VERSION} ${CCSOURCE_FLAGS}
+COMPILE.c= ${CC} ${CFLAGS} ${CPPFLAGS} -c
+LINK.c= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CXX= g++
+CXXFLAGS= ${CFLAGS}
+COMPILE.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c
+LINK.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CPP= cpp
+
+MK_DEP= mkdeps.sh -N
+FC= f77
+FFLAGS= -O
+RFLAGS=
+COMPILE.f= ${FC} ${FFLAGS} -c
+LINK.f= ${FC} ${FFLAGS} ${LDFLAGS}
+COMPILE.F= ${FC} ${FFLAGS} ${CPPFLAGS} -c
+LINK.F= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS}
+COMPILE.r= ${FC} ${FFLAGS} ${RFLAGS} -c
+LINK.r= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS}
+
+LEX= lex
+LFLAGS=
+LEX.l= ${LEX} ${LFLAGS}
+
+LD= ld
+LDFLAGS=
+
+LINT= lint
+LINTFLAGS= -chapbx
+
+MAKE= bmake
+
+PC= pc
+PFLAGS=
+COMPILE.p= ${PC} ${PFLAGS} ${CPPFLAGS} -c
+LINK.p= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+# HP's sh sucks
+ENV=
+SHELL= /bin/ksh
+
+.if exists(/usr/local/bin/bison)
+YACC= bison -y
+.else
+YACC= yacc
+.endif
+YFLAGS= -d
+YACC.y= ${YACC} ${YFLAGS}
+
+# C
+.c:
+ ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.c.o:
+ ${COMPILE.c} ${.IMPSRC}
+.c.a:
+ ${COMPILE.c} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# C++
+.cc:
+ ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.cc.o:
+ ${COMPILE.cc} ${.IMPSRC}
+.cc.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}
+.f.o:
+ ${COMPILE.f} ${.IMPSRC}
+.f.a:
+ ${COMPILE.f} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.F:
+ ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.F.o:
+ ${COMPILE.F} ${.IMPSRC}
+.F.a:
+ ${COMPILE.F} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.r:
+ ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.r.o:
+ ${COMPILE.r} ${.IMPSRC}
+.r.a:
+ ${COMPILE.r} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Pascal
+.p:
+ ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.p.o:
+ ${COMPILE.p} ${.IMPSRC}
+.p.a:
+ ${COMPILE.p} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Assembly
+.s:
+ ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.s.o:
+ ${COMPILE.s} -o ${.TARGET} ${.IMPSRC}
+.s.a:
+ ${COMPILE.s} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+.S:
+ ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.S.o:
+ ${COMPILE.S} ${.IMPSRC}
+.S.a:
+ ${COMPILE.S} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Lex
+.l:
+ ${LEX.l} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll
+ rm -f lex.yy.c
+.l.c:
+ ${LEX.l} ${.IMPSRC}
+ mv lex.yy.c ${.TARGET}
+.l.o:
+ ${LEX.l} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} lex.yy.c
+ rm -f lex.yy.c
+
+# Yacc
+.y:
+ ${YACC.y} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS}
+ rm -f y.tab.c
+.y.c:
+ ${YACC.y} ${.IMPSRC}
+ mv y.tab.c ${.TARGET}
+.y.o:
+ ${YACC.y} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} y.tab.c
+ rm -f y.tab.c
+
+# Shell
+.sh:
+ rm -f ${.TARGET}
+ cp ${.IMPSRC} ${.TARGET}
diff --git a/contrib/bmake/mk/sys/IRIX.mk b/contrib/bmake/mk/sys/IRIX.mk
new file mode 100644
index 000000000000..783e405b24c6
--- /dev/null
+++ b/contrib/bmake/mk/sys/IRIX.mk
@@ -0,0 +1,199 @@
+# $NetBSD: IRIX.sys.mk,v 1.2 2002/12/24 23:03:27 jschauma Exp $
+# @(#)sys.mk 8.2 (Berkeley) 3/21/94
+
+.if ${.PARSEFILE} == "sys.mk"
+.ifndef ROOT_GROUP
+OS!= uname -s
+ROOT_GROUP!= sed -n /:0:/s/:.*//p /etc/group
+.MAKEOVERRIDES+= OS ROOT_GROUP
+.endif
+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: .sh .m4
+
+.LIBS: .a
+
+AR?= ar
+ARFLAGS?= rl
+RANLIB?= ranlib
+
+AS?= as
+AFLAGS?=
+COMPILE.s?= ${CC} ${AFLAGS} -c
+LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS}
+COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp
+LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CC?= cc
+NOGCCERROR?= # defined
+DBG?= -O2
+CFLAGS?= ${DBG}
+COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c
+LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CXX?= CC
+CXXFLAGS?= ${CFLAGS}
+COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c
+LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+OBJC?= ${CC}
+OBJCFLAGS?= ${CFLAGS}
+COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c
+LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CPP?= CC
+CPPFLAGS?=
+
+FC?= f77
+FFLAGS?= -O
+RFLAGS?=
+COMPILE.f?= ${FC} ${FFLAGS} -c
+LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS}
+COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c
+LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS}
+COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c
+LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS}
+
+INSTALL?= ${PREFIX}/bin/install-sh
+
+LEX?= lex
+LFLAGS?=
+LEX.l?= ${LEX} ${LFLAGS}
+
+LD?= ld
+LDFLAGS?=
+
+LINT?= lint
+LINTFLAGS?= -chapbxzF
+
+LORDER?= lorder
+
+MAKE?= make
+
+NM?= nm
+
+PC?= pc
+PFLAGS?=
+COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c
+LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+SHELL?= sh
+
+SIZE?= size
+
+TSORT?= tsort -q
+
+YACC?= yacc
+YFLAGS?=
+YACC.y?= ${YACC} ${YFLAGS}
+
+# C
+.c:
+ ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.c.o:
+ ${COMPILE.c} ${.IMPSRC}
+.c.a:
+ ${COMPILE.c} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+.c.ln:
+ ${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC}
+
+# C++
+.cc .cpp .cxx .C:
+ ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.cc.o .cpp.o .cxx.o .C.o:
+ ${COMPILE.cc} ${.IMPSRC}
+.cc.a .cpp.a .cxx.a .C.a:
+ ${COMPILE.cc} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Fortran/Ratfor
+.f:
+ ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.f.o:
+ ${COMPILE.f} ${.IMPSRC}
+.f.a:
+ ${COMPILE.f} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.F:
+ ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.F.o:
+ ${COMPILE.F} ${.IMPSRC}
+.F.a:
+ ${COMPILE.F} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.r:
+ ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.r.o:
+ ${COMPILE.r} ${.IMPSRC}
+.r.a:
+ ${COMPILE.r} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Pascal
+.p:
+ ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.p.o:
+ ${COMPILE.p} ${.IMPSRC}
+.p.a:
+ ${COMPILE.p} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Assembly
+.s:
+ ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.s.o:
+ ${COMPILE.s} ${.IMPSRC}
+.s.a:
+ ${COMPILE.s} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+.S:
+ ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.S.o:
+ ${COMPILE.S} ${.IMPSRC}
+.S.a:
+ ${COMPILE.S} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Lex
+.l:
+ ${LEX.l} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll
+ rm -f lex.yy.c
+.l.c:
+ ${LEX.l} ${.IMPSRC}
+ mv lex.yy.c ${.TARGET}
+.l.o:
+ ${LEX.l} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} lex.yy.c
+ rm -f lex.yy.c
+
+# Yacc
+.y:
+ ${YACC.y} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS}
+ rm -f y.tab.c
+.y.c:
+ ${YACC.y} ${.IMPSRC}
+ mv y.tab.c ${.TARGET}
+.y.o:
+ ${YACC.y} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} y.tab.c
+ rm -f y.tab.c
+
+# Shell
+.sh:
+ rm -f ${.TARGET}
+ cp ${.IMPSRC} ${.TARGET}
diff --git a/contrib/bmake/mk/sys/Linux.mk b/contrib/bmake/mk/sys/Linux.mk
new file mode 100644
index 000000000000..862cde647800
--- /dev/null
+++ b/contrib/bmake/mk/sys/Linux.mk
@@ -0,0 +1,200 @@
+# $Id: Linux.mk,v 1.7 2011/03/02 05:05:21 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
+
+OS?= Linux
+unix?= We run ${OS}.
+
+ROOT_GROUP= root
+
+# would be better to work out where it is...
+LIBCRT0= /dev/null
+
+NEED_SOLINKS=yes
+
+.SUFFIXES: .out .a .ln .o .c .cc .C .F .f .r .y .l .s .S .cl .p .h .sh .m4
+
+.LIBS: .a
+
+AR= ar
+ARFLAGS= rl
+RANLIB= ranlib
+
+AS= as
+AFLAGS=
+COMPILE.s= ${AS} ${AFLAGS}
+LINK.s= ${CC} ${AFLAGS} ${LDFLAGS}
+COMPILE.S= ${CC} ${AFLAGS} ${CPPFLAGS} -c
+LINK.S= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS}
+.if exists(/usr/local/bin/gcc)
+CC= gcc -pipe
+DBG= -O -g
+STATIC?= -static
+.else
+CC= cc -pipe
+DBG= -g
+STATIC= -Bstatic
+.endif
+CFLAGS= ${DBG}
+COMPILE.c= ${CC} ${CFLAGS} ${CPPFLAGS} -c
+LINK.c= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CXX= g++
+CXXFLAGS= ${CFLAGS}
+COMPILE.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c
+LINK.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CPP= cpp
+.if defined(DESTDIR)
+CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include
+.endif
+
+MK_DEP= mkdeps.sh -N
+FC= f77
+FFLAGS= -O
+RFLAGS=
+COMPILE.f= ${FC} ${FFLAGS} -c
+LINK.f= ${FC} ${FFLAGS} ${LDFLAGS}
+COMPILE.F= ${FC} ${FFLAGS} ${CPPFLAGS} -c
+LINK.F= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS}
+COMPILE.r= ${FC} ${FFLAGS} ${RFLAGS} -c
+LINK.r= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS}
+
+LEX= lex
+LFLAGS=
+LEX.l= ${LEX} ${LFLAGS}
+
+LD= ld
+LDFLAGS=
+
+LINT= lint
+LINTFLAGS= -chapbx
+
+MAKE= bmake
+
+PC= pc
+PFLAGS=
+COMPILE.p= ${PC} ${PFLAGS} ${CPPFLAGS} -c
+LINK.p= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+SHELL= sh
+
+YACC= yacc
+YFLAGS= -d
+YACC.y= ${YACC} ${YFLAGS}
+
+# C
+.c:
+ ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.c.o:
+ ${COMPILE.c} ${.IMPSRC}
+.c.a:
+ ${COMPILE.c} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# C++
+.cc:
+ ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.cc.o:
+ ${COMPILE.cc} ${.IMPSRC}
+.cc.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}
+.f.o:
+ ${COMPILE.f} ${.IMPSRC}
+.f.a:
+ ${COMPILE.f} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.F:
+ ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.F.o:
+ ${COMPILE.F} ${.IMPSRC}
+.F.a:
+ ${COMPILE.F} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.r:
+ ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.r.o:
+ ${COMPILE.r} ${.IMPSRC}
+.r.a:
+ ${COMPILE.r} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Pascal
+.p:
+ ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.p.o:
+ ${COMPILE.p} ${.IMPSRC}
+.p.a:
+ ${COMPILE.p} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Assembly
+.s:
+ ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.s.o:
+ ${COMPILE.s} -o ${.TARGET} ${.IMPSRC}
+.s.a:
+ ${COMPILE.s} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+.S:
+ ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.S.o:
+ ${COMPILE.S} ${.IMPSRC}
+.S.a:
+ ${COMPILE.S} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Lex
+.l:
+ ${LEX.l} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll
+ rm -f lex.yy.c
+.l.c:
+ ${LEX.l} ${.IMPSRC}
+ mv lex.yy.c ${.TARGET}
+.l.o:
+ ${LEX.l} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} lex.yy.c
+ rm -f lex.yy.c
+
+# Yacc
+.y:
+ ${YACC.y} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS}
+ rm -f y.tab.c
+.y.c:
+ ${YACC.y} ${.IMPSRC}
+ mv y.tab.c ${.TARGET}
+.y.o:
+ ${YACC.y} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} y.tab.c
+ rm -f y.tab.c
+
+# Shell
+.sh:
+ rm -f ${.TARGET}
+ cp ${.IMPSRC} ${.TARGET}
diff --git a/contrib/bmake/mk/sys/NetBSD.mk b/contrib/bmake/mk/sys/NetBSD.mk
new file mode 100644
index 000000000000..4bc7da1d840a
--- /dev/null
+++ b/contrib/bmake/mk/sys/NetBSD.mk
@@ -0,0 +1,234 @@
+# $NetBSD: sys.mk,v 1.66.2.1 2002/06/05 03:31:01 lukem Exp $
+# @(#)sys.mk 8.2 (Berkeley) 3/21/94
+
+OS= NetBSD
+unix?= We run ${OS}.
+
+.if !defined(MAKE_VERSION)
+# we are running native make
+# which defined MAKE_VERSION between 20010609 and 20090324
+# so we can make a rough guess
+.if defined(.MAKE.LEVEL)
+MAKE_VERSION = 20090908
+.elif defined(.MAKE.MAKEFILES)
+# introduced 20071008
+MAKE_VERSION = 20090324
+.else
+# this just before when MAKE_VERSION was introduced
+MAKE_VERSION = 20010606
+.endif
+.endif
+
+.SUFFIXES: .out .a .ln .o .s .S .c .cc .cpp .cxx .C .F .f .r .y .l .cl .p .h
+.SUFFIXES: .sh .m4
+
+.LIBS: .a
+
+AR?= ar
+ARFLAGS?= rl
+RANLIB?= ranlib
+
+AS?= as
+AFLAGS?=
+COMPILE.s?= ${CC} ${AFLAGS} -c
+LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS}
+COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp
+LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CC?= cc
+
+# need to make sure this is set
+MACHINE_ARCH.${MACHINE} ?= ${MACHINE}
+.if empty(MACHINE_ARCH)
+MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}}
+.endif
+
+#
+# CPU model, derived from MACHINE_ARCH
+#
+MACHINE_CPU= ${MACHINE_ARCH:C/mipse[bl]/mips/:C/mips64e[bl]/mips/:C/sh3e[bl]/sh3/:S/m68000/m68k/:S/armeb/arm/}
+
+.if ${MACHINE_CPU} == "alpha" || \
+ ${MACHINE_CPU} == "arm" || \
+ ${MACHINE_CPU} == "i386" || \
+ ${MACHINE_CPU} == "m68k" || \
+ ${MACHINE_CPU} == "mips" || \
+ ${MACHINE_CPU} == "powerpc" || \
+ ${MACHINE_CPU} == "sparc" || \
+ ${MACHINE_CPU} == "vax"
+DBG?= -O2
+.elif ${MACHINE_ARCH} == "x86_64"
+DBG?=
+.elif ${MACHINE_ARCH} == "sparc64"
+DBG?= -O -ffixed-g4 #Hack for embedany memory model compatibility
+.else
+DBG?= -O
+.endif
+CFLAGS?= ${DBG}
+COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c
+LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CXX?= c++
+CXXFLAGS?= ${CFLAGS}
+COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c
+LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+OBJC?= ${CC}
+OBJCFLAGS?= ${CFLAGS}
+COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c
+LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CPP?= cpp
+CPPFLAGS?=
+
+FC?= f77
+FFLAGS?= -O
+RFLAGS?=
+COMPILE.f?= ${FC} ${FFLAGS} -c
+LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS}
+COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c
+LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS}
+COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c
+LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS}
+
+INSTALL?= install
+
+LEX?= lex
+LFLAGS?=
+LEX.l?= ${LEX} ${LFLAGS}
+
+LD?= ld
+LDFLAGS?=
+
+LINT?= lint
+LINTFLAGS?= -chapbxzF
+
+LORDER?= lorder
+
+MAKE?= make
+
+NM?= nm
+
+PC?= pc
+PFLAGS?=
+COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c
+LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+SHELL?= sh
+
+SIZE?= size
+
+TSORT?= tsort -q
+
+YACC?= yacc
+YFLAGS?=
+YACC.y?= ${YACC} ${YFLAGS}
+
+# C
+.c:
+ ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.c.o:
+ ${COMPILE.c} ${.IMPSRC}
+.c.a:
+ ${COMPILE.c} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+.c.ln:
+ ${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC}
+
+# C++
+.cc .cpp .cxx .C:
+ ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.cc.o .cpp.o .cxx.o .C.o:
+ ${COMPILE.cc} ${.IMPSRC}
+.cc.a .cpp.a .cxx.a .C.a:
+ ${COMPILE.cc} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Fortran/Ratfor
+.f:
+ ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.f.o:
+ ${COMPILE.f} ${.IMPSRC}
+.f.a:
+ ${COMPILE.f} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.F:
+ ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.F.o:
+ ${COMPILE.F} ${.IMPSRC}
+.F.a:
+ ${COMPILE.F} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.r:
+ ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.r.o:
+ ${COMPILE.r} ${.IMPSRC}
+.r.a:
+ ${COMPILE.r} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Pascal
+.p:
+ ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.p.o:
+ ${COMPILE.p} ${.IMPSRC}
+.p.a:
+ ${COMPILE.p} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Assembly
+.s:
+ ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.s.o:
+ ${COMPILE.s} ${.IMPSRC}
+.s.a:
+ ${COMPILE.s} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+.S:
+ ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.S.o:
+ ${COMPILE.S} ${.IMPSRC}
+.S.a:
+ ${COMPILE.S} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Lex
+.l:
+ ${LEX.l} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll
+ rm -f lex.yy.c
+.l.c:
+ ${LEX.l} ${.IMPSRC}
+ mv lex.yy.c ${.TARGET}
+.l.o:
+ ${LEX.l} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} lex.yy.c
+ rm -f lex.yy.c
+
+# Yacc
+.y:
+ ${YACC.y} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS}
+ rm -f y.tab.c
+.y.c:
+ ${YACC.y} ${.IMPSRC}
+ mv y.tab.c ${.TARGET}
+.y.o:
+ ${YACC.y} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} y.tab.c
+ rm -f y.tab.c
+
+# Shell
+.sh:
+ rm -f ${.TARGET}
+ cp ${.IMPSRC} ${.TARGET}
diff --git a/contrib/bmake/mk/sys/OSF1.mk b/contrib/bmake/mk/sys/OSF1.mk
new file mode 100644
index 000000000000..a8d729a6c2db
--- /dev/null
+++ b/contrib/bmake/mk/sys/OSF1.mk
@@ -0,0 +1,211 @@
+# $Id: OSF1.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
+
+OS?= OSF1
+unix?= We run ${OS}.
+ROOT_GROUP= system
+
+# can't fine one anywhere, so just stop the dependency
+LIBCRT0= /dev/null
+
+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
+
+.LIBS: .a
+
+# no -X
+LD_X=
+LD_x= -x
+LD_r= -r
+AR= ar
+ARFLAGS= rl
+RANLIB= ranlib
+
+AS= as
+AS_STDIN= -
+AFLAGS=
+COMPILE.s= ${AS} ${AFLAGS}
+LINK.s= ${CC} ${AFLAGS} ${LDFLAGS}
+COMPILE.S= ${CC} ${AFLAGS} ${CPPFLAGS} -c
+LINK.S= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS}
+.if exists(/opt/gnu/bin/gcc) || exists(/usr/local/bin/gcc)
+CC?= gcc
+.else
+CC?= cc -std
+.endif
+.if (${CC:T} == "gcc")
+DBG= -O -g
+STATIC= -static
+DBG= -g
+STATIC= -non_shared
+.endif
+
+CFLAGS= ${DBG}
+COMPILE.c= ${CC} ${CFLAGS} ${CPPFLAGS} -c
+LINK.c= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CXX= g++
+CXXFLAGS= ${CFLAGS}
+COMPILE.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c
+LINK.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CPP= /usr/ccs/lib/cpp
+.if defined(DESTDIR)
+CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include
+.endif
+
+MK_DEP= mkdeps.sh -N
+FC= f77
+FFLAGS= -O
+RFLAGS=
+COMPILE.f= ${FC} ${FFLAGS} -c
+LINK.f= ${FC} ${FFLAGS} ${LDFLAGS}
+COMPILE.F= ${FC} ${FFLAGS} ${CPPFLAGS} -c
+LINK.F= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS}
+COMPILE.r= ${FC} ${FFLAGS} ${RFLAGS} -c
+LINK.r= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS}
+
+LEX= lex
+LFLAGS=
+LEX.l= ${LEX} ${LFLAGS}
+
+LD= ld
+LDFLAGS=
+
+LINT= lint
+LINTFLAGS= -chapbx
+
+MAKE= bmake
+
+PC= pc
+PFLAGS=
+COMPILE.p= ${PC} ${PFLAGS} ${CPPFLAGS} -c
+LINK.p= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+SHELL= sh
+
+.if exists(/usr/local/bin/bison) || exists(/opt/gnu/bin/bison)
+YACC= bison -y
+.else
+YACC= yacc
+.endif
+YFLAGS= -d
+YACC.y= ${YACC} ${YFLAGS}
+
+# C
+.c:
+ ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.c.o:
+ ${COMPILE.c} ${.IMPSRC}
+.c.a:
+ ${COMPILE.c} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# C++
+.cc:
+ ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.cc.o:
+ ${COMPILE.cc} ${.IMPSRC}
+.cc.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}
+.f.o:
+ ${COMPILE.f} ${.IMPSRC}
+.f.a:
+ ${COMPILE.f} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.F:
+ ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.F.o:
+ ${COMPILE.F} ${.IMPSRC}
+.F.a:
+ ${COMPILE.F} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.r:
+ ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.r.o:
+ ${COMPILE.r} ${.IMPSRC}
+.r.a:
+ ${COMPILE.r} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Pascal
+.p:
+ ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.p.o:
+ ${COMPILE.p} ${.IMPSRC}
+.p.a:
+ ${COMPILE.p} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Assembly
+.s:
+ ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.s.o:
+ ${COMPILE.s} ${.IMPSRC}
+.s.a:
+ ${COMPILE.s} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+.S:
+ ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.S.o:
+ ${COMPILE.S} ${.IMPSRC}
+.S.a:
+ ${COMPILE.S} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Lex
+.l:
+ ${LEX.l} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll
+ rm -f lex.yy.c
+.l.c:
+ ${LEX.l} ${.IMPSRC}
+ mv lex.yy.c ${.TARGET}
+.l.o:
+ ${LEX.l} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} lex.yy.c
+ rm -f lex.yy.c
+
+# Yacc
+.y:
+ ${YACC.y} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS}
+ rm -f y.tab.c
+.y.c:
+ ${YACC.y} ${.IMPSRC}
+ mv y.tab.c ${.TARGET}
+.y.o:
+ ${YACC.y} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} y.tab.c
+ rm -f y.tab.c
+
+# Shell
+.sh:
+ rm -f ${.TARGET}
+ cp ${.IMPSRC} ${.TARGET}
diff --git a/contrib/bmake/mk/sys/OpenBSD.mk b/contrib/bmake/mk/sys/OpenBSD.mk
new file mode 100644
index 000000000000..ed496f12c208
--- /dev/null
+++ b/contrib/bmake/mk/sys/OpenBSD.mk
@@ -0,0 +1,209 @@
+# $NetBSD: OpenBSD.sys.mk,v 1.1 2002/11/17 09:18:00 cjep Exp $
+# @(#)sys.mk 8.2 (Berkeley) 3/21/94
+
+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: .sh .m4
+
+.LIBS: .a
+
+# need to make sure this is set
+MACHINE_ARCH.${MACHINE} ?= ${MACHINE}
+.if empty(MACHINE_ARCH)
+MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}}
+.endif
+
+AR?= ar
+ARFLAGS?= rl
+RANLIB?= ranlib
+
+AS?= as
+AFLAGS?=
+.if ${MACHINE_ARCH} == "sparc64"
+AFLAGS+= -Wa,-Av9a
+.endif
+COMPILE.s?= ${CC} ${AFLAGS} -c
+LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS}
+COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp
+LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CC?= cc
+.if ${MACHINE_ARCH} == "alpha" || \
+ ${MACHINE_ARCH} == "i386" || \
+ ${MACHINE_ARCH} == "m68k" || \
+ ${MACHINE_ARCH} == "sparc" || \
+ ${MACHINE_ARCH} == "vax"
+DBG?= -O2
+.else
+DBG?= -O
+.endif
+CFLAGS?= ${DBG}
+COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c
+LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CXX?= c++
+CXXFLAGS?= ${CFLAGS}
+COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c
+LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+OBJC?= ${CC}
+OBJCFLAGS?= ${CFLAGS}
+COMPILE.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c
+LINK.m?= ${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CPP?= cpp
+CPPFLAGS?=
+
+FC?= f77
+FFLAGS?= -O
+RFLAGS?=
+COMPILE.f?= ${FC} ${FFLAGS} -c
+LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS}
+COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c
+LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS}
+COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c
+LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS}
+
+INSTALL?= install
+
+LEX?= lex
+LFLAGS?=
+LEX.l?= ${LEX} ${LFLAGS}
+
+LD?= ld
+LDFLAGS?=
+
+LINT?= lint
+LINTFLAGS?= -chapbxzF
+
+LORDER?= lorder
+
+MAKE?= make
+
+NM?= nm
+
+PC?= pc
+PFLAGS?=
+COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c
+LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+SHELL?= sh
+
+SIZE?= size
+
+TSORT?= tsort -q
+
+YACC?= yacc
+YFLAGS?=
+YACC.y?= ${YACC} ${YFLAGS}
+
+# C
+.c:
+ ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.c.o:
+ ${COMPILE.c} ${.IMPSRC}
+.c.a:
+ ${COMPILE.c} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+.c.ln:
+ ${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC}
+
+# C++
+.cc .cpp .cxx .C:
+ ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.cc.o .cpp.o .cxx.o .C.o:
+ ${COMPILE.cc} ${.IMPSRC}
+.cc.a .cpp.a .cxx.a .C.a:
+ ${COMPILE.cc} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Fortran/Ratfor
+.f:
+ ${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.f.o:
+ ${COMPILE.f} ${.IMPSRC}
+.f.a:
+ ${COMPILE.f} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.F:
+ ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.F.o:
+ ${COMPILE.F} ${.IMPSRC}
+.F.a:
+ ${COMPILE.F} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.r:
+ ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.r.o:
+ ${COMPILE.r} ${.IMPSRC}
+.r.a:
+ ${COMPILE.r} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Pascal
+.p:
+ ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.p.o:
+ ${COMPILE.p} ${.IMPSRC}
+.p.a:
+ ${COMPILE.p} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Assembly
+.s:
+ ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.s.o:
+ ${COMPILE.s} ${.IMPSRC}
+.s.a:
+ ${COMPILE.s} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+.S:
+ ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.S.o:
+ ${COMPILE.S} ${.IMPSRC}
+.S.a:
+ ${COMPILE.S} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Lex
+.l:
+ ${LEX.l} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll
+ rm -f lex.yy.c
+.l.c:
+ ${LEX.l} ${.IMPSRC}
+ mv lex.yy.c ${.TARGET}
+.l.o:
+ ${LEX.l} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} lex.yy.c
+ rm -f lex.yy.c
+
+# Yacc
+.y:
+ ${YACC.y} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS}
+ rm -f y.tab.c
+.y.c:
+ ${YACC.y} ${.IMPSRC}
+ mv y.tab.c ${.TARGET}
+.y.o:
+ ${YACC.y} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} y.tab.c
+ rm -f y.tab.c
+
+# Shell
+.sh:
+ rm -f ${.TARGET}
+ cp ${.IMPSRC} ${.TARGET}
diff --git a/contrib/bmake/mk/sys/SunOS.mk b/contrib/bmake/mk/sys/SunOS.mk
new file mode 100644
index 000000000000..f164aa282be9
--- /dev/null
+++ b/contrib/bmake/mk/sys/SunOS.mk
@@ -0,0 +1,232 @@
+# $Id: SunOS.mk,v 1.5 2010/01/11 23:02:05 sjg Exp $
+
+.if ${.PARSEFILE} == "sys.mk"
+.include <host-target.mk>
+
+OS?= SunOS.${HOST_OSMAJOR}
+unix?= We run ${OS}.
+.endif
+
+.if ${HOST_OSMAJOR} > 4
+ROOT_GROUP= root
+
+SHLIB_FULLVERSION = ${SHLIB_MAJOR}
+
+# supress the dependency
+LIBCRT0= /dev/null
+
+.ifndef CC
+# the PATH below may find an ancient gcc
+CC := ${gcc:L:${M_whence}}
+.export CC
+.endif
+
+# the stuff in /usr/xpg4/bin is usually more sane.
+PATH=/usr/xpg4/bin:/usr/sbin:/usr/bin:/usr/ucb:/usr/sfw/bin:/opt/gnu/bin:/usr/ccs/bin:/usr/local/bin
+.export PATH
+
+DSHLIBEXT = .so
+HOST_LIBDIRS = /usr/lib /lib /usr/sfw/lib
+
+# no -X
+LD_X=
+LD_x=
+RANLIB= :
+CPP= /usr/ccs/lib/cpp
+.else
+ROOT_GROUP= wheel
+RANLIB= ranlib
+CPP= cpp
+.endif
+
+# the rest is common
+
+.SUFFIXES: .out .a .ln .o .c .cc .C .F .f .r .y .l .s .S .cl .p .h .sh .m4
+
+.LIBS: .a
+
+AR= ar
+ARFLAGS= rl
+
+AS= as
+AS_STDIN= -
+AFLAGS=
+COMPILE.s= ${AS} ${AFLAGS}
+LINK.s= ${CC} ${AFLAGS} ${LDFLAGS}
+COMPILE.S= ${CC} ${AFLAGS} ${CPPFLAGS} -c
+LINK.S= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS}
+.if exists(/opt/gnu/bin/gcc) || exists(/usr/local/bin/gcc)
+CC ?= gcc -pipe
+DBG= -O -g
+STATIC= -static
+.else
+CC ?= cc
+DBG= -g
+STATIC= -Bstatic
+.endif
+CFLAGS= ${DBG}
+COMPILE.c= ${CC} ${CFLAGS} ${CPPFLAGS} -c
+LINK.c= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CXX= g++
+CXXFLAGS= ${CFLAGS}
+COMPILE.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c
+LINK.cc= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+.if defined(DESTDIR)
+CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include
+.endif
+
+MK_DEP= mkdeps.sh -N
+FC= f77
+FFLAGS= -O
+RFLAGS=
+COMPILE.f= ${FC} ${FFLAGS} -c
+LINK.f= ${FC} ${FFLAGS} ${LDFLAGS}
+COMPILE.F= ${FC} ${FFLAGS} ${CPPFLAGS} -c
+LINK.F= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS}
+COMPILE.r= ${FC} ${FFLAGS} ${RFLAGS} -c
+LINK.r= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS}
+
+LEX= lex
+LFLAGS=
+LEX.l= ${LEX} ${LFLAGS}
+
+LD= ld
+LDFLAGS=
+
+LINT= lint
+LINTFLAGS= -chapbx
+
+MAKE= bmake
+
+PC= pc
+PFLAGS=
+COMPILE.p= ${PC} ${PFLAGS} ${CPPFLAGS} -c
+LINK.p= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+SHELL= sh
+
+.if exists(/usr/local/bin/bison) || exists(/opt/gnu/bin/bison)
+YACC= bison -y
+.else
+YACC= yacc
+.endif
+YFLAGS= -d
+YACC.y= ${YACC} ${YFLAGS}
+
+# C
+.c:
+ ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.c.o:
+ ${COMPILE.c} ${.IMPSRC}
+.c.a:
+ ${COMPILE.c} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# C++
+.cc:
+ ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.cc.o:
+ ${COMPILE.cc} ${.IMPSRC}
+.cc.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}
+.f.o:
+ ${COMPILE.f} ${.IMPSRC}
+.f.a:
+ ${COMPILE.f} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.F:
+ ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.F.o:
+ ${COMPILE.F} ${.IMPSRC}
+.F.a:
+ ${COMPILE.F} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.r:
+ ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.r.o:
+ ${COMPILE.r} ${.IMPSRC}
+.r.a:
+ ${COMPILE.r} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Pascal
+.p:
+ ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.p.o:
+ ${COMPILE.p} ${.IMPSRC}
+.p.a:
+ ${COMPILE.p} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Assembly
+.s:
+ ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.s.o:
+ ${COMPILE.s} ${.IMPSRC}
+.s.a:
+ ${COMPILE.s} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+.S:
+ ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.S.o:
+ ${COMPILE.S} ${.IMPSRC}
+.S.a:
+ ${COMPILE.S} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Lex
+.l:
+ ${LEX.l} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll
+ rm -f lex.yy.c
+.l.c:
+ ${LEX.l} ${.IMPSRC}
+ mv lex.yy.c ${.TARGET}
+.l.o:
+ ${LEX.l} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} lex.yy.c
+ rm -f lex.yy.c
+
+# Yacc
+.y:
+ ${YACC.y} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS}
+ rm -f y.tab.c
+.y.c:
+ ${YACC.y} ${.IMPSRC}
+ mv y.tab.c ${.TARGET}
+.y.o:
+ ${YACC.y} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} y.tab.c
+ rm -f y.tab.c
+
+# Shell
+.sh:
+ rm -f ${.TARGET}
+ cp ${.IMPSRC} ${.TARGET}
diff --git a/contrib/bmake/mk/sys/UnixWare.mk b/contrib/bmake/mk/sys/UnixWare.mk
new file mode 100644
index 000000000000..f21895b6e60b
--- /dev/null
+++ b/contrib/bmake/mk/sys/UnixWare.mk
@@ -0,0 +1,254 @@
+# $Id: UnixWare.mk,v 1.1 2005/10/09 22:56:40 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
+
+OS?= UnixWare
+unix?= We run ${OS}.
+ROOT_GROUP= root
+
+# can't fine one anywhere, so just stop the dependency
+LIBCRT0= /dev/null
+
+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
+
+.LIBS: .a
+
+# no -X
+LD_X=
+LD_x=
+AR?= ar
+ARFLAGS?= rl
+RANLIB?= :
+
+AS?= as
+AS_STDIN?= -
+AFLAGS?=
+COMPILE.s?= ${AS} ${AFLAGS}
+LINK.s?= ${CC} ${AFLAGS} ${LDFLAGS}
+COMPILE.S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c
+LINK.S?= ${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+# at least gcc 2.95 on UnixWare has no internal macro to identify the system
+.if exists(/usr/local/bin/gcc)
+CC?= gcc -pipe -DUNIXWARE
+DBG?= -O -g
+STATIC?= -static
+.else
+CC?= cc
+DBG?= -g
+STATIC?= -Bstatic # XXX: don't know about UDK compilers
+.endif
+CFLAGS?= ${DBG}
+COMPILE.c?= ${CC} ${CFLAGS} ${CPPFLAGS} -c
+LINK.c?= ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+.if exists(/usr/local/bin/g++)
+CXX?= g++ -DUNIXWARE
+.else
+CXX?= c++ # XXX: don't know about UDK compilers
+.endif
+CXXFLAGS?= ${CFLAGS}
+COMPILE.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c
+LINK.cc?= ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+CPP?= /usr/ccs/lib/cpp
+.if defined(DESTDIR)
+CPPFLAGS+= -nostdinc -idirafter ${DESTDIR}/usr/include
+.endif
+
+MK_DEP?= mkdeps.sh -N
+.if exists(/usr/local/bin/g77)
+FC?= g77
+.else
+FC?= f77 # XXX: don't know about UDK compilers
+.endif
+FFLAGS?= -O
+RFLAGS?=
+COMPILE.f?= ${FC} ${FFLAGS} -c
+LINK.f?= ${FC} ${FFLAGS} ${LDFLAGS}
+COMPILE.F?= ${FC} ${FFLAGS} ${CPPFLAGS} -c
+LINK.F?= ${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS}
+COMPILE.r?= ${FC} ${FFLAGS} ${RFLAGS} -c
+LINK.r?= ${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS}
+
+INSTALL?= /usr/ucb/install # BSD install
+
+LEX?= lex
+LFLAGS?=
+LEX.l?= ${LEX} ${LFLAGS}
+
+LD?= ld
+LDFLAGS?=
+
+LIBC?= ${DESTDIR}/usr/ccs/lib/libc.a
+LIBCOMPAT?=
+LIBCRYPT?= ${DESTDIR}/usr/lib/libcrypt.a
+LIBCURSES?= ${DESTDIR}/usr/ccs/lib/libcurses.a
+LIBDBM?=
+LIBDES?=
+LIBEDIT?=
+LIBGCC?=
+LIBKDB?=
+LIBKRB?=
+LIBKVM?=
+LIBL?= ${DESTDIR}/usr/ccs/lib/libl.a
+LIBM?= ${DESTDIR}/usr/ccs/lib/libm.a
+LIBMP?=
+LIBPC?=
+LIBPCAP?=
+LIBPLOT?=
+LIBRESOLV?=
+LIBRPCSVC?= ${DESTDIR}/usr/lib/librpcsvc.a
+LIBSKEY?= ${DESTDIR}/usr/lib/libskey.a
+LIBTERMCAP?= ${DESTDIR}/usr/ccs/lib/libtermcap.a
+LIBUTIL?=
+LIBWRAP?=
+LIBY?= ${DESTDIR}/usr/ccs/lib/liby.a
+LIBZ?=
+
+LINT?= lint
+LINTFLAGS?= -pF
+
+LORDER?= lorder
+
+MAKE?= bmake
+
+NM?= nm
+
+PC?= pc # XXX: UDK probably does not have pc
+PFLAGS?=
+COMPILE.p?= ${PC} ${PFLAGS} ${CPPFLAGS} -c
+LINK.p?= ${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS}
+
+SHELL?= sh
+
+SIZE?= size
+
+TSORT?= tsort
+
+.if exists(/usr/local/bin/bison)
+YACC?= bison -y
+.else
+YACC?= yacc
+.endif
+YFLAGS?= -d
+YACC.y?= ${YACC} ${YFLAGS}
+
+# C
+.c:
+ ${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.c.o:
+ ${COMPILE.c} ${.IMPSRC}
+.c.a:
+ ${COMPILE.c} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# C++
+.cc:
+ ${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.cc.o:
+ ${COMPILE.cc} ${.IMPSRC}
+.cc.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}
+.f.o:
+ ${COMPILE.f} ${.IMPSRC}
+.f.a:
+ ${COMPILE.f} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.F:
+ ${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.F.o:
+ ${COMPILE.F} ${.IMPSRC}
+.F.a:
+ ${COMPILE.F} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+.r:
+ ${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.r.o:
+ ${COMPILE.r} ${.IMPSRC}
+.r.a:
+ ${COMPILE.r} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Pascal
+.p:
+ ${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.p.o:
+ ${COMPILE.p} ${.IMPSRC}
+.p.a:
+ ${COMPILE.p} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Assembly
+.s:
+ ${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.s.o:
+ ${COMPILE.s} ${.IMPSRC}
+.s.a:
+ ${COMPILE.s} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+.S:
+ ${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
+.S.o:
+ ${COMPILE.S} ${.IMPSRC}
+.S.a:
+ ${COMPILE.S} ${.IMPSRC}
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+# Lex
+.l:
+ ${LEX.l} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll
+ rm -f lex.yy.c
+.l.c:
+ ${LEX.l} ${.IMPSRC}
+ mv lex.yy.c ${.TARGET}
+.l.o:
+ ${LEX.l} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} lex.yy.c
+ rm -f lex.yy.c
+
+# Yacc
+.y:
+ ${YACC.y} ${.IMPSRC}
+ ${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS}
+ rm -f y.tab.c
+.y.c:
+ ${YACC.y} ${.IMPSRC}
+ mv y.tab.c ${.TARGET}
+.y.o:
+ ${YACC.y} ${.IMPSRC}
+ ${COMPILE.c} -o ${.TARGET} y.tab.c
+ rm -f y.tab.c
+
+# Shell
+.sh:
+ rm -f ${.TARGET}
+ cp ${.IMPSRC} ${.TARGET}
diff --git a/contrib/bmake/mk/target-flags.mk b/contrib/bmake/mk/target-flags.mk
new file mode 100644
index 000000000000..f8932b2f17b9
--- /dev/null
+++ b/contrib/bmake/mk/target-flags.mk
@@ -0,0 +1,62 @@
+# NAME:
+# target-flags.mk - target specific flags
+#
+# DESCRIPTION:
+# Include this macro file after all others in a makefile and
+# follow it with any target specfic flag settings.
+# For each such variable v in TARGET_FLAG_VARS we set:
+#.nf
+#
+# _$v := ${$v}
+# $v = ${${v}_${.TARGET:T}:U${_$v}}
+#.fi
+#
+# This allows one to do things like:
+#.nf
+#
+# TARGET_FLAG_VARS= CFLAGS
+# .include <target-flags.mk>
+# CFLAGS_fu.o = ${_CFLAGS:N-Wall}
+#.fi
+#
+# To turn off -Wall for just the target fu.o
+# Actually CFLAGS is the default value for TARGET_FLAG_VARS.
+#
+# BUGS:
+# One must be careful to avoid creating circular references in
+# variables. The original version of this macro file did
+# elaborate things with CFLAGS. The current, simpler
+# implementation is ultimately more flexible.
+#
+# It is important that target-flags.mk is included after other
+# macro files and that target specific flags that may reference
+# _$v are set after that.
+#
+# Only works with a make(1) that does nested evaluation correctly.
+
+
+
+# RCSid:
+# $Id: target-flags.mk,v 1.8 2002/05/08 06:01:00 sjg Exp $
+#
+# @(#) Copyright (c) 1998-2002, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+TARGET_FLAG_VARS?= CFLAGS
+.for v in ${TARGET_FLAG_VARS}
+.ifndef _$v
+_$v := ${$v}
+$v = ${${v}_${.TARGET:T}:U${_$v}}
+.endif
+.endfor
+
diff --git a/contrib/bmake/mk/warnings.mk b/contrib/bmake/mk/warnings.mk
new file mode 100644
index 000000000000..9143e4289fd5
--- /dev/null
+++ b/contrib/bmake/mk/warnings.mk
@@ -0,0 +1,148 @@
+# RCSid:
+# $Id: warnings.mk,v 1.7 2009/12/11 17:06:03 sjg Exp $
+#
+# @(#) Copyright (c) 2002, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+.ifndef _w_cflags
+
+# Any number of warnings sets can be added.
+.-include "warnings-sets.mk"
+
+# Modest defaults - put more elaborate sets in warnings-sets.mk
+# -Wunused etc are here so you can set
+# W_unused=-Wno-unused etc.
+MIN_WARNINGS?= -Wall \
+ -Wformat \
+ -Wimplicit \
+ -Wunused \
+ -Wuninitialized
+
+LOW_WARNINGS?= ${MIN_WARNINGS} -W -Wstrict-prototypes -Wmissing-prototypes
+
+MEDIUM_WARNINGS?= ${LOW_WARNINGS} -Werror
+
+HIGH_WARNINGS?= ${MEDIUM_WARNINGS} \
+ -Wcast-align \
+ -Wcast-qual \
+ -Wparentheses \
+ -Wpointer-arith \
+ -Wmissing-declarations \
+ -Wreturn-type \
+ -Wswitch \
+ -Wwrite-strings
+
+# The two step default makes it easier to test build with different defaults.
+DEFAULT_WARNINGS_SET?= MIN
+WARNINGS_SET?= ${DEFAULT_WARNINGS_SET}
+
+# If you add sets, besure to list them (you don't have to touch this list).
+ALL_WARNINGS_SETS+= MIN LOW MEDIUM HIGH
+
+.if empty(${WARNINGS_SET}_WARNINGS)
+.if ${MAKE_VERSION:U0:[1]:C/.*-//} >= 20050530
+.BEGIN: _empty_warnings
+_empty_warnings: .PHONY
+.else
+.BEGIN:
+.endif
+ @echo "ERROR: Invalid: WARNINGS_SET=${WARNINGS_SET}"
+ @echo "ERROR: Try one of: ${ALL_WARNINGS_SETS:O:u}"; exit 1
+
+.endif
+
+# 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}
+.if ${_w_cflags:M-O*} == "" || ${_w_cflags:M-O0} != ""
+W_uninitialized=
+.endif
+
+.if ${MAKE_VERSION:U0:[1]:C/.*-//} <= 20040118
+# This version uses .for loops to avoid a double free bug in old bmake's
+# but the .for loops are sensitive to when this file is read.
+
+# first, make a list of all the warning flags - doesn't matter if
+# its redundant - we'll sort -u
+_all_sets= ${WARNINGS_SET_${MACHINE_ARCH}} ${WARNINGS_SET} ${ALL_WARNINGS_SETS}
+_all_warnings= ${WARNINGS} ${_all_sets:O:u:@s@${$s_WARNINGS}@}
+
+# we want to set W_* for each warning so they are easy to turn off.
+# :O:u does a sort -u
+# using :C allows us to handle -f* -w* etc as well as -W*
+.for w in ${_all_warnings:O:u}
+${w:C/-(.)/\1_/} ?= $w
+.endfor
+
+# Allow for per-target warnings
+# Warning: the WARNINGS+= line below,
+# may make your brain hurt - trust me; it works --sjg
+# the idea is that you can set WARNINGS_SET[_${MACHINE_ARCH}]=HIGH
+# and use one of
+# W_format_mips_foo.o=
+# W_format_foo.o=
+# to turn off -Wformat for foo.o (on mips only in the first case), or
+# W_format_foo.o=-Wformat=2
+# for stricter checking.
+#
+# NOTE: that we force the target extension to be .o
+#
+.for w in ${WARNINGS_SET_${MACHINE_ARCH}:U${WARNINGS_SET}:@s@${$s_WARNINGS}@:O:u}
+WARNINGS+= ${${w:C/-(.)/\1_/}_${MACHINE_ARCH}_${.TARGET:T:R}.o:U${${w:C/-(.)/\1_/}_${.TARGET:T:R}.o:U${${w:C/-(.)/\1_/}_${MACHINE_ARCH}:U${${w:C/-(.)/\1_/}}}}}
+.endfor
+
+.else
+
+# .for loops have the [dis]advantage of being evaluated when read,
+# so adding to WARNINGS_SET[_${MACHINE_ARCH}] after this file is
+# read has no effect.
+# Replacing the above .for loops with the WARNINGS+= below solves that
+# but tiggers a double free bug in bmake-20040118 and earlier.
+# Don't try and read this too fast!
+#
+# The first :@ "loop" handles multiple sets in WARNINGS_SET
+#
+# In the second :@ "loop", the ::?= noise sets W_foo?=-Wfoo etc
+# which makes it easy to turn off override individual flags
+# (see W_uninitialized above).
+#
+# The last bit expands to ${W_foo_${.TARGET:T}:U${W_foo}}
+# which is the bit we ultimately want. It allows W_* to be set on a
+# per target basis.
+#
+# NOTE: that we force the target extension to be .o
+#
+WARNINGS+= ${WARNINGS_SET_${MACHINE_ARCH}:U${WARNINGS_SET}:@s@${$s_WARNINGS}@:O:u:@w@${${w:C/-(.)/\1_/}::?=$w} ${${w:C/-(.)/\1_/}_${MACHINE_ARCH}_${.TARGET:T:R}.o:U${${w:C/-(.)/\1_/}_${.TARGET:T:R}.o:U${${w:C/-(.)/\1_/}_${MACHINE_ARCH}:U${${w:C/-(.)/\1_/}}}}}@}
+
+.endif
+
+.ifndef NO_CFLAGS_WARNINGS
+# Just ${WARNINGS} should do, but this is more flexible?
+CFLAGS+= ${WARNINGS_${.TARGET:T:R}.o:U${WARNINGS}}
+.endif
+
+# it is rather silly that g++ blows up on some warning flags
+NO_CXX_WARNINGS+= \
+ missing-declarations \
+ missing-prototypes \
+ nested-externs \
+ strict-prototypes
+
+.for s in ${SRCS:M*.cc}
+.for w in ${NO_CXX_WARNINGS}
+W_$w_${s:T:R}.o=
+.endfor
+.endfor
+
+.endif # _w_cflags
diff --git a/contrib/bmake/mk/yacc.mk b/contrib/bmake/mk/yacc.mk
new file mode 100644
index 000000000000..910b004431df
--- /dev/null
+++ b/contrib/bmake/mk/yacc.mk
@@ -0,0 +1,57 @@
+# $Id: yacc.mk,v 1.6 2011/06/10 22:45:46 sjg Exp $
+
+#
+# @(#) Copyright (c) 1999-2011, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+# this file contains rules to DTRT when SRCS contains foo.y or foo.c
+# when only a foo.y exists.
+
+YACC?= yacc
+YFLAGS?= -v -t
+RM?= rm
+
+YACC.y?= ${YACC} ${YFLAGS}
+
+.if ${YACC.y:M-d} == "" || defined(NO_RENAME_Y_TAB_H)
+
+.y.c:
+ ${YACC.y} ${.IMPSRC}
+ [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET}
+ ${RM} -f y.tab.[!h]
+
+.else
+
+# the touch of the .c is to ensure it is newer than .h (paranoia)
+.y.h:
+ ${YACC.y} ${.IMPSRC}
+ [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET:T:R}.c
+ [ ! -s y.tab.h ] || cmp -s y.tab.h ${.TARGET:T:R}.h \
+ || mv y.tab.h ${.TARGET:T:R}.h
+ touch ${.TARGET:T:R}.c
+ ${RM} -f y.tab.*
+
+# Normally the .y.h rule does the work - to avoid races.
+# If for any reason the .c is lost but the .h remains,
+# regenerate the .c
+.y.c: ${.TARGET:T:R}.h
+ [ -s ${.TARGET} ] || { \
+ ${YACC.y} ${.IMPSRC} && \
+ { [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET}; \
+ ${RM} y.tab.*; }; }
+.endif
+
+beforedepend: ${SRCS:T:M*.y:S/.y/.c/g}
+
+CLEANFILES+= ${SRCS:T:M*.y:S/.y/.[ch]/g}
+CLEANFILES+= y.tab.[ch]