pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/pkgtools



Module Name:    pkgsrc
Committed By:   jlam
Date:           Thu Jun  1 01:58:34 UTC 2017

Modified Files:
        pkgsrc/pkgtools: Makefile
Added Files:
        pkgsrc/pkgtools/pkgtasks: DESCR Makefile PLIST
        pkgsrc/pkgtools/pkgtasks/files: AUTHORS COPYING Makefile.am Makefile.in
            README.md aclocal.m4 cleanup.subr compare.subr configure
            configure.ac createfile.subr directories.subr dirwalk.subr
            echo.subr files.subr fonts.subr groups.subr info_files.subr
            load.subr lock.subr makedir.subr maketemp.subr match.subr
            ocaml_findlib.subr permissions.subr platform.subr postinstall.subr
            postremove.subr preinstall.subr preremove.subr quote.subr
            random.subr refcount.subr refcount_file.subr say.subr shells.subr
            shlibs.subr sort.subr taskfunc.subr tee.subr truthy.subr
            unittest.subr usergroup.subr usergroup_FreeBSD.subr
            usergroup_Linux.subr usergroup_MirBSD.subr usergroup_NetBSD.subr
            usergroup_exists.subr usergroup_mock.subr users.subr
            valid_options.subr version.subr.in which.subr
        pkgsrc/pkgtools/pkgtasks/files/build-aux: install-sh missing
        pkgsrc/pkgtools/pkgtasks/files/t: Kyuafile build_test.sh run_tests.sh
            t_compare.sh t_createfile.sh t_directories.sh t_dirwalk.sh
            t_echo.sh t_files.sh t_fonts.sh t_groups.sh t_info_files.sh
            t_lock.sh t_makedir.sh t_maketemp.sh t_match.sh t_ocaml_findlib.sh
            t_permissions.sh t_platform.sh t_postinstall.sh t_postremove.sh
            t_preinstall.sh t_preremove.sh t_quote.sh t_random.sh t_refcount.sh
            t_shells.sh t_shlibs.sh t_sort.sh t_taskfunc.sh t_tee.sh
            t_truthy.sh t_usergroup.sh t_usergroup_FreeBSD.sh
            t_usergroup_Linux.sh t_usergroup_MirBSD.sh t_usergroup_NetBSD.sh
            t_usergroup_exists.sh t_usergroup_mock.sh t_users.sh
            t_valid_options.sh t_version.sh t_which.sh

Log Message:
Import pkgtasks-1-1.9 as pkgsrc/pkgtools/pkgtasks.

pkgtasks is a shell script library to ease writing POSIX-compliant
shell scripts to handle common tasks during installation or removal
of a package, e.g.,

  * creating groups and users needed by the package

  * creating and removing directories with special permissions and
    ownership,

  * copying example config files to their final locations during
    package installation, and removing them during package removal
    if they don't differ from the example ones,

  * reminding the user of files that may be customized after
    package installation.


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 pkgsrc/pkgtools/Makefile
cvs rdiff -u -r0 -r1.1 pkgsrc/pkgtools/pkgtasks/DESCR \
    pkgsrc/pkgtools/pkgtasks/Makefile pkgsrc/pkgtools/pkgtasks/PLIST
cvs rdiff -u -r0 -r1.1 pkgsrc/pkgtools/pkgtasks/files/AUTHORS \
    pkgsrc/pkgtools/pkgtasks/files/COPYING \
    pkgsrc/pkgtools/pkgtasks/files/Makefile.am \
    pkgsrc/pkgtools/pkgtasks/files/Makefile.in \
    pkgsrc/pkgtools/pkgtasks/files/README.md \
    pkgsrc/pkgtools/pkgtasks/files/aclocal.m4 \
    pkgsrc/pkgtools/pkgtasks/files/cleanup.subr \
    pkgsrc/pkgtools/pkgtasks/files/compare.subr \
    pkgsrc/pkgtools/pkgtasks/files/configure \
    pkgsrc/pkgtools/pkgtasks/files/configure.ac \
    pkgsrc/pkgtools/pkgtasks/files/createfile.subr \
    pkgsrc/pkgtools/pkgtasks/files/directories.subr \
    pkgsrc/pkgtools/pkgtasks/files/dirwalk.subr \
    pkgsrc/pkgtools/pkgtasks/files/echo.subr \
    pkgsrc/pkgtools/pkgtasks/files/files.subr \
    pkgsrc/pkgtools/pkgtasks/files/fonts.subr \
    pkgsrc/pkgtools/pkgtasks/files/groups.subr \
    pkgsrc/pkgtools/pkgtasks/files/info_files.subr \
    pkgsrc/pkgtools/pkgtasks/files/load.subr \
    pkgsrc/pkgtools/pkgtasks/files/lock.subr \
    pkgsrc/pkgtools/pkgtasks/files/makedir.subr \
    pkgsrc/pkgtools/pkgtasks/files/maketemp.subr \
    pkgsrc/pkgtools/pkgtasks/files/match.subr \
    pkgsrc/pkgtools/pkgtasks/files/ocaml_findlib.subr \
    pkgsrc/pkgtools/pkgtasks/files/permissions.subr \
    pkgsrc/pkgtools/pkgtasks/files/platform.subr \
    pkgsrc/pkgtools/pkgtasks/files/postinstall.subr \
    pkgsrc/pkgtools/pkgtasks/files/postremove.subr \
    pkgsrc/pkgtools/pkgtasks/files/preinstall.subr \
    pkgsrc/pkgtools/pkgtasks/files/preremove.subr \
    pkgsrc/pkgtools/pkgtasks/files/quote.subr \
    pkgsrc/pkgtools/pkgtasks/files/random.subr \
    pkgsrc/pkgtools/pkgtasks/files/refcount.subr \
    pkgsrc/pkgtools/pkgtasks/files/refcount_file.subr \
    pkgsrc/pkgtools/pkgtasks/files/say.subr \
    pkgsrc/pkgtools/pkgtasks/files/shells.subr \
    pkgsrc/pkgtools/pkgtasks/files/shlibs.subr \
    pkgsrc/pkgtools/pkgtasks/files/sort.subr \
    pkgsrc/pkgtools/pkgtasks/files/taskfunc.subr \
    pkgsrc/pkgtools/pkgtasks/files/tee.subr \
    pkgsrc/pkgtools/pkgtasks/files/truthy.subr \
    pkgsrc/pkgtools/pkgtasks/files/unittest.subr \
    pkgsrc/pkgtools/pkgtasks/files/usergroup.subr \
    pkgsrc/pkgtools/pkgtasks/files/usergroup_FreeBSD.subr \
    pkgsrc/pkgtools/pkgtasks/files/usergroup_Linux.subr \
    pkgsrc/pkgtools/pkgtasks/files/usergroup_MirBSD.subr \
    pkgsrc/pkgtools/pkgtasks/files/usergroup_NetBSD.subr \
    pkgsrc/pkgtools/pkgtasks/files/usergroup_exists.subr \
    pkgsrc/pkgtools/pkgtasks/files/usergroup_mock.subr \
    pkgsrc/pkgtools/pkgtasks/files/users.subr \
    pkgsrc/pkgtools/pkgtasks/files/valid_options.subr \
    pkgsrc/pkgtools/pkgtasks/files/version.subr.in \
    pkgsrc/pkgtools/pkgtasks/files/which.subr
cvs rdiff -u -r0 -r1.1 pkgsrc/pkgtools/pkgtasks/files/build-aux/install-sh \
    pkgsrc/pkgtools/pkgtasks/files/build-aux/missing
cvs rdiff -u -r0 -r1.1 pkgsrc/pkgtools/pkgtasks/files/t/Kyuafile \
    pkgsrc/pkgtools/pkgtasks/files/t/build_test.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/run_tests.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_compare.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_createfile.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_directories.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_dirwalk.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_echo.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_files.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_fonts.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_groups.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_info_files.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_lock.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_makedir.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_maketemp.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_match.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_ocaml_findlib.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_permissions.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_platform.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_postinstall.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_postremove.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_preinstall.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_preremove.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_quote.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_random.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_refcount.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_shells.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_shlibs.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_sort.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_taskfunc.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_tee.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_truthy.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_FreeBSD.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_Linux.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_MirBSD.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_NetBSD.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_exists.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_mock.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_users.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_valid_options.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_version.sh \
    pkgsrc/pkgtools/pkgtasks/files/t/t_which.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/pkgtools/Makefile
diff -u pkgsrc/pkgtools/Makefile:1.117 pkgsrc/pkgtools/Makefile:1.118
--- pkgsrc/pkgtools/Makefile:1.117      Fri Feb 17 21:27:38 2017
+++ pkgsrc/pkgtools/Makefile    Thu Jun  1 01:58:34 2017
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.117 2017/02/17 21:27:38 jmmv Exp $
+# $NetBSD: Makefile,v 1.118 2017/06/01 01:58:34 jlam Exp $
 #
 
 COMMENT=       Tools for use in the packages collection
@@ -62,6 +62,7 @@ SUBDIR+=      pkglint4
 SUBDIR+=       pkgse
 SUBDIR+=       pkgsrc-todo
 SUBDIR+=       pkgsurvey
+SUBDIR+=       pkgtasks
 SUBDIR+=       plist-utils
 SUBDIR+=       port2pkg
 #SUBDIR+=      prereq-readme   # Only used by the README.html generation

Added files:

Index: pkgsrc/pkgtools/pkgtasks/DESCR
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/DESCR:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/DESCR      Thu Jun  1 01:58:34 2017
@@ -0,0 +1,15 @@
+pkgtasks is a shell script library to ease writing POSIX-compliant shell
+scripts to handle common tasks during installation or removal of a
+package, e.g.,
+
+  * creating groups and users needed by the package
+
+  * creating and removing directories with special permissions and
+    ownership,
+
+  * copying example config files to their final locations during package
+    installation, and removing them during package removal if they don't
+    differ from the example ones,
+
+  * reminding the user of files that may be customized after package
+    installation.
Index: pkgsrc/pkgtools/pkgtasks/Makefile
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/Makefile:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/Makefile   Thu Jun  1 01:58:34 2017
@@ -0,0 +1,22 @@
+# $NetBSD: Makefile,v 1.1 2017/06/01 01:58:34 jlam Exp $
+
+DISTNAME=              pkgtasks-1-1.9
+CATEGORIES=            pkgtools
+MASTER_SITES=          # empty
+DISTFILES=             # empty
+
+MAINTAINER=            jlam%NetBSD.org@localhost
+COMMENT=               Package tasks
+LICENSE=               2-clause-bsd
+
+TEST_TARGET=           check
+USE_LANGUAGES=         # empty
+USE_TOOLS=             sh
+
+GNU_CONFIGURE=         yes
+CONFIGURE_ENV+=                POSIX_SHELL=${TOOLS_SH:Q}
+
+do-extract:
+       @${CP} -R ${FILESDIR} ${WRKSRC}
+
+.include "../../mk/bsd.pkg.mk"
Index: pkgsrc/pkgtools/pkgtasks/PLIST
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/PLIST:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/PLIST      Thu Jun  1 01:58:34 2017
@@ -0,0 +1,91 @@
+@comment $NetBSD: PLIST,v 1.1 2017/06/01 01:58:34 jlam Exp $
+share/doc/${PKGBASE}/AUTHORS
+share/doc/${PKGBASE}/COPYING
+share/doc/${PKGBASE}/README.md
+share/${PKGBASE}/cleanup.subr
+share/${PKGBASE}/compare.subr
+share/${PKGBASE}/createfile.subr
+share/${PKGBASE}/directories.subr
+share/${PKGBASE}/dirwalk.subr
+share/${PKGBASE}/echo.subr
+share/${PKGBASE}/files.subr
+share/${PKGBASE}/fonts.subr
+share/${PKGBASE}/groups.subr
+share/${PKGBASE}/info_files.subr
+share/${PKGBASE}/load.subr
+share/${PKGBASE}/lock.subr
+share/${PKGBASE}/makedir.subr
+share/${PKGBASE}/maketemp.subr
+share/${PKGBASE}/match.subr
+share/${PKGBASE}/ocaml_findlib.subr
+share/${PKGBASE}/permissions.subr
+share/${PKGBASE}/platform.subr
+share/${PKGBASE}/postinstall.subr
+share/${PKGBASE}/postremove.subr
+share/${PKGBASE}/preinstall.subr
+share/${PKGBASE}/preremove.subr
+share/${PKGBASE}/quote.subr
+share/${PKGBASE}/random.subr
+share/${PKGBASE}/refcount.subr
+share/${PKGBASE}/refcount_file.subr
+share/${PKGBASE}/say.subr
+share/${PKGBASE}/shells.subr
+share/${PKGBASE}/shlibs.subr
+share/${PKGBASE}/sort.subr
+share/${PKGBASE}/taskfunc.subr
+share/${PKGBASE}/tee.subr
+share/${PKGBASE}/truthy.subr
+share/${PKGBASE}/unittest.subr
+share/${PKGBASE}/usergroup.subr
+share/${PKGBASE}/usergroup_FreeBSD.subr
+share/${PKGBASE}/usergroup_Linux.subr
+share/${PKGBASE}/usergroup_MirBSD.subr
+share/${PKGBASE}/usergroup_NetBSD.subr
+share/${PKGBASE}/usergroup_exists.subr
+share/${PKGBASE}/usergroup_mock.subr
+share/${PKGBASE}/users.subr
+share/${PKGBASE}/valid_options.subr
+share/${PKGBASE}/version.subr
+share/${PKGBASE}/which.subr
+tests/${PKGBASE}/Kyuafile
+tests/${PKGBASE}/run_tests
+tests/${PKGBASE}/t_compare
+tests/${PKGBASE}/t_createfile
+tests/${PKGBASE}/t_directories
+tests/${PKGBASE}/t_dirwalk
+tests/${PKGBASE}/t_echo
+tests/${PKGBASE}/t_files
+tests/${PKGBASE}/t_fonts
+tests/${PKGBASE}/t_groups
+tests/${PKGBASE}/t_info_files
+tests/${PKGBASE}/t_lock
+tests/${PKGBASE}/t_makedir
+tests/${PKGBASE}/t_maketemp
+tests/${PKGBASE}/t_match
+tests/${PKGBASE}/t_ocaml_findlib
+tests/${PKGBASE}/t_permissions
+tests/${PKGBASE}/t_platform
+tests/${PKGBASE}/t_postinstall
+tests/${PKGBASE}/t_postremove
+tests/${PKGBASE}/t_preinstall
+tests/${PKGBASE}/t_preremove
+tests/${PKGBASE}/t_quote
+tests/${PKGBASE}/t_random
+tests/${PKGBASE}/t_refcount
+tests/${PKGBASE}/t_shells
+tests/${PKGBASE}/t_shlibs
+tests/${PKGBASE}/t_sort
+tests/${PKGBASE}/t_taskfunc
+tests/${PKGBASE}/t_tee
+tests/${PKGBASE}/t_truthy
+tests/${PKGBASE}/t_usergroup
+tests/${PKGBASE}/t_usergroup_FreeBSD
+tests/${PKGBASE}/t_usergroup_Linux
+tests/${PKGBASE}/t_usergroup_MirBSD
+tests/${PKGBASE}/t_usergroup_NetBSD
+tests/${PKGBASE}/t_usergroup_exists
+tests/${PKGBASE}/t_usergroup_mock
+tests/${PKGBASE}/t_users
+tests/${PKGBASE}/t_valid_options
+tests/${PKGBASE}/t_version
+tests/${PKGBASE}/t_which

Index: pkgsrc/pkgtools/pkgtasks/files/AUTHORS
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/AUTHORS:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/AUTHORS      Thu Jun  1 01:58:34 2017
@@ -0,0 +1 @@
+* Johnny C. Lam <jlam%NetBSD.org@localhost>
Index: pkgsrc/pkgtools/pkgtasks/files/COPYING
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/COPYING:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/COPYING      Thu Jun  1 01:58:34 2017
@@ -0,0 +1,26 @@
+Copyright (c) 2017 The NetBSD Foundation, Inc.
+All rights reserved.
+
+This code is derived from software contributed to The NetBSD Foundation
+by Johnny C. Lam.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
Index: pkgsrc/pkgtools/pkgtasks/files/Makefile.am
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/Makefile.am:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/Makefile.am  Thu Jun  1 01:58:34 2017
@@ -0,0 +1,496 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+doc_DATA = AUTHORS COPYING README.md
+noinst_DATA = README.md
+EXTRA_DIST = $(doc_DATA)
+
+PHONY_TARGETS = 
+
+CHMOD = chmod
+MV = mv
+
+# Assume that $source and $target are in the same directory.
+BUILD_FILE = \
+       $(SED)  -e "s,__POSIX_SHELL__,$(POSIX_SHELL),g" \
+               -e "s,__TASK_MODULE_DIR__,$(pkgdatadir),g" \
+               -e "s,__TASK_TESTS_DIR__,$(pkgtestsdir),g" \
+               -e "s,__TASK_VERSION__,$(PACKAGE_VERSION),g" \
+               < "$$source" > "$$target.tmp" && \
+       $(MV) -f "$$target.tmp" "$$target"
+
+BUILD_SCRIPT = $(BUILD_FILE) && $(CHMOD) +x "$$target"
+
+dist_pkgdata_DATA = cleanup.subr
+dist_pkgdata_DATA += compare.subr
+dist_pkgdata_DATA += createfile.subr
+dist_pkgdata_DATA += directories.subr
+dist_pkgdata_DATA += dirwalk.subr
+dist_pkgdata_DATA += echo.subr
+dist_pkgdata_DATA += files.subr
+dist_pkgdata_DATA += fonts.subr
+dist_pkgdata_DATA += groups.subr
+dist_pkgdata_DATA += info_files.subr
+dist_pkgdata_DATA += load.subr
+dist_pkgdata_DATA += lock.subr
+dist_pkgdata_DATA += makedir.subr
+dist_pkgdata_DATA += maketemp.subr
+dist_pkgdata_DATA += match.subr
+dist_pkgdata_DATA += ocaml_findlib.subr
+dist_pkgdata_DATA += permissions.subr
+dist_pkgdata_DATA += platform.subr
+dist_pkgdata_DATA += postinstall.subr
+dist_pkgdata_DATA += postremove.subr
+dist_pkgdata_DATA += preinstall.subr
+dist_pkgdata_DATA += preremove.subr
+dist_pkgdata_DATA += quote.subr
+dist_pkgdata_DATA += random.subr
+dist_pkgdata_DATA += refcount.subr
+dist_pkgdata_DATA += refcount_file.subr
+dist_pkgdata_DATA += say.subr
+dist_pkgdata_DATA += shells.subr
+dist_pkgdata_DATA += shlibs.subr
+dist_pkgdata_DATA += sort.subr
+dist_pkgdata_DATA += taskfunc.subr
+dist_pkgdata_DATA += tee.subr
+dist_pkgdata_DATA += truthy.subr
+dist_pkgdata_DATA += unittest.subr
+dist_pkgdata_DATA += usergroup.subr
+dist_pkgdata_DATA += usergroup_FreeBSD.subr
+dist_pkgdata_DATA += usergroup_Linux.subr
+dist_pkgdata_DATA += usergroup_MirBSD.subr
+dist_pkgdata_DATA += usergroup_NetBSD.subr
+dist_pkgdata_DATA += usergroup_exists.subr
+dist_pkgdata_DATA += usergroup_mock.subr
+dist_pkgdata_DATA += users.subr
+dist_pkgdata_DATA += valid_options.subr
+dist_pkgdata_DATA += which.subr
+
+pkgdata_DATA = version.subr
+CLEANFILES = version.subr
+EXTRA_DIST += version.subr.in
+version.subr: version.subr.in
+       -$(MKDIR_P) $(builddir)
+       $(AM_V_GEN)target="$(builddir)/version.subr" source="$(srcdir)/version.subr.in"; \
+       $(BUILD_FILE)
+
+# Build a test script.
+BUILD_TEST = \
+       TASK_MODULE_DIR="$(top_srcdir)" TASK_TESTS_DIR="$(top_srcdir)/t" \
+       $(builddir)/t/build_test -o "$$target" "$$source"
+dist_pkgtests_DATA = t/Kyuafile
+
+noinst_SCRIPTS = t/build_test
+CLEANFILES += t/build_test
+EXTRA_DIST += t/build_test.sh
+t/build_test: t/build_test.sh
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/build_test" source="$(srcdir)/t/build_test.sh"; \
+       $(BUILD_SCRIPT)
+
+pkgtests_SCRIPTS = t/run_tests
+CLEANFILES += t/run_tests
+EXTRA_DIST += t/run_tests.sh
+t/run_tests: t/run_tests.sh
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/run_tests" source="$(srcdir)/t/run_tests.sh"; \
+       $(BUILD_SCRIPT)
+
+pkgtests_SCRIPTS += t/t_compare
+CLEANFILES += t/t_compare
+EXTRA_DIST += t/t_compare.sh
+t/t_compare: t/t_compare.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_compare" source="$(srcdir)/t/t_compare.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_createfile
+CLEANFILES += t/t_createfile
+EXTRA_DIST += t/t_createfile.sh
+t/t_createfile: t/t_createfile.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_createfile" source="$(srcdir)/t/t_createfile.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_directories
+CLEANFILES += t/t_directories
+EXTRA_DIST += t/t_directories.sh
+t/t_directories: t/t_directories.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_directories" source="$(srcdir)/t/t_directories.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_dirwalk
+CLEANFILES += t/t_dirwalk
+EXTRA_DIST += t/t_dirwalk.sh
+t/t_dirwalk: t/t_dirwalk.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_dirwalk" source="$(srcdir)/t/t_dirwalk.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_echo
+CLEANFILES += t/t_echo
+EXTRA_DIST += t/t_echo.sh
+t/t_echo: t/t_echo.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_echo" source="$(srcdir)/t/t_echo.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_files
+CLEANFILES += t/t_files
+EXTRA_DIST += t/t_files.sh
+t/t_files: t/t_files.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_files" source="$(srcdir)/t/t_files.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_fonts
+CLEANFILES += t/t_fonts
+EXTRA_DIST += t/t_fonts.sh
+t/t_fonts: t/t_fonts.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_fonts" source="$(srcdir)/t/t_fonts.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_groups
+CLEANFILES += t/t_groups
+EXTRA_DIST += t/t_groups.sh
+t/t_groups: t/t_groups.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_groups" source="$(srcdir)/t/t_groups.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_info_files
+CLEANFILES += t/t_info_files
+EXTRA_DIST += t/t_info_files.sh
+t/t_info_files: t/t_info_files.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_info_files" source="$(srcdir)/t/t_info_files.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_lock
+CLEANFILES += t/t_lock
+EXTRA_DIST += t/t_lock.sh
+t/t_lock: t/t_lock.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_lock" source="$(srcdir)/t/t_lock.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_makedir
+CLEANFILES += t/t_makedir
+EXTRA_DIST += t/t_makedir.sh
+t/t_makedir: t/t_makedir.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_makedir" source="$(srcdir)/t/t_makedir.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_maketemp
+CLEANFILES += t/t_maketemp
+EXTRA_DIST += t/t_maketemp.sh
+t/t_maketemp: t/t_maketemp.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_maketemp" source="$(srcdir)/t/t_maketemp.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_match
+CLEANFILES += t/t_match
+EXTRA_DIST += t/t_match.sh
+t/t_match: t/t_match.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_match" source="$(srcdir)/t/t_match.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_ocaml_findlib
+CLEANFILES += t/t_ocaml_findlib
+EXTRA_DIST += t/t_ocaml_findlib.sh
+t/t_ocaml_findlib: t/t_ocaml_findlib.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_ocaml_findlib" source="$(srcdir)/t/t_ocaml_findlib.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_permissions
+CLEANFILES += t/t_permissions
+EXTRA_DIST += t/t_permissions.sh
+t/t_permissions: t/t_permissions.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_permissions" source="$(srcdir)/t/t_permissions.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_platform
+CLEANFILES += t/t_platform
+EXTRA_DIST += t/t_platform.sh
+t/t_platform: t/t_platform.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_platform" source="$(srcdir)/t/t_platform.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_postinstall
+CLEANFILES += t/t_postinstall
+EXTRA_DIST += t/t_postinstall.sh
+t/t_postinstall: t/t_postinstall.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_postinstall" source="$(srcdir)/t/t_postinstall.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_postremove
+CLEANFILES += t/t_postremove
+EXTRA_DIST += t/t_postremove.sh
+t/t_postremove: t/t_postremove.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_postremove" source="$(srcdir)/t/t_postremove.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_preinstall
+CLEANFILES += t/t_preinstall
+EXTRA_DIST += t/t_preinstall.sh
+t/t_preinstall: t/t_preinstall.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_preinstall" source="$(srcdir)/t/t_preinstall.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_preremove
+CLEANFILES += t/t_preremove
+EXTRA_DIST += t/t_preremove.sh
+t/t_preremove: t/t_preremove.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_preremove" source="$(srcdir)/t/t_preremove.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_quote
+CLEANFILES += t/t_quote
+EXTRA_DIST += t/t_quote.sh
+t/t_quote: t/t_quote.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_quote" source="$(srcdir)/t/t_quote.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_random
+CLEANFILES += t/t_random
+EXTRA_DIST += t/t_random.sh
+t/t_random: t/t_random.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_random" source="$(srcdir)/t/t_random.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_refcount
+CLEANFILES += t/t_refcount
+EXTRA_DIST += t/t_refcount.sh
+t/t_refcount: t/t_refcount.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_refcount" source="$(srcdir)/t/t_refcount.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_shells
+CLEANFILES += t/t_shells
+EXTRA_DIST += t/t_shells.sh
+t/t_shells: t/t_shells.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_shells" source="$(srcdir)/t/t_shells.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_shlibs
+CLEANFILES += t/t_shlibs
+EXTRA_DIST += t/t_shlibs.sh
+t/t_shlibs: t/t_shlibs.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_shlibs" source="$(srcdir)/t/t_shlibs.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_sort
+CLEANFILES += t/t_sort
+EXTRA_DIST += t/t_sort.sh
+t/t_sort: t/t_sort.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_sort" source="$(srcdir)/t/t_sort.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_taskfunc
+CLEANFILES += t/t_taskfunc
+EXTRA_DIST += t/t_taskfunc.sh
+t/t_taskfunc: t/t_taskfunc.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_taskfunc" source="$(srcdir)/t/t_taskfunc.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_tee
+CLEANFILES += t/t_tee
+EXTRA_DIST += t/t_tee.sh
+t/t_tee: t/t_tee.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_tee" source="$(srcdir)/t/t_tee.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_truthy
+CLEANFILES += t/t_truthy
+EXTRA_DIST += t/t_truthy.sh
+t/t_truthy: t/t_truthy.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_truthy" source="$(srcdir)/t/t_truthy.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_usergroup
+CLEANFILES += t/t_usergroup
+EXTRA_DIST += t/t_usergroup.sh
+t/t_usergroup: t/t_usergroup.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_usergroup" source="$(srcdir)/t/t_usergroup.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_usergroup_FreeBSD
+CLEANFILES += t/t_usergroup_FreeBSD
+EXTRA_DIST += t/t_usergroup_FreeBSD.sh
+t/t_usergroup_FreeBSD: t/t_usergroup_FreeBSD.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_usergroup_FreeBSD" source="$(srcdir)/t/t_usergroup_FreeBSD.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_usergroup_Linux
+CLEANFILES += t/t_usergroup_Linux
+EXTRA_DIST += t/t_usergroup_Linux.sh
+t/t_usergroup_Linux: t/t_usergroup_Linux.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_usergroup_Linux" source="$(srcdir)/t/t_usergroup_Linux.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_usergroup_MirBSD
+CLEANFILES += t/t_usergroup_MirBSD
+EXTRA_DIST += t/t_usergroup_MirBSD.sh
+t/t_usergroup_MirBSD: t/t_usergroup_MirBSD.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_usergroup_MirBSD" source="$(srcdir)/t/t_usergroup_MirBSD.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_usergroup_NetBSD
+CLEANFILES += t/t_usergroup_NetBSD
+EXTRA_DIST += t/t_usergroup_NetBSD.sh
+t/t_usergroup_NetBSD: t/t_usergroup_NetBSD.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_usergroup_NetBSD" source="$(srcdir)/t/t_usergroup_NetBSD.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_usergroup_exists
+CLEANFILES += t/t_usergroup_exists
+EXTRA_DIST += t/t_usergroup_exists.sh
+t/t_usergroup_exists: t/t_usergroup_exists.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_usergroup_exists" source="$(srcdir)/t/t_usergroup_exists.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_usergroup_mock
+CLEANFILES += t/t_usergroup_mock
+EXTRA_DIST += t/t_usergroup_mock.sh
+t/t_usergroup_mock: t/t_usergroup_mock.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_usergroup_mock" source="$(srcdir)/t/t_usergroup_mock.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_users
+CLEANFILES += t/t_users
+EXTRA_DIST += t/t_users.sh
+t/t_users: t/t_users.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_users" source="$(srcdir)/t/t_users.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_valid_options
+CLEANFILES += t/t_valid_options
+EXTRA_DIST += t/t_valid_options.sh
+t/t_valid_options: t/t_valid_options.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_valid_options" source="$(srcdir)/t/t_valid_options.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_version
+CLEANFILES += t/t_version
+EXTRA_DIST += t/t_version.sh
+t/t_version: t/t_version.sh version.subr $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_version" source="$(srcdir)/t/t_version.sh"; \
+       $(BUILD_TEST)
+
+pkgtests_SCRIPTS += t/t_which
+CLEANFILES += t/t_which
+EXTRA_DIST += t/t_which.sh
+t/t_which: t/t_which.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_which" source="$(srcdir)/t/t_which.sh"; \
+       $(BUILD_TEST)
+
+PHONY_TARGETS += check-run-tets
+check-run-tests:
+       @cd $(srcdir)/t && $(SHELL) run_tests.sh
+
+PHONY_TARGETS += installcheck-run-tests
+installcheck-run-tests:
+       @cd $(pkgtestsdir) && ./run_tests
+
+if HAVE_KYUA
+# CHECK_ENVIRONMENT
+#      This is used to set variables before calling kyua on the tests in
+#      the build directory.
+#
+# TESTS_ENVIRONMENT
+#      This is used to set variables before calling kyua, regardless of
+#      whether the tests are installed or in the build directory.
+
+CHECK_ENVIRONMENT = \
+       TASK_MODULE_DIR=$(abs_top_srcdir) \
+       TASK_TESTS_DIR=$(abs_top_srcdir)/t
+
+PHONY_TARGETS += check-kyua
+check-local: check-kyua
+check-kyua:
+       @failed=no; \
+       $(CHECK_ENVIRONMENT) $(TESTS_ENVIRONMENT) $(KYUA) test \
+               --kyuafile='$(top_srcdir)/t/Kyuafile' \
+               --build-root='$(top_builddir)/t' || failed=yes; \
+       if [ "$$failed" = yes ]; then \
+               $(CHECK_ENVIRONMENT) $(TESTS_ENVIRONMENT) $(KYUA) report \
+                       --results-file='$(abs_top_srcdir)' \
+                       --verbose --results-filter=broken,failed; \
+               exit 1; \
+       fi
+
+PHONY_TARGETS += installcheck-kyua
+installcheck-local: installcheck-kyua
+installcheck-kyua:
+       @failed=no; \
+       cd $(pkgtestsdir) && $(TESTS_ENVIRONMENT) $(KYUA) test  || failed=yes; \
+       if [ "$$failed" = yes ]; then \
+               cd $(pkgtestsdir) && $(TESTS_ENVIRONMENT) $(KYUA) report \
+                       --verbose --results-filter=broken,failed; \
+               exit 1; \
+       fi
+else  # HAVE_KYUA
+check-local: check-run-tests
+installcheck-local: installcheck-run-tests
+endif # HAVE_KYUA
+
+maintainer-clean-local:
+       -rm -f Makefile.in aclocal.m4 configure
+       -rm -f build-aux/install-sh build-aux/missing
+       -rm -f $(PACKAGE)-*.tar.*
Index: pkgsrc/pkgtools/pkgtasks/files/Makefile.in
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/Makefile.in:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/Makefile.in  Thu Jun  1 01:58:34 2017
@@ -0,0 +1,1034 @@
+# Makefile.in generated by automake 1.15 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+
+VPATH = @srcdir@
+am__is_gnu_make = { \
+  if test -z '$(MAKELEVEL)'; then \
+    false; \
+  elif test -n '$(MAKE_HOST)'; then \
+    true; \
+  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
+    true; \
+  else \
+    false; \
+  fi; \
+}
+am__make_running_with_option = \
+  case $${target_option-} in \
+      ?) ;; \
+      *) echo "am__make_running_with_option: internal error: invalid" \
+              "target option '$${target_option-}' specified" >&2; \
+         exit 1;; \
+  esac; \
+  has_opt=no; \
+  sane_makeflags=$$MAKEFLAGS; \
+  if $(am__is_gnu_make); then \
+    sane_makeflags=$$MFLAGS; \
+  else \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        bs=\\; \
+        sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+          | sed "s/$$bs$$bs[$$bs $$bs  ]*//g"`;; \
+    esac; \
+  fi; \
+  skip_next=no; \
+  strip_trailopt () \
+  { \
+    flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+  }; \
+  for flg in $$sane_makeflags; do \
+    test $$skip_next = yes && { skip_next=no; continue; }; \
+    case $$flg in \
+      *=*|--*) continue;; \
+        -*I) strip_trailopt 'I'; skip_next=yes;; \
+      -*I?*) strip_trailopt 'I';; \
+        -*O) strip_trailopt 'O'; skip_next=yes;; \
+      -*O?*) strip_trailopt 'O';; \
+        -*l) strip_trailopt 'l'; skip_next=yes;; \
+      -*l?*) strip_trailopt 'l';; \
+      -[dEDm]) skip_next=yes;; \
+      -[JT]) skip_next=yes;; \
+    esac; \
+    case $$flg in \
+      *$$target_option*) has_opt=yes; break;; \
+    esac; \
+  done; \
+  test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+@HAVE_KYUA_TRUE@am__append_1 = check-kyua installcheck-kyua
+subdir = .
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+       $(ACLOCAL_M4)
+DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \
+       $(am__configure_deps) $(dist_pkgdata_DATA) \
+       $(dist_pkgtests_DATA) $(am__DIST_COMMON)
+am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
+ configure.lineno config.status.lineno
+mkinstalldirs = $(install_sh) -d
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+    *) f=$$p;; \
+  esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+  test -z "$$files" \
+    || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+    || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+         $(am__cd) "$$dir" && rm -f $$files; }; \
+  }
+am__installdirs = "$(DESTDIR)$(pkgtestsdir)" "$(DESTDIR)$(pkgdatadir)" \
+       "$(DESTDIR)$(pkgtestsdir)" "$(DESTDIR)$(docdir)" \
+       "$(DESTDIR)$(pkgdatadir)"
+SCRIPTS = $(noinst_SCRIPTS) $(pkgtests_SCRIPTS)
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo "  GEN     " $@;
+am__v_GEN_1 = 
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 = 
+SOURCES =
+DIST_SOURCES =
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
+DATA = $(dist_pkgdata_DATA) $(dist_pkgtests_DATA) $(doc_DATA) \
+       $(noinst_DATA) $(pkgdata_DATA)
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+am__DIST_COMMON = $(srcdir)/Makefile.in \
+       $(top_srcdir)/build-aux/install-sh \
+       $(top_srcdir)/build-aux/missing AUTHORS COPYING \
+       build-aux/install-sh build-aux/missing
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+distdir = $(PACKAGE)-$(VERSION)
+top_distdir = $(distdir)
+am__remove_distdir = \
+  if test -d "$(distdir)"; then \
+    find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
+      && rm -rf "$(distdir)" \
+      || { sleep 5 && rm -rf "$(distdir)"; }; \
+  else :; fi
+am__post_remove_distdir = $(am__remove_distdir)
+DIST_ARCHIVES = $(distdir).tar.gz
+GZIP_ENV = --best
+DIST_TARGETS = dist-gzip
+distuninstallcheck_listfiles = find . -type f -print
+am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \
+  | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$'
+distcleancheck_listfiles = find . -type f -print
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+KYUA = @KYUA@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+POSIX_SHELL = @POSIX_SHELL@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+am__leading_dot = @am__leading_dot@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build_alias = @build_alias@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host_alias = @host_alias@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pkgtestsdir = @pkgtestsdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+testsdir = @testsdir@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+doc_DATA = AUTHORS COPYING README.md
+noinst_DATA = README.md
+EXTRA_DIST = $(doc_DATA) version.subr.in t/build_test.sh \
+       t/run_tests.sh t/t_compare.sh t/t_createfile.sh \
+       t/t_directories.sh t/t_dirwalk.sh t/t_echo.sh t/t_files.sh \
+       t/t_fonts.sh t/t_groups.sh t/t_info_files.sh t/t_lock.sh \
+       t/t_makedir.sh t/t_maketemp.sh t/t_match.sh \
+       t/t_ocaml_findlib.sh t/t_permissions.sh t/t_platform.sh \
+       t/t_postinstall.sh t/t_postremove.sh t/t_preinstall.sh \
+       t/t_preremove.sh t/t_quote.sh t/t_random.sh t/t_refcount.sh \
+       t/t_shells.sh t/t_shlibs.sh t/t_sort.sh t/t_taskfunc.sh \
+       t/t_tee.sh t/t_truthy.sh t/t_usergroup.sh \
+       t/t_usergroup_FreeBSD.sh t/t_usergroup_Linux.sh \
+       t/t_usergroup_MirBSD.sh t/t_usergroup_NetBSD.sh \
+       t/t_usergroup_exists.sh t/t_usergroup_mock.sh t/t_users.sh \
+       t/t_valid_options.sh t/t_version.sh t/t_which.sh
+PHONY_TARGETS = check-run-tets installcheck-run-tests $(am__append_1)
+CHMOD = chmod
+MV = mv
+
+# Assume that $source and $target are in the same directory.
+BUILD_FILE = \
+       $(SED)  -e "s,__POSIX_SHELL__,$(POSIX_SHELL),g" \
+               -e "s,__TASK_MODULE_DIR__,$(pkgdatadir),g" \
+               -e "s,__TASK_TESTS_DIR__,$(pkgtestsdir),g" \
+               -e "s,__TASK_VERSION__,$(PACKAGE_VERSION),g" \
+               < "$$source" > "$$target.tmp" && \
+       $(MV) -f "$$target.tmp" "$$target"
+
+BUILD_SCRIPT = $(BUILD_FILE) && $(CHMOD) +x "$$target"
+dist_pkgdata_DATA = cleanup.subr compare.subr createfile.subr \
+       directories.subr dirwalk.subr echo.subr files.subr fonts.subr \
+       groups.subr info_files.subr load.subr lock.subr makedir.subr \
+       maketemp.subr match.subr ocaml_findlib.subr permissions.subr \
+       platform.subr postinstall.subr postremove.subr preinstall.subr \
+       preremove.subr quote.subr random.subr refcount.subr \
+       refcount_file.subr say.subr shells.subr shlibs.subr sort.subr \
+       taskfunc.subr tee.subr truthy.subr unittest.subr \
+       usergroup.subr usergroup_FreeBSD.subr usergroup_Linux.subr \
+       usergroup_MirBSD.subr usergroup_NetBSD.subr \
+       usergroup_exists.subr usergroup_mock.subr users.subr \
+       valid_options.subr which.subr
+pkgdata_DATA = version.subr
+CLEANFILES = version.subr t/build_test t/run_tests t/t_compare \
+       t/t_createfile t/t_directories t/t_dirwalk t/t_echo t/t_files \
+       t/t_fonts t/t_groups t/t_info_files t/t_lock t/t_makedir \
+       t/t_maketemp t/t_match t/t_ocaml_findlib t/t_permissions \
+       t/t_platform t/t_postinstall t/t_postremove t/t_preinstall \
+       t/t_preremove t/t_quote t/t_random t/t_refcount t/t_shells \
+       t/t_shlibs t/t_sort t/t_taskfunc t/t_tee t/t_truthy \
+       t/t_usergroup t/t_usergroup_FreeBSD t/t_usergroup_Linux \
+       t/t_usergroup_MirBSD t/t_usergroup_NetBSD t/t_usergroup_exists \
+       t/t_usergroup_mock t/t_users t/t_valid_options t/t_version \
+       t/t_which
+
+# Build a test script.
+BUILD_TEST = \
+       TASK_MODULE_DIR="$(top_srcdir)" TASK_TESTS_DIR="$(top_srcdir)/t" \
+       $(builddir)/t/build_test -o "$$target" "$$source"
+
+dist_pkgtests_DATA = t/Kyuafile
+noinst_SCRIPTS = t/build_test
+pkgtests_SCRIPTS = t/run_tests t/t_compare t/t_createfile \
+       t/t_directories t/t_dirwalk t/t_echo t/t_files t/t_fonts \
+       t/t_groups t/t_info_files t/t_lock t/t_makedir t/t_maketemp \
+       t/t_match t/t_ocaml_findlib t/t_permissions t/t_platform \
+       t/t_postinstall t/t_postremove t/t_preinstall t/t_preremove \
+       t/t_quote t/t_random t/t_refcount t/t_shells t/t_shlibs \
+       t/t_sort t/t_taskfunc t/t_tee t/t_truthy t/t_usergroup \
+       t/t_usergroup_FreeBSD t/t_usergroup_Linux t/t_usergroup_MirBSD \
+       t/t_usergroup_NetBSD t/t_usergroup_exists t/t_usergroup_mock \
+       t/t_users t/t_valid_options t/t_version t/t_which
+
+# CHECK_ENVIRONMENT
+#      This is used to set variables before calling kyua on the tests in
+#      the build directory.
+#
+# TESTS_ENVIRONMENT
+#      This is used to set variables before calling kyua, regardless of
+#      whether the tests are installed or in the build directory.
+@HAVE_KYUA_TRUE@CHECK_ENVIRONMENT = \
+@HAVE_KYUA_TRUE@       TASK_MODULE_DIR=$(abs_top_srcdir) \
+@HAVE_KYUA_TRUE@       TASK_TESTS_DIR=$(abs_top_srcdir)/t
+
+all: all-am
+
+.SUFFIXES:
+am--refresh: Makefile
+       @:
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+       @for dep in $?; do \
+         case '$(am__configure_deps)' in \
+           *$$dep*) \
+             echo ' cd $(srcdir) && $(AUTOMAKE) --foreign'; \
+             $(am__cd) $(srcdir) && $(AUTOMAKE) --foreign \
+               && exit 0; \
+             exit 1;; \
+         esac; \
+       done; \
+       echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \
+       $(am__cd) $(top_srcdir) && \
+         $(AUTOMAKE) --foreign Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+       @case '$?' in \
+         *config.status*) \
+           echo ' $(SHELL) ./config.status'; \
+           $(SHELL) ./config.status;; \
+         *) \
+           echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \
+           cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \
+       esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+       $(SHELL) ./config.status --recheck
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+       $(am__cd) $(srcdir) && $(AUTOCONF)
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+       $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
+$(am__aclocal_m4_deps):
+install-pkgtestsSCRIPTS: $(pkgtests_SCRIPTS)
+       @$(NORMAL_INSTALL)
+       @list='$(pkgtests_SCRIPTS)'; test -n "$(pkgtestsdir)" || list=; \
+       if test -n "$$list"; then \
+         echo " $(MKDIR_P) '$(DESTDIR)$(pkgtestsdir)'"; \
+         $(MKDIR_P) "$(DESTDIR)$(pkgtestsdir)" || exit 1; \
+       fi; \
+       for p in $$list; do \
+         if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+         if test -f "$$d$$p"; then echo "$$d$$p"; echo "$$p"; else :; fi; \
+       done | \
+       sed -e 'p;s,.*/,,;n' \
+           -e 'h;s|.*|.|' \
+           -e 'p;x;s,.*/,,;$(transform)' | sed 'N;N;N;s,\n, ,g' | \
+       $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1; } \
+         { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+           if ($$2 == $$4) { files[d] = files[d] " " $$1; \
+             if (++n[d] == $(am__install_max)) { \
+               print "f", d, files[d]; n[d] = 0; files[d] = "" } } \
+           else { print "f", d "/" $$4, $$1 } } \
+         END { for (d in files) print "f", d, files[d] }' | \
+       while read type dir files; do \
+            if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+            test -z "$$files" || { \
+              echo " $(INSTALL_SCRIPT) $$files '$(DESTDIR)$(pkgtestsdir)$$dir'"; \
+              $(INSTALL_SCRIPT) $$files "$(DESTDIR)$(pkgtestsdir)$$dir" || exit $$?; \
+            } \
+       ; done
+
+uninstall-pkgtestsSCRIPTS:
+       @$(NORMAL_UNINSTALL)
+       @list='$(pkgtests_SCRIPTS)'; test -n "$(pkgtestsdir)" || exit 0; \
+       files=`for p in $$list; do echo "$$p"; done | \
+              sed -e 's,.*/,,;$(transform)'`; \
+       dir='$(DESTDIR)$(pkgtestsdir)'; $(am__uninstall_files_from_dir)
+install-dist_pkgdataDATA: $(dist_pkgdata_DATA)
+       @$(NORMAL_INSTALL)
+       @list='$(dist_pkgdata_DATA)'; test -n "$(pkgdatadir)" || list=; \
+       if test -n "$$list"; then \
+         echo " $(MKDIR_P) '$(DESTDIR)$(pkgdatadir)'"; \
+         $(MKDIR_P) "$(DESTDIR)$(pkgdatadir)" || exit 1; \
+       fi; \
+       for p in $$list; do \
+         if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+         echo "$$d$$p"; \
+       done | $(am__base_list) | \
+       while read files; do \
+         echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pkgdatadir)'"; \
+         $(INSTALL_DATA) $$files "$(DESTDIR)$(pkgdatadir)" || exit $$?; \
+       done
+
+uninstall-dist_pkgdataDATA:
+       @$(NORMAL_UNINSTALL)
+       @list='$(dist_pkgdata_DATA)'; test -n "$(pkgdatadir)" || list=; \
+       files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+       dir='$(DESTDIR)$(pkgdatadir)'; $(am__uninstall_files_from_dir)
+install-dist_pkgtestsDATA: $(dist_pkgtests_DATA)
+       @$(NORMAL_INSTALL)
+       @list='$(dist_pkgtests_DATA)'; test -n "$(pkgtestsdir)" || list=; \
+       if test -n "$$list"; then \
+         echo " $(MKDIR_P) '$(DESTDIR)$(pkgtestsdir)'"; \
+         $(MKDIR_P) "$(DESTDIR)$(pkgtestsdir)" || exit 1; \
+       fi; \
+       for p in $$list; do \
+         if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+         echo "$$d$$p"; \
+       done | $(am__base_list) | \
+       while read files; do \
+         echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pkgtestsdir)'"; \
+         $(INSTALL_DATA) $$files "$(DESTDIR)$(pkgtestsdir)" || exit $$?; \
+       done
+
+uninstall-dist_pkgtestsDATA:
+       @$(NORMAL_UNINSTALL)
+       @list='$(dist_pkgtests_DATA)'; test -n "$(pkgtestsdir)" || list=; \
+       files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+       dir='$(DESTDIR)$(pkgtestsdir)'; $(am__uninstall_files_from_dir)
+install-docDATA: $(doc_DATA)
+       @$(NORMAL_INSTALL)
+       @list='$(doc_DATA)'; test -n "$(docdir)" || list=; \
+       if test -n "$$list"; then \
+         echo " $(MKDIR_P) '$(DESTDIR)$(docdir)'"; \
+         $(MKDIR_P) "$(DESTDIR)$(docdir)" || exit 1; \
+       fi; \
+       for p in $$list; do \
+         if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+         echo "$$d$$p"; \
+       done | $(am__base_list) | \
+       while read files; do \
+         echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(docdir)'"; \
+         $(INSTALL_DATA) $$files "$(DESTDIR)$(docdir)" || exit $$?; \
+       done
+
+uninstall-docDATA:
+       @$(NORMAL_UNINSTALL)
+       @list='$(doc_DATA)'; test -n "$(docdir)" || list=; \
+       files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+       dir='$(DESTDIR)$(docdir)'; $(am__uninstall_files_from_dir)
+install-pkgdataDATA: $(pkgdata_DATA)
+       @$(NORMAL_INSTALL)
+       @list='$(pkgdata_DATA)'; test -n "$(pkgdatadir)" || list=; \
+       if test -n "$$list"; then \
+         echo " $(MKDIR_P) '$(DESTDIR)$(pkgdatadir)'"; \
+         $(MKDIR_P) "$(DESTDIR)$(pkgdatadir)" || exit 1; \
+       fi; \
+       for p in $$list; do \
+         if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+         echo "$$d$$p"; \
+       done | $(am__base_list) | \
+       while read files; do \
+         echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pkgdatadir)'"; \
+         $(INSTALL_DATA) $$files "$(DESTDIR)$(pkgdatadir)" || exit $$?; \
+       done
+
+uninstall-pkgdataDATA:
+       @$(NORMAL_UNINSTALL)
+       @list='$(pkgdata_DATA)'; test -n "$(pkgdatadir)" || list=; \
+       files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+       dir='$(DESTDIR)$(pkgdatadir)'; $(am__uninstall_files_from_dir)
+tags TAGS:
+
+ctags CTAGS:
+
+cscope cscopelist:
+
+
+distdir: $(DISTFILES)
+       $(am__remove_distdir)
+       test -d "$(distdir)" || mkdir "$(distdir)"
+       @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       list='$(DISTFILES)'; \
+         dist_files=`for file in $$list; do echo $$file; done | \
+         sed -e "s|^$$srcdirstrip/||;t" \
+             -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+       case $$dist_files in \
+         */*) $(MKDIR_P) `echo "$$dist_files" | \
+                          sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+                          sort -u` ;; \
+       esac; \
+       for file in $$dist_files; do \
+         if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+         if test -d $$d/$$file; then \
+           dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+           if test -d "$(distdir)/$$file"; then \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+             cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+         else \
+           test -f "$(distdir)/$$file" \
+           || cp -p $$d/$$file "$(distdir)/$$file" \
+           || exit 1; \
+         fi; \
+       done
+       -test -n "$(am__skip_mode_fix)" \
+       || find "$(distdir)" -type d ! -perm -755 \
+               -exec chmod u+rwx,go+rx {} \; -o \
+         ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
+         ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
+         ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \
+       || chmod -R a+r "$(distdir)"
+dist-gzip: distdir
+       tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
+       $(am__post_remove_distdir)
+
+dist-bzip2: distdir
+       tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2
+       $(am__post_remove_distdir)
+
+dist-lzip: distdir
+       tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz
+       $(am__post_remove_distdir)
+
+dist-xz: distdir
+       tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz
+       $(am__post_remove_distdir)
+
+dist-tarZ: distdir
+       @echo WARNING: "Support for distribution archives compressed with" \
+                      "legacy program 'compress' is deprecated." >&2
+       @echo WARNING: "It will be removed altogether in Automake 2.0" >&2
+       tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
+       $(am__post_remove_distdir)
+
+dist-shar: distdir
+       @echo WARNING: "Support for shar distribution archives is" \
+                      "deprecated." >&2
+       @echo WARNING: "It will be removed altogether in Automake 2.0" >&2
+       shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
+       $(am__post_remove_distdir)
+
+dist-zip: distdir
+       -rm -f $(distdir).zip
+       zip -rq $(distdir).zip $(distdir)
+       $(am__post_remove_distdir)
+
+dist dist-all:
+       $(MAKE) $(AM_MAKEFLAGS) $(DIST_TARGETS) am__post_remove_distdir='@:'
+       $(am__post_remove_distdir)
+
+# This target untars the dist file and tries a VPATH configuration.  Then
+# it guarantees that the distribution is self-contained by making another
+# tarfile.
+distcheck: dist
+       case '$(DIST_ARCHIVES)' in \
+       *.tar.gz*) \
+         GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\
+       *.tar.bz2*) \
+         bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\
+       *.tar.lz*) \
+         lzip -dc $(distdir).tar.lz | $(am__untar) ;;\
+       *.tar.xz*) \
+         xz -dc $(distdir).tar.xz | $(am__untar) ;;\
+       *.tar.Z*) \
+         uncompress -c $(distdir).tar.Z | $(am__untar) ;;\
+       *.shar.gz*) \
+         GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\
+       *.zip*) \
+         unzip $(distdir).zip ;;\
+       esac
+       chmod -R a-w $(distdir)
+       chmod u+w $(distdir)
+       mkdir $(distdir)/_build $(distdir)/_build/sub $(distdir)/_inst
+       chmod a-w $(distdir)
+       test -d $(distdir)/_build || exit 0; \
+       dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
+         && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
+         && am__cwd=`pwd` \
+         && $(am__cd) $(distdir)/_build/sub \
+         && ../../configure \
+           $(AM_DISTCHECK_CONFIGURE_FLAGS) \
+           $(DISTCHECK_CONFIGURE_FLAGS) \
+           --srcdir=../.. --prefix="$$dc_install_base" \
+         && $(MAKE) $(AM_MAKEFLAGS) \
+         && $(MAKE) $(AM_MAKEFLAGS) dvi \
+         && $(MAKE) $(AM_MAKEFLAGS) check \
+         && $(MAKE) $(AM_MAKEFLAGS) install \
+         && $(MAKE) $(AM_MAKEFLAGS) installcheck \
+         && $(MAKE) $(AM_MAKEFLAGS) uninstall \
+         && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
+               distuninstallcheck \
+         && chmod -R a-w "$$dc_install_base" \
+         && ({ \
+              (cd ../.. && umask 077 && mkdir "$$dc_destdir") \
+              && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \
+              && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \
+              && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \
+                   distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \
+             } || { rm -rf "$$dc_destdir"; exit 1; }) \
+         && rm -rf "$$dc_destdir" \
+         && $(MAKE) $(AM_MAKEFLAGS) dist \
+         && rm -rf $(DIST_ARCHIVES) \
+         && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \
+         && cd "$$am__cwd" \
+         || exit 1
+       $(am__post_remove_distdir)
+       @(echo "$(distdir) archives ready for distribution: "; \
+         list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
+         sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x'
+distuninstallcheck:
+       @test -n '$(distuninstallcheck_dir)' || { \
+         echo 'ERROR: trying to run $@ with an empty' \
+              '$$(distuninstallcheck_dir)' >&2; \
+         exit 1; \
+       }; \
+       $(am__cd) '$(distuninstallcheck_dir)' || { \
+         echo 'ERROR: cannot chdir into $(distuninstallcheck_dir)' >&2; \
+         exit 1; \
+       }; \
+       test `$(am__distuninstallcheck_listfiles) | wc -l` -eq 0 \
+          || { echo "ERROR: files left after uninstall:" ; \
+               if test -n "$(DESTDIR)"; then \
+                 echo "  (check DESTDIR support)"; \
+               fi ; \
+               $(distuninstallcheck_listfiles) ; \
+               exit 1; } >&2
+distcleancheck: distclean
+       @if test '$(srcdir)' = . ; then \
+         echo "ERROR: distcleancheck can only run from a VPATH build" ; \
+         exit 1 ; \
+       fi
+       @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \
+         || { echo "ERROR: files left in build directory after distclean:" ; \
+              $(distcleancheck_listfiles) ; \
+              exit 1; } >&2
+check-am: all-am
+       $(MAKE) $(AM_MAKEFLAGS) check-local
+check: check-am
+all-am: Makefile $(SCRIPTS) $(DATA)
+installdirs:
+       for dir in "$(DESTDIR)$(pkgtestsdir)" "$(DESTDIR)$(pkgdatadir)" "$(DESTDIR)$(pkgtestsdir)" "$(DESTDIR)$(docdir)" "$(DESTDIR)$(pkgdatadir)"; do \
+         test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+       done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+       @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
+mostlyclean-generic:
+
+clean-generic:
+       -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+       -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+       -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+       @echo "This command is intended for maintainers to use"
+       @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic mostlyclean-am
+
+distclean: distclean-am
+       -rm -f $(am__CONFIG_DISTCLEAN_FILES)
+       -rm -f Makefile
+distclean-am: clean-am distclean-generic
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-dist_pkgdataDATA install-dist_pkgtestsDATA \
+       install-docDATA install-pkgdataDATA install-pkgtestsSCRIPTS
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am: installcheck-local
+
+maintainer-clean: maintainer-clean-am
+       -rm -f $(am__CONFIG_DISTCLEAN_FILES)
+       -rm -rf $(top_srcdir)/autom4te.cache
+       -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic \
+       maintainer-clean-local
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-generic
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-dist_pkgdataDATA uninstall-dist_pkgtestsDATA \
+       uninstall-docDATA uninstall-pkgdataDATA \
+       uninstall-pkgtestsSCRIPTS
+
+.MAKE: check-am install-am install-strip
+
+.PHONY: all all-am am--refresh check check-am check-local clean \
+       clean-generic cscopelist-am ctags-am dist dist-all dist-bzip2 \
+       dist-gzip dist-lzip dist-shar dist-tarZ dist-xz dist-zip \
+       distcheck distclean distclean-generic distcleancheck distdir \
+       distuninstallcheck dvi dvi-am html html-am info info-am \
+       install install-am install-data install-data-am \
+       install-dist_pkgdataDATA install-dist_pkgtestsDATA \
+       install-docDATA install-dvi install-dvi-am install-exec \
+       install-exec-am install-html install-html-am install-info \
+       install-info-am install-man install-pdf install-pdf-am \
+       install-pkgdataDATA install-pkgtestsSCRIPTS install-ps \
+       install-ps-am install-strip installcheck installcheck-am \
+       installcheck-local installdirs maintainer-clean \
+       maintainer-clean-generic maintainer-clean-local mostlyclean \
+       mostlyclean-generic pdf pdf-am ps ps-am tags-am uninstall \
+       uninstall-am uninstall-dist_pkgdataDATA \
+       uninstall-dist_pkgtestsDATA uninstall-docDATA \
+       uninstall-pkgdataDATA uninstall-pkgtestsSCRIPTS
+
+.PRECIOUS: Makefile
+
+version.subr: version.subr.in
+       -$(MKDIR_P) $(builddir)
+       $(AM_V_GEN)target="$(builddir)/version.subr" source="$(srcdir)/version.subr.in"; \
+       $(BUILD_FILE)
+t/build_test: t/build_test.sh
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/build_test" source="$(srcdir)/t/build_test.sh"; \
+       $(BUILD_SCRIPT)
+t/run_tests: t/run_tests.sh
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/run_tests" source="$(srcdir)/t/run_tests.sh"; \
+       $(BUILD_SCRIPT)
+t/t_compare: t/t_compare.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_compare" source="$(srcdir)/t/t_compare.sh"; \
+       $(BUILD_TEST)
+t/t_createfile: t/t_createfile.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_createfile" source="$(srcdir)/t/t_createfile.sh"; \
+       $(BUILD_TEST)
+t/t_directories: t/t_directories.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_directories" source="$(srcdir)/t/t_directories.sh"; \
+       $(BUILD_TEST)
+t/t_dirwalk: t/t_dirwalk.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_dirwalk" source="$(srcdir)/t/t_dirwalk.sh"; \
+       $(BUILD_TEST)
+t/t_echo: t/t_echo.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_echo" source="$(srcdir)/t/t_echo.sh"; \
+       $(BUILD_TEST)
+t/t_files: t/t_files.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_files" source="$(srcdir)/t/t_files.sh"; \
+       $(BUILD_TEST)
+t/t_fonts: t/t_fonts.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_fonts" source="$(srcdir)/t/t_fonts.sh"; \
+       $(BUILD_TEST)
+t/t_groups: t/t_groups.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_groups" source="$(srcdir)/t/t_groups.sh"; \
+       $(BUILD_TEST)
+t/t_info_files: t/t_info_files.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_info_files" source="$(srcdir)/t/t_info_files.sh"; \
+       $(BUILD_TEST)
+t/t_lock: t/t_lock.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_lock" source="$(srcdir)/t/t_lock.sh"; \
+       $(BUILD_TEST)
+t/t_makedir: t/t_makedir.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_makedir" source="$(srcdir)/t/t_makedir.sh"; \
+       $(BUILD_TEST)
+t/t_maketemp: t/t_maketemp.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_maketemp" source="$(srcdir)/t/t_maketemp.sh"; \
+       $(BUILD_TEST)
+t/t_match: t/t_match.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_match" source="$(srcdir)/t/t_match.sh"; \
+       $(BUILD_TEST)
+t/t_ocaml_findlib: t/t_ocaml_findlib.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_ocaml_findlib" source="$(srcdir)/t/t_ocaml_findlib.sh"; \
+       $(BUILD_TEST)
+t/t_permissions: t/t_permissions.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_permissions" source="$(srcdir)/t/t_permissions.sh"; \
+       $(BUILD_TEST)
+t/t_platform: t/t_platform.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_platform" source="$(srcdir)/t/t_platform.sh"; \
+       $(BUILD_TEST)
+t/t_postinstall: t/t_postinstall.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_postinstall" source="$(srcdir)/t/t_postinstall.sh"; \
+       $(BUILD_TEST)
+t/t_postremove: t/t_postremove.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_postremove" source="$(srcdir)/t/t_postremove.sh"; \
+       $(BUILD_TEST)
+t/t_preinstall: t/t_preinstall.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_preinstall" source="$(srcdir)/t/t_preinstall.sh"; \
+       $(BUILD_TEST)
+t/t_preremove: t/t_preremove.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_preremove" source="$(srcdir)/t/t_preremove.sh"; \
+       $(BUILD_TEST)
+t/t_quote: t/t_quote.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_quote" source="$(srcdir)/t/t_quote.sh"; \
+       $(BUILD_TEST)
+t/t_random: t/t_random.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_random" source="$(srcdir)/t/t_random.sh"; \
+       $(BUILD_TEST)
+t/t_refcount: t/t_refcount.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_refcount" source="$(srcdir)/t/t_refcount.sh"; \
+       $(BUILD_TEST)
+t/t_shells: t/t_shells.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_shells" source="$(srcdir)/t/t_shells.sh"; \
+       $(BUILD_TEST)
+t/t_shlibs: t/t_shlibs.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_shlibs" source="$(srcdir)/t/t_shlibs.sh"; \
+       $(BUILD_TEST)
+t/t_sort: t/t_sort.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_sort" source="$(srcdir)/t/t_sort.sh"; \
+       $(BUILD_TEST)
+t/t_taskfunc: t/t_taskfunc.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_taskfunc" source="$(srcdir)/t/t_taskfunc.sh"; \
+       $(BUILD_TEST)
+t/t_tee: t/t_tee.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_tee" source="$(srcdir)/t/t_tee.sh"; \
+       $(BUILD_TEST)
+t/t_truthy: t/t_truthy.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_truthy" source="$(srcdir)/t/t_truthy.sh"; \
+       $(BUILD_TEST)
+t/t_usergroup: t/t_usergroup.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_usergroup" source="$(srcdir)/t/t_usergroup.sh"; \
+       $(BUILD_TEST)
+t/t_usergroup_FreeBSD: t/t_usergroup_FreeBSD.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_usergroup_FreeBSD" source="$(srcdir)/t/t_usergroup_FreeBSD.sh"; \
+       $(BUILD_TEST)
+t/t_usergroup_Linux: t/t_usergroup_Linux.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_usergroup_Linux" source="$(srcdir)/t/t_usergroup_Linux.sh"; \
+       $(BUILD_TEST)
+t/t_usergroup_MirBSD: t/t_usergroup_MirBSD.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_usergroup_MirBSD" source="$(srcdir)/t/t_usergroup_MirBSD.sh"; \
+       $(BUILD_TEST)
+t/t_usergroup_NetBSD: t/t_usergroup_NetBSD.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_usergroup_NetBSD" source="$(srcdir)/t/t_usergroup_NetBSD.sh"; \
+       $(BUILD_TEST)
+t/t_usergroup_exists: t/t_usergroup_exists.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_usergroup_exists" source="$(srcdir)/t/t_usergroup_exists.sh"; \
+       $(BUILD_TEST)
+t/t_usergroup_mock: t/t_usergroup_mock.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_usergroup_mock" source="$(srcdir)/t/t_usergroup_mock.sh"; \
+       $(BUILD_TEST)
+t/t_users: t/t_users.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_users" source="$(srcdir)/t/t_users.sh"; \
+       $(BUILD_TEST)
+t/t_valid_options: t/t_valid_options.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_valid_options" source="$(srcdir)/t/t_valid_options.sh"; \
+       $(BUILD_TEST)
+t/t_version: t/t_version.sh version.subr $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_version" source="$(srcdir)/t/t_version.sh"; \
+       $(BUILD_TEST)
+t/t_which: t/t_which.sh $(builddir)/t/build_test
+       -$(MKDIR_P) $(builddir)/t
+       $(AM_V_GEN)target="$(builddir)/t/t_which" source="$(srcdir)/t/t_which.sh"; \
+       $(BUILD_TEST)
+check-run-tests:
+       @cd $(srcdir)/t && $(SHELL) run_tests.sh
+installcheck-run-tests:
+       @cd $(pkgtestsdir) && ./run_tests
+@HAVE_KYUA_TRUE@check-local: check-kyua
+@HAVE_KYUA_TRUE@check-kyua:
+@HAVE_KYUA_TRUE@       @failed=no; \
+@HAVE_KYUA_TRUE@       $(CHECK_ENVIRONMENT) $(TESTS_ENVIRONMENT) $(KYUA) test \
+@HAVE_KYUA_TRUE@               --kyuafile='$(top_srcdir)/t/Kyuafile' \
+@HAVE_KYUA_TRUE@               --build-root='$(top_builddir)/t' || failed=yes; \
+@HAVE_KYUA_TRUE@       if [ "$$failed" = yes ]; then \
+@HAVE_KYUA_TRUE@               $(CHECK_ENVIRONMENT) $(TESTS_ENVIRONMENT) $(KYUA) report \
+@HAVE_KYUA_TRUE@                       --results-file='$(abs_top_srcdir)' \
+@HAVE_KYUA_TRUE@                       --verbose --results-filter=broken,failed; \
+@HAVE_KYUA_TRUE@               exit 1; \
+@HAVE_KYUA_TRUE@       fi
+@HAVE_KYUA_TRUE@installcheck-local: installcheck-kyua
+@HAVE_KYUA_TRUE@installcheck-kyua:
+@HAVE_KYUA_TRUE@       @failed=no; \
+@HAVE_KYUA_TRUE@       cd $(pkgtestsdir) && $(TESTS_ENVIRONMENT) $(KYUA) test  || failed=yes; \
+@HAVE_KYUA_TRUE@       if [ "$$failed" = yes ]; then \
+@HAVE_KYUA_TRUE@               cd $(pkgtestsdir) && $(TESTS_ENVIRONMENT) $(KYUA) report \
+@HAVE_KYUA_TRUE@                       --verbose --results-filter=broken,failed; \
+@HAVE_KYUA_TRUE@               exit 1; \
+@HAVE_KYUA_TRUE@       fi
+@HAVE_KYUA_FALSE@check-local: check-run-tests
+@HAVE_KYUA_FALSE@installcheck-local: installcheck-run-tests
+
+maintainer-clean-local:
+       -rm -f Makefile.in aclocal.m4 configure
+       -rm -f build-aux/install-sh build-aux/missing
+       -rm -f $(PACKAGE)-*.tar.*
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
Index: pkgsrc/pkgtools/pkgtasks/files/README.md
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/README.md:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/README.md    Thu Jun  1 01:58:34 2017
@@ -0,0 +1,98 @@
+Package Tasks
+=============
+
+*pkgtasks* is a shell script library to ease writing POSIX-compliant shell
+scripts to handle common tasks during installation or removal of a package,
+e.g.,
+
+  * creating groups and users needed by the package
+
+  * creating and removing directories with special permissions and
+    ownership,
+
+  * copying example config files to their final locations during package
+    installation, and removing them during package removal if they don't
+    differ from the example ones,
+
+  * reminding the user of files that may be customized after package
+    installation.
+
+Package tasks have the property of *idempotence* -- they may be invoked
+multiple times, but the result must be the same as when invoked once, e.g.,
+the `shells` task adds an entry to /etc/shells, but will avoid adding the
+same entry more than once.
+
+
+Getting sources
+---------------
+
+The latest version of *pkgtasks* is 1.9 and was released on May 31st, 2017.
+
+See the [release notes](NEWS.md) for information about the changes in this
+and all previous releases.
+
+
+Documentation
+-------------
+
+A script may load task modules to define shell functions to perform
+various tasks.  A task module is loaded in a POSIX-compliant shell script
+by adding the following boilerplate to the script:
+
+       # Import the task loader.
+       : ${TASK_MODULE_DIR:=/usr/pkg/share/pkgtasks-1}
+       . "${TASK_MODULE_DIR}/load.subr"
+
+       # Load task modules.
+       task_load preinstall
+
+The individual package tasks supported by *pkgtasks* are:
+
+  * `directories`: create and remove directories outside of package tree
+  * `files`: copy and remove configuration files
+  * `fonts`: regenerate X11 font indices
+  * `groups`: create groups and warn about groups that may be removed
+  * `info_files`: register and unregister GNU info files
+  * `ocaml_findlib`: update OCaml findlib search paths
+  * `permissions`: check and set modes and permissions on special files
+  * `shells`: register and unregister login shells
+  * `shlibs`: update the shared library cache
+  * `users`: create users and warn about users that may be removed
+
+These package tasks support `${PKG_DESTDIR}` to manipulate the correct
+filesystem paths for a destdir-installed package.
+
+For convenience, these have been composed into larger meta-tasks:
+
+  * `preinstall`: tasks performed before files are installed
+  * `preremove`: tasks performed before files are removed
+  * `postinstall`: tasks performed after files are installed
+  * `postremove`: tasks performed after files are removed
+
+There are also several utility tasks that may be used to write portable
+scripts:
+
+  * `cleanup`: run functions upon improper exit
+  * `compare`: compare two files for equality
+  * `createfile`: create empty files
+  * `dirwalk`: walk a directory tree using depth-first traversal
+  * `echo`: write to standard output through a buffer
+  * `lock`: create or release a lock file
+  * `makedir`: make a directory hierarchy
+  * `maketemp`: make unique, temporary files
+  * `match`: match lines with a fnmatch(3) glob pattern
+  * `platform`: determine the platform (operating system)
+  * `quote`: quote strings for use with shell eval
+  * `random`: generate random numbers (badly)
+  * `refcount`: reference-count system resources
+  * `say`: write to standard output with a tag
+  * `sort`: sort lines from standard input
+  * `taskfunc`: generic function hook for meta-tasks
+  * `tee`: duplicate writes to standard output into files
+  * `truthy`: evaluate truthiness
+  * `valid_options`: check validity of option strings
+  * `version`: compare version strings
+  * `which`: locate a program file in the $PATH
+
+The documentation for each of these tasks is in man-page style in the
+header comments for each task module.
Index: pkgsrc/pkgtools/pkgtasks/files/aclocal.m4
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/aclocal.m4:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/aclocal.m4   Thu Jun  1 01:58:34 2017
@@ -0,0 +1,773 @@
+# generated automatically by aclocal 1.15 -*- Autoconf -*-
+
+# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
+m4_ifndef([AC_AUTOCONF_VERSION],
+  [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
+m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],,
+[m4_warning([this file was generated for autoconf 2.69.
+You have another version of autoconf.  It may work, but is not guaranteed to.
+If you have problems, you may need to regenerate the build system entirely.
+To do so, use the procedure documented by the package, typically 'autoreconf'.])])
+
+# Copyright (C) 2002-2014 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_AUTOMAKE_VERSION(VERSION)
+# ----------------------------
+# Automake X.Y traces this macro to ensure aclocal.m4 has been
+# generated from the m4 files accompanying Automake X.Y.
+# (This private macro should not be called outside this file.)
+AC_DEFUN([AM_AUTOMAKE_VERSION],
+[am__api_version='1.15'
+dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
+dnl require some minimum version.  Point them to the right macro.
+m4_if([$1], [1.15], [],
+      [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
+])
+
+# _AM_AUTOCONF_VERSION(VERSION)
+# -----------------------------
+# aclocal traces this macro to find the Autoconf version.
+# This is a private macro too.  Using m4_define simplifies
+# the logic in aclocal, which can simply ignore this definition.
+m4_define([_AM_AUTOCONF_VERSION], [])
+
+# AM_SET_CURRENT_AUTOMAKE_VERSION
+# -------------------------------
+# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
+# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
+AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
+[AM_AUTOMAKE_VERSION([1.15])dnl
+m4_ifndef([AC_AUTOCONF_VERSION],
+  [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
+_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
+
+# AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
+
+# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
+# $ac_aux_dir to '$srcdir/foo'.  In other projects, it is set to
+# '$srcdir', '$srcdir/..', or '$srcdir/../..'.
+#
+# Of course, Automake must honor this variable whenever it calls a
+# tool from the auxiliary directory.  The problem is that $srcdir (and
+# therefore $ac_aux_dir as well) can be either absolute or relative,
+# depending on how configure is run.  This is pretty annoying, since
+# it makes $ac_aux_dir quite unusable in subdirectories: in the top
+# source directory, any form will work fine, but in subdirectories a
+# relative path needs to be adjusted first.
+#
+# $ac_aux_dir/missing
+#    fails when called from a subdirectory if $ac_aux_dir is relative
+# $top_srcdir/$ac_aux_dir/missing
+#    fails if $ac_aux_dir is absolute,
+#    fails when called from a subdirectory in a VPATH build with
+#          a relative $ac_aux_dir
+#
+# The reason of the latter failure is that $top_srcdir and $ac_aux_dir
+# are both prefixed by $srcdir.  In an in-source build this is usually
+# harmless because $srcdir is '.', but things will broke when you
+# start a VPATH build or use an absolute $srcdir.
+#
+# So we could use something similar to $top_srcdir/$ac_aux_dir/missing,
+# iff we strip the leading $srcdir from $ac_aux_dir.  That would be:
+#   am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"`
+# and then we would define $MISSING as
+#   MISSING="\${SHELL} $am_aux_dir/missing"
+# This will work as long as MISSING is not called from configure, because
+# unfortunately $(top_srcdir) has no meaning in configure.
+# However there are other variables, like CC, which are often used in
+# configure, and could therefore not use this "fixed" $ac_aux_dir.
+#
+# Another solution, used here, is to always expand $ac_aux_dir to an
+# absolute PATH.  The drawback is that using absolute paths prevent a
+# configured tree to be moved without reconfiguration.
+
+AC_DEFUN([AM_AUX_DIR_EXPAND],
+[AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
+# Expand $ac_aux_dir to an absolute path.
+am_aux_dir=`cd "$ac_aux_dir" && pwd`
+])
+
+# AM_CONDITIONAL                                            -*- Autoconf -*-
+
+# Copyright (C) 1997-2014 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_CONDITIONAL(NAME, SHELL-CONDITION)
+# -------------------------------------
+# Define a conditional.
+AC_DEFUN([AM_CONDITIONAL],
+[AC_PREREQ([2.52])dnl
+ m4_if([$1], [TRUE],  [AC_FATAL([$0: invalid condition: $1])],
+       [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
+AC_SUBST([$1_TRUE])dnl
+AC_SUBST([$1_FALSE])dnl
+_AM_SUBST_NOTMAKE([$1_TRUE])dnl
+_AM_SUBST_NOTMAKE([$1_FALSE])dnl
+m4_define([_AM_COND_VALUE_$1], [$2])dnl
+if $2; then
+  $1_TRUE=
+  $1_FALSE='#'
+else
+  $1_TRUE='#'
+  $1_FALSE=
+fi
+AC_CONFIG_COMMANDS_PRE(
+[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
+  AC_MSG_ERROR([[conditional "$1" was never defined.
+Usually this means the macro was only invoked conditionally.]])
+fi])])
+
+# Do all the work for Automake.                             -*- Autoconf -*-
+
+# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This macro actually does too much.  Some checks are only needed if
+# your package does certain things.  But this isn't really a big deal.
+
+dnl Redefine AC_PROG_CC to automatically invoke _AM_PROG_CC_C_O.
+m4_define([AC_PROG_CC],
+m4_defn([AC_PROG_CC])
+[_AM_PROG_CC_C_O
+])
+
+# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
+# AM_INIT_AUTOMAKE([OPTIONS])
+# -----------------------------------------------
+# The call with PACKAGE and VERSION arguments is the old style
+# call (pre autoconf-2.50), which is being phased out.  PACKAGE
+# and VERSION should now be passed to AC_INIT and removed from
+# the call to AM_INIT_AUTOMAKE.
+# We support both call styles for the transition.  After
+# the next Automake release, Autoconf can make the AC_INIT
+# arguments mandatory, and then we can depend on a new Autoconf
+# release and drop the old call support.
+AC_DEFUN([AM_INIT_AUTOMAKE],
+[AC_PREREQ([2.65])dnl
+dnl Autoconf wants to disallow AM_ names.  We explicitly allow
+dnl the ones we care about.
+m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl
+AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl
+AC_REQUIRE([AC_PROG_INSTALL])dnl
+if test "`cd $srcdir && pwd`" != "`pwd`"; then
+  # Use -I$(srcdir) only when $(srcdir) != ., so that make's output
+  # is not polluted with repeated "-I."
+  AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl
+  # test to see if srcdir already configured
+  if test -f $srcdir/config.status; then
+    AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
+  fi
+fi
+
+# test whether we have cygpath
+if test -z "$CYGPATH_W"; then
+  if (cygpath --version) >/dev/null 2>/dev/null; then
+    CYGPATH_W='cygpath -w'
+  else
+    CYGPATH_W=echo
+  fi
+fi
+AC_SUBST([CYGPATH_W])
+
+# Define the identity of the package.
+dnl Distinguish between old-style and new-style calls.
+m4_ifval([$2],
+[AC_DIAGNOSE([obsolete],
+             [$0: two- and three-arguments forms are deprecated.])
+m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl
+ AC_SUBST([PACKAGE], [$1])dnl
+ AC_SUBST([VERSION], [$2])],
+[_AM_SET_OPTIONS([$1])dnl
+dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT.
+m4_if(
+  m4_ifdef([AC_PACKAGE_NAME], [ok]):m4_ifdef([AC_PACKAGE_VERSION], [ok]),
+  [ok:ok],,
+  [m4_fatal([AC_INIT should be called with package and version arguments])])dnl
+ AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl
+ AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl
+
+_AM_IF_OPTION([no-define],,
+[AC_DEFINE_UNQUOTED([PACKAGE], ["$PACKAGE"], [Name of package])
+ AC_DEFINE_UNQUOTED([VERSION], ["$VERSION"], [Version number of package])])dnl
+
+# Some tools Automake needs.
+AC_REQUIRE([AM_SANITY_CHECK])dnl
+AC_REQUIRE([AC_ARG_PROGRAM])dnl
+AM_MISSING_PROG([ACLOCAL], [aclocal-${am__api_version}])
+AM_MISSING_PROG([AUTOCONF], [autoconf])
+AM_MISSING_PROG([AUTOMAKE], [automake-${am__api_version}])
+AM_MISSING_PROG([AUTOHEADER], [autoheader])
+AM_MISSING_PROG([MAKEINFO], [makeinfo])
+AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
+AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl
+AC_REQUIRE([AC_PROG_MKDIR_P])dnl
+# For better backward compatibility.  To be removed once Automake 1.9.x
+# dies out for good.  For more background, see:
+# <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
+# <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
+AC_SUBST([mkdir_p], ['$(MKDIR_P)'])
+# We need awk for the "check" target (and possibly the TAP driver).  The
+# system "awk" is bad on some platforms.
+AC_REQUIRE([AC_PROG_AWK])dnl
+AC_REQUIRE([AC_PROG_MAKE_SET])dnl
+AC_REQUIRE([AM_SET_LEADING_DOT])dnl
+_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])],
+             [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])],
+                            [_AM_PROG_TAR([v7])])])
+_AM_IF_OPTION([no-dependencies],,
+[AC_PROVIDE_IFELSE([AC_PROG_CC],
+                 [_AM_DEPENDENCIES([CC])],
+                 [m4_define([AC_PROG_CC],
+                            m4_defn([AC_PROG_CC])[_AM_DEPENDENCIES([CC])])])dnl
+AC_PROVIDE_IFELSE([AC_PROG_CXX],
+                 [_AM_DEPENDENCIES([CXX])],
+                 [m4_define([AC_PROG_CXX],
+                            m4_defn([AC_PROG_CXX])[_AM_DEPENDENCIES([CXX])])])dnl
+AC_PROVIDE_IFELSE([AC_PROG_OBJC],
+                 [_AM_DEPENDENCIES([OBJC])],
+                 [m4_define([AC_PROG_OBJC],
+                            m4_defn([AC_PROG_OBJC])[_AM_DEPENDENCIES([OBJC])])])dnl
+AC_PROVIDE_IFELSE([AC_PROG_OBJCXX],
+                 [_AM_DEPENDENCIES([OBJCXX])],
+                 [m4_define([AC_PROG_OBJCXX],
+                            m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])dnl
+])
+AC_REQUIRE([AM_SILENT_RULES])dnl
+dnl The testsuite driver may need to know about EXEEXT, so add the
+dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen.  This
+dnl macro is hooked onto _AC_COMPILER_EXEEXT early, see below.
+AC_CONFIG_COMMANDS_PRE(dnl
+[m4_provide_if([_AM_COMPILER_EXEEXT],
+  [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl
+
+# POSIX will say in a future version that running "rm -f" with no argument
+# is OK; and we want to be able to make that assumption in our Makefile
+# recipes.  So use an aggressive probe to check that the usage we want is
+# actually supported "in the wild" to an acceptable degree.
+# See automake bug#10828.
+# To make any issue more visible, cause the running configure to be aborted
+# by default if the 'rm' program in use doesn't match our expectations; the
+# user can still override this though.
+if rm -f && rm -fr && rm -rf; then : OK; else
+  cat >&2 <<'END'
+Oops!
+
+Your 'rm' program seems unable to run without file operands specified
+on the command line, even when the '-f' option is present.  This is contrary
+to the behaviour of most rm programs out there, and not conforming with
+the upcoming POSIX standard: <http://austingroupbugs.net/view.php?id=542>
+
+Please tell bug-automake%gnu.org@localhost about your system, including the value
+of your $PATH and any error possibly output before this message.  This
+can help us improve future automake versions.
+
+END
+  if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then
+    echo 'Configuration will proceed anyway, since you have set the' >&2
+    echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2
+    echo >&2
+  else
+    cat >&2 <<'END'
+Aborting the configuration process, to ensure you take notice of the issue.
+
+You can download and install GNU coreutils to get an 'rm' implementation
+that behaves properly: <http://www.gnu.org/software/coreutils/>.
+
+If you want to complete the configuration process using your problematic
+'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
+to "yes", and re-run configure.
+
+END
+    AC_MSG_ERROR([Your 'rm' program is bad, sorry.])
+  fi
+fi
+dnl The trailing newline in this macro's definition is deliberate, for
+dnl backward compatibility and to allow trailing 'dnl'-style comments
+dnl after the AM_INIT_AUTOMAKE invocation. See automake bug#16841.
+])
+
+dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion.  Do not
+dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further
+dnl mangled by Autoconf and run in a shell conditional statement.
+m4_define([_AC_COMPILER_EXEEXT],
+m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])])
+
+# When config.status generates a header, we must update the stamp-h file.
+# This file resides in the same directory as the config header
+# that is generated.  The stamp files are numbered to have different names.
+
+# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the
+# loop where config.status creates the headers, so we can generate
+# our stamp files there.
+AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK],
+[# Compute $1's index in $config_headers.
+_am_arg=$1
+_am_stamp_count=1
+for _am_header in $config_headers :; do
+  case $_am_header in
+    $_am_arg | $_am_arg:* )
+      break ;;
+    * )
+      _am_stamp_count=`expr $_am_stamp_count + 1` ;;
+  esac
+done
+echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
+
+# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_PROG_INSTALL_SH
+# ------------------
+# Define $install_sh.
+AC_DEFUN([AM_PROG_INSTALL_SH],
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+if test x"${install_sh+set}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\    *)
+    install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
+  *)
+    install_sh="\${SHELL} $am_aux_dir/install-sh"
+  esac
+fi
+AC_SUBST([install_sh])])
+
+# Copyright (C) 2003-2014 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# Check whether the underlying file-system supports filenames
+# with a leading dot.  For instance MS-DOS doesn't.
+AC_DEFUN([AM_SET_LEADING_DOT],
+[rm -rf .tst 2>/dev/null
+mkdir .tst 2>/dev/null
+if test -d .tst; then
+  am__leading_dot=.
+else
+  am__leading_dot=_
+fi
+rmdir .tst 2>/dev/null
+AC_SUBST([am__leading_dot])])
+
+# Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-
+
+# Copyright (C) 1997-2014 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_MISSING_PROG(NAME, PROGRAM)
+# ------------------------------
+AC_DEFUN([AM_MISSING_PROG],
+[AC_REQUIRE([AM_MISSING_HAS_RUN])
+$1=${$1-"${am_missing_run}$2"}
+AC_SUBST($1)])
+
+# AM_MISSING_HAS_RUN
+# ------------------
+# Define MISSING if not defined so far and test if it is modern enough.
+# If it is, set am_missing_run to use it, otherwise, to nothing.
+AC_DEFUN([AM_MISSING_HAS_RUN],
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+AC_REQUIRE_AUX_FILE([missing])dnl
+if test x"${MISSING+set}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\    *)
+    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
+  *)
+    MISSING="\${SHELL} $am_aux_dir/missing" ;;
+  esac
+fi
+# Use eval to expand $SHELL
+if eval "$MISSING --is-lightweight"; then
+  am_missing_run="$MISSING "
+else
+  am_missing_run=
+  AC_MSG_WARN(['missing' script is too old or missing])
+fi
+])
+
+# Helper functions for option handling.                     -*- Autoconf -*-
+
+# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# _AM_MANGLE_OPTION(NAME)
+# -----------------------
+AC_DEFUN([_AM_MANGLE_OPTION],
+[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])])
+
+# _AM_SET_OPTION(NAME)
+# --------------------
+# Set option NAME.  Presently that only means defining a flag for this option.
+AC_DEFUN([_AM_SET_OPTION],
+[m4_define(_AM_MANGLE_OPTION([$1]), [1])])
+
+# _AM_SET_OPTIONS(OPTIONS)
+# ------------------------
+# OPTIONS is a space-separated list of Automake options.
+AC_DEFUN([_AM_SET_OPTIONS],
+[m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
+
+# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET])
+# -------------------------------------------
+# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
+AC_DEFUN([_AM_IF_OPTION],
+[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
+
+# Check to make sure that the build environment is sane.    -*- Autoconf -*-
+
+# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_SANITY_CHECK
+# ---------------
+AC_DEFUN([AM_SANITY_CHECK],
+[AC_MSG_CHECKING([whether build environment is sane])
+# Reject unsafe characters in $srcdir or the absolute working directory
+# name.  Accept space and tab only in the latter.
+am_lf='
+'
+case `pwd` in
+  *[[\\\"\#\$\&\'\`$am_lf]]*)
+    AC_MSG_ERROR([unsafe absolute working directory name]);;
+esac
+case $srcdir in
+  *[[\\\"\#\$\&\'\`$am_lf\ \   ]]*)
+    AC_MSG_ERROR([unsafe srcdir value: '$srcdir']);;
+esac
+
+# Do 'set' in a subshell so we don't clobber the current shell's
+# arguments.  Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+   am_has_slept=no
+   for am_try in 1 2; do
+     echo "timestamp, slept: $am_has_slept" > conftest.file
+     set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
+     if test "$[*]" = "X"; then
+       # -L didn't work.
+       set X `ls -t "$srcdir/configure" conftest.file`
+     fi
+     if test "$[*]" != "X $srcdir/configure conftest.file" \
+       && test "$[*]" != "X conftest.file $srcdir/configure"; then
+
+       # If neither matched, then we have a broken ls.  This can happen
+       # if, for instance, CONFIG_SHELL is bash and it inherits a
+       # broken ls alias from the environment.  This has actually
+       # happened.  Such a system could not be considered "sane".
+       AC_MSG_ERROR([ls -t appears to fail.  Make sure there is not a broken
+  alias in your environment])
+     fi
+     if test "$[2]" = conftest.file || test $am_try -eq 2; then
+       break
+     fi
+     # Just in case.
+     sleep 1
+     am_has_slept=yes
+   done
+   test "$[2]" = conftest.file
+   )
+then
+   # Ok.
+   :
+else
+   AC_MSG_ERROR([newly created file is older than distributed files!
+Check your system clock])
+fi
+AC_MSG_RESULT([yes])
+# If we didn't sleep, we still need to ensure time stamps of config.status and
+# generated files are strictly newer.
+am_sleep_pid=
+if grep 'slept: no' conftest.file >/dev/null 2>&1; then
+  ( sleep 1 ) &
+  am_sleep_pid=$!
+fi
+AC_CONFIG_COMMANDS_PRE(
+  [AC_MSG_CHECKING([that generated files are newer than configure])
+   if test -n "$am_sleep_pid"; then
+     # Hide warnings about reused PIDs.
+     wait $am_sleep_pid 2>/dev/null
+   fi
+   AC_MSG_RESULT([done])])
+rm -f conftest.file
+])
+
+# Copyright (C) 2009-2014 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_SILENT_RULES([DEFAULT])
+# --------------------------
+# Enable less verbose build rules; with the default set to DEFAULT
+# ("yes" being less verbose, "no" or empty being verbose).
+AC_DEFUN([AM_SILENT_RULES],
+[AC_ARG_ENABLE([silent-rules], [dnl
+AS_HELP_STRING(
+  [--enable-silent-rules],
+  [less verbose build output (undo: "make V=1")])
+AS_HELP_STRING(
+  [--disable-silent-rules],
+  [verbose build output (undo: "make V=0")])dnl
+])
+case $enable_silent_rules in @%:@ (((
+  yes) AM_DEFAULT_VERBOSITY=0;;
+   no) AM_DEFAULT_VERBOSITY=1;;
+    *) AM_DEFAULT_VERBOSITY=m4_if([$1], [yes], [0], [1]);;
+esac
+dnl
+dnl A few 'make' implementations (e.g., NonStop OS and NextStep)
+dnl do not support nested variable expansions.
+dnl See automake bug#9928 and bug#10237.
+am_make=${MAKE-make}
+AC_CACHE_CHECK([whether $am_make supports nested variables],
+   [am_cv_make_support_nested_variables],
+   [if AS_ECHO([['TRUE=$(BAR$(V))
+BAR0=false
+BAR1=true
+V=1
+am__doit:
+       @$(TRUE)
+.PHONY: am__doit']]) | $am_make -f - >/dev/null 2>&1; then
+  am_cv_make_support_nested_variables=yes
+else
+  am_cv_make_support_nested_variables=no
+fi])
+if test $am_cv_make_support_nested_variables = yes; then
+  dnl Using '$V' instead of '$(V)' breaks IRIX make.
+  AM_V='$(V)'
+  AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)'
+else
+  AM_V=$AM_DEFAULT_VERBOSITY
+  AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY
+fi
+AC_SUBST([AM_V])dnl
+AM_SUBST_NOTMAKE([AM_V])dnl
+AC_SUBST([AM_DEFAULT_V])dnl
+AM_SUBST_NOTMAKE([AM_DEFAULT_V])dnl
+AC_SUBST([AM_DEFAULT_VERBOSITY])dnl
+AM_BACKSLASH='\'
+AC_SUBST([AM_BACKSLASH])dnl
+_AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl
+])
+
+# Copyright (C) 2001-2014 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_PROG_INSTALL_STRIP
+# ---------------------
+# One issue with vendor 'install' (even GNU) is that you can't
+# specify the program used to strip binaries.  This is especially
+# annoying in cross-compiling environments, where the build's strip
+# is unlikely to handle the host's binaries.
+# Fortunately install-sh will honor a STRIPPROG variable, so we
+# always use install-sh in "make install-strip", and initialize
+# STRIPPROG with the value of the STRIP variable (set by the user).
+AC_DEFUN([AM_PROG_INSTALL_STRIP],
+[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
+# Installed binaries are usually stripped using 'strip' when the user
+# run "make install-strip".  However 'strip' might not be the right
+# tool to use in cross-compilation environments, therefore Automake
+# will honor the 'STRIP' environment variable to overrule this program.
+dnl Don't test for $cross_compiling = yes, because it might be 'maybe'.
+if test "$cross_compiling" != no; then
+  AC_CHECK_TOOL([STRIP], [strip], :)
+fi
+INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
+AC_SUBST([INSTALL_STRIP_PROGRAM])])
+
+# Copyright (C) 2006-2014 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# _AM_SUBST_NOTMAKE(VARIABLE)
+# ---------------------------
+# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in.
+# This macro is traced by Automake.
+AC_DEFUN([_AM_SUBST_NOTMAKE])
+
+# AM_SUBST_NOTMAKE(VARIABLE)
+# --------------------------
+# Public sister of _AM_SUBST_NOTMAKE.
+AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
+
+# Check how to create a tarball.                            -*- Autoconf -*-
+
+# Copyright (C) 2004-2014 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# _AM_PROG_TAR(FORMAT)
+# --------------------
+# Check how to create a tarball in format FORMAT.
+# FORMAT should be one of 'v7', 'ustar', or 'pax'.
+#
+# Substitute a variable $(am__tar) that is a command
+# writing to stdout a FORMAT-tarball containing the directory
+# $tardir.
+#     tardir=directory && $(am__tar) > result.tar
+#
+# Substitute a variable $(am__untar) that extract such
+# a tarball read from stdin.
+#     $(am__untar) < result.tar
+#
+AC_DEFUN([_AM_PROG_TAR],
+[# Always define AMTAR for backward compatibility.  Yes, it's still used
+# in the wild :-(  We should find a proper way to deprecate it ...
+AC_SUBST([AMTAR], ['$${TAR-tar}'])
+
+# We'll loop over all known methods to create a tar archive until one works.
+_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none'
+
+m4_if([$1], [v7],
+  [am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'],
+
+  [m4_case([$1],
+    [ustar],
+     [# The POSIX 1988 'ustar' format is defined with fixed-size fields.
+      # There is notably a 21 bits limit for the UID and the GID.  In fact,
+      # the 'pax' utility can hang on bigger UID/GID (see automake bug#8343
+      # and bug#13588).
+      am_max_uid=2097151 # 2^21 - 1
+      am_max_gid=$am_max_uid
+      # The $UID and $GID variables are not portable, so we need to resort
+      # to the POSIX-mandated id(1) utility.  Errors in the 'id' calls
+      # below are definitely unexpected, so allow the users to see them
+      # (that is, avoid stderr redirection).
+      am_uid=`id -u || echo unknown`
+      am_gid=`id -g || echo unknown`
+      AC_MSG_CHECKING([whether UID '$am_uid' is supported by ustar format])
+      if test $am_uid -le $am_max_uid; then
+         AC_MSG_RESULT([yes])
+      else
+         AC_MSG_RESULT([no])
+         _am_tools=none
+      fi
+      AC_MSG_CHECKING([whether GID '$am_gid' is supported by ustar format])
+      if test $am_gid -le $am_max_gid; then
+         AC_MSG_RESULT([yes])
+      else
+        AC_MSG_RESULT([no])
+        _am_tools=none
+      fi],
+
+  [pax],
+    [],
+
+  [m4_fatal([Unknown tar format])])
+
+  AC_MSG_CHECKING([how to create a $1 tar archive])
+
+  # Go ahead even if we have the value already cached.  We do so because we
+  # need to set the values for the 'am__tar' and 'am__untar' variables.
+  _am_tools=${am_cv_prog_tar_$1-$_am_tools}
+
+  for _am_tool in $_am_tools; do
+    case $_am_tool in
+    gnutar)
+      for _am_tar in tar gnutar gtar; do
+        AM_RUN_LOG([$_am_tar --version]) && break
+      done
+      am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"'
+      am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"'
+      am__untar="$_am_tar -xf -"
+      ;;
+    plaintar)
+      # Must skip GNU tar: if it does not support --format= it doesn't create
+      # ustar tarball either.
+      (tar --version) >/dev/null 2>&1 && continue
+      am__tar='tar chf - "$$tardir"'
+      am__tar_='tar chf - "$tardir"'
+      am__untar='tar xf -'
+      ;;
+    pax)
+      am__tar='pax -L -x $1 -w "$$tardir"'
+      am__tar_='pax -L -x $1 -w "$tardir"'
+      am__untar='pax -r'
+      ;;
+    cpio)
+      am__tar='find "$$tardir" -print | cpio -o -H $1 -L'
+      am__tar_='find "$tardir" -print | cpio -o -H $1 -L'
+      am__untar='cpio -i -H $1 -d'
+      ;;
+    none)
+      am__tar=false
+      am__tar_=false
+      am__untar=false
+      ;;
+    esac
+
+    # If the value was cached, stop now.  We just wanted to have am__tar
+    # and am__untar set.
+    test -n "${am_cv_prog_tar_$1}" && break
+
+    # tar/untar a dummy directory, and stop if the command works.
+    rm -rf conftest.dir
+    mkdir conftest.dir
+    echo GrepMe > conftest.dir/file
+    AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar])
+    rm -rf conftest.dir
+    if test -s conftest.tar; then
+      AM_RUN_LOG([$am__untar <conftest.tar])
+      AM_RUN_LOG([cat conftest.dir/file])
+      grep GrepMe conftest.dir/file >/dev/null 2>&1 && break
+    fi
+  done
+  rm -rf conftest.dir
+
+  AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool])
+  AC_MSG_RESULT([$am_cv_prog_tar_$1])])
+
+AC_SUBST([am__tar])
+AC_SUBST([am__untar])
+]) # _AM_PROG_TAR
+
Index: pkgsrc/pkgtools/pkgtasks/files/cleanup.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/cleanup.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/cleanup.subr Thu Jun  1 01:58:34 2017
@@ -0,0 +1,68 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      cleanup.subr -- run functions upon improper exit
+#
+# SYNOPSIS
+#      task_cleanup
+#
+#      task_cleanup_add_hook <funcname> ...
+#
+# DESCRIPTION
+#      The task_cleanup function runs the hooks previously added by the
+#      task_cleanup_add_hook function upon receiving a signal for improper
+#      exit.
+#
+# SIGNALS
+#      SIGHUP, SIGINT, SIGTERM
+#              Run the hooks in the order listed.
+#
+
+__task_cleanup__="yes"
+__task_cleanup_init__="_task_cleanup_init"
+
+task_cleanup()
+{
+       set -- $__task_cleanup_hooks__
+       local hook
+       for hook; do $hook; done
+}
+
+task_cleanup_add_hook()
+{
+       __task_cleanup_hooks__="$__task_cleanup_hook__ $*"
+}
+
+_task_cleanup_init()
+{
+       # Trap signals to trigger task_cleanup().
+       trap "task_cleanup; exit 1" 1 2 15
+}
+
+# Static variable that holds a list of names of hooks.
+__task_cleanup_hooks__=
Index: pkgsrc/pkgtools/pkgtasks/files/compare.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/compare.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/compare.subr Thu Jun  1 01:58:34 2017
@@ -0,0 +1,61 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      compare.subr -- compare two files for equality
+#
+# SYNOPSIS
+#      task_compare <file1> <file2>
+#
+# DESCRIPTION
+#      The task_compare function compares two text files and returns
+#      whether the two files are the same.
+#
+# RETURN VALUES
+#      Returns 0 if the two files are identical, and >0 otherwise.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      AWK     The name or path to the awk(1) utility.
+#
+
+__task_compare__="yes"
+
+task_compare()
+{
+       : ${AWK:=awk}
+
+       [ $# -eq 2 ] || return 127
+       [ -n "$1" -a -n "$2" ] || return 127
+       [ -f "$1" -a -f "$2" ] || return 127
+
+       ${AWK} 'NR == FNR { n1 = NR; a[NR] = $0; next }
+                         { n2 = FNR; if ( a[n2] != $0 ) exit 1 }
+               END       { if ( n1 != n2 ) exit 1 }' "$1" "$2"
+       return $?
+}
Index: pkgsrc/pkgtools/pkgtasks/files/configure
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/configure:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/configure    Thu Jun  1 01:58:34 2017
@@ -0,0 +1,3707 @@
+#! /bin/sh
+# Guess values for system-dependent variables and create Makefiles.
+# Generated by GNU Autoconf 2.69 for pkgtasks-1 1.9.
+#
+# Report bugs to <jlam%NetBSD.org@localhost>.
+#
+#
+# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
+#
+#
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='print -r --'
+  as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='printf %s\n'
+  as_echo_n='printf %s'
+else
+  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+    as_echo_n='/usr/ucb/echo -n'
+  else
+    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+    as_echo_n_body='eval
+      arg=$1;
+      case $arg in #(
+      *"$as_nl"*)
+       expr "X$arg" : "X\\(.*\\)$as_nl";
+       arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+      esac;
+      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+    '
+    export as_echo_n_body
+    as_echo_n='sh -c $as_echo_n_body as_echo'
+  fi
+  export as_echo_body
+  as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" ""       $as_nl"
+
+# Find who we are.  Look in the path if we contain no directory separator.
+as_myself=
+case $0 in #((
+  *[\\/]* ) as_myself=$0 ;;
+  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+  done
+IFS=$as_save_IFS
+
+     ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+  as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there.  '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+# Use a proper internal environment variable to ensure we don't fall
+  # into an infinite loop, continuously re-executing ourselves.
+  if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
+    _as_can_reexec=no; export _as_can_reexec;
+    # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+  *v*x* | *x*v* ) as_opts=-vx ;;
+  *v* ) as_opts=-v ;;
+  *x* ) as_opts=-x ;;
+  * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+as_fn_exit 255
+  fi
+  # We don't want this to propagate to other subprocesses.
+          { _as_can_reexec=; unset _as_can_reexec;}
+if test "x$CONFIG_SHELL" = x; then
+  as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '\${1+\"\$@\"}'='\"\$@\"'
+  setopt NO_GLOB_SUBST
+else
+  case \`(set -o) 2>/dev/null\` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+"
+  as_required="as_fn_return () { (exit \$1); }
+as_fn_success () { as_fn_return 0; }
+as_fn_failure () { as_fn_return 1; }
+as_fn_ret_success () { return 0; }
+as_fn_ret_failure () { return 1; }
+
+exitcode=0
+as_fn_success || { exitcode=1; echo as_fn_success failed.; }
+as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }
+as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }
+as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }
+if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
+
+else
+  exitcode=1; echo positional parameters were not saved.
+fi
+test x\$exitcode = x0 || exit 1
+test -x / || exit 1"
+  as_suggested="  as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
+  as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
+  eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
+  test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1
+test \$(( 1 + 1 )) = 2 || exit 1"
+  if (eval "$as_required") 2>/dev/null; then :
+  as_have_required=yes
+else
+  as_have_required=no
+fi
+  if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then :
+
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_found=false
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  as_found=:
+  case $as_dir in #(
+        /*)
+          for as_base in sh bash ksh sh5; do
+            # Try only shells that exist, to save several forks.
+            as_shell=$as_dir/$as_base
+            if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
+                   { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
+  CONFIG_SHELL=$as_shell as_have_required=yes
+                  if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
+  break 2
+fi
+fi
+          done;;
+       esac
+  as_found=false
+done
+$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
+             { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
+  CONFIG_SHELL=$SHELL as_have_required=yes
+fi; }
+IFS=$as_save_IFS
+
+
+      if test "x$CONFIG_SHELL" != x; then :
+  export CONFIG_SHELL
+             # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+  *v*x* | *x*v* ) as_opts=-vx ;;
+  *v* ) as_opts=-v ;;
+  *x* ) as_opts=-x ;;
+  * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+exit 255
+fi
+
+    if test x$as_have_required = xno; then :
+  $as_echo "$0: This script requires a shell more modern than all"
+  $as_echo "$0: the shells that I found on your system."
+  if test x${ZSH_VERSION+set} = xset ; then
+    $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
+    $as_echo "$0: be upgraded to zsh 4.3.4 or later."
+  else
+    $as_echo "$0: Please tell bug-autoconf%gnu.org@localhost and jlam%NetBSD.org@localhost
+$0: about your system, including any error possibly output
+$0: before this message. Then install a modern shell, or
+$0: manually run the script under such a shell if you do
+$0: have one."
+  fi
+  exit 1
+fi
+fi
+fi
+SHELL=${CONFIG_SHELL-/bin/sh}
+export SHELL
+# Unset more variables known to interfere with behavior of common tools.
+CLICOLOR_FORCE= GREP_OPTIONS=
+unset CLICOLOR_FORCE GREP_OPTIONS
+
+## --------------------- ##
+## M4sh Shell Functions. ##
+## --------------------- ##
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+  { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+  return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+  set +e
+  as_fn_set_status $1
+  exit $1
+} # as_fn_exit
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || eval $as_mkdir_p || {
+    as_dirs=
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+        X"$as_dir" : 'X\(//\)[^/]' \| \
+        X"$as_dir" : 'X\(//\)$' \| \
+        X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)[^/].*/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\).*/{
+           s//\1/
+           q
+         }
+         s/.*/./; q'`
+      test -d "$as_dir" && break
+    done
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+  test -f "$1" && test -x "$1"
+} # as_fn_executable_p
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+  eval 'as_fn_append ()
+  {
+    eval $1+=\$2
+  }'
+else
+  as_fn_append ()
+  {
+    eval $1=\$$1\$2
+  }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+  eval 'as_fn_arith ()
+  {
+    as_val=$(( $* ))
+  }'
+else
+  as_fn_arith ()
+  {
+    as_val=`expr "$@" || test $? -eq 1`
+  }
+fi # as_fn_arith
+
+
+# as_fn_error STATUS ERROR [LINENO LOG_FD]
+# ----------------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with STATUS, using 1 if that was 0.
+as_fn_error ()
+{
+  as_status=$1; test $as_status -eq 0 && as_status=1
+  if test "$4"; then
+    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
+  fi
+  $as_echo "$as_me: error: $2" >&2
+  as_fn_exit $as_status
+} # as_fn_error
+
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+        X"$0" : 'X\(//\)$' \| \
+        X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+           s//\1/
+           q
+         }
+         /^X\/\(\/\/\)$/{
+           s//\1/
+           q
+         }
+         /^X\/\(\/\).*/{
+           s//\1/
+           q
+         }
+         s/.*/./; q'`
+
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+
+  as_lineno_1=$LINENO as_lineno_1a=$LINENO
+  as_lineno_2=$LINENO as_lineno_2a=$LINENO
+  eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" &&
+  test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || {
+  # Blame Lee E. McMahon (1931-1989) for sed's syntax.  :-)
+  sed -n '
+    p
+    /[$]LINENO/=
+  ' <$as_myself |
+    sed '
+      s/[$]LINENO.*/&-/
+      t lineno
+      b
+      :lineno
+      N
+      :loop
+      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
+      t loop
+      s/-\n.*//
+    ' >$as_me.lineno &&
+  chmod +x "$as_me.lineno" ||
+    { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
+
+  # If we had to re-execute with $CONFIG_SHELL, we're ensured to have
+  # already done that, so ensure we don't try to do so again and fall
+  # in an infinite loop.  This has already happened in practice.
+  _as_can_reexec=no; export _as_can_reexec
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensitive to this).
+  . "./$as_me.lineno"
+  # Exit status is that of the last command.
+  exit
+}
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in #(((((
+-n*)
+  case `echo 'xy\c'` in
+  *c*) ECHO_T='        ';;     # ECHO_T is single tab character.
+  xy)  ECHO_C='\c';;
+  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
+       ECHO_T='        ';;
+  esac;;
+*)
+  ECHO_N='-n';;
+esac
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+  rm -f conf$$.dir/conf$$.file
+else
+  rm -f conf$$.dir
+  mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+  if ln -s conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s='ln -s'
+    # ... but there are two gotchas:
+    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+    # In both cases, we have to default to `cp -pR'.
+    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+      as_ln_s='cp -pR'
+  elif ln conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s=ln
+  else
+    as_ln_s='cp -pR'
+  fi
+else
+  as_ln_s='cp -pR'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p='mkdir -p "$as_dir"'
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+test -n "$DJDIR" || exec 7<&0 </dev/null
+exec 6>&1
+
+# Name of the host.
+# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status,
+# so uname gets run too.
+ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
+
+#
+# Initializations.
+#
+ac_default_prefix=/usr/local
+ac_clean_files=
+ac_config_libobj_dir=.
+LIBOBJS=
+cross_compiling=no
+subdirs=
+MFLAGS=
+MAKEFLAGS=
+
+# Identity of this package.
+PACKAGE_NAME='pkgtasks-1'
+PACKAGE_TARNAME='pkgtasks-1'
+PACKAGE_VERSION='1.9'
+PACKAGE_STRING='pkgtasks-1 1.9'
+PACKAGE_BUGREPORT='jlam%NetBSD.org@localhost'
+PACKAGE_URL=''
+
+ac_unique_file="load.subr"
+ac_subst_vars='LTLIBOBJS
+LIBOBJS
+pkgtestsdir
+testsdir
+SED
+HAVE_KYUA_FALSE
+HAVE_KYUA_TRUE
+KYUA
+POSIX_SHELL
+AM_BACKSLASH
+AM_DEFAULT_VERBOSITY
+AM_DEFAULT_V
+AM_V
+am__untar
+am__tar
+AMTAR
+am__leading_dot
+SET_MAKE
+AWK
+mkdir_p
+MKDIR_P
+INSTALL_STRIP_PROGRAM
+STRIP
+install_sh
+MAKEINFO
+AUTOHEADER
+AUTOMAKE
+AUTOCONF
+ACLOCAL
+VERSION
+PACKAGE
+CYGPATH_W
+am__isrc
+INSTALL_DATA
+INSTALL_SCRIPT
+INSTALL_PROGRAM
+target_alias
+host_alias
+build_alias
+LIBS
+ECHO_T
+ECHO_N
+ECHO_C
+DEFS
+mandir
+localedir
+libdir
+psdir
+pdfdir
+dvidir
+htmldir
+infodir
+docdir
+oldincludedir
+includedir
+localstatedir
+sharedstatedir
+sysconfdir
+datadir
+datarootdir
+libexecdir
+sbindir
+bindir
+program_transform_name
+prefix
+exec_prefix
+PACKAGE_URL
+PACKAGE_BUGREPORT
+PACKAGE_STRING
+PACKAGE_VERSION
+PACKAGE_TARNAME
+PACKAGE_NAME
+PATH_SEPARATOR
+SHELL'
+ac_subst_files=''
+ac_user_opts='
+enable_option_checking
+enable_silent_rules
+'
+      ac_precious_vars='build_alias
+host_alias
+target_alias
+POSIX_SHELL'
+
+
+# Initialize some variables set by options.
+ac_init_help=
+ac_init_version=false
+ac_unrecognized_opts=
+ac_unrecognized_sep=
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+cache_file=/dev/null
+exec_prefix=NONE
+no_create=
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+verbose=
+x_includes=NONE
+x_libraries=NONE
+
+# Installation directory options.
+# These are left unexpanded so users can "make install exec_prefix=/foo"
+# and all the variables that are supposed to be based on exec_prefix
+# by default will actually change.
+# Use braces instead of parens because sh, perl, etc. also accept them.
+# (The list follows the same order as the GNU Coding Standards.)
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datarootdir='${prefix}/share'
+datadir='${datarootdir}'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
+infodir='${datarootdir}/info'
+htmldir='${docdir}'
+dvidir='${docdir}'
+pdfdir='${docdir}'
+psdir='${docdir}'
+libdir='${exec_prefix}/lib'
+localedir='${datarootdir}/locale'
+mandir='${datarootdir}/man'
+
+ac_prev=
+ac_dashdash=
+for ac_option
+do
+  # If the previous option needs an argument, assign it.
+  if test -n "$ac_prev"; then
+    eval $ac_prev=\$ac_option
+    ac_prev=
+    continue
+  fi
+
+  case $ac_option in
+  *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
+  *=)   ac_optarg= ;;
+  *)    ac_optarg=yes ;;
+  esac
+
+  # Accept the important Cygnus configure options, so we can diagnose typos.
+
+  case $ac_dashdash$ac_option in
+  --)
+    ac_dashdash=yes ;;
+
+  -bindir | --bindir | --bindi | --bind | --bin | --bi)
+    ac_prev=bindir ;;
+  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+    bindir=$ac_optarg ;;
+
+  -build | --build | --buil | --bui | --bu)
+    ac_prev=build_alias ;;
+  -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+    build_alias=$ac_optarg ;;
+
+  -cache-file | --cache-file | --cache-fil | --cache-fi \
+  | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+    ac_prev=cache_file ;;
+  -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+  | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+    cache_file=$ac_optarg ;;
+
+  --config-cache | -C)
+    cache_file=config.cache ;;
+
+  -datadir | --datadir | --datadi | --datad)
+    ac_prev=datadir ;;
+  -datadir=* | --datadir=* | --datadi=* | --datad=*)
+    datadir=$ac_optarg ;;
+
+  -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \
+  | --dataroo | --dataro | --datar)
+    ac_prev=datarootdir ;;
+  -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \
+  | --dataroot=* | --dataroo=* | --dataro=* | --datar=*)
+    datarootdir=$ac_optarg ;;
+
+  -disable-* | --disable-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid feature name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"enable_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
+        ac_unrecognized_sep=', ';;
+    esac
+    eval enable_$ac_useropt=no ;;
+
+  -docdir | --docdir | --docdi | --doc | --do)
+    ac_prev=docdir ;;
+  -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*)
+    docdir=$ac_optarg ;;
+
+  -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv)
+    ac_prev=dvidir ;;
+  -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)
+    dvidir=$ac_optarg ;;
+
+  -enable-* | --enable-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid feature name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"enable_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
+        ac_unrecognized_sep=', ';;
+    esac
+    eval enable_$ac_useropt=\$ac_optarg ;;
+
+  -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+  | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+  | --exec | --exe | --ex)
+    ac_prev=exec_prefix ;;
+  -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+  | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+  | --exec=* | --exe=* | --ex=*)
+    exec_prefix=$ac_optarg ;;
+
+  -gas | --gas | --ga | --g)
+    # Obsolete; use --with-gas.
+    with_gas=yes ;;
+
+  -help | --help | --hel | --he | -h)
+    ac_init_help=long ;;
+  -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
+    ac_init_help=recursive ;;
+  -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
+    ac_init_help=short ;;
+
+  -host | --host | --hos | --ho)
+    ac_prev=host_alias ;;
+  -host=* | --host=* | --hos=* | --ho=*)
+    host_alias=$ac_optarg ;;
+
+  -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht)
+    ac_prev=htmldir ;;
+  -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \
+  | --ht=*)
+    htmldir=$ac_optarg ;;
+
+  -includedir | --includedir | --includedi | --included | --include \
+  | --includ | --inclu | --incl | --inc)
+    ac_prev=includedir ;;
+  -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+  | --includ=* | --inclu=* | --incl=* | --inc=*)
+    includedir=$ac_optarg ;;
+
+  -infodir | --infodir | --infodi | --infod | --info | --inf)
+    ac_prev=infodir ;;
+  -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+    infodir=$ac_optarg ;;
+
+  -libdir | --libdir | --libdi | --libd)
+    ac_prev=libdir ;;
+  -libdir=* | --libdir=* | --libdi=* | --libd=*)
+    libdir=$ac_optarg ;;
+
+  -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+  | --libexe | --libex | --libe)
+    ac_prev=libexecdir ;;
+  -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+  | --libexe=* | --libex=* | --libe=*)
+    libexecdir=$ac_optarg ;;
+
+  -localedir | --localedir | --localedi | --localed | --locale)
+    ac_prev=localedir ;;
+  -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*)
+    localedir=$ac_optarg ;;
+
+  -localstatedir | --localstatedir | --localstatedi | --localstated \
+  | --localstate | --localstat | --localsta | --localst | --locals)
+    ac_prev=localstatedir ;;
+  -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+  | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*)
+    localstatedir=$ac_optarg ;;
+
+  -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+    ac_prev=mandir ;;
+  -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+    mandir=$ac_optarg ;;
+
+  -nfp | --nfp | --nf)
+    # Obsolete; use --without-fp.
+    with_fp=no ;;
+
+  -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+  | --no-cr | --no-c | -n)
+    no_create=yes ;;
+
+  -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+    no_recursion=yes ;;
+
+  -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+  | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+  | --oldin | --oldi | --old | --ol | --o)
+    ac_prev=oldincludedir ;;
+  -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+  | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+  | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+    oldincludedir=$ac_optarg ;;
+
+  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+    ac_prev=prefix ;;
+  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+    prefix=$ac_optarg ;;
+
+  -program-prefix | --program-prefix | --program-prefi | --program-pref \
+  | --program-pre | --program-pr | --program-p)
+    ac_prev=program_prefix ;;
+  -program-prefix=* | --program-prefix=* | --program-prefi=* \
+  | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+    program_prefix=$ac_optarg ;;
+
+  -program-suffix | --program-suffix | --program-suffi | --program-suff \
+  | --program-suf | --program-su | --program-s)
+    ac_prev=program_suffix ;;
+  -program-suffix=* | --program-suffix=* | --program-suffi=* \
+  | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+    program_suffix=$ac_optarg ;;
+
+  -program-transform-name | --program-transform-name \
+  | --program-transform-nam | --program-transform-na \
+  | --program-transform-n | --program-transform- \
+  | --program-transform | --program-transfor \
+  | --program-transfo | --program-transf \
+  | --program-trans | --program-tran \
+  | --progr-tra | --program-tr | --program-t)
+    ac_prev=program_transform_name ;;
+  -program-transform-name=* | --program-transform-name=* \
+  | --program-transform-nam=* | --program-transform-na=* \
+  | --program-transform-n=* | --program-transform-=* \
+  | --program-transform=* | --program-transfor=* \
+  | --program-transfo=* | --program-transf=* \
+  | --program-trans=* | --program-tran=* \
+  | --progr-tra=* | --program-tr=* | --program-t=*)
+    program_transform_name=$ac_optarg ;;
+
+  -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd)
+    ac_prev=pdfdir ;;
+  -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*)
+    pdfdir=$ac_optarg ;;
+
+  -psdir | --psdir | --psdi | --psd | --ps)
+    ac_prev=psdir ;;
+  -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
+    psdir=$ac_optarg ;;
+
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil)
+    silent=yes ;;
+
+  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+    ac_prev=sbindir ;;
+  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+  | --sbi=* | --sb=*)
+    sbindir=$ac_optarg ;;
+
+  -sharedstatedir | --sharedstatedir | --sharedstatedi \
+  | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+  | --sharedst | --shareds | --shared | --share | --shar \
+  | --sha | --sh)
+    ac_prev=sharedstatedir ;;
+  -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+  | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+  | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+  | --sha=* | --sh=*)
+    sharedstatedir=$ac_optarg ;;
+
+  -site | --site | --sit)
+    ac_prev=site ;;
+  -site=* | --site=* | --sit=*)
+    site=$ac_optarg ;;
+
+  -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+    ac_prev=srcdir ;;
+  -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+    srcdir=$ac_optarg ;;
+
+  -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+  | --syscon | --sysco | --sysc | --sys | --sy)
+    ac_prev=sysconfdir ;;
+  -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+  | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+    sysconfdir=$ac_optarg ;;
+
+  -target | --target | --targe | --targ | --tar | --ta | --t)
+    ac_prev=target_alias ;;
+  -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+    target_alias=$ac_optarg ;;
+
+  -v | -verbose | --verbose | --verbos | --verbo | --verb)
+    verbose=yes ;;
+
+  -version | --version | --versio | --versi | --vers | -V)
+    ac_init_version=: ;;
+
+  -with-* | --with-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid package name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"with_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
+        ac_unrecognized_sep=', ';;
+    esac
+    eval with_$ac_useropt=\$ac_optarg ;;
+
+  -without-* | --without-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid package name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"with_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig"
+        ac_unrecognized_sep=', ';;
+    esac
+    eval with_$ac_useropt=no ;;
+
+  --x)
+    # Obsolete; use --with-x.
+    with_x=yes ;;
+
+  -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+  | --x-incl | --x-inc | --x-in | --x-i)
+    ac_prev=x_includes ;;
+  -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+  | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+    x_includes=$ac_optarg ;;
+
+  -x-libraries | --x-libraries | --x-librarie | --x-librari \
+  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+    ac_prev=x_libraries ;;
+  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+    x_libraries=$ac_optarg ;;
+
+  -*) as_fn_error $? "unrecognized option: \`$ac_option'
+Try \`$0 --help' for more information"
+    ;;
+
+  *=*)
+    ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
+    # Reject names that are not valid shell variable names.
+    case $ac_envvar in #(
+      '' | [0-9]* | *[!_$as_cr_alnum]* )
+      as_fn_error $? "invalid variable name: \`$ac_envvar'" ;;
+    esac
+    eval $ac_envvar=\$ac_optarg
+    export $ac_envvar ;;
+
+  *)
+    # FIXME: should be removed in autoconf 3.0.
+    $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
+    expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
+      $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
+    : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}"
+    ;;
+
+  esac
+done
+
+if test -n "$ac_prev"; then
+  ac_option=--`echo $ac_prev | sed 's/_/-/g'`
+  as_fn_error $? "missing argument to $ac_option"
+fi
+
+if test -n "$ac_unrecognized_opts"; then
+  case $enable_option_checking in
+    no) ;;
+    fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;;
+    *)     $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
+  esac
+fi
+
+# Check all directory arguments for consistency.
+for ac_var in  exec_prefix prefix bindir sbindir libexecdir datarootdir \
+               datadir sysconfdir sharedstatedir localstatedir includedir \
+               oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
+               libdir localedir mandir
+do
+  eval ac_val=\$$ac_var
+  # Remove trailing slashes.
+  case $ac_val in
+    */ )
+      ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
+      eval $ac_var=\$ac_val;;
+  esac
+  # Be sure to have absolute directory names.
+  case $ac_val in
+    [\\/$]* | ?:[\\/]* )  continue;;
+    NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
+  esac
+  as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val"
+done
+
+# There might be people who depend on the old broken behavior: `$host'
+# used to hold the argument of --host etc.
+# FIXME: To remove some day.
+build=$build_alias
+host=$host_alias
+target=$target_alias
+
+# FIXME: To remove some day.
+if test "x$host_alias" != x; then
+  if test "x$build_alias" = x; then
+    cross_compiling=maybe
+  elif test "x$build_alias" != "x$host_alias"; then
+    cross_compiling=yes
+  fi
+fi
+
+ac_tool_prefix=
+test -n "$host_alias" && ac_tool_prefix=$host_alias-
+
+test "$silent" = yes && exec 6>/dev/null
+
+
+ac_pwd=`pwd` && test -n "$ac_pwd" &&
+ac_ls_di=`ls -di .` &&
+ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` ||
+  as_fn_error $? "working directory cannot be determined"
+test "X$ac_ls_di" = "X$ac_pwd_ls_di" ||
+  as_fn_error $? "pwd does not report name of working directory"
+
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+  ac_srcdir_defaulted=yes
+  # Try the directory containing this script, then the parent directory.
+  ac_confdir=`$as_dirname -- "$as_myself" ||
+$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+        X"$as_myself" : 'X\(//\)[^/]' \| \
+        X"$as_myself" : 'X\(//\)$' \| \
+        X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_myself" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)[^/].*/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\).*/{
+           s//\1/
+           q
+         }
+         s/.*/./; q'`
+  srcdir=$ac_confdir
+  if test ! -r "$srcdir/$ac_unique_file"; then
+    srcdir=..
+  fi
+else
+  ac_srcdir_defaulted=no
+fi
+if test ! -r "$srcdir/$ac_unique_file"; then
+  test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
+  as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir"
+fi
+ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
+ac_abs_confdir=`(
+       cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
+       pwd)`
+# When building in place, set srcdir=.
+if test "$ac_abs_confdir" = "$ac_pwd"; then
+  srcdir=.
+fi
+# Remove unnecessary trailing slashes from srcdir.
+# Double slashes in file names in object file debugging info
+# mess up M-x gdb in Emacs.
+case $srcdir in
+*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;;
+esac
+for ac_var in $ac_precious_vars; do
+  eval ac_env_${ac_var}_set=\${${ac_var}+set}
+  eval ac_env_${ac_var}_value=\$${ac_var}
+  eval ac_cv_env_${ac_var}_set=\${${ac_var}+set}
+  eval ac_cv_env_${ac_var}_value=\$${ac_var}
+done
+
+#
+# Report the --help message.
+#
+if test "$ac_init_help" = "long"; then
+  # Omit some internal or obsolete options to make the list less imposing.
+  # This message is too long to be a string in the A/UX 3.1 sh.
+  cat <<_ACEOF
+\`configure' configures pkgtasks-1 1.9 to adapt to many kinds of systems.
+
+Usage: $0 [OPTION]... [VAR=VALUE]...
+
+To assign environment variables (e.g., CC, CFLAGS...), specify them as
+VAR=VALUE.  See below for descriptions of some of the useful variables.
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+  -h, --help              display this help and exit
+      --help=short        display options specific to this package
+      --help=recursive    display the short help of all the included packages
+  -V, --version           display version information and exit
+  -q, --quiet, --silent   do not print \`checking ...' messages
+      --cache-file=FILE   cache test results in FILE [disabled]
+  -C, --config-cache      alias for \`--cache-file=config.cache'
+  -n, --no-create         do not create output files
+      --srcdir=DIR        find the sources in DIR [configure dir or \`..']
+
+Installation directories:
+  --prefix=PREFIX         install architecture-independent files in PREFIX
+                          [$ac_default_prefix]
+  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
+                          [PREFIX]
+
+By default, \`make install' will install all the files in
+\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc.  You can specify
+an installation prefix other than \`$ac_default_prefix' using \`--prefix',
+for instance \`--prefix=\$HOME'.
+
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+  --bindir=DIR            user executables [EPREFIX/bin]
+  --sbindir=DIR           system admin executables [EPREFIX/sbin]
+  --libexecdir=DIR        program executables [EPREFIX/libexec]
+  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
+  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
+  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
+  --libdir=DIR            object code libraries [EPREFIX/lib]
+  --includedir=DIR        C header files [PREFIX/include]
+  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
+  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
+  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
+  --infodir=DIR           info documentation [DATAROOTDIR/info]
+  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
+  --mandir=DIR            man documentation [DATAROOTDIR/man]
+  --docdir=DIR            documentation root [DATAROOTDIR/doc/pkgtasks-1]
+  --htmldir=DIR           html documentation [DOCDIR]
+  --dvidir=DIR            dvi documentation [DOCDIR]
+  --pdfdir=DIR            pdf documentation [DOCDIR]
+  --psdir=DIR             ps documentation [DOCDIR]
+_ACEOF
+
+  cat <<\_ACEOF
+
+Program names:
+  --program-prefix=PREFIX            prepend PREFIX to installed program names
+  --program-suffix=SUFFIX            append SUFFIX to installed program names
+  --program-transform-name=PROGRAM   run sed PROGRAM on installed program names
+_ACEOF
+fi
+
+if test -n "$ac_init_help"; then
+  case $ac_init_help in
+     short | recursive ) echo "Configuration of pkgtasks-1 1.9:";;
+   esac
+  cat <<\_ACEOF
+
+Optional Features:
+  --disable-option-checking  ignore unrecognized --enable/--with options
+  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
+  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
+  --enable-silent-rules   less verbose build output (undo: "make V=1")
+  --disable-silent-rules  verbose build output (undo: "make V=0")
+
+Some influential environment variables:
+  POSIX_SHELL Location of the POSIX shell interpreter to use
+
+Use these variables to override the choices made by `configure' or to help
+it to find libraries and programs with nonstandard names/locations.
+
+Report bugs to <jlam%NetBSD.org@localhost>.
+_ACEOF
+ac_status=$?
+fi
+
+if test "$ac_init_help" = "recursive"; then
+  # If there are subdirs, report their specific --help.
+  for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
+    test -d "$ac_dir" ||
+      { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } ||
+      continue
+    ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+  # A ".." for each directory in $ac_dir_suffix.
+  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+  case $ac_top_builddir_sub in
+  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+  esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+  .)  # We are building in place.
+    ac_srcdir=.
+    ac_top_srcdir=$ac_top_builddir_sub
+    ac_abs_top_srcdir=$ac_pwd ;;
+  [\\/]* | ?:[\\/]* )  # Absolute name.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir
+    ac_abs_top_srcdir=$srcdir ;;
+  *) # Relative name.
+    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_build_prefix$srcdir
+    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+    cd "$ac_dir" || { ac_status=$?; continue; }
+    # Check for guested configure.
+    if test -f "$ac_srcdir/configure.gnu"; then
+      echo &&
+      $SHELL "$ac_srcdir/configure.gnu" --help=recursive
+    elif test -f "$ac_srcdir/configure"; then
+      echo &&
+      $SHELL "$ac_srcdir/configure" --help=recursive
+    else
+      $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
+    fi || ac_status=$?
+    cd "$ac_pwd" || { ac_status=$?; break; }
+  done
+fi
+
+test -n "$ac_init_help" && exit $ac_status
+if $ac_init_version; then
+  cat <<\_ACEOF
+pkgtasks-1 configure 1.9
+generated by GNU Autoconf 2.69
+
+Copyright (C) 2012 Free Software Foundation, Inc.
+This configure script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it.
+_ACEOF
+  exit
+fi
+
+## ------------------------ ##
+## Autoconf initialization. ##
+## ------------------------ ##
+cat >config.log <<_ACEOF
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+
+It was created by pkgtasks-1 $as_me 1.9, which was
+generated by GNU Autoconf 2.69.  Invocation command line was
+
+  $ $0 $@
+
+_ACEOF
+exec 5>>config.log
+{
+cat <<_ASUNAME
+## --------- ##
+## Platform. ##
+## --------- ##
+
+hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null     || echo unknown`
+
+/bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
+/usr/bin/hostinfo      = `(/usr/bin/hostinfo) 2>/dev/null      || echo unknown`
+/bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`
+/bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`
+
+_ASUNAME
+
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    $as_echo "PATH: $as_dir"
+  done
+IFS=$as_save_IFS
+
+} >&5
+
+cat >&5 <<_ACEOF
+
+
+## ----------- ##
+## Core tests. ##
+## ----------- ##
+
+_ACEOF
+
+
+# Keep a trace of the command line.
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Strip out --silent because we don't want to record it for future runs.
+# Also quote any args containing shell meta-characters.
+# Make two passes to allow for proper duplicate-argument suppression.
+ac_configure_args=
+ac_configure_args0=
+ac_configure_args1=
+ac_must_keep_next=false
+for ac_pass in 1 2
+do
+  for ac_arg
+  do
+    case $ac_arg in
+    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
+    -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+    | -silent | --silent | --silen | --sile | --sil)
+      continue ;;
+    *\'*)
+      ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    case $ac_pass in
+    1) as_fn_append ac_configure_args0 " '$ac_arg'" ;;
+    2)
+      as_fn_append ac_configure_args1 " '$ac_arg'"
+      if test $ac_must_keep_next = true; then
+       ac_must_keep_next=false # Got value, back to normal.
+      else
+       case $ac_arg in
+         *=* | --config-cache | -C | -disable-* | --disable-* \
+         | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
+         | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
+         | -with-* | --with-* | -without-* | --without-* | --x)
+           case "$ac_configure_args0 " in
+             "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
+           esac
+           ;;
+         -* ) ac_must_keep_next=true ;;
+       esac
+      fi
+      as_fn_append ac_configure_args " '$ac_arg'"
+      ;;
+    esac
+  done
+done
+{ ac_configure_args0=; unset ac_configure_args0;}
+{ ac_configure_args1=; unset ac_configure_args1;}
+
+# When interrupted or exit'd, cleanup temporary files, and complete
+# config.log.  We remove comments because anyway the quotes in there
+# would cause problems or look ugly.
+# WARNING: Use '\'' to represent an apostrophe within the trap.
+# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
+trap 'exit_status=$?
+  # Save into config.log some information that might help in debugging.
+  {
+    echo
+
+    $as_echo "## ---------------- ##
+## Cache variables. ##
+## ---------------- ##"
+    echo
+    # The following way of writing the cache mishandles newlines in values,
+(
+  for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+      *) { eval $ac_var=; unset $ac_var;} ;;
+      esac ;;
+    esac
+  done
+  (set) 2>&1 |
+    case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
+      sed -n \
+       "s/'\''/'\''\\\\'\'''\''/g;
+         s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p"
+      ;; #(
+    *)
+      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+      ;;
+    esac |
+    sort
+)
+    echo
+
+    $as_echo "## ----------------- ##
+## Output variables. ##
+## ----------------- ##"
+    echo
+    for ac_var in $ac_subst_vars
+    do
+      eval ac_val=\$$ac_var
+      case $ac_val in
+      *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+      esac
+      $as_echo "$ac_var='\''$ac_val'\''"
+    done | sort
+    echo
+
+    if test -n "$ac_subst_files"; then
+      $as_echo "## ------------------- ##
+## File substitutions. ##
+## ------------------- ##"
+      echo
+      for ac_var in $ac_subst_files
+      do
+       eval ac_val=\$$ac_var
+       case $ac_val in
+       *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+       esac
+       $as_echo "$ac_var='\''$ac_val'\''"
+      done | sort
+      echo
+    fi
+
+    if test -s confdefs.h; then
+      $as_echo "## ----------- ##
+## confdefs.h. ##
+## ----------- ##"
+      echo
+      cat confdefs.h
+      echo
+    fi
+    test "$ac_signal" != 0 &&
+      $as_echo "$as_me: caught signal $ac_signal"
+    $as_echo "$as_me: exit $exit_status"
+  } >&5
+  rm -f core *.core core.conftest.* &&
+    rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&
+    exit $exit_status
+' 0
+for ac_signal in 1 2 13 15; do
+  trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal
+done
+ac_signal=0
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -f -r conftest* confdefs.h
+
+$as_echo "/* confdefs.h */" > confdefs.h
+
+# Predefined preprocessor variables.
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_NAME "$PACKAGE_NAME"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION "$PACKAGE_VERSION"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_STRING "$PACKAGE_STRING"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_URL "$PACKAGE_URL"
+_ACEOF
+
+
+# Let the site file select an alternate cache file if it wants to.
+# Prefer an explicitly selected file to automatically selected ones.
+ac_site_file1=NONE
+ac_site_file2=NONE
+if test -n "$CONFIG_SITE"; then
+  # We do not want a PATH search for config.site.
+  case $CONFIG_SITE in #((
+    -*)  ac_site_file1=./$CONFIG_SITE;;
+    */*) ac_site_file1=$CONFIG_SITE;;
+    *)   ac_site_file1=./$CONFIG_SITE;;
+  esac
+elif test "x$prefix" != xNONE; then
+  ac_site_file1=$prefix/share/config.site
+  ac_site_file2=$prefix/etc/config.site
+else
+  ac_site_file1=$ac_default_prefix/share/config.site
+  ac_site_file2=$ac_default_prefix/etc/config.site
+fi
+for ac_site_file in "$ac_site_file1" "$ac_site_file2"
+do
+  test "x$ac_site_file" = xNONE && continue
+  if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
+$as_echo "$as_me: loading site script $ac_site_file" >&6;}
+    sed 's/^/| /' "$ac_site_file" >&5
+    . "$ac_site_file" \
+      || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "failed to load site script $ac_site_file
+See \`config.log' for more details" "$LINENO" 5; }
+  fi
+done
+
+if test -r "$cache_file"; then
+  # Some versions of bash will fail to source /dev/null (special files
+  # actually), so we avoid doing that.  DJGPP emulates it as a regular file.
+  if test /dev/null != "$cache_file" && test -f "$cache_file"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
+$as_echo "$as_me: loading cache $cache_file" >&6;}
+    case $cache_file in
+      [\\/]* | ?:[\\/]* ) . "$cache_file";;
+      *)                      . "./$cache_file";;
+    esac
+  fi
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
+$as_echo "$as_me: creating cache $cache_file" >&6;}
+  >$cache_file
+fi
+
+# Check that the precious variables saved in the cache have kept the same
+# value.
+ac_cache_corrupted=false
+for ac_var in $ac_precious_vars; do
+  eval ac_old_set=\$ac_cv_env_${ac_var}_set
+  eval ac_new_set=\$ac_env_${ac_var}_set
+  eval ac_old_val=\$ac_cv_env_${ac_var}_value
+  eval ac_new_val=\$ac_env_${ac_var}_value
+  case $ac_old_set,$ac_new_set in
+    set,)
+      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,set)
+      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,);;
+    *)
+      if test "x$ac_old_val" != "x$ac_new_val"; then
+       # differences in whitespace do not lead to failure.
+       ac_old_val_w=`echo x $ac_old_val`
+       ac_new_val_w=`echo x $ac_new_val`
+       if test "$ac_old_val_w" != "$ac_new_val_w"; then
+         { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5
+$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
+         ac_cache_corrupted=:
+       else
+         { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
+$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
+         eval $ac_var=\$ac_old_val
+       fi
+       { $as_echo "$as_me:${as_lineno-$LINENO}:   former value:  \`$ac_old_val'" >&5
+$as_echo "$as_me:   former value:  \`$ac_old_val'" >&2;}
+       { $as_echo "$as_me:${as_lineno-$LINENO}:   current value: \`$ac_new_val'" >&5
+$as_echo "$as_me:   current value: \`$ac_new_val'" >&2;}
+      fi;;
+  esac
+  # Pass precious variables to config.status.
+  if test "$ac_new_set" = set; then
+    case $ac_new_val in
+    *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
+    *) ac_arg=$ac_var=$ac_new_val ;;
+    esac
+    case " $ac_configure_args " in
+      *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
+      *) as_fn_append ac_configure_args " '$ac_arg'" ;;
+    esac
+  fi
+done
+if $ac_cache_corrupted; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+  { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
+$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;}
+  as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5
+fi
+## -------------------- ##
+## Main body of script. ##
+## -------------------- ##
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
+
+ac_aux_dir=
+for ac_dir in build-aux "$srcdir"/build-aux; do
+  if test -f "$ac_dir/install-sh"; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install-sh -c"
+    break
+  elif test -f "$ac_dir/install.sh"; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install.sh -c"
+    break
+  elif test -f "$ac_dir/shtool"; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/shtool install -c"
+    break
+  fi
+done
+if test -z "$ac_aux_dir"; then
+  as_fn_error $? "cannot find install-sh, install.sh, or shtool in build-aux \"$srcdir\"/build-aux" "$LINENO" 5
+fi
+
+# These three variables are undocumented and unsupported,
+# and are intended to be withdrawn in a future Autoconf release.
+# They can cause serious problems if a builder's source tree is in a directory
+# whose full name contains unusual characters.
+ac_config_guess="$SHELL $ac_aux_dir/config.guess"  # Please don't use this var.
+ac_config_sub="$SHELL $ac_aux_dir/config.sub"  # Please don't use this var.
+ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.
+
+
+
+ac_config_files="$ac_config_files Makefile"
+
+
+
+am__api_version='1.15'
+
+# Find a good install program.  We prefer a C program (faster),
+# so one script is as good as another.  But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AmigaOS /C/install, which installs bootblocks on floppy discs
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# OS/2's system install, which has a completely different semantic
+# ./install, which can be erroneously created by make from ./install.sh.
+# Reject install programs that cannot install multiple files.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5
+$as_echo_n "checking for a BSD-compatible install... " >&6; }
+if test -z "$INSTALL"; then
+if ${ac_cv_path_install+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    # Account for people who put trailing slashes in PATH elements.
+case $as_dir/ in #((
+  ./ | .// | /[cC]/* | \
+  /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
+  ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \
+  /usr/ucb/* ) ;;
+  *)
+    # OSF1 and SCO ODT 3.0 have their own names for install.
+    # Don't use installbsd from OSF since it installs stuff as root
+    # by default.
+    for ac_prog in ginstall scoinst install; do
+      for ac_exec_ext in '' $ac_executable_extensions; do
+       if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then
+         if test $ac_prog = install &&
+           grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+           # AIX install.  It has an incompatible calling convention.
+           :
+         elif test $ac_prog = install &&
+           grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+           # program-specific install script used by HP pwplus--don't use.
+           :
+         else
+           rm -rf conftest.one conftest.two conftest.dir
+           echo one > conftest.one
+           echo two > conftest.two
+           mkdir conftest.dir
+           if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" &&
+             test -s conftest.one && test -s conftest.two &&
+             test -s conftest.dir/conftest.one &&
+             test -s conftest.dir/conftest.two
+           then
+             ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
+             break 3
+           fi
+         fi
+       fi
+      done
+    done
+    ;;
+esac
+
+  done
+IFS=$as_save_IFS
+
+rm -rf conftest.one conftest.two conftest.dir
+
+fi
+  if test "${ac_cv_path_install+set}" = set; then
+    INSTALL=$ac_cv_path_install
+  else
+    # As a last resort, use the slow shell script.  Don't cache a
+    # value for INSTALL within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the value is a relative name.
+    INSTALL=$ac_install_sh
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5
+$as_echo "$INSTALL" >&6; }
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5
+$as_echo_n "checking whether build environment is sane... " >&6; }
+# Reject unsafe characters in $srcdir or the absolute working directory
+# name.  Accept space and tab only in the latter.
+am_lf='
+'
+case `pwd` in
+  *[\\\"\#\$\&\'\`$am_lf]*)
+    as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5;;
+esac
+case $srcdir in
+  *[\\\"\#\$\&\'\`$am_lf\ \    ]*)
+    as_fn_error $? "unsafe srcdir value: '$srcdir'" "$LINENO" 5;;
+esac
+
+# Do 'set' in a subshell so we don't clobber the current shell's
+# arguments.  Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+   am_has_slept=no
+   for am_try in 1 2; do
+     echo "timestamp, slept: $am_has_slept" > conftest.file
+     set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
+     if test "$*" = "X"; then
+       # -L didn't work.
+       set X `ls -t "$srcdir/configure" conftest.file`
+     fi
+     if test "$*" != "X $srcdir/configure conftest.file" \
+       && test "$*" != "X conftest.file $srcdir/configure"; then
+
+       # If neither matched, then we have a broken ls.  This can happen
+       # if, for instance, CONFIG_SHELL is bash and it inherits a
+       # broken ls alias from the environment.  This has actually
+       # happened.  Such a system could not be considered "sane".
+       as_fn_error $? "ls -t appears to fail.  Make sure there is not a broken
+  alias in your environment" "$LINENO" 5
+     fi
+     if test "$2" = conftest.file || test $am_try -eq 2; then
+       break
+     fi
+     # Just in case.
+     sleep 1
+     am_has_slept=yes
+   done
+   test "$2" = conftest.file
+   )
+then
+   # Ok.
+   :
+else
+   as_fn_error $? "newly created file is older than distributed files!
+Check your system clock" "$LINENO" 5
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+# If we didn't sleep, we still need to ensure time stamps of config.status and
+# generated files are strictly newer.
+am_sleep_pid=
+if grep 'slept: no' conftest.file >/dev/null 2>&1; then
+  ( sleep 1 ) &
+  am_sleep_pid=$!
+fi
+
+rm -f conftest.file
+
+test "$program_prefix" != NONE &&
+  program_transform_name="s&^&$program_prefix&;$program_transform_name"
+# Use a double $ so make ignores it.
+test "$program_suffix" != NONE &&
+  program_transform_name="s&\$&$program_suffix&;$program_transform_name"
+# Double any \ or $.
+# By default was `s,x,x', remove it if useless.
+ac_script='s/[\\$]/&&/g;s/;s,x,x,$//'
+program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"`
+
+# Expand $ac_aux_dir to an absolute path.
+am_aux_dir=`cd "$ac_aux_dir" && pwd`
+
+if test x"${MISSING+set}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\    *)
+    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
+  *)
+    MISSING="\${SHELL} $am_aux_dir/missing" ;;
+  esac
+fi
+# Use eval to expand $SHELL
+if eval "$MISSING --is-lightweight"; then
+  am_missing_run="$MISSING "
+else
+  am_missing_run=
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5
+$as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;}
+fi
+
+if test x"${install_sh+set}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\    *)
+    install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
+  *)
+    install_sh="\${SHELL} $am_aux_dir/install-sh"
+  esac
+fi
+
+# Installed binaries are usually stripped using 'strip' when the user
+# run "make install-strip".  However 'strip' might not be the right
+# tool to use in cross-compilation environments, therefore Automake
+# will honor the 'STRIP' environment variable to overrule this program.
+if test "$cross_compiling" != no; then
+  if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args.
+set dummy ${ac_tool_prefix}strip; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_STRIP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$STRIP"; then
+  ac_cv_prog_STRIP="$STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_STRIP="${ac_tool_prefix}strip"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+STRIP=$ac_cv_prog_STRIP
+if test -n "$STRIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5
+$as_echo "$STRIP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_STRIP"; then
+  ac_ct_STRIP=$STRIP
+  # Extract the first word of "strip", so it can be a program name with args.
+set dummy strip; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_STRIP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_STRIP"; then
+  ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_STRIP="strip"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP
+if test -n "$ac_ct_STRIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5
+$as_echo "$ac_ct_STRIP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_STRIP" = x; then
+    STRIP=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    STRIP=$ac_ct_STRIP
+  fi
+else
+  STRIP="$ac_cv_prog_STRIP"
+fi
+
+fi
+INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5
+$as_echo_n "checking for a thread-safe mkdir -p... " >&6; }
+if test -z "$MKDIR_P"; then
+  if ${ac_cv_path_mkdir+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in mkdir gmkdir; do
+        for ac_exec_ext in '' $ac_executable_extensions; do
+          as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue
+          case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #(
+            'mkdir (GNU coreutils) '* | \
+            'mkdir (coreutils) '* | \
+            'mkdir (fileutils) '4.1*)
+              ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext
+              break 3;;
+          esac
+        done
+       done
+  done
+IFS=$as_save_IFS
+
+fi
+
+  test -d ./--version && rmdir ./--version
+  if test "${ac_cv_path_mkdir+set}" = set; then
+    MKDIR_P="$ac_cv_path_mkdir -p"
+  else
+    # As a last resort, use the slow shell script.  Don't cache a
+    # value for MKDIR_P within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the value is a relative name.
+    MKDIR_P="$ac_install_sh -d"
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5
+$as_echo "$MKDIR_P" >&6; }
+
+for ac_prog in gawk mawk nawk awk
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_AWK+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$AWK"; then
+  ac_cv_prog_AWK="$AWK" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_AWK="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+AWK=$ac_cv_prog_AWK
+if test -n "$AWK"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5
+$as_echo "$AWK" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$AWK" && break
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5
+$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; }
+set x ${MAKE-make}
+ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'`
+if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.make <<\_ACEOF
+SHELL = /bin/sh
+all:
+       @echo '@@@%%%=$(MAKE)=@@@%%%'
+_ACEOF
+# GNU make sometimes prints "make[1]: Entering ...", which would confuse us.
+case `${MAKE-make} -f conftest.make 2>/dev/null` in
+  *@@@%%%=?*=@@@%%%*)
+    eval ac_cv_prog_make_${ac_make}_set=yes;;
+  *)
+    eval ac_cv_prog_make_${ac_make}_set=no;;
+esac
+rm -f conftest.make
+fi
+if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+  SET_MAKE=
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+  SET_MAKE="MAKE=${MAKE-make}"
+fi
+
+rm -rf .tst 2>/dev/null
+mkdir .tst 2>/dev/null
+if test -d .tst; then
+  am__leading_dot=.
+else
+  am__leading_dot=_
+fi
+rmdir .tst 2>/dev/null
+
+# Check whether --enable-silent-rules was given.
+if test "${enable_silent_rules+set}" = set; then :
+  enableval=$enable_silent_rules;
+fi
+
+case $enable_silent_rules in # (((
+  yes) AM_DEFAULT_VERBOSITY=0;;
+   no) AM_DEFAULT_VERBOSITY=1;;
+    *) AM_DEFAULT_VERBOSITY=1;;
+esac
+am_make=${MAKE-make}
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5
+$as_echo_n "checking whether $am_make supports nested variables... " >&6; }
+if ${am_cv_make_support_nested_variables+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if $as_echo 'TRUE=$(BAR$(V))
+BAR0=false
+BAR1=true
+V=1
+am__doit:
+       @$(TRUE)
+.PHONY: am__doit' | $am_make -f - >/dev/null 2>&1; then
+  am_cv_make_support_nested_variables=yes
+else
+  am_cv_make_support_nested_variables=no
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5
+$as_echo "$am_cv_make_support_nested_variables" >&6; }
+if test $am_cv_make_support_nested_variables = yes; then
+    AM_V='$(V)'
+  AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)'
+else
+  AM_V=$AM_DEFAULT_VERBOSITY
+  AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY
+fi
+AM_BACKSLASH='\'
+
+if test "`cd $srcdir && pwd`" != "`pwd`"; then
+  # Use -I$(srcdir) only when $(srcdir) != ., so that make's output
+  # is not polluted with repeated "-I."
+  am__isrc=' -I$(srcdir)'
+  # test to see if srcdir already configured
+  if test -f $srcdir/config.status; then
+    as_fn_error $? "source directory already configured; run \"make distclean\" there first" "$LINENO" 5
+  fi
+fi
+
+# test whether we have cygpath
+if test -z "$CYGPATH_W"; then
+  if (cygpath --version) >/dev/null 2>/dev/null; then
+    CYGPATH_W='cygpath -w'
+  else
+    CYGPATH_W=echo
+  fi
+fi
+
+
+# Define the identity of the package.
+ PACKAGE='pkgtasks-1'
+ VERSION='1.9'
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE "$PACKAGE"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define VERSION "$VERSION"
+_ACEOF
+
+# Some tools Automake needs.
+
+ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"}
+
+
+AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"}
+
+
+AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"}
+
+
+AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"}
+
+
+MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"}
+
+# For better backward compatibility.  To be removed once Automake 1.9.x
+# dies out for good.  For more background, see:
+# <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
+# <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
+mkdir_p='$(MKDIR_P)'
+
+# We need awk for the "check" target (and possibly the TAP driver).  The
+# system "awk" is bad on some platforms.
+# Always define AMTAR for backward compatibility.  Yes, it's still used
+# in the wild :-(  We should find a proper way to deprecate it ...
+AMTAR='$${TAR-tar}'
+
+
+# We'll loop over all known methods to create a tar archive until one works.
+_am_tools='gnutar  pax cpio none'
+
+am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'
+
+
+
+
+
+
+# POSIX will say in a future version that running "rm -f" with no argument
+# is OK; and we want to be able to make that assumption in our Makefile
+# recipes.  So use an aggressive probe to check that the usage we want is
+# actually supported "in the wild" to an acceptable degree.
+# See automake bug#10828.
+# To make any issue more visible, cause the running configure to be aborted
+# by default if the 'rm' program in use doesn't match our expectations; the
+# user can still override this though.
+if rm -f && rm -fr && rm -rf; then : OK; else
+  cat >&2 <<'END'
+Oops!
+
+Your 'rm' program seems unable to run without file operands specified
+on the command line, even when the '-f' option is present.  This is contrary
+to the behaviour of most rm programs out there, and not conforming with
+the upcoming POSIX standard: <http://austingroupbugs.net/view.php?id=542>
+
+Please tell bug-automake%gnu.org@localhost about your system, including the value
+of your $PATH and any error possibly output before this message.  This
+can help us improve future automake versions.
+
+END
+  if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then
+    echo 'Configuration will proceed anyway, since you have set the' >&2
+    echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2
+    echo >&2
+  else
+    cat >&2 <<'END'
+Aborting the configuration process, to ensure you take notice of the issue.
+
+You can download and install GNU coreutils to get an 'rm' implementation
+that behaves properly: <http://www.gnu.org/software/coreutils/>.
+
+If you want to complete the configuration process using your problematic
+'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
+to "yes", and re-run configure.
+
+END
+    as_fn_error $? "Your 'rm' program is bad, sorry." "$LINENO" 5
+  fi
+fi
+
+
+
+
+if test "${POSIX_SHELL}" = ""; then
+       for ac_prog in ksh bash sh
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_POSIX_SHELL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $POSIX_SHELL in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_POSIX_SHELL="$POSIX_SHELL" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_POSIX_SHELL="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+POSIX_SHELL=$ac_cv_path_POSIX_SHELL
+if test -n "$POSIX_SHELL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $POSIX_SHELL" >&5
+$as_echo "$POSIX_SHELL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$POSIX_SHELL" && break
+done
+
+else
+       case ${POSIX_SHELL} in
+       /*)     : "path is an absolute path"
+               ;;
+       *)      as_fn_error $? "POSIX_SHELL must hold an absolute path" "$LINENO" 5
+               ;;
+       esac
+fi
+if test "${POSIX_SHELL}" = ""; then
+       as_fn_error $? "No POSIX shell interpreter found; maybe set POSIX_SHELL?" "$LINENO" 5
+fi
+
+
+# Extract the first word of "kyua", so it can be a program name with args.
+set dummy kyua; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_KYUA+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $KYUA in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_KYUA="$KYUA" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_KYUA="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+KYUA=$ac_cv_path_KYUA
+if test -n "$KYUA"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $KYUA" >&5
+$as_echo "$KYUA" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ if test -n "${KYUA}"; then
+  HAVE_KYUA_TRUE=
+  HAVE_KYUA_FALSE='#'
+else
+  HAVE_KYUA_TRUE='#'
+  HAVE_KYUA_FALSE=
+fi
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5
+$as_echo_n "checking for a sed that does not truncate output... " >&6; }
+if ${ac_cv_path_SED+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+            ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
+     for ac_i in 1 2 3 4 5 6 7; do
+       ac_script="$ac_script$as_nl$ac_script"
+     done
+     echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed
+     { ac_script=; unset ac_script;}
+     if test -z "$SED"; then
+  ac_path_SED_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in sed gsed; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_SED="$as_dir/$ac_prog$ac_exec_ext"
+      as_fn_executable_p "$ac_path_SED" || continue
+# Check for GNU ac_path_SED and select it if it is found.
+  # Check for GNU $ac_path_SED
+case `"$ac_path_SED" --version 2>&1` in
+*GNU*)
+  ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo '' >> "conftest.nl"
+    "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_SED_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_SED="$ac_path_SED"
+      ac_path_SED_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_SED_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_SED"; then
+    as_fn_error $? "no acceptable sed could be found in \$PATH" "$LINENO" 5
+  fi
+else
+  ac_cv_path_SED=$SED
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5
+$as_echo "$ac_cv_path_SED" >&6; }
+ SED="$ac_cv_path_SED"
+  rm -f conftest.sed
+
+
+testsdir='${exec_prefix}/tests'
+
+pkgtestsdir='${testsdir}/$(PACKAGE)'
+
+
+
+cat >confcache <<\_ACEOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems.  If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+_ACEOF
+
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, we kill variables containing newlines.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+(
+  for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+      *) { eval $ac_var=; unset $ac_var;} ;;
+      esac ;;
+    esac
+  done
+
+  (set) 2>&1 |
+    case $as_nl`(ac_space=' '; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
+      # `set' does not quote correctly, so add quotes: double-quote
+      # substitution turns \\\\ into \\, and sed turns \\ into \.
+      sed -n \
+       "s/'/'\\\\''/g;
+         s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
+      ;; #(
+    *)
+      # `set' quotes correctly as required by POSIX, so do not add quotes.
+      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+      ;;
+    esac |
+    sort
+) |
+  sed '
+     /^ac_cv_env_/b end
+     t clear
+     :clear
+     s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
+     t end
+     s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
+     :end' >>confcache
+if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
+  if test -w "$cache_file"; then
+    if test "x$cache_file" != "x/dev/null"; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
+$as_echo "$as_me: updating cache $cache_file" >&6;}
+      if test ! -f "$cache_file" || test -h "$cache_file"; then
+       cat confcache >"$cache_file"
+      else
+        case $cache_file in #(
+        */* | ?:*)
+         mv -f confcache "$cache_file"$$ &&
+         mv -f "$cache_file"$$ "$cache_file" ;; #(
+        *)
+         mv -f confcache "$cache_file" ;;
+       esac
+      fi
+    fi
+  else
+    { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
+$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
+  fi
+fi
+rm -f confcache
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+# Transform confdefs.h into DEFS.
+# Protect against shell expansion while executing Makefile rules.
+# Protect against Makefile macro expansion.
+#
+# If the first sed substitution is executed (which looks for macros that
+# take arguments), then branch to the quote section.  Otherwise,
+# look for a macro that doesn't take arguments.
+ac_script='
+:mline
+/\\$/{
+ N
+ s,\\\n,,
+ b mline
+}
+t clear
+:clear
+s/^[    ]*#[    ]*define[       ][      ]*\([^  (][^    (]*([^)]*)\)[   ]*\(.*\)/-D\1=\2/g
+t quote
+s/^[    ]*#[    ]*define[       ][      ]*\([^  ][^     ]*\)[   ]*\(.*\)/-D\1=\2/g
+t quote
+b any
+:quote
+s/[     `~#$^&*(){}\\|;'\''"<>?]/\\&/g
+s/\[/\\&/g
+s/\]/\\&/g
+s/\$/$$/g
+H
+:any
+${
+       g
+       s/^\n//
+       s/\n/ /g
+       p
+}
+'
+DEFS=`sed -n "$ac_script" confdefs.h`
+
+
+ac_libobjs=
+ac_ltlibobjs=
+U=
+for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
+  # 1. Remove the extension, and $U if already installed.
+  ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
+  ac_i=`$as_echo "$ac_i" | sed "$ac_script"`
+  # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR
+  #    will be set to the directory where LIBOBJS objects are built.
+  as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext"
+  as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo'
+done
+LIBOBJS=$ac_libobjs
+
+LTLIBOBJS=$ac_ltlibobjs
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5
+$as_echo_n "checking that generated files are newer than configure... " >&6; }
+   if test -n "$am_sleep_pid"; then
+     # Hide warnings about reused PIDs.
+     wait $am_sleep_pid 2>/dev/null
+   fi
+   { $as_echo "$as_me:${as_lineno-$LINENO}: result: done" >&5
+$as_echo "done" >&6; }
+
+if test -z "${HAVE_KYUA_TRUE}" && test -z "${HAVE_KYUA_FALSE}"; then
+  as_fn_error $? "conditional \"HAVE_KYUA\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+
+: "${CONFIG_STATUS=./config.status}"
+ac_write_fail=0
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files $CONFIG_STATUS"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
+$as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
+as_write_fail=0
+cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate the current configuration.
+# Compiler output produced by configure, useful for debugging
+# configure, is in config.log if it exists.
+
+debug=false
+ac_cs_recheck=false
+ac_cs_silent=false
+
+SHELL=\${CONFIG_SHELL-$SHELL}
+export SHELL
+_ASEOF
+cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='print -r --'
+  as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='printf %s\n'
+  as_echo_n='printf %s'
+else
+  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+    as_echo_n='/usr/ucb/echo -n'
+  else
+    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+    as_echo_n_body='eval
+      arg=$1;
+      case $arg in #(
+      *"$as_nl"*)
+       expr "X$arg" : "X\\(.*\\)$as_nl";
+       arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+      esac;
+      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+    '
+    export as_echo_n_body
+    as_echo_n='sh -c $as_echo_n_body as_echo'
+  fi
+  export as_echo_body
+  as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" ""       $as_nl"
+
+# Find who we are.  Look in the path if we contain no directory separator.
+as_myself=
+case $0 in #((
+  *[\\/]* ) as_myself=$0 ;;
+  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+  done
+IFS=$as_save_IFS
+
+     ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+  as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there.  '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+
+# as_fn_error STATUS ERROR [LINENO LOG_FD]
+# ----------------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with STATUS, using 1 if that was 0.
+as_fn_error ()
+{
+  as_status=$1; test $as_status -eq 0 && as_status=1
+  if test "$4"; then
+    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
+  fi
+  $as_echo "$as_me: error: $2" >&2
+  as_fn_exit $as_status
+} # as_fn_error
+
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+  return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+  set +e
+  as_fn_set_status $1
+  exit $1
+} # as_fn_exit
+
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+  { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+  eval 'as_fn_append ()
+  {
+    eval $1+=\$2
+  }'
+else
+  as_fn_append ()
+  {
+    eval $1=\$$1\$2
+  }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+  eval 'as_fn_arith ()
+  {
+    as_val=$(( $* ))
+  }'
+else
+  as_fn_arith ()
+  {
+    as_val=`expr "$@" || test $? -eq 1`
+  }
+fi # as_fn_arith
+
+
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+        X"$0" : 'X\(//\)$' \| \
+        X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+           s//\1/
+           q
+         }
+         /^X\/\(\/\/\)$/{
+           s//\1/
+           q
+         }
+         /^X\/\(\/\).*/{
+           s//\1/
+           q
+         }
+         s/.*/./; q'`
+
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in #(((((
+-n*)
+  case `echo 'xy\c'` in
+  *c*) ECHO_T='        ';;     # ECHO_T is single tab character.
+  xy)  ECHO_C='\c';;
+  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
+       ECHO_T='        ';;
+  esac;;
+*)
+  ECHO_N='-n';;
+esac
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+  rm -f conf$$.dir/conf$$.file
+else
+  rm -f conf$$.dir
+  mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+  if ln -s conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s='ln -s'
+    # ... but there are two gotchas:
+    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+    # In both cases, we have to default to `cp -pR'.
+    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+      as_ln_s='cp -pR'
+  elif ln conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s=ln
+  else
+    as_ln_s='cp -pR'
+  fi
+else
+  as_ln_s='cp -pR'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || eval $as_mkdir_p || {
+    as_dirs=
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+        X"$as_dir" : 'X\(//\)[^/]' \| \
+        X"$as_dir" : 'X\(//\)$' \| \
+        X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)[^/].*/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\).*/{
+           s//\1/
+           q
+         }
+         s/.*/./; q'`
+      test -d "$as_dir" && break
+    done
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p='mkdir -p "$as_dir"'
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+  test -f "$1" && test -x "$1"
+} # as_fn_executable_p
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+exec 6>&1
+## ----------------------------------- ##
+## Main body of $CONFIG_STATUS script. ##
+## ----------------------------------- ##
+_ASEOF
+test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# Save the log message, to keep $0 and so on meaningful, and to
+# report actual input values of CONFIG_FILES etc. instead of their
+# values after options handling.
+ac_log="
+This file was extended by pkgtasks-1 $as_me 1.9, which was
+generated by GNU Autoconf 2.69.  Invocation command line was
+
+  CONFIG_FILES    = $CONFIG_FILES
+  CONFIG_HEADERS  = $CONFIG_HEADERS
+  CONFIG_LINKS    = $CONFIG_LINKS
+  CONFIG_COMMANDS = $CONFIG_COMMANDS
+  $ $0 $@
+
+on `(hostname || uname -n) 2>/dev/null | sed 1q`
+"
+
+_ACEOF
+
+case $ac_config_files in *"
+"*) set x $ac_config_files; shift; ac_config_files=$*;;
+esac
+
+
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+# Files that config.status was made for.
+config_files="$ac_config_files"
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+ac_cs_usage="\
+\`$as_me' instantiates files and other configuration actions
+from templates according to the current configuration.  Unless the files
+and actions are specified as TAGs, all are instantiated by default.
+
+Usage: $0 [OPTION]... [TAG]...
+
+  -h, --help       print this help, then exit
+  -V, --version    print version number and configuration settings, then exit
+      --config     print configuration, then exit
+  -q, --quiet, --silent
+                   do not print progress messages
+  -d, --debug      don't remove temporary files
+      --recheck    update $as_me by reconfiguring in the same conditions
+      --file=FILE[:TEMPLATE]
+                   instantiate the configuration file FILE
+
+Configuration files:
+$config_files
+
+Report bugs to <jlam%NetBSD.org@localhost>."
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
+ac_cs_version="\\
+pkgtasks-1 config.status 1.9
+configured by $0, generated by GNU Autoconf 2.69,
+  with options \\"\$ac_cs_config\\"
+
+Copyright (C) 2012 Free Software Foundation, Inc.
+This config.status script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it."
+
+ac_pwd='$ac_pwd'
+srcdir='$srcdir'
+INSTALL='$INSTALL'
+MKDIR_P='$MKDIR_P'
+AWK='$AWK'
+test -n "\$AWK" || AWK=awk
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# The default lists apply if the user does not specify any file.
+ac_need_defaults=:
+while test $# != 0
+do
+  case $1 in
+  --*=?*)
+    ac_option=`expr "X$1" : 'X\([^=]*\)='`
+    ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
+    ac_shift=:
+    ;;
+  --*=)
+    ac_option=`expr "X$1" : 'X\([^=]*\)='`
+    ac_optarg=
+    ac_shift=:
+    ;;
+  *)
+    ac_option=$1
+    ac_optarg=$2
+    ac_shift=shift
+    ;;
+  esac
+
+  case $ac_option in
+  # Handling of the options.
+  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+    ac_cs_recheck=: ;;
+  --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
+    $as_echo "$ac_cs_version"; exit ;;
+  --config | --confi | --conf | --con | --co | --c )
+    $as_echo "$ac_cs_config"; exit ;;
+  --debug | --debu | --deb | --de | --d | -d )
+    debug=: ;;
+  --file | --fil | --fi | --f )
+    $ac_shift
+    case $ac_optarg in
+    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    '') as_fn_error $? "missing file argument" ;;
+    esac
+    as_fn_append CONFIG_FILES " '$ac_optarg'"
+    ac_need_defaults=false;;
+  --he | --h |  --help | --hel | -h )
+    $as_echo "$ac_cs_usage"; exit ;;
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil | --si | --s)
+    ac_cs_silent=: ;;
+
+  # This is an error.
+  -*) as_fn_error $? "unrecognized option: \`$1'
+Try \`$0 --help' for more information." ;;
+
+  *) as_fn_append ac_config_targets " $1"
+     ac_need_defaults=false ;;
+
+  esac
+  shift
+done
+
+ac_configure_extra_args=
+
+if $ac_cs_silent; then
+  exec 6>/dev/null
+  ac_configure_extra_args="$ac_configure_extra_args --silent"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+if \$ac_cs_recheck; then
+  set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+  shift
+  \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
+  CONFIG_SHELL='$SHELL'
+  export CONFIG_SHELL
+  exec "\$@"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+exec 5>>config.log
+{
+  echo
+  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
+## Running $as_me. ##
+_ASBOX
+  $as_echo "$ac_log"
+} >&5
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+
+# Handling of arguments.
+for ac_config_target in $ac_config_targets
+do
+  case $ac_config_target in
+    "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
+
+  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
+  esac
+done
+
+
+# If the user did not use the arguments to specify the items to instantiate,
+# then the envvar interface is used.  Set only those that are not.
+# We use the long form for the default assignment because of an extremely
+# bizarre bug on SunOS 4.1.3.
+if $ac_need_defaults; then
+  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+fi
+
+# Have a temporary directory for convenience.  Make it in the build tree
+# simply because there is no reason against having it here, and in addition,
+# creating and moving files from /tmp can sometimes cause problems.
+# Hook for its removal unless debugging.
+# Note that there is a small window in which the directory will not be cleaned:
+# after its creation but before its name has been assigned to `$tmp'.
+$debug ||
+{
+  tmp= ac_tmp=
+  trap 'exit_status=$?
+  : "${ac_tmp:=$tmp}"
+  { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status
+' 0
+  trap 'as_fn_exit 1' 1 2 13 15
+}
+# Create a (secure) tmp directory for tmp files.
+
+{
+  tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
+  test -d "$tmp"
+}  ||
+{
+  tmp=./conf$$-$RANDOM
+  (umask 077 && mkdir "$tmp")
+} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
+ac_tmp=$tmp
+
+# Set up the scripts for CONFIG_FILES section.
+# No need to generate them if there are no CONFIG_FILES.
+# This happens for instance with `./config.status config.h'.
+if test -n "$CONFIG_FILES"; then
+
+
+ac_cr=`echo X | tr X '\015'`
+# On cygwin, bash can eat \r inside `` if the user requested igncr.
+# But we know of no other shell where ac_cr would be empty at this
+# point, so we can use a bashism as a fallback.
+if test "x$ac_cr" = x; then
+  eval ac_cr=\$\'\\r\'
+fi
+ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' </dev/null 2>/dev/null`
+if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then
+  ac_cs_awk_cr='\\r'
+else
+  ac_cs_awk_cr=$ac_cr
+fi
+
+echo 'BEGIN {' >"$ac_tmp/subs1.awk" &&
+_ACEOF
+
+
+{
+  echo "cat >conf$$subs.awk <<_ACEOF" &&
+  echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' &&
+  echo "_ACEOF"
+} >conf$$subs.sh ||
+  as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'`
+ac_delim='%!_!# '
+for ac_last_try in false false false false false :; do
+  . ./conf$$subs.sh ||
+    as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+
+  ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X`
+  if test $ac_delim_n = $ac_delim_num; then
+    break
+  elif $ac_last_try; then
+    as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+  fi
+done
+rm -f conf$$subs.sh
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK &&
+_ACEOF
+sed -n '
+h
+s/^/S["/; s/!.*/"]=/
+p
+g
+s/^[^!]*!//
+:repl
+t repl
+s/'"$ac_delim"'$//
+t delim
+:nl
+h
+s/\(.\{148\}\)..*/\1/
+t more1
+s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/
+p
+n
+b repl
+:more1
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t nl
+:delim
+h
+s/\(.\{148\}\)..*/\1/
+t more2
+s/["\\]/\\&/g; s/^/"/; s/$/"/
+p
+b
+:more2
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t delim
+' <conf$$subs.awk | sed '
+/^[^""]/{
+  N
+  s/\n//
+}
+' >>$CONFIG_STATUS || ac_write_fail=1
+rm -f conf$$subs.awk
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+_ACAWK
+cat >>"\$ac_tmp/subs1.awk" <<_ACAWK &&
+  for (key in S) S_is_set[key] = 1
+  FS = ""
+
+}
+{
+  line = $ 0
+  nfields = split(line, field, "@")
+  substed = 0
+  len = length(field[1])
+  for (i = 2; i < nfields; i++) {
+    key = field[i]
+    keylen = length(key)
+    if (S_is_set[key]) {
+      value = S[key]
+      line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3)
+      len += length(value) + length(field[++i])
+      substed = 1
+    } else
+      len += 1 + keylen
+  }
+
+  print line
+}
+
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then
+  sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g"
+else
+  cat
+fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \
+  || as_fn_error $? "could not setup config files machinery" "$LINENO" 5
+_ACEOF
+
+# VPATH may cause trouble with some makes, so we remove sole $(srcdir),
+# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and
+# trailing colons and then remove the whole line if VPATH becomes empty
+# (actually we leave an empty line to preserve line numbers).
+if test "x$srcdir" = x.; then
+  ac_vpsub='/^[         ]*VPATH[        ]*=[    ]*/{
+h
+s///
+s/^/:/
+s/[     ]*$/:/
+s/:\$(srcdir):/:/g
+s/:\${srcdir}:/:/g
+s/:@srcdir@:/:/g
+s/^:*//
+s/:*$//
+x
+s/\(=[  ]*\).*/\1/
+G
+s/\n//
+s/^[^=]*=[      ]*$//
+}'
+fi
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+fi # test -n "$CONFIG_FILES"
+
+
+eval set X "  :F $CONFIG_FILES      "
+shift
+for ac_tag
+do
+  case $ac_tag in
+  :[FHLC]) ac_mode=$ac_tag; continue;;
+  esac
+  case $ac_mode$ac_tag in
+  :[FHL]*:*);;
+  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;;
+  :[FH]-) ac_tag=-:-;;
+  :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
+  esac
+  ac_save_IFS=$IFS
+  IFS=:
+  set x $ac_tag
+  IFS=$ac_save_IFS
+  shift
+  ac_file=$1
+  shift
+
+  case $ac_mode in
+  :L) ac_source=$1;;
+  :[FH])
+    ac_file_inputs=
+    for ac_f
+    do
+      case $ac_f in
+      -) ac_f="$ac_tmp/stdin";;
+      *) # Look for the file first in the build tree, then in the source tree
+        # (if the path is not absolute).  The absolute path cannot be DOS-style,
+        # because $ac_f cannot contain `:'.
+        test -f "$ac_f" ||
+          case $ac_f in
+          [\\/$]*) false;;
+          *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
+          esac ||
+          as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
+      esac
+      case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
+      as_fn_append ac_file_inputs " '$ac_f'"
+    done
+
+    # Let's still pretend it is `configure' which instantiates (i.e., don't
+    # use $as_me), people would be surprised to read:
+    #    /* config.h.  Generated by config.status.  */
+    configure_input='Generated from '`
+         $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
+       `' by configure.'
+    if test x"$ac_file" != x-; then
+      configure_input="$ac_file.  $configure_input"
+      { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
+$as_echo "$as_me: creating $ac_file" >&6;}
+    fi
+    # Neutralize special characters interpreted by sed in replacement strings.
+    case $configure_input in #(
+    *\&* | *\|* | *\\* )
+       ac_sed_conf_input=`$as_echo "$configure_input" |
+       sed 's/[\\\\&|]/\\\\&/g'`;; #(
+    *) ac_sed_conf_input=$configure_input;;
+    esac
+
+    case $ac_tag in
+    *:-:* | *:-) cat >"$ac_tmp/stdin" \
+      || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;;
+    esac
+    ;;
+  esac
+
+  ac_dir=`$as_dirname -- "$ac_file" ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+        X"$ac_file" : 'X\(//\)[^/]' \| \
+        X"$ac_file" : 'X\(//\)$' \| \
+        X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$ac_file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)[^/].*/{
+           s//\1/
+           q
+         }
+         /^X\(\/\/\)$/{
+           s//\1/
+           q
+         }
+         /^X\(\/\).*/{
+           s//\1/
+           q
+         }
+         s/.*/./; q'`
+  as_dir="$ac_dir"; as_fn_mkdir_p
+  ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+  # A ".." for each directory in $ac_dir_suffix.
+  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+  case $ac_top_builddir_sub in
+  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+  esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+  .)  # We are building in place.
+    ac_srcdir=.
+    ac_top_srcdir=$ac_top_builddir_sub
+    ac_abs_top_srcdir=$ac_pwd ;;
+  [\\/]* | ?:[\\/]* )  # Absolute name.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir
+    ac_abs_top_srcdir=$srcdir ;;
+  *) # Relative name.
+    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_build_prefix$srcdir
+    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+
+  case $ac_mode in
+  :F)
+  #
+  # CONFIG_FILE
+  #
+
+  case $INSTALL in
+  [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;;
+  *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;;
+  esac
+  ac_MKDIR_P=$MKDIR_P
+  case $MKDIR_P in
+  [\\/$]* | ?:[\\/]* ) ;;
+  */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;;
+  esac
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# If the template does not know about datarootdir, expand it.
+# FIXME: This hack should be removed a few years after 2.60.
+ac_datarootdir_hack=; ac_datarootdir_seen=
+ac_sed_dataroot='
+/datarootdir/ {
+  p
+  q
+}
+/@datadir@/p
+/@docdir@/p
+/@infodir@/p
+/@localedir@/p
+/@mandir@/p'
+case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
+*datarootdir*) ac_datarootdir_seen=yes;;
+*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
+$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+  ac_datarootdir_hack='
+  s&@datadir@&$datadir&g
+  s&@docdir@&$docdir&g
+  s&@infodir@&$infodir&g
+  s&@localedir@&$localedir&g
+  s&@mandir@&$mandir&g
+  s&\\\${datarootdir}&$datarootdir&g' ;;
+esac
+_ACEOF
+
+# Neutralize VPATH when `$srcdir' = `.'.
+# Shell code in configure.ac might set extrasub.
+# FIXME: do we really want to maintain this feature?
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_sed_extra="$ac_vpsub
+$extrasub
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+:t
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+s|@configure_input@|$ac_sed_conf_input|;t t
+s&@top_builddir@&$ac_top_builddir_sub&;t t
+s&@top_build_prefix@&$ac_top_build_prefix&;t t
+s&@srcdir@&$ac_srcdir&;t t
+s&@abs_srcdir@&$ac_abs_srcdir&;t t
+s&@top_srcdir@&$ac_top_srcdir&;t t
+s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t
+s&@builddir@&$ac_builddir&;t t
+s&@abs_builddir@&$ac_abs_builddir&;t t
+s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
+s&@INSTALL@&$ac_INSTALL&;t t
+s&@MKDIR_P@&$ac_MKDIR_P&;t t
+$ac_datarootdir_hack
+"
+eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \
+  >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+
+test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
+  { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } &&
+  { ac_out=`sed -n '/^[         ]*datarootdir[  ]*:*=/p' \
+      "$ac_tmp/out"`; test -z "$ac_out"; } &&
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined" >&5
+$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined" >&2;}
+
+  rm -f "$ac_tmp/stdin"
+  case $ac_file in
+  -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";;
+  *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;
+  esac \
+  || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+ ;;
+
+
+
+  esac
+
+done # for ac_tag
+
+
+as_fn_exit 0
+_ACEOF
+ac_clean_files=$ac_clean_files_save
+
+test $ac_write_fail = 0 ||
+  as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5
+
+
+# configure is writing to config.log, and then calls config.status.
+# config.status does its own redirection, appending to config.log.
+# Unfortunately, on DOS this fails, as config.log is still kept open
+# by configure, so config.status won't be able to write to it; its
+# output is simply discarded.  So we exec the FD to /dev/null,
+# effectively closing config.log, so it can be properly (re)opened and
+# appended to by config.status.  When coming back to configure, we
+# need to make the FD available again.
+if test "$no_create" != yes; then
+  ac_cs_success=:
+  ac_config_status_args=
+  test "$silent" = yes &&
+    ac_config_status_args="$ac_config_status_args --quiet"
+  exec 5>/dev/null
+  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
+  exec 5>>config.log
+  # Use ||, not &&, to avoid exiting from the if with $? = 1, which
+  # would make configure fail if this is the last instruction.
+  $ac_cs_success || as_fn_exit 1
+fi
+if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
+$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
+fi
+
Index: pkgsrc/pkgtools/pkgtasks/files/configure.ac
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/configure.ac:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/configure.ac Thu Jun  1 01:58:34 2017
@@ -0,0 +1,66 @@
+dnl Copyright (c) 2017 The NetBSD Foundation, Inc.
+dnl All rights reserved.
+dnl
+dnl This code is derived from software contributed to The NetBSD Foundation
+dnl by Johnny C. Lam.
+dnl
+dnl Redistribution and use in source and binary forms, with or without
+dnl modification, are permitted provided that the following conditions
+dnl are met:
+dnl 1. Redistributions of source code must retain the above copyright
+dnl    notice, this list of conditions and the following disclaimer.
+dnl 2. Redistributions in binary form must reproduce the above copyright
+dnl    notice, this list of conditions and the following disclaimer in the
+dnl    documentation and/or other materials provided with the distribution.
+dnl
+dnl THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+dnl ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+dnl TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+dnl PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+dnl BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+dnl CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+dnl SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+dnl INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+dnl CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+dnl ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+dnl POSSIBILITY OF SUCH DAMAGE.
+dnl
+
+AC_INIT([pkgtasks-1], [1.9], [jlam%NetBSD.org@localhost])
+
+
+AC_CONFIG_AUX_DIR([build-aux])
+AC_CONFIG_SRCDIR([load.subr])
+AC_CONFIG_FILES([Makefile])
+
+
+AM_INIT_AUTOMAKE([foreign subdir-objects -Wall])
+
+
+AC_ARG_VAR([POSIX_SHELL], [Location of the POSIX shell interpreter to use])
+if test "${POSIX_SHELL}" = ""; then
+       AC_PATH_PROGS(POSIX_SHELL, [ksh bash sh])
+else
+       case ${POSIX_SHELL} in
+       /*)     : "path is an absolute path"
+               ;;
+       *)      AC_MSG_ERROR([POSIX_SHELL must hold an absolute path])
+               ;;
+       esac
+fi
+if test "${POSIX_SHELL}" = ""; then
+       AC_MSG_ERROR([No POSIX shell interpreter found; maybe set POSIX_SHELL?])
+fi
+
+
+AC_PATH_PROG([KYUA], [kyua])
+AM_CONDITIONAL([HAVE_KYUA], [test -n "${KYUA}"])
+
+AC_PROG_MKDIR_P
+AC_PROG_SED
+
+AC_SUBST(testsdir, '${exec_prefix}/tests')
+AC_SUBST(pkgtestsdir, '${testsdir}/$(PACKAGE)')
+
+
+AC_OUTPUT
Index: pkgsrc/pkgtools/pkgtasks/files/createfile.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/createfile.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/createfile.subr      Thu Jun  1 01:58:34 2017
@@ -0,0 +1,76 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      createfile.subr -- create empty files
+#
+# SYNOPSIS
+#      task_createfile [-m mode] <file> ...
+#
+# DESCRIPTION
+#      The task_createfile function creates empty files in the order
+#      specified.
+#
+#      The options are as follows:
+#
+#      -m      Set the permissions of the created file to the specified
+#              mode.
+#
+# RETURN VALUES
+#      Returns 0 on success, and >0 if an error occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      CHMOD   The name or path to the chmod(1) utility.
+#
+
+__task_createfile__="yes"
+
+task_createfile()
+{
+       : ${CHMOD:=chmod}
+
+       local mode=
+       local arg
+       local OPTIND=1
+       while getopts ":m:" arg "$@"; do
+               case $arg in
+               m)      mode=${OPTARG} ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+
+       local file
+       for file; do
+               ( exec > $file ) || return 1
+               if [ -n "$mode" ]; then
+                       ${CHMOD} "$mode" "$file" || return 1
+               fi
+       done
+}
Index: pkgsrc/pkgtools/pkgtasks/files/directories.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/directories.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/directories.subr     Thu Jun  1 01:58:34 2017
@@ -0,0 +1,388 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      directories.subr -- directory management for packages
+#
+# SYNOPSIS
+#      task_directories [-s] add | remove | perms
+#      task_directories check-add | check-remove | check-perms
+#
+# DESCRIPTION
+#      The task_directories function supports six actions: "add", "remove",
+#      "perms", "check-add", "check-remove", and "check-perms".
+#
+#      The available options are as follows:
+#
+#      -s      Silent; don't write to standard output.
+#
+#      The task_directories function reads standard input line by line and
+#      looks for lines of the form:
+#
+#          # DIR: <directory> <flags> [<mode> [<user> [<group>]]]
+#
+#      If directory path is relative, then it is assumed to be relative to
+#      ${PKG_PREFIX}.
+#
+#      The third field in each line is set of flags with the following
+#      meaning:
+#
+#          f   ignore ${PKG_CONFIG} value
+#          m   directory is created
+#          o   directory is owned by the package
+#          .   placeholder flag to ensure the field is non-empty
+#
+#      The "add" action creates the directory and sets the permissions on
+#      the directory if given.  A reference count for the directory will
+#      be added for the package.
+#
+#      The "remove" action removes the directory.  A reference count for
+#      the directory will be removed for the package.
+#
+#      The "perms" action sets the mode and permissions on the directory
+#      if they are given.
+#
+#      The "check-add" action will check whether the directory exists or
+#      otherwise writes a message to standard output noting the missing
+#      directory.
+#
+#      The "check-remove" action will check whether the directory has
+#      been removed or otherwise writes a message to standard output
+#      noting the directory still exist.
+#
+#      The "check-perms" action will check whether the directory has the
+#      correct permissions or otherwise writes a message to standard
+#      output noting the directory has incorrect permissions.
+#
+# RETURN VALUES
+#      The "add", "remove", and "perms" actions return 0 if they are
+#      successful for all directories, and >0 if an error occurs.
+#
+#      The "check-add", "check-remove", and "check-perms" actions return
+#      >0 if they write informative messages, and return 0 otherwise.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      PKGNAME
+#              The name of the package.
+#
+#      PKG_CONFIG
+#              If ${PKG_CONFIG} is a "truthy" value, then the "add" and
+#              "remove" actions are allowed to make changes to the
+#              filesystem as needed.
+#
+#      PKG_CONFIG_PERMS
+#              If ${PKG_CONFIG_PERMS} is a "truthy" value, then the
+#              "perms" action is allowed to make changes to the
+#              filesystem as needed.
+#
+#      PKG_DESTDIR
+#              A "destdir" prefix that is prepended to all filesystem
+#              paths.  The default value is the empty string.
+#
+#      PKG_PREFIX
+#              The installation prefix of the package.  The default is
+#              "/usr/pkg".
+#
+#      RMDIR   The name or path to the rmdir(1) utility.
+#
+#      TASK_MSG
+#              String prepended to all normal message written to
+#              standard output.
+#
+
+__task_directories__="yes"
+
+task_load echo
+task_load makedir
+task_load permissions
+task_load refcount
+task_load truthy
+task_load valid_options
+
+task_directories()
+{
+       : ${RMDIR:=rmdir}
+
+       : ${PKG_PREFIX:=/usr/pkg}
+       : ${PKGNAME:=${0##*/}}
+
+       : ${PKG_CONFIG:=yes}
+       : ${PKG_CONFIG_PERMS:=yes}
+       : ${TASK_MSG:=""}
+
+       local arg
+       local echo="task_echo"
+       local OPTIND=1
+       while getopts ":s" arg "$@"; do
+               case $arg in
+               s)      echo=":" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+
+       local action="$1"; shift
+        case $action in
+       add|remove|perms|check-add|check-remove|check-perms)
+               : "valid actions" ;;
+       *)      return 0 ;;
+       esac
+
+       # Guard against ${PKG_PREFIX} == "/".
+       local prefix
+       case ${PKG_PREFIX}/ in
+       //)     prefix= ;;
+       *)      prefix=${PKG_PREFIX} ;;
+       esac
+
+       local pkg_config="yes"
+       local pkg_config_perms="yes"
+       task_is_truthy "${PKG_CONFIG}" || pkg_config=
+       task_is_truthy "${PKG_CONFIG_PERMS}" || pkg_config_perms=
+
+       local result line_result
+       local msg
+       local owned makedir removedir changes
+       local refcount
+
+       result=0
+       local d_path
+       local hash tag path flags mode user group
+       while read hash tag path flags mode user group; do
+               # Filter for "# DIR:".
+               case $hash/$tag in
+               "#/DIR:")
+                       : "use this line" ;;
+               *)      continue ;;
+               esac
+               task_valid_options "$flags" "fmo." || continue
+
+               # Canonicalize paths.
+               case $path in
+               "")     # skip lines without any required args
+                       continue ;;
+               [!/]*)  path="$prefix/$path" ;;
+               esac
+               d_path="${PKG_DESTDIR}$path"
+
+               msg=
+               case $mode/$user/$group in
+                //)    msg="$d_path" ;;
+               [!/]*//)
+                       msg="$d_path (m=$mode)" ;;
+               [!/]*/[!/]*/)
+                       msg="$d_path (m=$mode, o=$user)" ;;
+               [!/]*/[!/]*/[!/]*)
+                       msg="$d_path (m=$mode, o=$user, g=$group)" ;;
+               esac
+
+               # Set owner values if the directory should be owned by this package.
+               owned=
+               dir_msg="directory"
+               case $flags in
+               *o*)    owned="yes"
+                       dir_msg="owned directory"
+                       if task_refcount prop_exists dirs "$path" owner; then
+                               # previous owner detected
+                               if task_refcount prop_match dirs "$path" owner; then
+                                       : "same owner"
+                               else
+                                       # conflicting owners; failure event
+                                       $echo "${TASK_MSG}! directory owner conflict: $d_path"
+                                       result=1
+                                       continue
+                               fi
+                       fi ;;
+               esac
+
+               makedir=
+               case $flags in
+               *m*)    makedir="seen"
+                       case $flags in
+                       *f*)    # "f" always implies makedir.
+                               makedir="yes" ;;
+                       *)      # otherwise, makedir only if PKG_CONFIG is truthy.
+                               [ -z "$pkg_config" ] || makedir="yes" ;;
+                       esac ;;
+               esac
+
+               removedir=
+               case $flags in
+               *)      removedir="seen"
+                       case $flags in
+                       *f*)    # "f" always implies removedir.
+                               removedir="yes" ;;
+                       *)      # otherwise, removedir only if PKG_CONFIG is truthy.
+                               [ -z "$pkg_config" ] || removedir="yes" ;;
+                       esac ;;
+               esac
+
+               line_result=0
+               changes=
+               case $action in
+               add)    refcount="yes"
+                       task_refcount exists dirs "$path" || refcount=
+                       if task_refcount add dirs "$path"; then
+                               if [ -n "$owned" ]; then
+                                       # Directory is owned by this package.
+                                       if task_refcount prop_put dirs "$path" owner; then
+                                               : "directory owner property added"
+                                       else
+                                               line_result=1
+                                       fi
+                               fi
+                               if [ $line_result -gt 0 ]; then
+                                       : "skip directory creation"
+                               elif [ -d "$d_path" ]; then
+                                       # Directory already exists.
+                                       if [ -z "$refcount" ]; then
+                                               task_refcount prop_put dirs "$path" preexist || line_result=1
+                                       fi
+                                       # Only warn if directory exists if it should be owned.
+                                       if [ -n "$owned" ]; then
+                                               $echo "${TASK_MSG}! $dir_msg already exists: $d_path"
+                                       fi
+                               elif [ -z "$makedir" ]; then
+                                       : "directory is never created"
+                               elif [ "$makedir" = "seen" ]; then
+                                       $echo "${TASK_MSG}! $dir_msg creation skipped: $d_path"
+                               elif task_makedir "$d_path"; then
+                                       $echo "${TASK_MSG}> $dir_msg created: $d_path"
+                                       changes="$changes create"
+                               else
+                                       $echo "${TASK_MSG}! $dir_msg not created: $d_path"
+                                       line_result=1
+                               fi
+                       else
+                               # add refcount failed; skip to next line
+                               $echo "${TASK_MSG}! refcount add failure: directories $path"
+                               result=1
+                               continue
+                       fi ;;
+               check-add)
+                       if [ -d "$d_path" ]; then
+                               : "directory already exists"
+                       elif [ -n "$makedir" ]; then
+                               task_echo "!!! INFO: ${PKGNAME}: Create directory: $msg"
+                               line_result=1
+                       fi ;;
+               esac
+               if [ $line_result -eq 0 ]; then
+                       case $mode/$user/$group in
+                       //)     : "no permissions to set" ;;
+                       *)      case $action in
+                               add|perms)
+                                       task_refcount prop_put dirs "$path" permissions "$mode" "$user" "$group" || line_result=1
+                                       if [ ! -d "$d_path" ]; then
+                                               $echo "${TASK_MSG}! $dir_msg permissions not set on missing: $msg"
+                                               if [ "$makedir" = "yes" ]; then
+                                                       # The directory should have been created; otherwise,
+                                                       # it's an error.
+                                                       #
+                                                       line_result=1
+                                               fi
+                                       elif [ "$action" = "perms" -a -z "$pkg_config_perms" ]; then
+                                               # "perms" action, but PKG_CONFIG_PERMS is not trutyy.
+                                               $echo "${TASK_MSG}! $dir_msg permissions skipped: $msg"
+                                       elif task_set_permissions "$d_path" "$mode" "$user" "$group"; then
+                                               $echo "${TASK_MSG}> $dir_msg permissions set: $msg"
+                                       else
+                                               $echo "${TASK_MSG}! $dir_msg permissions not set: $msg"
+                                               line_result=1
+                                       fi ;;
+                               check-add|check-perms)
+                                       if [ -d "$d_path" ] &&
+                                          task_check_permissions "$d_path" "$mode" "$user" "$group"; then
+                                               : "directory has correct permissions"
+                                       else
+                                               task_echo "!!! INFO: ${PKGNAME}: Set directory permissions: $msg"
+                                               line_result=1
+                                       fi
+                               esac ;;
+                       esac
+               fi
+               if [ $line_result -eq 0 ]; then
+                       case $action in
+                       remove) if task_refcount remove dirs "$path"; then
+                                       if task_refcount exists dirs "$path"; then
+                                               # refcount is not zero
+                                               if [ -n "$owned" ]; then
+                                                       # owned directory has existing references; failure event.
+                                                       $echo "${TASK_MSG}! directory owned but references exist: $path"
+                                                       line_result=1
+                                               fi
+                                       else
+                                               # no more references
+                                               if task_refcount prop_exists dirs "$path" preexist; then
+                                                       : "directory is preexisting"
+                                               elif [ ! -d "$d_path" ]; then
+                                                       : "directory already removed"
+                                               elif [ "$removedir" = "yes" ]; then
+                                                       ${RMDIR} -p "$d_path" 2>/dev/null
+                                               fi
+                                               # Only warn if the directory is owned by the package.
+                                               if [ -n "$owned" ]; then
+                                                       if [ -d "$d_path" ]; then
+                                                               $echo "${TASK_MSG}! $dir_msg not removed: $d_path"
+                                                       else
+                                                               $echo "${TASK_MSG}> $dir_msg removed: $d_path"
+                                                       fi
+                                               fi
+                                               # delete the reference count
+                                               task_refcount delete dirs "$path"
+                                       fi
+                               else
+                                       # remove refcount failed
+                                       $echo "${TASK_MSG}! refcount remove failure: directories $path"
+                                       line_result=1
+                               fi ;;
+                       check-remove)
+                               if task_refcount exists dirs "$path"; then
+                                       : "refcount is not zero"
+                               elif [ ! -d "$d_path" ]; then
+                                       : "directory already removed"
+                               elif [ -n "$removedir" -a -n "$owned" ]; then
+                                       # Only warn if the directory is owned by the package.
+                                       task_echo "!!! INFO: ${PKGNAME}: Remove $dir_msg: $d_path"
+                                       line_result=1
+                               fi
+                       esac
+               fi
+               if [ $line_result -gt 0 ]; then
+                       # Undo changes if there was an error.
+                       case " $changes " in
+                       *" create "*)
+                               ${RMDIR} -p "$d_path" 2>/dev/null ;;
+                       esac
+               fi
+               [ $line_result -eq 0 ] || result=1
+       done
+       return $result
+}
Index: pkgsrc/pkgtools/pkgtasks/files/dirwalk.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/dirwalk.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/dirwalk.subr Thu Jun  1 01:58:34 2017
@@ -0,0 +1,148 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      dirwalk.subr -- walk a directory tree using depth-first traversal
+#
+# SYNOPSIS
+#      task_dirwalk [-d | -f] path
+#
+# DESCRIPTION
+#      The task_dirwalk function walks the filesystem starting at the given
+#      path and outputs the contents using depth-first traversal.
+#
+#      The options are as follows:
+#
+#      -d      Only output the directory entries.
+#
+#      -f      Only output non-directory entries (files, symlinks, etc).
+#
+# RETURN VALUES
+#      Returns 0 on success, and >0 if an error occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      FIND    The name or path to the find(1) utility.
+#
+
+__task_dirwalk__="yes"
+
+task_load quote
+
+task_dirwalk()
+{
+       : ${FIND:=find}
+
+       local output="all"
+       local arg
+       local OPTIND=1
+       while getopts ":df" arg "$@"; do
+               case $arg in
+               d)      case $output in
+                       all)    output="dirs" ;;
+                       *)      return 127 ;;
+                       esac ;;
+               f)      case $output in
+                       all)    output="files" ;;
+                       *)      return 127 ;;
+                       esac ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+
+       [ -e "$1" ] || return 0
+       if [ ! -d "$1" ]; then
+               case $output in
+               files)  echo "$1" ;;
+               esac
+               return 0
+       fi
+
+       # Use find(1) if it is present.
+       case $output in
+       all)    { ${FIND} "$1" -print; } 2>/dev/null ;;
+       dirs)   { ${FIND} "$1" -type d -print; } 2>/dev/null ;;
+       files)  { ${FIND} "$1" \! -type d -print; } 2>/dev/null ;;
+       esac
+       [ $? -gt 0 ] || return 0
+
+       ( cwd=
+         set -- "$1"
+         while [ $# -gt 0 ]; do
+               # Pop the top entry off the front of the stack and print it.
+               top=$1; shift
+               if [ "$top" = "__EOD__" ]; then
+                       cd ..
+                       case $cwd in
+                       */*)    cwd=${cwd%/*} ;;
+                       *)      cwd= ;;
+                       esac
+                       continue
+               fi
+               case $cwd in
+               "")     path=$top ;;
+               *)      path="$cwd/$top" ;;
+               esac
+               case $output in
+               all)    echo "$path" ;;
+               dirs)   if [ ! -h "$top" -a -d "$top" ]; then
+                               echo "$path"
+                       fi ;;
+               files)  if [ ! -h "$top" -a -d "$top" ]; then
+                               : "directory"
+                       else
+                               echo "$path"
+                       fi ;;
+               esac
+
+               # Push all entries in the directory onto the stack.
+               if [ ! -h "$top" -a -d "$top" ]; then
+                       cd "$top" 2>/dev/null || continue
+                       cwd=$path
+                       stack=
+                       # XXX This expansion could break with too many files.
+                       for entry in .* *; do
+                               case $entry in
+                               .|..)   continue ;;
+                               ".*"|"*")
+                                       break ;;
+                               esac
+                               task_quote "$entry"
+                               stack="$stack $quoted"
+                       done
+                       case $stack in
+                       "")     stack="__EOD__" ;;
+                       *)      stack="$stack __EOD__" ;;
+                       esac
+                       task_quote "$@"
+                       eval set -- $stack $quoted
+               fi
+         done )
+}
Index: pkgsrc/pkgtools/pkgtasks/files/echo.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/echo.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/echo.subr    Thu Jun  1 01:58:34 2017
@@ -0,0 +1,113 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      echo.subr -- write to standard output through a buffer
+#
+# SYNOPSIS
+#      task_echo [-bcn] ...
+#
+# DESCRIPTION
+#      The task_echo function provides a buffered output facility.  It
+#      write the contents of the shared buffer to the standard output, then
+#      writes the operands, separated by a single blank character and
+#      followed by a newline character, to the standard output.
+#
+#      The options are as follows:
+#
+#      -b      Write the operands into a shared buffer instead of to the
+#              standard output.
+#
+#      -c      Clear the contents of the shared buffer before writing the
+#              operands.
+#
+#      -n      Do not write the trailing newline character.
+#
+# RETURN VALUES
+#      Returns 0 on success, and >0 if an error occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      TASK_LOGFILE
+#              The location of the log file for appending a duplicate of
+#              the output.  If this variable is unset or empty, then no log
+#              output is written.
+#
+# EXAMPLES
+#      task_echo -bcn "Only write this if there is at least one argument:"
+#      for arg; do
+#              task_echo "    $arg"
+#      done
+#
+
+__task_echo__="yes"
+
+task_load tee
+
+task_echo()
+{
+       : ${TASK_LOGFILE:=}
+
+       local action="echo"
+       local newline="
+"
+       local arg
+       local OPTIND=1
+       while getopts ":bcn" arg "$@"; do
+               case $arg in
+               b)      action="buffer" ;;
+               c)      __task_echo_buffer__= ;;
+               n)      newline= ;;
+               *)      echo 1>&2 "${0##*/}: task_echo: unknown option \`$arg'" ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+
+       case $action in
+       buffer) case $newline in
+               "")     __task_echo_buffer__="$__task_echo_buffer__""$@" ;;
+               *)      __task_echo_buffer__="$__task_echo_buffer__""$@""$newline" ;;
+               esac ;;
+       echo)   case ${TASK_LOGFILE} in
+               "")     case $newline in
+                       "")     echo -n "$__task_echo_buffer__""$@" ;;
+                       *)      echo "$__task_echo_buffer__""$@" ;;
+                       esac ;;
+               *)      case $newline in
+                       "")     echo -n "$__task_echo_buffer__""$@" ;;
+                       *)      echo "$__task_echo_buffer__""$@" ;;
+                       esac | task_tee -a "${TASK_LOGFILE}" ;;
+               esac
+               __task_echo_buffer__= ;;
+
+       esac
+       return 0
+}
+
+# Static variable to hold the buffered output.
+__task_echo_buffer__=
Index: pkgsrc/pkgtools/pkgtasks/files/files.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/files.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/files.subr   Thu Jun  1 01:58:34 2017
@@ -0,0 +1,406 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      files.subr -- config file management for packages
+#
+# SYNOPSIS
+#      task_files [-s] add | remove | perms
+#      task_files check-add | check-remove | check-perms
+#
+# DESCRIPTION
+#      The task_files function supports six actions: "add", "remove",
+#      "perms", "check-add", "check-remove", and "check-perms".
+#
+#      The available options are as follows:
+#
+#      -s      Silent; don't write to standard output.
+#
+#      The task_files function reads standard input line by line and
+#      looks for lines of the form:
+#
+#          # FILE: <target> <flags> <source> [<mode> [<user> [<group>]]]
+#
+#      If the target or source paths are relative, then they are assumed
+#      to be relative to ${PKG_PREFIX}.
+#
+#      The third field in each line is set of flags with the following
+#      meaning:
+#
+#          c   file is copied into place
+#          f   ignore ${PKG_CONFIG} value
+#          r   file is an init script (consider ${PKG_INIT_SCRIPTS})
+#          .   placeholder flag to ensure the field is non-empty
+#
+#      The "add" action copies the source path to the target path if the
+#      target path doesn't exist and sets the permissions on the path if
+#      given.  A reference count for the path will be added for the
+#      package.
+#
+#      The "remove" action removes the target path if it differs from
+#      the source path.  A reference count for the path will be removed
+#      for the package.
+#
+#      The "perms" action sets the mode and permissions on the target if
+#      they are given.
+#
+#      The "check-add" action will check whether the target path exists
+#      or otherwise writes a message to standard output noting the
+#      missing target path.
+#
+#      The "check-remove" action will check whether the target path has
+#      been removed or otherwise writes a message to standard output
+#      noting the target paths still exist.
+#
+#      The "check-perms" action will check whether the target path has
+#      the correct permissions or otherwise writes a message to standard
+#      output noting the target path has incorrect permissions.
+#
+# RETURN VALUES
+#      The "add", "remove", and "perms" actions return 0 if they are
+#      successful for all files, and >0 if an error occurs.
+#
+#      The "check-add", "check-remove", and "check-perms" actions return
+#      >0 if they write informative messages, and return 0 otherwise.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      CP      The name or path to the cp(1) utility.
+#
+#      PKGNAME
+#              The name of the package.
+#
+#      PKG_CONFIG
+#              If ${PKG_CONFIG} is a "truthy" value, then the "add" and
+#              "remove" actions are allowed to make changes to the
+#              filesystem as needed.
+#
+#      PKG_CONFIG_PERMS
+#              If ${PKG_CONFIG_PERMS} is a "truthy" value, then the
+#              "perms" action is allowed to make changes to the
+#              filesystem as needed.
+#
+#      PKG_DESTDIR
+#              A "destdir" prefix that is prepended to all filesystem
+#              paths.  The default value is the empty string.
+#
+#      PKG_INIT_SCRIPTS
+#              If ${PKG_CONFIG} and ${PKG_INIT_SCRIPTS} are both "truthy"
+#              values, then the "add" and "remove" actions are allowed
+#              to copy and remove files that are flagged as init scripts.
+#
+#      PKG_PREFIX
+#              The installation prefix of the package.  The default is
+#              "/usr/pkg".
+#
+#      RM      The name or path to the rm(1) utility.
+#
+#      TASK_MSG
+#              String prepended to all normal message written to
+#              standard output.
+#
+
+__task_files__="yes"
+
+task_load compare
+task_load echo
+task_load permissions
+task_load refcount
+task_load truthy
+task_load valid_options
+
+task_files()
+{
+       : ${CP:=cp}
+       : ${RM:=rm}
+
+       : ${PKG_PREFIX:=/usr/pkg}
+       : ${PKGNAME:=${0##*/}}
+
+       : ${PKG_CONFIG:=yes}
+       : ${PKG_CONFIG_PERMS:=yes}
+       : ${PKG_INIT_SCRIPTS:=yes}
+       : ${TASK_MSG:=""}
+
+       local arg
+       local echo="task_echo"
+       local OPTIND=1
+       while getopts ":s" arg "$@"; do
+               case $arg in
+               s)      echo=":" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+
+       local action="$1"; shift
+        case $action in
+       add|remove|perms|check-add|check-remove|check-perms)
+               : "valid actions" ;;
+       *)      return 0 ;;
+       esac
+
+       # Guard against ${PKG_PREFIX} == "/".
+       local prefix
+       case ${PKG_PREFIX}/ in
+       //)     prefix= ;;
+       *)      prefix=${PKG_PREFIX} ;;
+       esac
+
+       local pkg_config="yes"
+       local pkg_config_perms="yes"
+       local pkg_init_scripts="yes"
+       task_is_truthy "${PKG_CONFIG}" || pkg_config=
+       task_is_truthy "${PKG_CONFIG_PERMS}" || pkg_config_perms=
+       task_is_truthy "${PKG_INIT_SCRIPTS}" || pkg_init_scripts=
+       #
+       # Deprecated: PKG_RCD_SCRIPTS is deprecated, but if it's set, it
+       # overrides ${PKG_INIT_SCRIPTS}.
+       #
+       if [ -n "${PKG_RCD_SCRIPTS}" ]; then
+               if task_is_truthy "${PKG_RCD_SCRIPTS}"; then
+                       pkg_init_scripts="yes"
+               else
+                       pkg_init_scripts=
+               fi
+       fi
+
+       local result line_result
+       local msg
+       local copy remove changes
+       local refcount
+
+       result=0
+       local d_path
+       local hash tag path flags egfile mode user group
+       while read hash tag path flags egfile mode user group; do
+               # Filter for "# FILE:".
+               case $hash/$tag in
+               "#/FILE:")
+                       : "use this line" ;;
+               *)      continue ;;
+               esac
+               task_valid_options "$flags" "cfr." || continue
+
+               # Canonicalize paths.
+               case $path in
+               "")     # skip lines without any required args
+                       continue ;;
+               [!/]*)  path="$prefix/$path" ;;
+               esac
+               d_path="${PKG_DESTDIR}$path"
+               case $egfile in
+               "")     # skip lines without any required args
+                       continue ;;
+               [!/]*)  egfile="$prefix/$egfile" ;;
+               esac
+               egfile="${PKG_DESTDIR}$egfile"
+
+               msg=
+               case $mode/$user/$group in
+                //)     msg="$d_path" ;;
+               [!/]*//)
+                       msg="$d_path (m=$mode)" ;;
+               [!/]*/[!/]*/)
+                       msg="$d_path (m=$mode, o=$user)" ;;
+               [!/]*/[!/]*/[!/]*)
+                       msg="$d_path (m=$mode, o=$user, g=$group)" ;;
+               esac
+
+               copy=
+               case $flags in
+               *c*)    copy="seen"
+                       case $flags in
+                       *f*)    # "f" always implies copy.
+                               copy="yes" ;;
+                       *r*)    # "r" implies copy if PKG_CONFIG and PKG_INIT_SCRIPTS are both truthy.
+                               if [ -n "$pkg_config" -a -n "$pkg_init_scripts" ]; then
+                                       copy="yes"
+                               fi ;;
+                       *)      # otherwise, copy if PKG_CONFIG is truthy.
+                               if [ -n "$pkg_config" ]; then
+                                       copy="yes"
+                               fi ;;
+                       esac ;;
+               esac
+
+               remove=
+               case $flags in
+               *)      remove="seen"
+                       case $flags in
+                       *f*)    # "f" always implies remove.
+                               remove="yes" ;;
+                       *r*)    # "r" implies remove if PKG_CONFIG and PKG_INIT_SCRIPTS are both truthy.
+                               if [ -n "$pkg_config" -a -n "$pkg_init_scripts" ]; then
+                                       remove="yes"
+                               fi ;;
+                       *)      # otherwise, remove if PKG_CONFIG is truthy.
+                               if [ -n "$pkg_config" ]; then
+                                       remove="yes"
+                               fi ;;
+                       esac ;;
+               esac
+
+               line_result=0
+               changes=
+               case $action in
+               add)    refcount="yes"
+                       task_refcount exists files "$path" || refcount=
+                       if task_refcount add files "$path"; then
+                               if [ -f "$d_path" ]; then
+                                       # File already exists.
+                                       if [ -z "$refcount" ]; then
+                                               task_refcount prop_put files "$path" preexist || line_result=1
+                                       fi
+                                       $echo "${TASK_MSG}! file already exists: $d_path"
+                               elif [ -f "$egfile" -o -c "$egfile" ]; then
+                                       # Example file exists.
+                                       if [ -z "$copy" ]; then
+                                               : "file is never copied"
+                                       elif [ "$copy" = "seen" ]; then
+                                               $echo "${TASK_MSG}! file copy skipped: $d_path"
+                                       elif ${CP} "$egfile" "$d_path"; then
+                                               $echo "${TASK_MSG}> file copied: $d_path"
+                                               changes="$changes copy"
+                                       else
+                                               $echo "${TASK_MSG}! file not copied: $d_path"
+                                               line_result=1
+                                       fi
+                               else
+                                       $echo "${TASK_MSG}! file not copied: $d_path"
+                                       line_result=1
+                               fi
+                       else
+                               # add refcount failed; skip to next line
+                               $echo "${TASK_MSG}! refcount add failure: files $path"
+                               result=1
+                               continue
+                       fi ;;
+               check-add)
+                       if [ -f "$d_path" ]; then
+                               : "file already exists"
+                       elif [ -z "$copy" ]; then
+                               : "file is never copied"
+                       elif [ -f "$egfile" -o -c "$egfile" ]; then
+                               task_echo "!!! INFO: ${PKGNAME}: Create file: $msg [$egfile]"
+                               line_result=1
+                       else
+                               task_echo "!!! INFO: ${PKGNAME}: Create file: $msg"
+                               line_result=1
+                       fi ;;
+               esac
+               if [ $line_result -eq 0 ]; then
+                       case $mode/$user/$group in
+                       //)     : "no permissions to set" ;;
+                       *)      case $action in
+                               add|perms)
+                                       task_refcount prop_put files "$path" permissions "$mode" "$user" "$group" || line_result=1
+                                       if [ ! -f "$d_path" ]; then
+                                               $echo "${TASK_MSG}! file permissions not set on missing: $msg"
+                                               if [ "$copy" = "yes" ]; then
+                                                       # The should have been copied; otherwise, it's an error.
+                                                       line_result=1
+                                               fi
+                                       elif [ "$action" = "perms" -a -z "$pkg_config_perms" ]; then
+                                               # "perms" action, but PKG_CONFIG_PERMS is not truthy.
+                                               $echo "${TASK_MSG}! file permissions skipped: $msg"
+                                       elif task_set_permissions "$d_path" "$mode" "$user" "$group"; then
+                                               $echo "${TASK_MSG}> file permissions set: $msg"
+                                       else
+                                               $echo "${TASK_MSG}! file permissions not set: $msg"
+                                               line_result=1
+                                       fi ;;
+                               check-add|check-perms)
+                                       if [ -f "$d_path" ] &&
+                                          task_check_permissions "$d_path" "$mode" "$user" "$group"; then
+                                               : "file has correct permissions"
+                                       else
+                                               task_echo "!!! INFO: ${PKGNAME}: Set file permissions: $msg"
+                                               line_result=1
+                                       fi
+                               esac ;;
+                       esac
+               fi
+               if [ $line_result -eq 0 ]; then
+                       case $action in
+                       remove) if task_refcount remove files "$path"; then
+                                       if task_refcount exists files "$path"; then
+                                               : "refcount is not zero"
+                                       else
+                                               # no more references.
+                                               if task_refcount prop_exists dirs "$path" preexist; then
+                                                       : "file is preexisting"
+                                               elif [ ! -f "$d_path" ]; then
+                                                       : "file already removed"
+                                               elif [ -f "$egfile" -o -c "$egfile" ]; then
+                                                       if task_compare "$d_path" "$egfile"; then
+                                                               if [ "$remove" = "yes" ]; then
+                                                                       if ${RM} -f "$d_path"; then
+                                                                               $echo "${TASK_MSG}> file removed: $d_path"
+                                                                       else
+                                                                               line_result=1
+                                                                       fi
+                                                               fi
+                                                       else
+                                                               $echo "${TASK_MSG}! file differs from default: $d_path"
+                                                       fi
+                                               fi
+                                               if [ -f "$d_path" ]; then
+                                                       $echo "${TASK_MSG}! file not removed: $d_path"
+                                               fi
+                                               # delete the reference count
+                                               task_refcount delete files "$path"
+                                       fi
+                               else
+                                       # remove refcount failed
+                                       $echo "${TASK_MSG}! refcount remove failure: files $path"
+                                       line_result=1
+                               fi ;;
+                       check-remove)
+                               if task_refcount exists files "$path"; then
+                                       : "refcount is not zero"
+                               elif [ ! -f "$d_path" ]; then
+                                       : "file already removed"
+                               elif [ -n "$remove" ]; then
+                                       task_echo "!!! INFO: ${PKGNAME}: Remove file: $d_path"
+                                       line_result=1
+                               fi
+                       esac
+               fi
+               if [ $line_result -gt 0 ]; then
+                       # Undo changes if there was an error.
+                       case " $changes " in
+                       *" copy "*)
+                               ${RM} -f "$d_path" ;;
+                       esac
+               fi
+               [ $line_result -eq 0 ] || result=1
+       done
+       return $result
+}
Index: pkgsrc/pkgtools/pkgtasks/files/fonts.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/fonts.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/fonts.subr   Thu Jun  1 01:58:34 2017
@@ -0,0 +1,431 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      fonts.subr -- X11 font directory management for packages
+#
+# SYNOPSIS
+#      task_fonts [-s] add | remove
+#
+# DESCRIPTION
+#      The task_fonts function supports two actions: "add" and "remove".
+#
+#      The available options are as follows:
+#
+#      -s      Silent; don't write to standard output.
+#
+#      The task_fonts function reads standard input line by line and
+#      looks for lines of the form:
+#
+#          # FONTS: <fontdir> <fonttype> [<encodings_dir>]
+#
+#      <encodings_dir> is an optional argument containing the location
+#      to the X11 font encoding information files and is used for the
+#      "x11" font type.
+#
+#      If any of the paths are relative, then it is assumed to be
+#      relative to ${PKG_PREFIX}.
+#
+#      Both the "add" and "remove" actions regenerate the index files
+#      for X11 fonts directories.
+#
+# RETURN VALUES
+#      Returns 0 if reindexing is successful for all font directories,
+#      and >0 if an error occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      MKFONTDIR
+#              The name or path to the mkfontdir(1) utility.
+#
+#      MKFONTSCALE
+#              The name or path to the mkfontscale(1) utility.
+#
+#      PKGNAME
+#              The name of the package.
+#
+#      PKG_DESTDIR
+#              A "destdir" prefix that is prepended to all filesystem
+#              paths.  The default value is the empty string.
+#
+#      PKG_PREFIX
+#              The installation prefix of the package.  The default is
+#              "/usr/pkg".
+#
+#      PKG_UPDATE_FONTS_DB
+#              If ${PKG_UPDATE_FONTS_DB} is a "truthy" value, then the
+#              "add" and "remove" actions are allowed to update the font
+#              indices files.
+#
+#      RM      The name or path to the rm(1) utility.
+#
+#      RMDIR   The name or path to the rmdir(1) utility.
+#
+#      TASK_MSG
+#              String prepended to all normal message written to
+#              standard output.
+#
+#      TTMKFDIR
+#              The name or path to the ttmkfdir(1) utility.
+#
+#      X11_ENCODINGSDIR
+#              The directory containing font-encoding information files.
+#
+
+__task_fonts__="yes"
+__task_fonts_init__="_task_fonts_init"
+
+task_load cleanup
+task_load echo
+task_load dirwalk
+task_load quote
+task_load truthy
+task_load which
+
+task_fonts()
+{
+       : ${PKG_PREFIX:=/usr/pkg}
+       : ${PKGNAME:=${0##*/}}
+
+       : ${PKG_UPDATE_FONTS_DB:=yes}
+       : ${TASK_MSG:=""}
+
+       local arg
+       local echo="task_echo"
+       local silent=
+       local OPTIND=1
+       while getopts ":s" arg "$@"; do
+               case $arg in
+               s)      echo=":"; silent="-s" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+
+       local action="$1"; shift
+       case $action in
+       add|remove)
+               : "valid actions" ;;
+       *)      return 0 ;;
+       esac
+
+       # Skip actions if ${PKG_UPDATE_FONTS_DB} isn't truthy.
+       local update_fonts="yes"
+       task_is_truthy "${PKG_UPDATE_FONTS_DB}" || update_fonts=
+
+       # Guard against ${PKG_PREFIX} == "/".
+       local prefix
+       case ${PKG_PREFIX}/ in
+       //)     prefix= ;;
+       *)      prefix=${PKG_PREFIX} ;;
+       esac
+
+       local result line_result
+       local quoted
+
+       result=0
+       local hash tag fontdir fonttype
+       while read hash tag fontdir fonttype encodings_dir; do
+               # Filter for "# FONTS:".
+               case $hash/$tag in
+               "#/FONTS:")
+                       : "use this line" ;;
+               *)      continue ;;
+               esac
+               case $fonttype in
+               "")     # skip lines without required args
+                       continue ;;
+               esac
+               # Canonicalize paths.
+               case $fontdir in
+               "")     # skip lines without required args
+                       continue ;;
+               [!/]*)  fontdir="$prefix/$fontdir" ;;
+               esac
+               fontdir="${PKG_DESTDIR}$fontdir"
+               case $encodings_dir in
+               "")     encodings_dir=${X11_ENCODINGSDIR} ;;
+               [!/]*)  encodings_dir="$prefix/$encodings_dir" ;;
+               esac
+               encodings_dir="${PKG_DESTDIR}$encodings_dir"
+
+               if [ ! -d "$fontdir" ]; then
+                       $echo "${TASK_MSG}! fonts directory missing: $fontdir"
+                       result=1
+                       continue
+               fi
+
+               task_quote "$fontdir"
+               __task_fonts_dirs__="$__task_fonts_dirs__ $quoted"
+
+               line_result=0
+
+               # Generate font index for the directory.
+               if [ -n "$update_fonts" ]; then
+                       case $fonttype in
+                       [Tt][Tt][Ff])
+                               _task_fonts_index_ttf $silent "$fontdir" || line_result=1 ;;
+                       [Tt][Yy][Pp][Ee]1)
+                               _task_fonts_index_type1 $silent "$fontdir" || line_result=1 ;;
+                       [Xx]11)
+                               _task_fonts_index_x11 $silent "$fontdir" "$encodings_dir" || line_result=1 ;;
+                       esac
+               fi
+               if [ -n "$update_fonts" -a $line_result -eq 0 ]; then
+                       $echo "${TASK_MSG}> fonts index rebuilt: $fontdir"
+               else
+                       $echo "${TASK_MSG}! fonts index not rebuilt: $fontdir"
+               fi
+
+               [ $line_result -eq 0 ] || result=1
+       done
+
+       _task_fonts_cleanup $silent
+       return $result
+}
+
+_task_fonts_index_ttf()
+{
+       : ${MKFONTSCALE:=mkfontscale}
+       : ${TTMKFDIR:=ttmkfdir}
+
+       : ${TASK_MSG:=""}
+
+       local arg
+       local echo="task_echo"
+       local silent=
+       local OPTIND=1
+       while getopts ":s" arg "$@"; do
+               case $arg in
+               s)      echo=":"; silent="-s" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+
+       local fontdir="$1"; shift
+       local command=
+
+       # Cache mkfontscale(1) location.
+       if [ -z "$__task_fonts_mkfontscale__" ]; then
+               __task_fonts_mkfontscale__=$( task_which "${MKFONTSCALE}" )
+               [ -n "$__task_fonts_mkfontscale__" ] ||
+                       __task_fonts_mkfontscale__="missing"
+       fi
+       if [ "$__task_fonts_mkfontscale__" != "missing" ]; then
+               command=$__task_fonts_mkfontscale__
+       else
+               # Cache ttmkfdir(1) location.
+               if [ -z "$__task_fonts_ttmkfdir__" ]; then
+                       __task_fonts_ttmkfdir__=$( task_which "${TTMKFDIR}" )
+                       [ -n "$__task_fonts_ttmkfdir__" ] ||
+                               __task_fonts_ttmkfdir__="missing"
+               fi
+               if [ "$__task_fonts_ttmkfdir__" != "missing" ]; then
+                       command=$__task_fonts_ttmkfdir__
+               elif [ -n "${MKFONTSCALE}" ]; then
+                       command=${MKFONTSCALE}
+               elif [ -n "${TTMKFDIR}" ]; then
+                       command=${TTMKFDIR}
+               else
+                       $echo "${TASK_MSG}! ttf-indexing command missing"
+                       return 1
+               fi
+       fi
+       ( cd "$fontdir" && $command >/dev/null )
+       # TTF font directories also require X11 indexing.
+       _task_fonts_index_x11 $silent "$fontdir"
+       return 0
+}
+
+_task_fonts_index_type1()
+{
+       : ${MKFONTSCALE:=mkfontscale}
+       : ${TYPE1INST:=type1inst}
+
+       : ${TASK_MSG:=""}
+
+       local arg
+       local echo="task_echo"
+       local silent=
+       local OPTIND=1
+       while getopts ":s" arg "$@"; do
+               case $arg in
+               s)      echo=":"; silent="-s" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+
+       local fontdir="$1"; shift
+       local command=
+
+       # Cache mkfontscale(1) location.
+       if [ -z "$__task_fonts_mkfontscale__" ]; then
+               __task_fonts_mkfontscale__=$( task_which "${MKFONTSCALE}" )
+               [ -n "$__task_fonts_mkfontscale__" ] ||
+                       __task_fonts_mkfontscale__="missing"
+       fi
+       if [ "$__task_fonts_mkfontscale__" != "missing" ]; then
+               command=$__task_fonts_mkfontscale__
+       else
+               # Cache type1inst(1) location.
+               if [ -z "$__task_fonts_type1inst__" ]; then
+                       __task_fonts_type1inst__=$( task_which "${TYPE1INST}" )
+                       [ -n "$__task_fonts_type1inst__" ] ||
+                               __task_fonts_type1inst__="missing"
+               fi
+               if [ "$__task_fonts_type1inst__" != "missing" ]; then
+                       command=$__task_fonts_type1inst__
+               elif [ -n "${MKFONTSCALE}" ]; then
+                       command=${MKFONTSCALE}
+               elif [ -n "${TYPE1INST}" ]; then
+                       command=${TTMKFDIR}
+               else
+                       $echo "${TASK_MSG}! type1-indexing command missing"
+                       return 1
+               fi
+       fi
+       ( cd "$fontdir" && $command >/dev/null )
+       # Type1 font directories also require X11 indexing.
+       _task_fonts_index_x11 $silent "$fontdir"
+       return 0
+}
+
+_task_fonts_index_x11()
+{
+       : ${MKFONTDIR:=mkfontdir}
+
+       : ${TASK_MSG:=""}
+
+       local arg
+       local echo="task_echo"
+       local OPTIND=1
+       while getopts ":s" arg "$@"; do
+               case $arg in
+               s)      echo=":"; ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+
+       local fontdir="$1"; shift
+       local encodings_dir="$1"
+       local command=
+
+       # Cache mkfontdir(1) location.
+       if [ -z "$__task_fonts_mkfontdir__" ]; then
+               __task_fonts_mkfontdir__=$( task_which "${MKFONTDIR}" )
+               [ -n "$__task_fonts_mkfontdir__" ] ||
+                       __task_fonts_mkfontdir__="missing"
+       fi
+       if [ "$__task_fonts_mkfontdir__" != "missing" ]; then
+               command=$__task_fonts_mkfontdir__
+       elif [ -n "${MKFONTDIR}" ]; then
+               command=${MKFONTDIR}
+       else
+               $echo "${TASK_MSG}! x11-indexing command missing"
+               return 1
+       fi
+       if [ -n "$encodings_dir" ]; then
+               ( cd "$fontdir" && $command -e "$encodings_dir" >/dev/null )
+       else
+               ( cd "$fontdir" && $command >/dev/null )
+       fi
+       return 0
+}
+
+_task_fonts_cleanup()
+{
+       : ${RM:=rm}
+       : ${RMDIR:=rmdir}
+
+       : ${TASK_MSG:=""}
+
+       local arg
+       local echo="task_echo"
+       local OPTIND=1
+       while getopts ":s" arg "$@"; do
+               case $arg in
+               s)      echo=":"; ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+
+       eval set -- $__task_fonts_dirs__
+       local fontdir
+       for fontdir; do
+               [ -d "$fontdir" ] || continue
+               # Remove log file from Type1 font scaling.
+               [ ! -f "$fontdir/type1inst.log" ] ||
+                       ${RM} -f "$fontdir/type1inst.log"
+               # Remove directories that have no font files remaining.
+               task_dirwalk -f "$fontdir" |
+               while IFS= read fontfile; do
+                       case $fontfile in
+                       */encodings.dir|*/fonts.dir|*/fonts.scale|*/Fontmap*)
+                               : "skip index files" ;;
+                       *)      # font found
+                               return 0 ;;
+                       esac
+                       # no fonts found
+                       return 1
+               done
+               if [ $? -gt 0 ]; then
+                       ${RM} -f \
+                               "$fontdir/encodings.dir" \
+                               "$fontdir/fonts.dir" \
+                               "$fontdir/fonts.scale" \
+                               "$fontdir/Fontmap"*
+                       ${RMDIR} -p "$fontdir" 2>/dev/null
+                       $echo "${TASK_MSG}> empty fonts directory removed: $fontdir"
+               fi
+       done
+       __task_fonts_dirs__=
+}
+
+_task_fonts_init()
+{
+       task_cleanup_add_hook _task_fonts_cleanup
+}
+
+# Static variable for directories that should be pruned if they are empty
+# if an error occors.
+#
+__task_fonts_dirs__=
+
+# Static variables for the paths to indexing utilities.
+__task_fonts_mkfontdir__=
+__task_fonts_mkfontscale__=
+__task_fonts_ttmkfdir__=
+__task_fonts_type1inst__=
Index: pkgsrc/pkgtools/pkgtasks/files/groups.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/groups.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/groups.subr  Thu Jun  1 01:58:34 2017
@@ -0,0 +1,240 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      groups.subr -- group management for packages
+#
+# SYNOPSIS
+#      task_groups [-s] add | remove
+#      task_groups check-add | check-remove
+#
+# DESCRIPTION
+#      The task_groups function supports four actions: "add", "remove",
+#      "check-add", and "check-remove".
+#
+#      The available options are as follows:
+#
+#      -s      Silent; don't write to standard output.
+#
+#      The task_groups function reads standard input line by line and
+#      looks for lines of the form:
+#
+#          # GROUP: <name>[:<groupid>]
+#
+#      Only the group is required; the groupid is optional.
+#
+#      The "add" action creates the group with the given name if it is
+#      missing, with the given group ID, if ${PKG_CREATE_USERGROUP} is
+#      "yes".  A reference count for the group will be error for the
+#      package.
+#
+#      The "remove" action removes a reference count for the group by
+#      the package.  This function shall not remove any group on the
+#      system.
+#
+#      The "check-add" action will check whether the groups exist with
+#      the optional group IDs if they are given, or otherwise writes a
+#      message to standard output noting the missing groups.
+#
+#      The "check-remove" action will check whether the groups have been
+#      removed, or otherwise writes a message to standard output noting
+#      the groups still exists.
+#
+# RETURN VALUES
+#      The "add" and "remove" actions return 0 if they are successful
+#      for all groups, and >0 if an error occurs.
+#
+#      The "check-add" and "check-remove" actions return >0 if they
+#      write informative messages, and return 0 otherwise.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      PKGNAME
+#              The name of the package.
+#
+#      PKG_CREATE_USERGROUP
+#              If ${PKG_CREATE_USERGROUP} is a "truthy" value, then the
+#              "add" and "remove" actions are allowed to create and
+#              remove groups from the system.
+#
+#      TASK_MSG
+#              String prepended to all normal message written to
+#              standard output.
+#
+
+__task_groups__="yes"
+__task_groups_init__="_task_groups_init"
+
+task_load cleanup
+task_load echo
+task_load quote
+task_load refcount
+task_load truthy
+task_load usergroup
+task_load usergroup_exists
+
+task_groups()
+{
+       : ${PKGNAME:=${0##*/}}
+       : ${PKG_CREATE_USERGROUP:=yes}
+       : ${TASK_MSG:=""}
+
+       local arg
+       local echo="task_echo"
+       local OPTIND=1
+       while getopts ":s" arg "$@"; do
+               case $arg in
+               s)      echo=":" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+
+       local action="$1"; shift
+       case $action in
+       add|remove|check-add|check-remove)
+               : "valid action" ;;
+       *)      return 0 ;;
+       esac
+
+       local create="yes"
+       task_is_truthy "${PKG_CREATE_USERGROUP}" || create=
+
+       local result line_result
+       local save_IFS group gid msg
+
+       result=0
+       local hash tag entry
+       while read hash tag entry; do
+               # Filter for "# GROUP:".
+               case $hash/$tag in
+               "#/GROUP:")
+                       : "use this line" ;;
+               *)      continue ;;
+               esac
+
+               save_IFS=$IFS; IFS=:
+               set -o noglob; set -- $entry; set +o noglob
+               group=$1; gid=$2
+               IFS=$save_IFS
+               [ -n "$group" ] || continue
+
+               if [ -n "$gid" ]; then
+                       msg="$group (gid = $gid)"
+               else
+                       msg="$group"
+               fi
+
+               line_result=0
+               case $action in
+               add)    if task_refcount add groups "$group"; then
+                               task_group_exists "$group" "$gid"
+                               case $? in
+                               0)      # $group exists and has gid $gid
+                                       $echo "${TASK_MSG}! group already exists: $msg" ;;
+                               1)      # neither $group nor $gid exist
+                                       if [ -z "$create" ]; then
+                                               $echo "${TASK_MSG}! group creation skipped: $msg"
+                                       elif task_addgroup "$group" "$gid"; then
+                                               $echo "${TASK_MSG}> group created: $msg"
+                                               # Keep track of groups added in case of error later.
+                                               task_quote "$group"
+                                               __task_groups_error__="$__task_groups_error__ $_quoted"
+                                       else
+                                               $echo "${TASK_MSG}! group not created: $msg"
+                                               line_result=1
+                                       fi ;;
+                               2)      $echo "${TASK_MSG}! group conflict: $msg"
+                                       result=1
+                                       break ;;
+                               *)      $echo "${TASK_MSG}! group not created: $msg"
+                                       line_result=1 ;;
+                               esac
+                       else
+                               # add refcount failed; skip to next line
+                               $echo "${TASK_MSG}! refcount add failure: groups $msg"
+                               result=1
+                               continue
+                       fi ;;
+               remove) if task_refcount remove groups "$group"; then
+                               if task_refcount exists groups "$group"; then
+                                       : "refcount is not zero"
+                               else
+                                       # delete the reference count
+                                       task_refcount delete groups "$group"
+                               fi
+                       else
+                               # remove refcount failed
+                               $echo "${TASK_MSG}! refcount remove failure: groups $msg"
+                               line_result=1
+                       fi ;;
+               check-add)
+                       if task_group_exists "$group" "$gid"; then
+                               : "group already exists"
+                       else
+                               task_echo "!!! INFO: ${PKGNAME}: Create group: $msg"
+                               line_result=1
+                       fi ;;
+               check-remove)
+                       if task_group_exists "$group" "$gid"; then
+                               task_echo "!!! INFO: ${PKGNAME}: Remove group if unused: $group"
+                               line_result=1
+                       fi ;;
+               esac
+               [ $line_result -eq 0 ] || result=1
+       done
+
+       # Clear groups to remove in case of error if all groups added
+       # successfully.
+       #
+       [ $result -gt 0 ] || __task_groups_error__=
+
+       return $result
+}
+
+
+_task_groups_cleanup()
+{
+       eval set -- $__task_groups_error__
+       local group
+       for group; do
+               if task_group_exists "$group"; then
+                       task_echo "!!! ERROR: ${PKGNAME}: Group created before error: $group"
+               fi
+       done
+       __task_groups_error__=
+}
+
+_task_groups_init()
+{
+       task_cleanup_add_hook _task_groups_cleanup
+}
+
+# Static variable for groups that should be removed if an error occurs.
+__task_groups_error__=
Index: pkgsrc/pkgtools/pkgtasks/files/info_files.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/info_files.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/info_files.subr      Thu Jun  1 01:58:34 2017
@@ -0,0 +1,248 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      info_files.subr -- GNU info file management for packages
+#
+# SYNOPSIS
+#      task_info_files [-s] add | remove
+#
+# DESCRIPTION
+#      The task_info_files function supports two actions, "add" and
+#      "remove", that will add or remove entries from GNU info files
+#      from index files (the "dir" file in the same diretory as the info
+#      files).
+#
+#      The available options are as follows:
+#
+#      -s      Silent; don't write to standard output.
+#
+#      The task_info_files function reads standard input line by line and
+#      looks for lines of the form:
+#
+#          # INFO: <file> [<infodir>]
+#
+#      If any of the paths to the file or infodir are relative, then they
+#      are assumed to be relative to ${PKG_PREFIX}.
+#
+# RETURN VALUES
+#      Returns 0 if the action is successful for all info files, and >0
+#      if an error occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      INSTALL_INFO
+#              The name or path to the install-info(1) utility that can
+#              add or remove GNU info files from index files.
+#
+#      PKGNAME
+#              The name of the package.
+#
+#      PKG_DESTDIR
+#              A "destdir" prefix that is prepended to all filesystem
+#              paths.  The default value is the empty string.
+#
+#      PKG_PREFIX
+#              The installation prefix of the package.  The default is
+#              "/usr/pkg".
+#
+#      RM      The name or path to the rm(1) utility.
+#
+#      RMDIR   The name or path to the rmdir(1) utility.
+#
+#      TASK_MSG
+#              String prepended to all normal message written to
+#              standard output.
+#
+
+__task_info_files__="yes"
+__task_info_files_init__="_task_info_files_init"
+
+task_load cleanup
+task_load echo
+task_load makedir
+task_load match
+task_load quote
+
+task_info_files()
+{
+       : ${INSTALL_INFO:=install-info}
+       : ${RM:=rm}
+       : ${RMDIR:=rmdir}
+
+       : ${PKG_PREFIX:=/usr/pkg}
+       : ${PKGNAME:=${0##*/}}
+       : ${TASK_MSG:=""}
+
+       local arg
+       local echo="task_echo"
+       local silent=
+       local OPTIND=1
+       while getopts ":s" arg "$@"; do
+               case $arg in
+               s)      echo=":"; silent="-s" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+
+       local action="$1"; shift
+       case $action in
+       add|remove)
+               : "valid action" ;;
+       *)      return 0 ;;
+       esac
+
+       # Guard against ${PKG_PREFIX} == "/".
+       local prefix
+       case ${PKG_PREFIX}/ in
+       //)     prefix= ;;
+       *)      prefix=${PKG_PREFIX} ;;
+       esac
+
+       local result line_result
+       local index quoted
+
+       result=0
+       local hash tag file infodir
+       while read hash tag file infodir; do
+               # Filter for "# INFO:"
+               case $hash/$tag in
+               "#/INFO:")
+                       : "use this line" ;;
+               *)      continue ;;
+               esac
+
+               # Canonicalize paths.
+               case $file in
+               "")     # skip lines without required args
+                       continue ;;
+               [!/]*)  file="$prefix/$file" ;;
+               esac
+               file="${PKG_DESTDIR}$file"
+               case $infodir in
+               "")     infodir=${file%/*} ;;
+               [!/]*)  infodir="$prefix/$infodir" ;;
+               esac
+               infodir="${PKG_DESTDIR}$infodir"
+
+               if [ ! -f "$file" ]; then
+                       $echo "${TASK_MSG}! info file missing: $file"
+                       result=1
+                       continue
+               fi
+
+               index="$infodir/dir"
+               task_quote "$index"
+               __task_info_files_indices__="$__task_info_files_indices__ $quoted"
+
+               line_result=0
+               case $action in
+               add)    # Remove any existing file entry from the "dir" file, even for
+                       # the "add" action to guard against a duplicate entry when we
+                       # add later.
+                       #
+                       if [ -f "$index" ]; then
+                               ${INSTALL_INFO} --delete "$file" "$index" >/dev/null 2>&1
+                       fi
+                       # Add the file entry to the "dir" file.
+                       [ -d "$infodir" ] || task_makedir "$infodir"
+                       ${INSTALL_INFO} "$file" "$index" || line_result=1
+                       if [ $line_result -eq 0 ]; then
+                               $echo "${TASK_MSG}> info file registered: $file"
+                       else
+                               $echo "${TASK_MSG}! info file not registered: $file"
+                       fi ;;
+               remove) if [ -f "$index" ]; then
+                               ${INSTALL_INFO} --delete "$file" "$index" || line_result=1
+                               if [ $line_result -eq 0 ]; then
+                                       $echo "${TASK_MSG}> info file unregistered: $file"
+                               else
+                                       $echo "${TASK_MSG}! info file not unregistered: $file"
+                               fi
+                       else
+                               $echo "${TASK_MSG}> info file already unregistered: $file"
+                       fi ;;
+               esac
+               [ $line_result -eq 0 ] || result=1
+       done
+
+       _task_info_files_cleanup $silent
+       return $result
+}
+
+_task_info_files_cleanup()
+{
+       : ${RM:=rm}
+       : ${RMDIR:=rmdir}
+
+       : ${TASK_MSG:=""}
+
+       local arg
+       local echo="task_echo"
+       local OPTIND=1
+       while getopts ":s" arg "$@"; do
+               case $arg in
+               s)      echo=":" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+
+       # Guard against ${PKG_PREFIX} == "/".
+       local prefix
+       eval set -- $__task_info_files_indices__
+       local index
+       for index; do
+               [ -f "$index" ] || continue
+               #
+               # Check if the "dir" file has any entries and
+               # remove it if it doesn't.
+               #
+               if task_match -v "[*][  ][mM]enu:*" < $index |
+                  task_match -q '[*][  ]*'; then
+                       : "entries exist"
+               else
+                       ${RM} -f "$index"
+                       ${RMDIR} -p "${index%/*}" 2>/dev/null
+                       $echo "${TASK_MSG}> empty dir file removed: $index"
+               fi
+       done
+       __task_info_files_indices__=
+}
+
+_task_info_files_init()
+{
+       task_cleanup_add_hook _task_info_files_cleanup
+}
+
+# Static variable for "dir" indices that should be removed if empty if an
+# error occurs.
+#
+__task_info_files_indices__=
Index: pkgsrc/pkgtools/pkgtasks/files/load.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/load.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/load.subr    Thu Jun  1 01:58:34 2017
@@ -0,0 +1,114 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      load.subr -- load task modules
+#
+# SYNOPSIS
+#      task_load [-s <suffix>] <module> ...
+#
+# DESCRIPTION
+#      The task_load function sources the module file for each specified
+#      module.
+#
+#      The module file is searched under ${TASK_MODULE_DIR} with a basename
+#      of <module><suffix>, where the default suffix is ".subr".
+#
+#      The module file should define and set a global guard variable
+#      __task_<module>__ to "yes".  This guard variable is checked by the
+#      task_load function to determine whether the module has been
+#      previously loaded.
+#
+# RETURN VALUES
+#      Returns 0 on success, and >0 if an error occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      TASK_MODULE_DIR
+#              The path to the directory containing the task modules.
+#
+
+if [ -z "$__task_load__" ]; then
+
+__task_load__="yes"
+
+task_load()
+{
+       : ${TASK_MODULE_DIR:=.}
+
+       local suffix=".subr"
+       local arg
+       local OPTIND=1
+       while getopts ":s:" arg "$@"; do
+               case $arg in
+               s)      suffix=${OPTARG} ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+
+       local save_IFS
+       local guard path init_fn
+       local module
+       for module; do
+               save_IFS=$IFS; IFS=/
+               set -o noglob; set -- $1; set +o noglob
+               IFS=$save_IFS
+               guard="__task"
+               path=${TASK_MODULE_DIR}
+               for component; do
+                       case $component in
+                       "")     : "skip empty path components" ;;
+                       *)      guard="${guard}_$component"
+                               path="$path/$component" ;;
+                       esac
+               done
+               init_fn="${guard}_init__"
+               guard="${guard}__"
+               path="$path$suffix"
+               if eval test -z "\$$guard"; then
+                       if [ -f "$path" ]; then
+                               . "$path"
+                               if eval test -n "\$$init_fn"; then
+                                       if eval "\$$init_fn"; then
+                                               : "successful initialization"
+                                       else
+                                               echo 1>&2 "Error: initializing $module failed"
+                                       fi
+                               fi
+                       else
+                               echo 1>&2 "Error: Loading $module failed: $path"
+                               return 1
+                       fi
+               fi
+       done
+       return 0
+}
+
+fi     # __task_load__
Index: pkgsrc/pkgtools/pkgtasks/files/lock.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/lock.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/lock.subr    Thu Jun  1 01:58:34 2017
@@ -0,0 +1,233 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      lock.subr -- create or release a lock file
+#
+# SYNOPSIS
+#      task_lock [-nr] lockfile
+#
+# DESCRIPTION
+#      The task_lock function can create or release a lock file on behalf
+#      of a shell script.  The requested lock file is a symlink to a
+#      uniquely-named file.
+#
+#      The options are as follows:
+#
+#      -n      Don't block and fail immediately if the lock could not be
+#              obtained.
+#
+#      -r      Release the existing lock file.
+#
+#      The task_lock function uses the symlink(2) system call via ln(1)
+#      to create the target lock file, which is an atomic operation.  It
+#      writes the name of the symlink target into the requested lock file.
+#
+#      The task_lock function uses the rename(2) system call via mv(1)
+#      to release the target lock file, which is an atomic operation.
+#      Upon success, it deletes the renamed symlink as well as the file
+#      named within the symlink target.
+#
+# RETURN VALUES
+#      Returns 0 on success, and >0 if an error occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      LN      The name or path to the ln(1) utility.
+#
+#      MV      The name or path to the mv(1) utility.
+#
+#      RM      The name or path to the rm(1) utility.
+#
+#      SLEEP   The name or path to the sleep(1) utility.
+#
+# EXAMPLES
+#     o Acquire a lock, waiting until it is created before continuing.
+#
+#      lockfile="/tmp/foo.lock"
+#      if task_lock "$lockfile"; then
+#              # do what required the lock
+#              # ...
+#              # release the lock
+#              task_lock -r "$lockfile"
+#      fi
+#
+#     o Attempt to create a lock, but fail immediately if not created.
+#
+#      lockfile="/tmp/foo.lock"
+#      if task_lock -n "$lockfile"; then
+#              # do what required the lock
+#              # ...
+#              # release the lock
+#              task_lock -r "$lockfile"
+#      else
+#              echo "Lock $lockfile already held by another process."
+#      fi
+#
+# BUGS
+#      The task_lock function should accept an optional timeout parameter.
+#
+
+__task_lock__="yes"
+__task_lock_init__="_task_lock_init"
+
+task_load cleanup
+task_load maketemp
+task_load quote
+
+task_lock()
+{
+       local action="create"
+       local nonblocking=
+       local timeout=
+
+       local arg
+       local OPTIND=1
+       while getopts ":nrw:" arg "$@"; do
+               case $arg in
+               n)      nonblocking="-n" ;;
+               r)      action="release" ;;
+               w)      timeout=${OPTARG} ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -eq 1 ] || return 127
+       local lockfile="$1"; shift
+
+       [ -n "$lockfile" ] || return 1
+
+       case $action in
+       create) _task_lock_create $nonblocking "$lockfile" || return 1 ;;
+       release)
+               _task_lock_release "$lockfile" || return 1 ;;
+       esac
+       return 0
+}
+
+_task_lock_create()
+{
+       : ${LN:=ln}
+       : ${RM:=rm}
+       : ${SLEEP:=sleep}
+
+       local nonblocking=
+       local arg
+       local OPTIND=1
+       while getopts ":n" arg "$@"; do
+               case $arg in
+               n)      nonblocking="yes" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -eq 1 ] || return 1
+       local lockfile="$1"; shift
+
+       local target quoted
+       target=$( task_maketemp "$lockfile.pkgtasks.XXXXXXXXXX" ) || return 1
+       task_quote "$target"
+       __task_lock_temps__="$__task_lock_temps__ $quoted"
+       echo "$target" > $target
+
+       while : ; do
+               # symlink(2) is atomic.
+               #
+               # Redirect standard error so an error message isn't
+               # written every time this symlink(2) is attempted while
+               # we're spinning.
+               #
+               if ${LN} -s "$target" "$lockfile" >/dev/null 2>&1; then
+                       # lock created
+                       return 0
+               fi
+               # don't spinlock if nonblocking was requested
+               [ -z "$nonblocking" ] || break
+               # sleep for 1s and try to create the lock again
+               ${SLEEP} 1
+       done
+       # lock not created
+       _task_lock_cleanup
+       return 1
+}
+
+_task_lock_release()
+{
+       : ${MV:=mv}
+       : ${RM:=rm}
+
+       [ $# -eq 1 ] || return 1
+       local lockfile="$1"; shift
+       [ -n "$lockfile" ] || return 1
+
+       # release a lock
+       local release="$lockfile.release"
+       # rename(2) is atomic.
+       #
+       # Redirect standard error so an error message isn't written every
+       # time this rename(2) is attempted.
+       #
+       if ${MV} -f "$lockfile" "$release" >/dev/null 2>&1; then
+               # lock released
+               if [ -f "$release" ]; then
+                       # clean up by deleting the target of the released lock
+                       local target
+                       while IFS= read target; do
+                               case $target in
+                               "$lockfile".*)
+                                       ${RM} -f "$target" ;;
+                               *)      : "skip invalid lockfile name" ;;
+                               esac
+                       done < $release
+               fi
+               ${RM} -f "$release"
+               return 0
+       fi
+       # lock not released
+       return 1
+}
+
+_task_lock_cleanup()
+{
+       : ${RM:=rm}
+
+       set -o noglob; eval set -- $__task_lock_temps__; set +o noglob
+       local file
+       for file; do
+               ${RM} -f "$file"
+       done
+       __task_lock_temps__=
+}
+
+_task_lock_init()
+{
+       task_cleanup_add_hook _task_lock_cleanup
+}
+
+# Static variable for temporary files that should be removed if an error occurs.
+__task_lock_temps__=
Index: pkgsrc/pkgtools/pkgtasks/files/makedir.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/makedir.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/makedir.subr Thu Jun  1 01:58:34 2017
@@ -0,0 +1,134 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      makedir.subr -- make a directory hierarchy
+#
+# SYNOPSIS
+#      task_makedir [-m mode] <directory> ...
+#
+# DESCRIPTION
+#      The task_makedir function creates the directories in the order
+#      specified.  If the intermediate directories do not exist, then they
+#      are created as well.
+#
+#      The options are as follows:
+#
+#      -i      Always create intermediate directories as separate steps.
+#              If this option is not given, then by default, the function
+#              will attempt to use "mkdir -p" to create the intermediate
+#              directories.
+#
+#      -m      Set the permissions of the final created directory to
+#              the specified mode.
+#
+# RETURN VALUES
+#      Returns 0 on success, and >0 if an error occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      CHMOD   The name or path to the chmod(1) utility.
+#
+#      MKDIR   The name or path to the mkdir(1) utility.
+#
+
+__task_makedir__="yes"
+
+task_makedir()
+{
+       : ${CHMOD:=chmod}
+       : ${MKDIR:=mkdir}
+
+       local execute="yes"
+       local intermediate=
+       local mode=
+       local opts="-p" # always create intermediate directories
+
+       local arg
+       local OPTIND=1
+       while getopts ":im:n" arg "$@"; do
+               case $arg in
+               i)      intermediate="yes" ;;
+               m)      mode=${OPTARG}
+                       opts="$opts -m $mode" ;;
+               n)      execute= ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+
+       # Attempt to do "mkdir -p" if "-i" was not given.
+       if [ -z "$intermediate" ]; then
+               case $execute in
+               "")     : "fall through" ;;
+               *)      { ${MKDIR} ${opts# } "$@"; } 2>/dev/null
+                       [ $? -gt 0 ] || return 0 ;;
+               esac
+       fi
+
+       local path=
+       local prev="/"  # seed with / to prevent attempting "mkdir /"
+       local save_IFS
+       local dir component
+       for dir; do
+               [ -n "$dir" ] || return 1
+               save_IFS=$IFS; IFS=/
+               set -o noglob; set -- $dir; set +o noglob
+               IFS=$save_IFS
+               while [ $# -gt 0 ]; do
+                       component=$1; shift
+                       case $component in
+                       "")     case $path in
+                               "")     path="/" ;;
+                               *)      : "path unchanged" ;;
+                               esac ;;
+                       *)      case $path in
+                               "")     path="$component" ;;
+                               */)     path="$path$component" ;;
+                               *)      path="$path/$component" ;;
+                               esac ;;
+                       esac
+                       if [ "$path" != "$prev" ]; then
+                               case $execute in
+                               "")     echo "${MKDIR} \"$path\"" ;;
+                               *)      if [ ! -d "$path" ]; then
+                                               ${MKDIR} "$path" 2>/dev/null
+                                               [ -d "$path" ] || return 1
+                                       fi
+                               esac
+                               prev=$path
+                       fi
+               done
+               if [ -n "$mode" ]; then
+                       case $execute in
+                       "")     echo "${CHMOD} \"$mode\" \"$dir\"" ;;
+                       *)      ${CHMOD} "$mode" "$dir" || return 1 ;;
+                       esac
+               fi
+       done
+}
Index: pkgsrc/pkgtools/pkgtasks/files/maketemp.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/maketemp.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/maketemp.subr        Thu Jun  1 01:58:34 2017
@@ -0,0 +1,201 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      maketemp.subr -- make unique, temporary files
+#
+# SYNOPSIS
+#      task_maketemp [-dq] [-p tmpdir] [-t prefix] [template ...]
+#
+# DESCRIPTION
+#      The task_maketemp function creates temporary files or directories using
+#      unique names, and prints the names.
+#
+# OPTIONS
+#      The available options are as follows:
+#
+#      -d      Make a directory instead of a file.
+#
+#      -p tmpdir
+#              Specifies the directory in which temporary files are created.
+#              If the "-p tmpdir" option is not specified, then the
+#              directory defaults to ${TMPDIR}, or to /tmp if ${TMPDIR} is
+#              empty.
+#
+#      -q      Fail silently if an error occurs.
+#
+#      -t prefix
+#              Generate a template using an appropriate directory name,
+#              followed by the supplied prefix, followed by ".XXXXXXXX".
+#              Any "X" characters in the supplied prefix are taken
+#              literally, but the trailing "X" characters in the appended
+#              ".XXXXXXXX" are replaced by unique values.
+#
+# EXIT STATUS
+#      Returns 0 on success, and >0 if an error occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      AWK     The name or path to the awk(1) utility.
+#
+#      CHMOD   The name or path to the chmod(1) utility.
+#
+#      MKTEMP  The name or path to the mktemp(1) utility.  task_maketemp
+#              attempts to use this utility first to create the requested
+#              temporary files.
+#
+#      TMPDIR  The default location in which temporary files are created.
+#
+
+__task_maketemp__="yes"
+__task_maketemp_init__="_task_maketemp_init"
+
+task_load cleanup
+task_load createfile
+task_load makedir
+task_load random
+
+task_maketemp()
+{
+       : ${AWK:=awk}
+       : ${CHMOD:=chmod}
+       : ${MKTEMP:=mktemp}
+
+       # Default location in which temporary files and directories are
+       # are created.
+       #
+       local tmpdir="/tmp"
+       [ -z "${TMPDIR}" ] || tmpdir=${TMPDIR}
+
+       local output
+       output=$( { export TMPDIR=$tmpdir && ${MKTEMP} "$@"; } 2>/dev/null )
+       if [ $? -eq 0 ]; then
+               echo "$output"
+               return 0
+       fi
+
+       local result=0
+
+       local filetype="file"
+       local prefix="temp"
+       local quiet=
+       local arg
+       local OPTIND=1
+       while getopts ":dp:qt:" arg "$@"; do
+               case $arg in
+               d)      filetype="dir" ;;
+               p)      tmpdir=${OPTARG} ;;
+               q)      quiet="yes" ;;
+               t)      prefix=${OPTARG} ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+
+       case $filetype in
+       dir|file)
+               : "valid temporary file type" ;;
+       *)      return 1 ;;
+       esac
+
+       # Explicitly set the creation umask to 077, only allowing r/w/x for
+       # the owner.
+       #
+       __task_maketemp_save_umask__=$( umask ) || return 1
+       umask 077
+
+       [ $# -gt 0 ] || set -- "$tmpdir/$prefix.XXXXXXXX"
+       task_random
+       local template; for template; do echo "$template"; done |
+       ${AWK} -v SEED=$RANDOM '
+               BEGIN {
+                       chars =       "abcdefghijklmnopqrstuvwxyz"
+                       chars = chars "ABCDEFGHIJKLMNOPQRSTUVWXZZY"
+                       chars = chars "0123456789"
+                       n = split( chars, array, "" )
+                       srand(SEED)
+               }
+               {
+                       if ( match( $0, "X+$" ) > 0 ) {
+                               s = substr( $0, 1, RSTART - 1 )
+                               for ( i = 0; i < RLENGTH; i++ )
+                                       s = s array[ int( n * rand() ) + 1 ]
+                               print s
+                       } else
+                               print
+               }' |
+       ( while IFS= read name; do
+               case $filetype in
+               dir)    if task_makedir -m 0700 "$name" 2>/dev/null &&
+                          [ ! -h "$name" -a -d "$name" -a \
+                               -r "$name" -a -w "$name" -a -x "$name" -a \
+                               -O "$name" ]; then
+                                : "success"
+                       elif [ -z "$quiet" ]; then
+                               return 1
+                       else
+                               echo 1>&2 "task_maketemp: error creating directory \`\`$name''"
+                               return 1
+                       fi ;;
+               file)   if [ ! -e "$name" ] &&
+                          task_createfile -m 0600 "$name" 2>/dev/null &&
+                          [ ! -h "$name" -a -f "$name" -a \
+                               -r "$name" -a -w "$name" -a \
+                               -O "$name" ]; then
+                               : "success"
+                       elif [ -z "$quiet" ]; then
+                               return 1
+                       else
+                               echo 1>&2 "task_maketemp: error creating file \`\`$name''"
+                               return 1
+                       fi ;;
+               esac
+               echo "$name"
+         done
+         return 0 )
+       result=$?
+
+       _task_maketemp_cleanup
+       return $result
+}
+
+_task_maketemp_cleanup()
+{
+       if [ -n "$__task_maketemp_save_umask__" ]; then
+               umask $__task_maketemp_save_umask__
+               __task_maketemp_save_umask__=
+       fi
+}
+
+_task_maketemp_init()
+{
+       task_cleanup_add_hook _task_maketemp_cleanup
+}
+
+# Static variable for the current umask before executing task_maketemp.
+__task_maketemp_save_umask__=
Index: pkgsrc/pkgtools/pkgtasks/files/match.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/match.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/match.subr   Thu Jun  1 01:58:34 2017
@@ -0,0 +1,114 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      match.subr -- match lines with a fnmatch(3) glob pattern
+#
+# SYNOPSIS
+#      task_match [-qsvw] pattern
+#
+# DESCRIPTION
+#      The task_match function selects lines from standard input that
+#      match the pattern and writes them to standard output.  The
+#      pattern is a shell-style glob pattern.
+#
+#      The options are as follows:
+#
+#      -q      Quiet; do not write anything to standard output.
+#
+#      -s      Skip selecting empty lines.
+#
+#      -v      Invert the sense of matching, to select non-matching
+#              lines.
+#
+#      -w      Select lines where that match the first "word", from
+#              the beginning of the line to the first whitespace or
+#              the end of the line.
+#
+# RETURN VALUES
+#      Returns 0 if selected lines are found, and >0 otherwise.
+#
+
+__task_match__="yes"
+
+task_match()
+{
+       local quiet=
+       local match="plain"
+       local style="exact"
+       local skip_empty=
+
+       local arg
+       local OPTIND=1
+       while getopts ":qsvw" arg "$@"; do
+               case $arg in
+               q)      quiet="yes" ;;
+               s)      skip_empty="yes" ;;
+               v)      match="reverse" ;;
+               w)      style="word" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+       local pattern="$1"; shift
+
+       # whitespace pattern: <space> & <tab>
+       local ws="[     ]"
+
+       local result=1
+       local line
+       while IFS= read line; do
+               case $line in
+               $pattern)
+                       # exact match
+                       result=0
+                       case $match in
+                       plain)  [ -z "$quiet" ] || break
+                               echo "$line" ;;
+                       esac ;;
+               $pattern${ws}*)
+                       # allow for trailing whitespace and additional words
+                       case $style in
+                       word)   result=0
+                               case $match in
+                               plain)  [ -z "$quiet" ] || break
+                                       echo "$line" ;;
+                               esac ;;
+                       esac ;;
+               *)      case $match in
+                       reverse)
+                               [ -z "$quiet" ] || continue
+                               case $line in
+                               "")     [ -n "$skip_empty" ] || echo "$line" ;;
+                               *)      echo "$line" ;;
+                               esac ;;
+                       esac ;;
+               esac
+       done
+       return $result
+}
Index: pkgsrc/pkgtools/pkgtasks/files/ocaml_findlib.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/ocaml_findlib.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/ocaml_findlib.subr   Thu Jun  1 01:58:34 2017
@@ -0,0 +1,290 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      ocaml_findlib.subr -- update OCaml findlib search paths
+#
+# SYNOPSIS
+#      task_ocaml_findlib [-s] add | remove
+#      task_ocaml_findlib check-add | check-remove
+#
+# DESCRIPTION
+#      The task_ocaml_findlib function supports four actions: "add",
+#      "remove", "check-add", and "check-remove".
+#
+#      The available options are as follows:
+#
+#      -s      Silent; don't write to standard output.
+#
+#      The task_ocaml_findlib function reads standard input line by line
+#      and looks for lines of the form:
+#
+#          # FINDLIB: <libdir> [<ldconf>]
+#
+#      If libdir is is a relative path, then it is assumed to be
+#      relative to ${OCAML_SITELIB}.  If ldconf is a relative path, then
+#      it is assumed to be relative to ${PKG_PREFIX}.
+#
+#      The "add" action adds pathnames to the ld.conf file.
+#
+#      The "remove" action removes pathnames from the ld.conf file.
+#
+#      The "check-add" action will check whether pathnames are missing
+#      from the ld.conf file and writes an informative message noting
+#      the missing pathnames.
+#
+#      The "check-remove" action will check whether pathnames are still
+#      present in the ld.conf file and writes an informative message
+#      noting the existing paths.
+#
+# RETURN VALUES
+#      The "add" and "remove" actions return 0 if they are successful
+#      for all paths, and >0 if an error occurs.
+#
+#      The "check-add" and "check-remove" actions return >0 if they
+#      write informative messages, and return 0 otherwise.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      MV      The name or path to the mv(1) utility.
+#
+#      OCAML_SITELIB
+#              The site library search path.  If this path is relative,
+#              then it is relative to ${PKG_PREFIX}.  The default is
+#              "lib/ocaml/site-lib".
+#
+#      PKGNAME
+#              The name of the package.
+#
+#      PKG_DESTDIR
+#              A "destdir" prefix that is prepended to all filesystem
+#              paths.  The default value is the empty string.
+#
+#      PKG_PREFIX
+#              The installation prefix of the package.  The default is
+#              "/usr/pkg".
+#
+#      RM      The name or path to the rm(1) utility.
+#
+#      TASK_MSG
+#              String prepended to all normal message written to
+#              standard output.
+#
+
+__task_ocaml_findlib__="yes"
+__task_ocaml_findlib_init__="_task_ocaml_findlib_init"
+
+task_load cleanup
+task_load echo
+task_load lock
+task_load maketemp
+task_load match
+task_load quote
+
+task_ocaml_findlib()
+{
+       : ${MV:=mv}
+
+       : ${OCAML_SITELIB:=lib/ocaml/site-lib}
+       : ${PKG_PREFIX:=/usr/pkg}
+       : ${PKGNAME:=${0##*/}}
+       : ${TASK_MSG:=""}
+
+       local arg
+       local echo="task_echo"
+       local OPTIND=1
+       while getopts ":s" arg "$@"; do
+               case $arg in
+               s)      echo=":" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+
+       local action="$1"; shift
+       case $action in
+       add|remove|check-add|check-remove)
+               : "valid actions" ;;
+       *)      return 0 ;;
+       esac
+
+       # Guard against ${PKG_PREFIX} == "/".
+       local prefix
+       case ${PKG_PREFIX}/ in
+       //)     prefix= ;;
+       *)      prefix=${PKG_PREFIX} ;;
+       esac
+
+       local sitelib
+       case ${OCAML_SITELIB} in
+       /*)     sitelib=${OCAML_SITELIB} ;;
+       *)      sitelib="$prefix/${OCAML_SITELIB}" ;;
+       esac
+
+       local result line_result
+       local quoted
+       local lock lock_quoted
+       local temp temp_quoted
+
+       result=0
+       local hash tag libdir ldconf
+       while read hash tag libdir ldconf; do
+               # Filter for "# SHELL:".
+               case $hash/$tag in
+               "#/FINDLIB:")
+                       : "use this line" ;;
+               *)      continue ;;
+               esac
+
+               # Canonicalize paths.
+               case $libdir in
+               "")     # skip lines without any required args
+                       continue ;;
+               [!/]*)  libdir="$sitelib/$libdir" ;;
+               esac
+               case $ldconf in
+               "")     ldconf="$prefix/lib/ocaml/ld.conf" ;;
+               [!/]*)  ldconf="$prefix/$ldconf" ;;
+               esac
+               ldconf="${PKG_DESTDIR}$ldconf"
+
+               line_result=0
+               case $action in
+               add|remove)
+                       lock="$ldconf.lock"
+                       task_quote "$lock"
+                       lock_quoted=$quoted
+                       __task_ocaml_findlib_locks__="$quoted $__task_ocaml_findlib_locks__"
+                       task_lock "$lock" || line_result=1
+               esac
+               if [ $line_result -eq 0 ]; then
+                       case $action in
+                       add)    if [ -f "$ldconf" ] && task_match -qw "$libdir" < $ldconf; then
+                                       $echo "${TASK_MSG}! path already added: $libdir"
+                               else
+                                       temp=$( task_maketemp "$ldconf.pkgtasks.XXXXXXXXXX" )
+                                       if [ -n "$temp" ]; then
+                                               task_quote "$temp"
+                                               temp_quoted="$quoted"
+                                               __task_ocaml_findlib_temps__="$__task_ocaml_findlib_temps__ $temp_quoted"
+                                               if [ ! -f "$ldconf" ]; then
+                                                       echo "$libdir"
+                                               else
+                                                       task_match -vw "$libdir" < $ldconf
+                                                       echo "$libdir"
+                                               fi > $temp
+                                               # rename(2) is atomic.
+                                               if ${MV} -f "$temp" "$ldconf"; then
+                                                       $echo "${TASK_MSG}> path added: $libdir"
+                                                       __task_ocaml_findlib_temps__=${__task_ocaml_findlib_temps__% $temp_quoted}
+                                               else
+                                                       $echo "${TASK_MSG}! path not added: $libdir"
+                                                       line_result=1
+                                               fi
+                                       else
+                                               $echo "${TASK_MSG}! cannot create temporary file for $ldconf"
+                                               line_result=1
+                                       fi
+                               fi ;;
+                       remove) if [ -f "$ldconf" ] && task_match -qw "$libdir" < $ldconf; then
+                                       temp=$( task_maketemp "$ldconf.pkgtasks.XXXXXXXXXX" )
+                                       if [ -n "$temp" ]; then
+                                               task_quote "$temp"
+                                               temp_quoted="$quoted"
+                                               __task_ocaml_findlib_temps__="$__task_ocaml_findlib_temps__ $temp_quoted"
+                                               task_match -vw "$libdir" < $ldconf > $temp
+                                               # rename(2) is atomic.
+                                               if ${MV} -f "$temp" "$ldconf"; then
+                                                       $echo "${TASK_MSG}> path removed: $libdir"
+                                                       __task_ocaml_findlib_temps__=${__task_ocaml_findlib_temps__% $temp_quoted}
+                                               else
+                                                       $echo "${TASK_MSG}! path not removed: $libdir"
+                                                       line_result=1
+                                               fi
+                                       else
+                                               $echo "${TASK_MSG}! cannot create temporary file for $ldconf"
+                                               line_result=1
+                                       fi
+                               else
+                                       $echo "${TASK_MSG}> path already removed: $libdir"
+                               fi ;;
+                       check-add)
+                               if [ -f "$ldconf" ] && task_match -qw "$libdir" < $ldconf; then
+                                       : "path already added"
+                               else
+                                       task_echo "!!! INFO: ${PKGNAME}: Add path \"$libdir\" to $ldconf."
+                                       line_result=1
+                               fi ;;
+                       check-remove)
+                               if [ -f "$ldconf" ] && task_match -qw "$libdir" < $ldconf; then
+                                       task_echo "!!! INFO: ${PKGNAME}: Remove path \"$libdir\" from $ldconf."
+                                       line_result=1
+                               fi ;;
+                       esac
+               fi
+               case $action in
+               add|remove)
+                       task_lock -r "$lock"
+                       __task_ocaml_findlib_locks__=${__task_ocaml_findlib_locks__#$lock_quoted } ;;
+               esac
+               [ $line_result -eq 0 ] || result=1
+       done
+
+       _task_ocaml_findlib_cleanup
+       return $result
+}
+
+_task_ocaml_findlib_cleanup()
+{
+       : ${RM:=rm}
+
+       eval set -- $__task_ocaml_findlib_temps__
+       local file
+       for file; do
+               ${RM} -f "$file"
+       done
+       __task_ocaml_findlib_temps__=
+
+       eval set -- $__task_ocaml_findlib_locks__
+       local lockfile
+       for lockfile; do
+               task_lock -r "$lockfile"
+       done
+       __task_ocaml_findlib_locks__=
+}
+
+_task_ocaml_findlib_init()
+{
+       task_cleanup_add_hook _task_ocaml_findlib_cleanup
+}
+
+# Static variable for temporary files that should be removed if an error occurs.
+__task_ocaml_findlib_temps__=
+# Static variable for locks that should be released if an error occurs.
+__task_ocaml_findlib_locks__=
Index: pkgsrc/pkgtools/pkgtasks/files/permissions.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/permissions.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/permissions.subr     Thu Jun  1 01:58:34 2017
@@ -0,0 +1,244 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      permissions.subr -- check and set modes and permissions for packages
+#
+# SYNOPSIS
+#      task_check_permissions path mode [owner [group]]
+#      task_set_permissions path mode [owner [group]]
+#
+#      task_permissions [-s] add
+#      task_permissions check-add
+#
+# DESCRIPTION
+#      The task_check_permissions function checks the mode, owner, and
+#      group of the path.
+#
+#      The task_set_permissions function sets the mode, owner, and group of
+#      the path.
+#
+#      The task_permissions function supports two actions: "check-add" and
+#      "add".
+#
+#      The available options are as follows:
+#
+#      -s      Silent; don't write to standard output.
+#
+#      The task_permissions function reads standard input line by line and
+#      looks for lines of the form:
+#
+#          # PERMS: <path> <mode> [<owner>] [<group>]
+#
+#      If the path is relative, then it is assumed to be relative to
+#      ${PKG_PREFIX}.
+#
+#      The "check-add" action checks whether the path has the correct mode
+#      and permissions or otherwise writes a message to standard output
+#      noting the path has incorrect permissions.
+#
+#      The "add" action sets the special modes and permissions on the path.
+#
+# RETURN VALUES
+#      The task_check_permissions function returns 0 if the mode and
+#      permissions match, and >0 otherwise.
+#
+#      The task_set_permissions and task_permissions functions return 0 on
+#      success, and >0 if an error occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      CHMOD   The name or path to the chmod(1) utility.
+#
+#      CHOWN   The name or path to the chown(8) utility.
+#
+#      LS      The name or path to the ls(1) utility.
+#
+#      PKGNAME
+#              The name of the package.
+#
+#      PKG_DESTDIR
+#              A "destdir" prefix that is prepended to all filesystem
+#              paths.  The default value is the empty string.  This
+#              variable is only used by task_permissions.
+#
+#      PKG_PREFIX
+#              The installation prefix of the package.  The default is
+#              "/usr/pkg".
+#
+#      TASK_MSG
+#              String prepended to all normal message written to
+#              standard output.
+#
+
+__task_permissions__="yes"
+
+task_load echo
+
+task_set_permissions()
+{
+       : ${CHMOD:=chmod}
+       : ${CHOWN:=chown}
+
+       local path="$1"; shift
+       local mode="$1"; shift
+       local owner="$1"; [ $# -eq 0 ] || shift
+       local group="$1"; [ $# -eq 0 ] || shift
+
+       local result=0
+       case $owner:$group in
+       :)      ;;
+       *)      ${CHOWN} "$owner:$group" "$path" || result=1 ;;
+       esac
+       case $mode in
+       "")     ;;
+       *)      ${CHMOD} "$mode" "$path" || result=1 ;;
+       esac
+       return $result
+}
+
+task_check_permissions()
+{
+       : ${LS:=ls}
+
+       local path="$1"; shift
+       local mode="$1"; shift
+       local owner="$1"; [ $# -eq 0 ] || shift
+       local group="$1"; [ $# -eq 0 ] || shift
+
+       ${LS} -dl "$path" 2>/dev/null |
+       ( read lsmode __ lsowner lsgroup __
+         [ -z "$owner" -o "$owner" = "$lsowner" ] || return 1
+         [ -z "$group" -o "$group" = "$lsgroup" ] || return 1
+         # Parse the ls(1) long file mode format.
+         nummode=0
+         case $lsmode in ?r????????) nummode="$nummode +  400" ;; esac
+         case $lsmode in ??w???????) nummode="$nummode +  200" ;; esac
+         case $lsmode in ???x??????) nummode="$nummode +  100" ;; esac
+         case $lsmode in ???S??????) nummode="$nummode + 4000" ;; esac
+         case $lsmode in ???s??????) nummode="$nummode + 4100" ;; esac
+         case $lsmode in ????r?????) nummode="$nummode +   40" ;; esac
+         case $lsmode in ?????w????) nummode="$nummode +   20" ;; esac
+         case $lsmode in ??????x???) nummode="$nummode +   10" ;; esac
+         case $lsmode in ??????S???) nummode="$nummode + 2000" ;; esac
+         case $lsmode in ??????s???) nummode="$nummode + 2010" ;; esac
+         case $lsmode in ???????r??) nummode="$nummode +    4" ;; esac
+         case $lsmode in ????????w?) nummode="$nummode +    2" ;; esac
+         case $lsmode in ?????????x) nummode="$nummode +    1" ;; esac
+         case $lsmode in ?????????T) nummode="$nummode + 1000" ;; esac
+         case $lsmode in ?????????t) nummode="$nummode + 1001" ;; esac
+         [ $(( $nummode )) -eq $mode ] )
+}
+
+task_permissions()
+{
+       : ${PKG_PREFIX:=/usr/pkg}
+       : ${PKGNAME:=${0##*/}}
+
+       : ${TASK_MSG=""}
+
+       local arg
+       local echo="task_echo"
+       local OPTIND=1
+       while getopts ":s" arg "$@"; do
+               case $arg in
+               s)      echo=":" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+
+       local action="$1"; shift
+       case $action in
+       add|check-add)
+               : "valid options" ;;
+       *)      return 0 ;;
+       esac
+
+       # Guard against ${PKG_PREFIX} == "/".
+       local prefix
+       case ${PKG_PREFIX}/ in
+       //)     prefix= ;;
+       *)      prefix=${PKG_PREFIX} ;;
+       esac
+
+       local result
+       local msg
+
+       result=0
+       local hash tag path mode user group
+       while read hash tag path mode user group; do
+               # Filter for "# PERMS:"
+               case $hash/$tag in
+               "#/PERMS:")
+                       : "use this line" ;;
+               *)      continue ;;
+               esac
+
+               # Canonicalize paths.
+               case $path in
+               "")     # skip lines without required args
+                       continue ;;
+               [!/]*)  path="$prefix/$path" ;;
+               esac
+               path="${PKG_DESTDIR}$path"
+
+               msg=
+               case $mode/$user/$group in
+               //)     msg="$path" ;;
+               [!/]*//)
+                       msg="$path (m=$mode)" ;;
+               [!/]*/[!/]*/)
+                       msg="$path (o=$user, m=$mode)" ;;
+               [!/]*/[!/]*/[!/]*)
+                       msg="$path (o=$user, g=$group, m=$mode)" ;;
+               esac
+
+               case "$action" in
+               add)    if [ ! -e "$path" ]; then
+                               $echo "${TASK_MSG}! permissions not set on missing: $path"
+                               result=1
+                       elif task_set_permissions "$path" "$mode" "$user" "$group"; then
+                               $echo "${TASK_MSG}> permissions set: $msg"
+                       else
+                               $echo "${TASK_MSG}! permissions not set: $msg"
+                               result=1
+                       fi ;;
+               check-add)
+                       if [ -e "$path" ] &&
+                          task_check_permissions "$path" "$mode" "$user" "$group"; then
+                               : "permissions already correct"
+                       else
+                               task_echo "!!! INFO: ${PKGNAME}: Set permissions: $msg"
+                               result=1
+                       fi ;;
+               esac
+       done
+       return $result
+}
Index: pkgsrc/pkgtools/pkgtasks/files/platform.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/platform.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/platform.subr        Thu Jun  1 01:58:34 2017
@@ -0,0 +1,65 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      platform.subr -- determine the platform (operating system.
+#
+# SYNOPSIS
+#      task_platform
+#
+# DESCRIPTION
+#      The task_platform function writes the platform to standard output.
+#
+# RETURN VALUES
+#      Returns 0 if the platform can be determined, and >0 if an error
+#      occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      SED     The name or path to the sed(1) utility.
+#
+#      UNAME   The name or path to the uname(1) utility.
+#
+
+__task_platform__="yes"
+
+task_platform()
+{
+       : ${SED:=sed}
+       : ${UNAME:=uname}
+
+       # Take uname(1) output and strip out dashes and slashes.
+       ${UNAME} -s | ${SED} -e "s,-,,g" -e "s,/,,g" |
+       ( read platform || return 1
+         case $platform in
+         [Cc][Yy][Gg][Ww][Ii][Nn]*)
+               echo "Cygwin"; return 0 ;;
+         *)    echo "$platform"; return 0 ;;
+         esac
+         return 1 )
+}
Index: pkgsrc/pkgtools/pkgtasks/files/postinstall.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/postinstall.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/postinstall.subr     Thu Jun  1 01:58:34 2017
@@ -0,0 +1,130 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      postinstall.subr -- post-installation actions for packages
+#
+# SYNOPSIS
+#      task_postinstall <datafile>
+#
+# DESCRIPTION
+#      The task_postinstall function performs actions that SHOULD occur
+#      AFTER the package files are installed into their final location
+#      for the installation:
+#
+#          o Copy configuration files into correct locations.
+#          o Set special permissions on package files and directories.
+#          o Rebuild the system run-time library search path database.
+#          o Update fonts databases.
+#          o Register shells in the system shells database.
+#          o Register GNU info files.
+#          o Update OCaml module run-time library search path database.
+#
+#      The datafile contains lines of the form:
+#
+#          # <keyword>: <arg> ...
+#
+#      These lines are used as input to the various script functions.
+#
+# RETURN VALUES
+#      Returns 0 on success, and >0 if an error occurs.
+#
+
+__task_postinstall__="yes"
+
+task_load directories
+task_load files
+task_load fonts
+task_load info_files
+task_load ocaml_findlib
+task_load permissions
+task_load shells
+task_load shlibs
+task_load sort
+task_load taskfunc
+
+task_postinstall()
+{
+       [ $# -gt 0 ] || return 127
+       local datafile="$1"; shift
+
+       [ -f "$datafile" ] || return 1
+
+       local post_actions=
+       # Copy configuration/support files into place.
+       post_actions="task_files"
+       # Set special permissions on files and directories that need them.
+       post_actions="$post_actions task_permissions"
+       # Rebuild the system run-time library search path database.
+       post_actions="$post_actions task_shlibs"
+       # Update font databases.
+       post_actions="$post_actions task_fonts"
+       # Register shells.
+       post_actions="$post_actions task_shells"
+       # Register GNU info files.
+       post_actions="$post_actions task_info_files"
+       # Update OCaml module run-time library search path database.
+       post_actions="$post_actions task_ocaml_findlib"
+       # Run generic package tasks.
+       post_actions="$post_actions task_function"
+
+       # Seed checks with actions from preinstall, in order.
+       local post_checks="task_directories"
+
+       local result=0
+       local stage="postinstall"
+
+       local post_fn silent
+       for post_fn in $post_actions; do
+               case $post_fn in
+               task_files|\
+               task_permissions|\
+               task_shells)
+                       # These tasks should be verbose since they touch
+                       # system files and directories.
+                       silent= ;;
+               *)      silent="-s" ;;
+               esac
+               $post_fn $silent add $stage < $datafile || result=1
+               post_checks="$post_checks $post_fn"
+       done
+
+       # Run all checks after all post-installation actions have completed
+       # and write messages to standard output for any checks that don't
+       # pass.
+       #
+       for post_fn in $post_checks; do
+               case $post_fn in
+               task_directories)
+                       # Sort data lines for this task.
+                       task_sort < $datafile | $post_fn check-add $stage ;;
+               *)      $post_fn check-add $stage < $datafile ;;
+               esac
+       done
+
+       return $result
+}
Index: pkgsrc/pkgtools/pkgtasks/files/postremove.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/postremove.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/postremove.subr      Thu Jun  1 01:58:34 2017
@@ -0,0 +1,137 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      postremove.subr -- post-removal actions for packages
+#
+# SYNOPSIS
+#      task_postremove <datafile>
+#
+# DESCRIPTION
+#      The task_postremove function performs actions that SHOULD occur
+#      AFTER deleting the package files:
+#
+#          o Unregister shells from the system shells database.
+#          o Update fonts databases.
+#          o Rebuild the system run-time library search path database.
+#          o Update OCaml module run-time library search path database.
+#          o Remove empty directories.
+#          o Remove unused users.
+#          o Remove unused groups.
+#
+#      The datafile contains lines of the form:
+#
+#          # <keyword>: <arg> ...
+#
+#      These lines are used as input to the various script functions.
+#
+# RETURN VALUES
+#      Returns 0 on success, and >0 if an error occurs.
+#
+
+__task_postremove__="yes"
+
+task_load directories
+task_load files
+task_load fonts
+task_load groups
+task_load info_files
+task_load ocaml_findlib
+task_load shells
+task_load shlibs
+task_load sort
+task_load taskfunc
+task_load users
+
+task_postremove()
+{
+       [ $# -gt 0 ] || return 127
+       local datafile="$1"; shift
+
+       [ -f "$datafile" ] || return 1
+
+       local post_actions=
+       # Remove shells from the system shells database.
+       post_actions="task_shells"
+       # Update font databases.
+       post_actions="$post_actions task_fonts"
+       # Rebuild the system run-time library search path database.
+       post_actions="$post_actions task_shlibs"
+       # Update OCaml module run-time library search path database.
+       post_actions="$post_actions task_ocaml_findlib"
+       # Remove empty directories.
+       post_actions="$post_actions task_directories"
+       # Remove unused users.
+       post_actions="$post_actions task_users"
+       # Remove unused groups.
+       post_actions="$post_actions task_groups"
+       # Run generic package tasks.
+       post_actions="$post_actions task_function"
+
+       # Seed checks with actions from preremove, in order.
+       local post_checks="task_info_files task_files"
+
+       local result=0
+       local stage="preinstall"
+
+       local post_fn silent
+       for post_fn in $post_actions; do
+               case $post_fn in
+               task_directories|\
+               task_groups|\
+               task_shells|\
+               task_users)
+                       # These tasks should be verbose since they touch
+                       # system files and directories.
+                       silent= ;;
+               *)      silent="-s" ;;
+               esac
+               case $post_fn in
+               task_directories)
+                       # Reverse-sort data lines for this task.
+                       task_sort -r < $datafile | $post_fn $silent remove $stage ;;
+               *)      $post_fn $silent remove $stage < $datafile ;;
+               esac
+               [ $? -eq 0 ] || result=1
+               post_checks="$post_checks $post_fn"
+       done
+
+       # Run all checks after all post-removal actions have completed
+       # and write messages to standard output for any checks that don't
+       # pass.
+       #
+       for post_fn in $post_checks; do
+               case $post_fn in
+               task_directories)
+                       # Reverse-sort data lines for this task.
+                       task_sort -r < $datafile | $post_fn check-remove $stage ;;
+               *)      $post_fn check-remove $stage < $datafile ;;
+               esac
+       done
+
+       return $result
+}
Index: pkgsrc/pkgtools/pkgtasks/files/preinstall.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/preinstall.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/preinstall.subr      Thu Jun  1 01:58:34 2017
@@ -0,0 +1,104 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      preinstall.subr -- pre-installation actions for packages
+#
+# SYNOPSIS
+#      task_preinstall <datafile>
+#
+# DESCRIPTION
+#      The task_preinstall function performs actions that MUST occur
+#      successfully BEFORE the package files are installed into their
+#      final location for the installation to be successful:
+#
+#          o Ensure that all required groups and users exist.
+#          o Create required directories.
+#
+#      The datafile contains lines of the form:
+#
+#          # <keyword>: <arg> ...
+#
+#      These lines are used as input to the various script functions.
+#
+# RETURN VALUES
+#      Returns 0 on success, and >0 if an error occurs.
+#
+
+__task_preinstall__="yes"
+
+task_load directories
+task_load groups
+task_load sort
+task_load taskfunc
+task_load users
+
+task_preinstall()
+{
+       [ $# -gt 0 ] || return 127
+       local datafile="$1"; shift
+
+       [ -f "$datafile" ] || return 1
+
+       local stage="preinstall"
+
+       # Require necessary groups and users before actions that may
+       # set permissions.
+       #
+       task_groups add $stage < $datafile
+       if task_groups check-add $stage < $datafile; then
+               : "groups exist"
+       else
+               # Fatal error: groups are missing.
+               return 1
+       fi
+
+       task_users add $stage < $datafile
+       if task_users check-add $stage < $datafile; then
+               : "users exist"
+       else
+               # Fatal error: users are missing.
+               return 1
+       fi
+
+       # Create directories so that pre-existing directories can be
+       # correctly identified.  Sort the entries prior to creation to
+       # create path components in order.  Any errors in creating
+       # directories are non-fatal.
+       #
+       task_sort < $datafile | task_directories add $stage
+
+       # Run the generic package tasks.
+       if task_function add $stage < $datafile; then
+               : "success"
+       else
+               # Fatal error: failures in generic package tasks.
+               return 1
+       fi
+
+       return 0
+}
Index: pkgsrc/pkgtools/pkgtasks/files/preremove.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/preremove.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/preremove.subr       Thu Jun  1 01:58:34 2017
@@ -0,0 +1,90 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      preremove.subr -- pre-removal actions for packages
+#
+# SYNOPSIS
+#      task_preremove <datafile>
+#
+# DESCRIPTION
+#      The task_preremove function performs actions that MUST occur BEFORE
+#      deleting the package files for the removal to be successful:
+#
+#          o Unregister GNU info files.
+#          o Remove unmodified configuration files.
+#
+#      The datafile contains lines of the form:
+#
+#          # <keyword>: <arg> ...
+#
+#      These lines are used as input to the various script functions.
+#
+# RETURN VALUES
+#      Returns 0 on success, and >0 if an error occurs.
+#
+
+__task_preremove__="yes"
+
+task_load files
+task_load info_files
+task_load sort
+task_load taskfunc
+
+task_preremove()
+{
+       [ $# -gt 0 ] || return 127
+       local datafile="$1"; shift
+
+       [ -f "$datafile" ] || return 1
+
+       local stage="preinstall"
+
+       # Unregistering a GNU info files requires reading the file to find
+       # all nodes listed in the file, so it must be done before the file
+       # is removed.  Any errors in unregistering GNU info files are
+       # non-fatal.
+       #
+       task_info_files -s remove $stage < $datafile
+
+       # Removing a configuration file requires comparing it to the
+       # example file from which it was copied, so it must be done before
+       # the example file is removed.  Any errors in removing
+       # configuration files are non-fatal.
+       #
+       task_files remove $stage < $datafile
+
+       # Run the generic package tasks.
+       if task_sort -r < $datafile | task_function remove $stage; then
+               : "success"
+       else
+               # Errors from the generic package tasks are fatal.
+               return 1
+       fi
+
+       return 0
+}
Index: pkgsrc/pkgtools/pkgtasks/files/quote.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/quote.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/quote.subr   Thu Jun  1 01:58:34 2017
@@ -0,0 +1,74 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      quote.subr -- quote strings for use with shell eval
+#
+# SYNOPSIS
+#      local quoted
+#      task_quote arg [...]
+#
+# DESCRIPTION
+#      The task_quote function sets a shell variable $quoted to a string
+#      that has all of the original function arguments quoted and
+#      concatenated together.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      SED     The name or path to the sed(1) utility.
+#
+# EXAMPLES
+#      local quoted
+#      task_quote "$arg1" "$arg2" "$arg3"
+#      eval func $quoted
+#
+
+__task_quote__="yes"
+
+task_quote()
+{
+       : ${SED:=sed}
+
+       # Return quoted args in $quoted.
+       quoted=
+
+       local arg
+       for arg; do
+               case $arg in
+               *'!'*|*'*'*|*'?'*|*'['*|*'\'*|*"'"*)
+                       arg="'"`echo "$arg" | ${SED} -e "s,','\\\\\\'',g"`"'" ;;
+               *)      arg="'"$arg"'" ;;
+               esac
+               case $quoted in
+               "")     quoted=$arg ;;
+               *)      quoted="$quoted $arg" ;;
+               esac
+       done
+       # POST-CONDITION:
+       # quoted is set to the string with all arguments quoted.
+}
Index: pkgsrc/pkgtools/pkgtasks/files/random.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/random.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/random.subr  Thu Jun  1 01:58:34 2017
@@ -0,0 +1,151 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      random.subr -- generate random number (badly)
+#
+# SYNOPSIS
+#      task_random [-i [<seed>]]
+#
+#      echo $RANDOM
+#
+# DESCRIPTION
+#      The task_random function sets RANDOM to a random integer from the
+#      range 0..32767.  It should always be called before using the $RANDOM
+#      value.  The seed can be explicitly set in order to ensure a
+#      deterministic sequence of $RANDOM values.
+#
+#      The options are as follows:
+#
+#      -i <seed>
+#              Explicitly initialize with a new seed.  If the seed is not
+#              given, then a new seed is chosen based on the current time.
+#
+#      If the shell already has a built-in implementation for $RANDOM,
+#      then the task_random function simply returns 0.
+#
+# RETURN VALUES
+#      The task_random function returns 0 on success, and >0 if an error
+#      occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      AWK     The name or path to the awk(1) utility.
+#
+#      DATE    The name or path to the date(1) utility.
+#
+# EXAMPLE
+#      for i in 1 2 3 4 5; do
+#              task_random && echo $RANDOM
+#      done
+#
+# BUGS
+#      The pseudorandom number sequence will eventually enter a cycle of
+#      length 209, so task_random should periodically reseeded if a long
+#      sequence of random numbers is needed.
+#
+
+__task_random__="yes"
+__task_random_init__="_random_init"
+
+task_random()
+{
+       : ${AWK:=awk}
+       : ${DATE:=date}
+
+       local randomseed=
+       local arg
+       local OPTIND=1
+       while getopts ":i:" arg "$@"; do
+               case $arg in
+               i)      randomseed=${OPTARG} ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -eq 0 ] || return 127
+
+       if [ -n "$__task_random_exists__" ]; then
+               #
+               # If the shell already has a $RANDOM implementation, then
+               # setting RANDOM to a value initializes the seed for the
+               # random sequence.
+               #
+               [ -z "$randomseed" ] || RANDOM=$randomseed
+               return 0
+       fi
+
+       local randomseed_init=
+       if [ -n "$randomseed" ]; then
+               #
+               # This function was called with an explicit seed, so the
+               # next time this function is called without an argument,
+               # a new seed must be generated.
+               #
+               randomseed_init="yes"
+       elif [ -z "$randomseed_init" ]; then
+               #
+               # If a random seed has not been initialized, then set the
+               # seed to the time prepended with 1 and appended with a
+               # process PID.  This ensures the it is a number not
+               # beginning with zero and that it differs between multiple
+               # invocations of this function within a short span of time.
+               #
+               randomseed_init="yes"
+               local randomseed_pid
+               ( : ) & randomseed_pid=$!
+               wait $randomseed_pid
+               randomseed=$( ${DATE} +"1%H%M%S$randomseed_pid" )
+       else
+               # A random seed was previously generated, so just use
+               # $RANDOM as the next seed.
+               #
+               randomseed=$RANDOM
+       fi
+
+       # Use awk's rand() to generate random numbers; however, the PRNG
+       # for awk needs to be seeded appropriately between invocations.
+       #
+       RANDOM=$( ${AWK} -v SEED=$randomseed -v RAND_MAX=32768 \
+                 'BEGIN { srand(SEED); print int( RAND_MAX * rand() ) } ')
+}
+
+_random_init()
+{
+       # Test for the presence of a $RANDOM implementation when this file is
+       # loaded, so that entropy is not wasted.
+       #
+       case $RANDOM in
+       $RANDOM)
+               __task_random_exists__= ;;
+       *)      __task_random_exists__="yes" ;;
+       esac
+}
+
+# Static variable for whether a builtin $RANDOM exists.
+__task_random_exists__=
Index: pkgsrc/pkgtools/pkgtasks/files/refcount.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/refcount.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/refcount.subr        Thu Jun  1 01:58:34 2017
@@ -0,0 +1,120 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      refcount.subr -- reference-count API
+#
+# SYNOPSIS
+#      task_refcount exists database resource
+#      task_refcount delete database resource
+#      task_refcount add [-t token] database resource
+#      task_refcount remove [-t token] database resource
+#
+#      task_refcount prop_exists database resource property
+#      task_refcount prop_put database resource property [value ...]
+#      task_refcount prop_match database resource property [value ...]
+#      task_refcount prop_delete database resource property
+#
+# DESCRIPTION
+#      task_refcount exists database resource
+#              Checks whether there is a reference on the resource.
+#
+#      task_refcount delete database resource
+#              Deletes any reference counts and properties on the
+#              resource.
+#
+#      task_refcount add [-t token] database resource
+#      task_refcount remove [-t token] database resource
+#              Adds or removes a reference identified by token on the
+#              resource.
+#
+#      task_refcount prop_exists database resource property
+#              Checks whether a stored value exists for the property on
+#              the resoure for the package.
+#
+#      task_refcount prop_delete database resource property
+#              Removes the property on the resource for the package.
+#
+#      task_refcount prop_put database resource property [value ...]
+#              Stores a value for the property on the resource for the
+#              package.  If no value is given, then the default value for
+#              the property is stored.
+#
+#      task_refcount prop_match database resource property [value ...]
+#              Checks whether the stored value of the property on the
+#              resource for the package matches the given value.  If no
+#              value is given, then the default value for the property
+#              is used.
+#
+# RETURN VALUES
+#      The exists, prop_exists and prop_match commands return 0 on success,
+#      and >0 otherwise.
+#
+#      The remaining commands return 0 on success, and >0 if an error
+#      occurs.
+#
+# EXAMPLES
+#     o Adding a reference count on resource alpha:
+#
+#      if task_refcount exists resource alpha; then
+#              refcount_was_zero=
+#      else
+#              refcount_was_zero="yes"
+#      fi
+#      if task_refcount add resource alpha; then
+#              if resource_exists alpha; then
+#                      if [ -n "$refcount_was_zero" ]; then
+#                              task_refcount prop_put resource alpha preexist
+#                      fi
+#              else
+#                      # create resource alpha
+#                      ...
+#              fi
+#      fi
+#
+#     o Removing a reference count on resource alpha:
+#
+#      if task_refcount remove resource alpha; then
+#              if task_refcount exists resource alpha; then
+#                      : "refcount is not zero"
+#              elif task_refcount prop_exists resource alpha preexist; then
+#                      : "resource was pre-existing; don't remove"
+#              elif resource_exists alpha; then
+#                      # destroy resource alpha
+#                      ...
+#              fi
+#      fi
+#
+
+__task_refcount__="yes"
+
+task_load refcount_file
+
+task_refcount()
+{
+       task_refcount_file "$@"
+}
Index: pkgsrc/pkgtools/pkgtasks/files/refcount_file.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/refcount_file.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/refcount_file.subr   Thu Jun  1 01:58:34 2017
@@ -0,0 +1,502 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      refcount_file.subr -- directory-based reference-count implementation
+#
+# SYNOPSIS
+#      task_refcount_file exists database resource
+#      task_refcount_file add [-t token] database resource
+#      task_refcount_file remove [-t token] database resource
+#      task_refcount_file delete database resource
+#
+#      task_refcount_file prop_exists database resource property
+#      task_refcount_file prop_put database resource property [value ...]
+#      task_refcount_file prop_match database resource property [value ...]
+#      task_refcount_file prop_delete database resource property
+#
+# DESCRIPTION
+#      The functions implement the refcount API functions with the
+#      corresponding names.
+#
+# IMPLEMENTATION
+#      This is a file-based implementation of a reference-counting API
+#      for packages.  The resource being reference-counted is assigned a
+#      directory pathname that "shadows" the resource.  It is populated
+#      with the following files:
+#
+#      ${PKGNAME}
+#              This text file represents a reference on the resource by
+#              the package whose full package name is ${PKGNAME}.  Each
+#              line of the file lists the location of the metadata files
+#              for the package, known as the "package metadata directory"
+#              (default "${PKG_DBDIR}/${PKGNAME}").
+#
+#      +OWNER
+#              This text file consists of one line that lists the package
+#              metadata directory of the package that owns the resource.
+#
+#      +PREEXISTING
+#              This text file consists of one line that lists the package
+#              metadata directory of the package that discovered the
+#              resource was pre-existing.
+#
+#      +PERMISSIONS
+#              This text file consists of one line that lists the mode
+#              and permissions of a file resource.  The line is of the
+#              form: "mode owner group", where "mode" is the file mode in
+#              octal form, "owner" is the user ID of the file, and
+#              "group" is the group ID of the file.
+#
+#      There are four directories located under ${PKG_REFCOUNT_DBDIR}
+#      that are databases for resources that are reference-counted by the
+#      packages:
+#
+#      dirs/
+#      files/  The relative paths under these directories shadow the
+#              resource at the same path relative to the root directory.
+#
+#      groups/
+#              The entries of this directory are the names of groups.
+#
+#      users/  The entries of this directory are the names of users.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      MV      The name or path to the mv(1) utility.
+#
+#      PKGNAME
+#              The name of the package manipulating the reference counts.
+#
+#      PKG_DBDIR
+#              The location of the package metadata directory database.
+#              The default is "/var/db/pkg".
+#
+#      PKG_DESTDIR
+#              A "destdir" prefix that is prepended to all filesystem
+#              paths.  The default value is the empty string.
+#
+#      PKG_METADATA_DIR
+#              The absolute path to the location of the meta-data files
+#              of ${PKGNAME}.  The default is "${PKG_DBDIR}/${PKGNAME}".
+#
+#      PKG_REFCOUNT_DBDIR
+#              The location of the directory tree that shadows the
+#              resources that are reference-counted.  The default is
+#              "${PKG_DBDIR}.refcount".
+#
+#      RM      The name or path to the rm(1) utility.
+#
+#      RMDIR   The name or path to the rmdir(1) utility.
+#
+
+__task_refcount_file__="yes"
+__task_refcount_file_init__="_task_refcount_file_init"
+
+task_load cleanup
+task_load makedir
+task_load maketemp
+task_load match
+task_load quote
+
+task_refcount_file()
+{
+       [ $# -gt 0 ] || return 127
+       local command="$1"; shift
+
+       local fn
+       case $command in
+       exists|add|remove|delete|prop_exists|prop_put|prop_match|prop_delete)
+               eval fn="_task_refcount_file_$command" ;;
+       *)      return 127 ;;
+       esac
+
+       $fn "$@"
+}
+
+_task_refcount_file_pkg_token()
+{
+       : ${PKGNAME:=${0##*/}}
+       : ${PKG_DBDIR:=/var/db/pkg}
+       : ${PKG_METADATA_DIR:=${PKG_DBDIR}/${PKGNAME}}
+
+       pkg_token=${PKG_METADATA_DIR}
+
+       # POST-CONDITION:
+       # pkg_token is set to the package token unique to the system.
+}
+
+_task_refcount_file_shadowdir()
+{
+       : ${PKG_DBDIR:=/var/db/pkg}
+       : ${PKG_REFCOUNT_DBDIR:=${PKG_DBDIR}.refcount}
+
+       local db="$1"; shift
+       local resource="$1"; shift
+
+       case $resource in
+       /*)     shadowdir="${PKG_REFCOUNT_DBDIR}/$db$resource" ;;
+       *)      shadowdir="${PKG_REFCOUNT_DBDIR}/$db/$resource" ;;
+       esac
+       shadowdir="${PKG_DESTDIR}/$shadowdir"
+
+       # POST-CONDITION:
+       # shadowdir is set to the location of the shadow directory.
+}
+
+_task_refcount_file_exists()
+{
+       local db="$1"; shift
+       local resource="$1"; shift
+
+       local shadowdir
+       _task_refcount_file_shadowdir "$db" "$resource"
+       # shadowdir is now set to the location of the shadow directory.
+
+       set -- "$shadowdir"/*
+       local entry
+       for entry; do
+               case $entry in
+               "$shadowdir/*")
+                       : "no references found" ;;
+               "$shadowdir"/+*)
+                       : "property file" ;;
+               *)      # package reference found
+                       return 0 ;;
+               esac
+       done
+       return 1
+}
+
+_task_refcount_file_delete()
+{
+       : ${RM:=rm}
+       : ${RMDIR:=rmdir}
+
+       local db="$1"; shift
+       local resource="$1"; shift
+
+       local shadowdir
+       _task_refcount_file_shadowdir "$db" "$resource"
+       # shadowdir is now set to the location of the shadow directory.
+
+       # Remove all references and properties.
+       ${RM} -f "$shadowdir"/*
+       # Remove the shadow directory.
+       ${RMDIR} -p "$shadowdir" 2>/dev/null
+       [ ! -d "$shadowdir" ] || return 1
+}
+
+_task_refcount_file_add()
+{
+       : ${MV:=mv}
+
+       local token=
+       local arg
+       local OPTIND=1
+       while getopts ":t:" arg "$@"; do
+               case $arg in
+               t)      token=${OPTARG} ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+
+       local db="$1"; shift
+       local resource="$1"; shift
+
+       if [ -z "$token" ]; then
+               local pkg_token
+               _task_refcount_file_pkg_token
+               # pkg_token is now set to the package token unique to the system.
+               token=$pkg_token
+       fi
+
+       local shadowdir
+       _task_refcount_file_shadowdir "$db" "$resource"
+       # shadowdir is now set to the location of the shadow directory.
+       local countfile="$shadowdir/${PKGNAME}"
+
+       task_makedir "$shadowdir" 2>/dev/null
+       [ -d "$shadowdir" ] || return 1
+
+       local result=0
+       local temp temp_quoted quoted
+       temp=$( task_maketemp "$countfile.pkgtasks.XXXXXXXXXX" )
+       if [ -n "$temp" ]; then
+               task_quote "$temp"
+               temp_quoted=$quoted
+               __task_refcount_file_temps__="$__task_refcount_file_temps__ $temp_quoted"
+               { if [ -f "$countfile" ]; then
+                       task_match -sv "$token" < $countfile
+                 fi
+                 echo "$token"
+               } > $temp
+               # rename(2) is atomic
+               if ${MV} -f "$temp" "$countfile"; then
+                       __task_refcount_file_temps__=${__task_refcount_file_temps__% $temp_quoted}
+               else
+                       result=1
+               fi
+       else
+               # cannot create temporary file
+               result=1
+       fi
+
+       _task_refcount_file_cleanup
+       return $result
+}
+
+_task_refcount_file_remove()
+{
+       : ${MV:=mv}
+       : ${RM:=rm}
+       : ${RMDIR:=rmdir}
+
+       local token=
+       local arg
+       local OPTIND=1
+       while getopts ":t:" arg "$@"; do
+               case $arg in
+               t)      token=${OPTARG} ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+
+       local db="$1"; shift
+       local resource="$1"; shift
+
+       if [ -z "$token" ]; then
+               local pkg_token
+               _task_refcount_file_pkg_token
+               # pkg_token is now set to the package token unique to the system.
+               token=$pkg_token
+       fi
+
+       local shadowdir
+       _task_refcount_file_shadowdir "$db" "$resource"
+       # shadowdir is now set to the location of the shadow directory.
+       local countfile="$shadowdir/${PKGNAME}"
+
+       local result=0
+       if [ -f "$countfile" ]; then
+               local temp temp_quoted quoted
+               temp=$( task_maketemp "$countfile.pkgtasks.XXXXXXXXXX" )
+               if [ -n "$temp" ]; then
+                       task_quote "$temp"
+                       temp_quoted=$quoted
+                       __task_refcount_file_temps__="$__task_refcount_file_temps__ $temp_quoted"
+                       task_match -sv "$token" < $countfile > $temp
+                       local remaining=
+                       if [ -f "$temp" ]; then
+                               local line
+                               while read line; do
+                                       # reference file is non-empty
+                                       remaining="yes"
+                                       break
+                               done < $temp
+                               # rename(2) is atomic
+                               if ${MV} -f "$temp" "$countfile"; then
+                                       __task_refcount_file_temps__=${__task_refcount_file_temps__% $temp_quoted}
+                               else
+                                       result=1
+                               fi
+                       else
+                               # cannot create temporary file
+                               result=1
+                       fi
+                       if [ -z "$remaining" ]; then
+                               ${RM} -f "$countfile" || result=1
+                       fi
+               fi
+       fi
+       # Remove shadow directory if empty.
+       ${RMDIR} -p "$shadowdir" 2>/dev/null
+
+       _task_refcount_file_cleanup
+       return $result
+}
+
+_task_refcount_file_propfile()
+{
+       local db="$1"; shift
+       local resource="$1"; shift
+       local property="$1"; shift
+
+       local shadowdir
+       _task_refcount_file_shadowdir "$db" "$resource"
+       # shadowdir is now set to the location of the shadow directory.
+
+       propfile=
+       case $property in
+       owner)  propfile="$shadowdir/+OWNER" ;;
+       preexist)
+               propfile="$shadowdir/+PREEXISTING" ;;
+       permissions)
+               propfile="$shadowdir/+PERMISSIONS" ;;
+       +*)     propfile="$shadowdir/$property" ;;
+       *)      propfile="$shadowdir/+$property" ;;
+       esac
+       # POST-CONDITION:
+       # propfile is set to the location of the property file.
+}
+
+_task_refcount_file_prop_exists()
+{
+       local db="$1"; shift
+       local resource="$1"; shift
+       local property="$1"; shift
+
+       local propfile
+       _task_refcount_file_propfile "$db" "$resource" "$property"
+       # propfile is now set to the location of the property file.
+
+       [ -f "$propfile" ] || return 1
+       return 0
+}
+
+_task_refcount_file_prop_put()
+{
+       : ${MV:=mv}
+
+       local db="$1"; shift
+       local resource="$1"; shift
+       local property="$1"; shift
+
+       local propfile
+       _task_refcount_file_propfile "$db" "$resource" "$property"
+       # propfile is now set to the location of the property file.
+
+       local pkg_token
+       _task_refcount_file_pkg_token
+       # pkg_token is now set to the package token unique to the system.
+
+       local shadowdir="${propfile%/*}"
+       task_makedir "$shadowdir" 2>/dev/null
+       [ -d "$shadowdir" ] || return 1
+
+       local result=0
+       local temp temp_quoted quoted
+       temp=$( task_maketemp "$propfile.pkgtasks.XXXXXXXXXX" )
+       if [ -n "$temp" ]; then
+               task_quote "$temp"
+               temp_quoted=$quoted
+               __task_refcount_file_temps__="$__task_refcount_file_temps__ $temp_quoted"
+               local value
+               if [ $# -gt 0 ]; then
+                       value="$@"
+               else
+                       value=$pkg_token
+               fi
+               echo "$value" > $temp
+               # rename(2) is atomic
+               if ${MV} -f "$temp" "$propfile"; then
+                       __task_refcount_file_temps__=${__task_refcount_file_temps__% $temp_quoted}
+               else
+                       result=1
+               fi
+       else
+               # cannot create temporary file
+               result=1
+       fi
+
+       _task_refcount_file_cleanup
+       return $result
+}
+
+_task_refcount_file_prop_match()
+{
+       local db="$1"; shift
+       local resource="$1"; shift
+       local property="$1"; shift
+
+       local propfile
+       _task_refcount_file_propfile "$db" "$resource" "$property"
+       # propfile is now set to the location of the property file.
+
+       local pkg_token
+       _task_refcount_file_pkg_token
+       # pkg_token is now set to the package token unique to the system.
+
+       if [ -f "$propfile" ]; then
+               local pattern
+               if [ $# -gt 0 ]; then
+                       pattern="$@"
+               else
+                       pattern=$pkg_token
+               fi
+               if task_match -q "$pattern" < $propfile; then
+                       return 0
+               fi
+       fi
+       return 1
+}
+
+_task_refcount_file_prop_delete()
+{
+       : ${RM:=rm}
+       : ${RMDIR:=rmdir}
+
+       local db="$1"; shift
+       local resource="$1"; shift
+       local property="$1"; shift
+
+       local propfile
+       _task_refcount_file_propfile "$db" "$resource" "$property"
+       # propfile is now set to the location of the property file.
+
+       local result=0
+       ${RM} -f "$propfile"
+       [ ! -f "$propfile" ] || result=1
+
+       # Try to clean up the shadow directory in case it is empty.
+       local shadowdir="${propfile%/*}"
+       ${RMDIR} -p "$shadowdir" 2>/dev/null
+       return $result
+}
+
+_task_refcount_file_cleanup()
+{
+       : ${RM:=rm}
+
+       eval set -- $__task_refcount_file_temps__
+       local file
+       for file; do
+               ${RM} -f "$file"
+       done
+       __task_refcount_file_temps__=
+}
+
+_task_refcount_file_init()
+{
+       task_cleanup_add_hook _task_refcount_file_cleanup
+}
+
+# Static variable for temporary files that should be removed if an error occurs.
+__task_refcount_file_temps__=
Index: pkgsrc/pkgtools/pkgtasks/files/say.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/say.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/say.subr     Thu Jun  1 01:58:34 2017
@@ -0,0 +1,116 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      say.subr -- write to standard output with a tag
+#
+# SYNOPSIS
+#      task_say <tag> [string ...]
+#
+# DESCRIPTION
+#      The task_say function writes any specified operands, separated by
+#      single blank (" ") characters and followed by a newline ("\n")
+#      character, to the standard output.  The tag specifies the type of
+#      information that is written.
+#
+#      If the terminal supports color, then the tags cause the output to
+#      be written in a matching color:
+#
+#              info            cyan
+#              error           red
+#              pass            green
+#              skip            blue
+#              warn            yellow
+#              - or none       white
+#
+# RETURN VALUES
+#      Returns 0 on success, and >0 if an error occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      PRINTF  The name or path to the printf(1) utility.
+#
+
+__task_say__="yes"
+
+_task_say_ansi_color()
+{
+       : ${TPUT:=tput}
+
+       case $__task_say_ansi_color__ in
+       yes)    return 0 ;;
+       no)     return 1 ;;
+       esac
+
+       # Only attempt to output ANSI color sequences if standard output
+       # is connected to a terminal.
+       #
+       [ -t 1 ] || return 1
+
+       local colors
+       local property
+       for property in Co colors; do
+               colors=$( ${TPUT} Co 2>/dev/null )
+               if [ $? -eq 0 ] && [ "$colors" -gt 2 ]; then
+                       __task_say_ansi_color__="yes" && return 0
+               fi
+       done
+       __task_say_ansi_color="no" && return 1
+}
+
+task_say()
+{
+       : ${PRINTF:=printf}
+
+       local none="\033[0m"
+       local blue="\033[34m"
+       local cyan="\033[36m"
+       local green="\033[32m"
+       local red="\033[31m"
+       local yellow="\033[33m"
+
+       local color
+       local msgtype="$1"; shift
+       case $msgtype in
+       info)   color=$cyan ;;
+       error)  color=$red ;;
+       pass)   color=$green ;;
+       skip)   color=$blue ;;
+       warn)   color=$yellow ;;
+       -|none) color=$none ;;
+       esac
+
+       if _task_say_ansi_color && [ -n "$color" ]; then
+               ${PRINTF} "$color$*$none\n"
+       else
+               echo "$*"
+       fi
+}
+
+# Static variable for whether the terminal supports ANSI colors.
+__task_say_ansi_color__=
Index: pkgsrc/pkgtools/pkgtasks/files/shells.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/shells.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/shells.subr  Thu Jun  1 01:58:34 2017
@@ -0,0 +1,292 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      shells.subr -- shell database management for packages
+#
+# SYNOPSIS
+#      task_shells [-s] add | remove
+#      task_shells check-add | check-remove
+#
+# DESCRIPTION
+#      The task_shells function supports four actions: "add", "remove",
+#      "check-add", and "check-remove".
+#
+#      The available options are as follows:
+#
+#      -s      Silent; don't write to standard output.
+#
+#      The task_shells function reads standard input line by line and
+#      looks for lines of the form:
+#
+#          # SHELL: <shell_path> [<shelldb_path>]
+#
+#      If any of the paths are relative, then they are assumed to be
+#      relative to ${PKG_PREFIX}.
+#
+#      The "add" action adds shell paths to the shell database.
+#
+#      The "remove" action removes shell paths from the shell database.
+#
+#      The "check-add" action will check whether shell paths are missing
+#      from the shell database and writes an informative message noting
+#      the missing shell paths.
+#
+#      The "check-remove" action will check whether shell paths are
+#      still present in the shell database and writes an informative
+#      message noting the existing paths.
+#
+# RETURN VALUES
+#      The "add" and "remove" actions return 0 if they are successful
+#      for all shell paths, and >0 if an error occurs.
+#
+#      The "check-add" and "check-remove" actions return >0 if they
+#      write informative messages, and return 0 otherwise.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      MV      The name or path to the mv(1) utility.
+#
+#      PKGNAME
+#              The name of the package.
+#
+#      PKG_DESTDIR
+#              A "destdir" prefix that is prepended to all filesystem
+#              paths.  The default value is the empty string.
+#
+#      PKG_REGISTER_SHELLS
+#              If ${PKG_REGISTER_SHELLS} is a "truthy" value, then the
+#              "add" and "remove" actions are allowed to modify the shell
+#              databases as needed.
+#
+#      PKG_PREFIX
+#              The installation prefix of the package.  The default is
+#              "/usr/pkg".
+#
+#      RM      The name or path to the rm(1) utility.
+#
+#      TASK_MSG
+#              String prepended to all normal message written to
+#              standard output.
+#
+
+__task_shells__="yes"
+__task_shells_init__="_task_shells_init"
+
+task_load cleanup
+task_load echo
+task_load lock
+task_load maketemp
+task_load match
+task_load quote
+task_load truthy
+
+task_shells()
+{
+       : ${MV:=mv}
+
+       : ${PKG_PREFIX:=/usr/pkg}
+       : ${PKGNAME:=${0##*/}}
+
+       : ${PKG_REGISTER_SHELLS:=yes}
+       : ${TASK_MSG:=""}
+
+       local arg
+       local echo="task_echo"
+       local OPTIND=1
+       while getopts ":s" arg "$@"; do
+               case $arg in
+               s)      echo=":" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+
+       local action="$1"; shift
+       case $action in
+       add|remove|check-add|check-remove)
+               : "valid actions" ;;
+       *)      return 0 ;;
+       esac
+
+       # Guard against ${PKG_PREFIX} == "/".
+       local prefix
+       case ${PKG_PREFIX}/ in
+       //)     prefix= ;;
+       *)      prefix=${PKG_PREFIX} ;;
+       esac
+
+       local register_shells="yes"
+       task_is_truthy "${PKG_REGISTER_SHELLS}" || register_shells=
+
+       local result line_result
+       local quoted
+       local lock lock_quoted
+       local temp temp_quoted
+
+       result=0
+       local hash tag shell shelldb
+       while read hash tag shell shelldb; do
+               # Filter for "# SHELL:".
+               case $hash/$tag in
+               "#/SHELL:")
+                       : "use this line" ;;
+               *)      continue ;;
+               esac
+
+               # Canonicalize paths.
+               case $shell in
+               "")     # skip lines without any required args
+                       continue ;;
+               [!/]*)  shell="$prefix/$shell" ;;
+               esac
+               case $shelldb in
+               "")     shelldb="/etc/shells" ;;
+               [!/]*)  shelldb="$prefix/$shelldb" ;;
+               esac
+               shelldb="${PKG_DESTDIR}$shelldb"
+
+               line_result=0
+               case $action in
+               add|remove)
+                       lock="$shelldb.lock"
+                       task_quote "$lock"
+                       lock_quoted=$quoted
+                       __task_shells_locks__="$lock_quoted $__task_shells_locks__"
+                       task_lock "$lock" || line_result=1 ;;
+               esac
+               if [ $line_result -eq 0 ]; then
+                       case $action in
+                       add)    if [ -n "$register_shells" ]; then
+                                       if [ -f "$shelldb" ] && task_match -qw "$shell" < $shelldb; then
+                                               $echo "${TASK_MSG}! shell already added: $shell"
+                                       else
+                                               temp=$( task_maketemp "$shelldb.pkgtasks.XXXXXXXXXX" )
+                                               if [ -n "$temp" ]; then
+                                                       task_quote "$temp"
+                                                       temp_quoted="$quoted"
+                                                       __task_shells_temps__="$__task_shells_temps__ $temp_quoted"
+                                                       if [ ! -f "$shelldb" ]; then
+                                                               echo "$shell"
+                                                       else
+                                                               task_match -vw "$shell" < $shelldb
+                                                               echo "$shell"
+                                                       fi > $temp
+                                                       # rename(2) is atomic.
+                                                       if ${MV} -f "$temp" "$shelldb"; then
+                                                               $echo "${TASK_MSG}> shell added: $shell"
+                                                               __task_shells_temps__=${__task_shells_temps__% $temp_quoted}
+                                                       else
+                                                               $echo "${TASK_MSG}! shell not added: $shell"
+                                                               line_result=1
+                                                       fi
+                                               else
+                                                       $echo "${TASK_MSG}! cannot create temporary file for $shelldb"
+                                                       line_result=1
+                                               fi
+                                       fi
+                               fi ;;
+                       remove) if [ -n "$register_shells" ]; then
+                                       if [ -f "$shelldb" ] && task_match -qw "$shell" < $shelldb; then
+                                               temp=$( task_maketemp "$shelldb.pkgtasks.XXXXXXXXXX" )
+                                               if [ -n "$temp" ]; then
+                                                       task_quote "$temp"
+                                                       temp_quoted="$quoted"
+                                                       __task_shells_temps__="$__task_shells_temps__ $temp_quoted"
+                                                       task_match -vw "$shell" < $shelldb > $temp
+                                                       # rename(2) is atomic.
+                                                       if ${MV} -f "$temp" "$shelldb"; then
+                                                               $echo "${TASK_MSG}> shell removed: $shell"
+                                                               __task_shells_temps__=${__task_shells_temps__% $temp_quoted}
+                                                       else
+                                                               $echo "${TASK_MSG}! shell not removed: $shell"
+                                                               line_result=1
+                                                       fi
+                                               else
+                                                       $echo "${TASK_MSG}! cannot create temporary file for $shelldb"
+                                                       line_result=1
+                                               fi
+                                       else
+                                               $echo "${TASK_MSG}! shell already removed: $shell"
+                                       fi
+                               fi ;;
+                       check-add)
+                               if [ -f "$shelldb" ] && task_match -qw "$shell" < $shelldb; then
+                                       : "shell already added"
+                               else
+                                       task_echo "!!! INFO: ${PKGNAME}: Add shell \"$shell\" to $shelldb."
+                                       line_result=1
+                               fi ;;
+                       check-remove)
+                               if [ -f "$shelldb" ] && task_match -qw "$shell" < $shelldb; then
+                                       task_echo "!!! INFO: ${PKGNAME}: Remove shell \"$shell\" from $shelldb."
+                                       line_result=1
+                               fi ;;
+                       esac
+               fi
+               case $action in
+               add|remove)
+                       task_lock -r "$lock"
+                       __task_shells_locks__=${__task_shells_locks__#$lock_quoted } ;;
+               esac
+               [ $line_result -eq 0 ] || result=1
+       done
+
+       _task_shells_cleanup
+       return $result
+}
+
+_task_shells_cleanup()
+{
+       : ${RM:=rm}
+
+       eval set -- $__task_shells_temps__
+       local file
+       for file; do
+               ${RM} -f "$file"
+       done
+       __task_shells_temps__=
+
+       eval set -- $__task_shells_locks__
+       local lockfile
+       for lockfile; do
+               task_lock -r "$lockfile"
+       done
+       __task_shells_locks__=
+}
+
+_task_shells_init()
+{
+       task_cleanup_add_hook _task_shells_cleanup
+}
+
+# Static variable for temporary files that should be removed in an error occurs.
+__task_shells_temps__=
+# Static variable for locks that should be released if an error occurs.
+__task_shells_locks__=
Index: pkgsrc/pkgtools/pkgtasks/files/shlibs.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/shlibs.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/shlibs.subr  Thu Jun  1 01:58:34 2017
@@ -0,0 +1,179 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      shlibs.subr -- update the shared library cache
+#
+# SYNOPSIS
+#      task_shlibs [-s] add | remove
+#
+# DESCRIPTION
+#      The task_shlibs function supports two actions: "add" and "remove".
+#
+#      Both the "add" and "remove" actions rebuild the system database
+#      of run-time library search paths so that the system can find the
+#      package's shared libraries.
+#
+#      The available options are as follows:
+#
+#      -s      Silent; don't write to standard output.
+#
+#      The task_shlibs function reads standard input line by line and
+#      looks for lines of the form:
+#
+#          # SHLIB: <directory> [...]
+#
+#      The directory paths are all passed as shell positional paramters
+#      to the ${LDCONFIG_ADD_CMD} and ${LDCONFIG_REMOVE_CMD} command
+#      lines.
+#
+#      If any directory paths are relative, then they are assumed to be
+#      relative to ${PKG_PREFIX}.
+#
+# RETURN VALUES
+#      Returns 0 on success, and >0 if an error occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      LDCONFIG
+#              The name or path to the ldconfig(8) utility.
+#
+#      LDCONFIG_ADD_CMD
+#      LDCONFIG_REMOVE_CMD
+#              The command-line to be invoked to update the system
+#              run-time library paths cache when adding or removing
+#              a package.
+#
+#              Possible: any shell command-line
+#              Default: ${LDCONFIG}
+#
+#      PKGNAME
+#              The name of the package.
+#
+#      PKG_DESTDIR
+#              A "destdir" prefix that is prepended to all filessystem
+#              paths.  The default value is the empty string.
+#
+#      PKG_PREFIX
+#              The installation prefix of the package.  The default is
+#              "/usr/pkg".
+#
+#      TASK_MSG
+#              String prepended to all normal message written to
+#              standard output.
+#
+
+__task_shlibs__="yes"
+
+task_load echo
+task_load quote
+
+task_shlibs()
+{
+       : ${LDCONFIG_ADD_CMD:=_task_shlibs_run}
+       : ${LDCONFIG_REMOVE_CMD:=_task_shlibs_run}
+
+       : ${PKGNAME:=${0##*/}}
+       : ${TASK_MSG:=""}
+
+       local arg
+       local echo="task_echo"
+       local OPTIND=1
+       while getopts ":s" arg "$@"; do
+               case $arg in
+               s)      echo=":" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+
+       local action="$1"; shift
+       case $action in
+       add|remove)
+               : "valid actions" ;;
+       *)      return 0 ;;
+       esac
+
+       # Guard against ${PKG_PREFIX} == "/".
+       local prefix
+       case ${PKG_PREFIX}/ in
+       //)     prefix= ;;
+       *)      prefix=${PKG_PREFIX} ;;
+       esac
+
+       local quoted paths
+       paths=
+       local hash tag path
+       while read hash tag dirs; do
+               # Filter for "# SHLIB:".
+               case $hash/$tag in
+               "#/SHLIB:")
+                       : "use this line" ;;
+               *)      continue ;;
+               esac
+               case $dirs in
+               "")     # skip lines without any required args
+                       continue ;;
+               esac
+               # Canonicalize paths.
+               set -o noglob; set -- $dirs; set +o noglob
+               for path; do
+                       case $path in
+                       "")     # skip empty pathnames
+                               continue ;;
+                       [!/]*)  path="$prefix/$path" ;;
+                       esac
+                       path="${PKG_DESTDIR}$path"
+                       task_quote "$path"
+                       paths="$paths $quoted"
+               done
+       done
+       [ -n "$paths" ] || return 0
+
+       local result=0
+       case $action in
+       add)    ( eval set -- $paths; ${LDCONFIG_ADD_CMD} ) >/dev/null ||
+                       result=1 ;;
+       remove) ( eval set -- $paths; ${LDCONFIG_REMOVE_CMD} ) >/dev/null ||
+                       result=1 ;;
+       esac
+       if [ $result -eq 0 ]; then
+               $echo "${TASK_MSG}> shared library cache rebuilt"
+       else
+               $echo "${TASK_MSG}! shared library cache not rebuilt"
+       fi
+       return $result
+}
+
+_task_shlibs_run()
+{
+       : ${LDCONFIG:=ldconfig}
+
+       ${LDCONFIG}
+}
Index: pkgsrc/pkgtools/pkgtasks/files/sort.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/sort.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/sort.subr    Thu Jun  1 01:58:34 2017
@@ -0,0 +1,94 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      sort.subr -- sort lines from standard input
+#
+# SYNOPSIS
+#      task_sort [-ru]
+#
+# DESCRIPTION
+#      The task_sort function reads lines from standard input until EOF is
+#      reached and writes them to standard output in lexographically-sorted
+#      order.
+#
+#      The options are as follows:
+#
+#      -r      Reverse: sort in reverse order.
+#      -u      Unique: suppress duplicate lines.
+#
+# RETURN VALUES
+#      Returns 0 on success, and >0 if an error occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      AWK     The name or path to the awk(1) utility.
+#
+
+__task_sort__="yes"
+
+task_sort()
+{
+       : ${AWK:=awk}
+
+       local cmp="<"
+       local uniq=0
+       local arg
+       local OPTIND=1
+       while getopts ":ru" arg "$@"; do
+               case $arg in
+               r)      cmp=">" ;;
+               u)      uniq=1 ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+
+       ${AWK} '        { line[NR] = $0 }
+               END     { # sort with insertion sort
+                       n = 0   # number of duplicates
+                       for ( i = 1; i <= NR; i++ ) {
+                               value = line[i]
+                               j = i - n - 1
+                               while ( j > 0 && value '"$cmp"' line[j] ) {
+                                       j--
+                               }
+                               if ( '"$uniq"' > 0 && j > 0 && value == line[j] ) {
+                                       # duplicate of jth value
+                                       n++
+                               } else {
+                                       for ( k = i - n - 1; k > j; k-- )
+                                               line[k+1] = line[k]
+                                       line[j+1] = value
+                               }
+                       }
+                       for ( i = 1; i <= NR - n; i++ )
+                               print line[i]
+               }'
+
+}
Index: pkgsrc/pkgtools/pkgtasks/files/taskfunc.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/taskfunc.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/taskfunc.subr        Thu Jun  1 01:58:34 2017
@@ -0,0 +1,148 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      taskfunc.subr -- generic package task
+#
+# SYNOPSIS
+#      task_is_function <value>
+#
+#      task_function add | remove [<stage>]
+#      task_function check-add | check-remove [<stage>]
+#
+# DESCRIPTION
+#      task_is_function checks whether <value> is a shell function defined
+#      in the current environment.
+#
+#      task_function supports four actions: "add", "remove", "check-add",
+#      and "check-remove".  The function reads standard input line by line
+#      and looks for lines of the form:
+#
+#          # TASK: <taskname> [<arg> ...]
+#
+#      <taskname> is the name of the task to invoke, and the remaining
+#      arguments are passed to the standard input of the task function.
+#
+#      The task function is invoked as:
+#
+#          <taskname> <action> [<stage>]
+#
+#      The task function should return 0 for unknown actions.
+#
+#      The <stage> is an optional parameter that is one of four values:
+#
+#      preinstall      invoked from the preinstall task
+#      preremove       invoked from the preremove task
+#      postinstall     invoked from the postinstall task
+#      postremove      invoked from the postremove task
+#
+# RETURN VALUES
+#      task_is_function returns 0 if the value is a shell function, and >0
+#      otherwise.
+#
+#      task_function returns the return value of the task invoked.
+#
+
+__task_taskfunc__="yes"
+
+task_is_function()
+{
+       type "$1" | while read line; do
+               case $line in
+               *" function") return 0 ;;
+               esac
+               return 1
+       done
+}
+
+task_function()
+{
+       : ${AWK:=awk}
+
+       local arg
+       local OPTIND=1
+       while getopts ":s" arg "$@"; do
+               case $arg in
+               s)      : "silently accept to match other package tasks" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+
+       [ $# -gt 0 ] || return 127
+       local action="$1"; shift
+       local stage="$1"
+
+       # Use AWK to re-sequence the standard input.
+       ${AWK} 'BEGIN {
+                       ws = "[[:space:]]"
+                       hashtag_re = "^" ws "*#" ws "+TASK:" ws "+"
+               }
+               match( $0, hashtag_re ) > 0 {
+                       name = $3
+                       if ( length( name ) > 0 ) {
+                               sub( hashtag_re name ws "+", "" )
+                               n = ( name in max_line ) ? max_line[name] + 1 : 1
+                               max_line[name] = n
+                               line[name, n] = $0
+                               if ( !( name in tasks ) ) {
+                                       tasks[name] = name
+                                       n = max_task ? max_task + 1 : 1
+                                       max_task = n
+                                       task[n] = name
+                               }
+                       }
+               }
+               END     {
+                       for ( i = 1; i <= max_task; i++ )
+                       {
+                               name = task[i]
+                               print "# FUNCTION: " name
+                               for ( j = 1; j <= max_line[name]; j++ ) {
+                                       print line[name, j]
+                               }
+                               print "# END"
+                       }
+               }
+       ' | (
+               local hash tag name task line
+               while read hash tag name; do
+                       case $hash/$tag in
+                       "#/FUNCTION:")
+                               # valid input stream
+                               task=$name ;;
+                       *)      return 0
+                       esac
+                       task_is_function "$task" || return 1
+                       while read line; do
+                               set -- $line; hash="$1"; tag="$2"; name="$3"
+                               case $hash/$tag in "#/END") break ;; esac
+                               echo "$line"
+                       done | $task $action $stage
+               done
+       )
+}
Index: pkgsrc/pkgtools/pkgtasks/files/tee.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/tee.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/tee.subr     Thu Jun  1 01:58:34 2017
@@ -0,0 +1,81 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      tee.subr -- duplicate standard input to standard output and files
+#
+# SYNOPSIS
+#      task_tee [-a] [<file> ...]
+#
+# DESCRIPTION
+#      The task_tee function copies standard input to standard output,
+#      making a copy in zero or more files.
+#
+#      The options are as follows:
+#
+#      -a      Append the output to the files rather than overwriting
+#              them.
+#
+#      The <file> parameters are the pathnames of the files in which
+#      copies of the output are made.
+#
+# RETURN VALUES
+#      Returns 0 on success, and >0 if an error occurs.
+#
+
+__task_tee__="yes"
+
+task_load createfile
+
+task_tee()
+{
+       local append=
+       local arg
+       local OPTIND=1
+       while getopts ":a" arg "$@"; do
+               case $arg in
+               a)      append="yes" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+
+       # Overwrite all output files with empty files unless append was
+       # requested.
+       #
+       if [ -z "$append" ]; then
+               task_createfile "$@"
+       fi
+
+       local line file
+       while IFS= read line; do
+               echo "$line"
+               for file; do
+                       echo "$line" >> $file
+               done
+       done
+}
Index: pkgsrc/pkgtools/pkgtasks/files/truthy.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/truthy.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/truthy.subr  Thu Jun  1 01:58:34 2017
@@ -0,0 +1,57 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      truthy.subr -- evaluate truthiness
+#
+# SYNOPSIS
+#      task_is_truthy value
+#
+# DESCRIPTION
+#      task_is_truthy evaluates whether the given value is "truthy", which
+#      means it has a value of "yes", "true", "on", or 1, disregarding
+#      case.
+#
+# RETURN VALUES
+#      Returns 0 if the value is truthy, and >0 otherwise.
+#
+# EXAMPLES
+#      if task_is_truthy "$variable"; then
+#              echo "$variable is truthy"
+#      fi
+#
+
+__task_truthy__="yes"
+
+task_is_truthy()
+{
+       case $1 in
+       [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
+               return 0 ;;
+       esac
+       return 1
+}
Index: pkgsrc/pkgtools/pkgtasks/files/unittest.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/unittest.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/unittest.subr        Thu Jun  1 01:58:34 2017
@@ -0,0 +1,376 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      unittest.subr -- run unit tests and produce TAP output
+#
+# SYNOPSIS
+#      task_requires_root
+#
+#      task_load_test <test_module> ...
+#
+#      task_run_tests [-q] [<n>]
+#
+# DESCRIPTION
+#      The task_requires_root function checks whether the the user is
+#      "root" and sets the "describe" environment variable to a "skip"
+#      directive.
+#
+#      The task_load_test function sources the test module from the
+#      ${TASK_TESTS_DIR} directory and passes it all of the remaining
+#      parameters.
+#
+#      The task_run_tests function runs all functions named "test<n>" in
+#      order, starting with "test1", and it produces output in Test
+#      Anything Protocol (TAP) format.
+#
+#      The options are as follows:
+#
+#      -q      Quiet; Close the standard output and standard error before
+#              running the test.  If the "-q" option is not present, then
+#              the standard output and standard error are left open.
+#
+#      <n>     Only run "test<n>".
+#
+#      task_run_tests sets the environment variable ${TEST_CURDIR} to the
+#      location where each test function is run.
+#
+#      A test function must set the "describe" environment variable to
+#      the "TAP test line" description for the test.
+#
+#      If the test_setup and test_teardown functions are present, then
+#      they are called respectively before and after each test function
+#      is called.
+#
+# RETURN VALUES
+#      The task_requires_root function returns 0 if the user is root,
+#      and >0 otherwise.
+#
+#      The task_load_test function returns 0 on success, and >0 if an
+#      error occurs.
+#
+#      The task_run_tests function returns the number of tests that failed
+#      when run.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      ID      The name or path to the id(1) utility.
+#
+#      RM      The name or path to the rm(1) utility.
+#
+#      TASK_TESTS_DIR
+#              The path to the directory containing the tests.
+#
+# EXAMPLE
+#
+#      # Load unittest functions.
+#      task_load unittest
+#
+#      # test_setup() is run before each test<n>.
+#      test_setup() {
+#              var="visible in all test functions"
+#      }
+#
+#      test1() {
+#              describe="guaranteed success"
+#              echo "This is visible in the output unless -q is given."
+#              # copied group file is automatically removed after test is run
+#              cp /etc/group .
+#              return 0
+#      }
+#
+#      task_run_tests "$@"
+#
+
+__task_unittest__="yes"
+
+task_load taskfunc     # task_is_function
+task_load maketemp
+task_load say
+
+task_requires_root()
+{
+       : ${ID:=id}
+
+       if [ -z "$__task_uid__" ]; then
+               __task_uid__=$( ${ID} -u )
+       fi
+       if [ "$__task_uid__" != 0 ]; then
+               describe="# skip $describe (requires root)"
+               return 1
+       fi
+       return 0
+}
+
+task_load_test()
+{
+       : ${TASK_TESTS_DIR:=.}
+
+       [ $# -gt 0 ] || return 127
+       local module="$1"; shift
+
+       local found=
+       local test_module_path suffix
+       for suffix in "" ".sh"; do
+               test_module_path="${TASK_TESTS_DIR}/$module$suffix"
+               if [ -f "$test_module_path" ]; then
+                       found=yes
+                       break
+               fi
+       done
+       if [ -n "$found" ]; then
+               unset found module suffix
+               . "$test_module_path"
+       else
+               echo 1>&2 "Error: Loading test $module failed: $test_module_path"
+               return 1
+       fi
+}
+
+task_run_tests()
+{
+       # If the first parameter is "-s", then short-circuit return 0.
+       case $1 in -s) return 0 ;; esac
+       _task_tap_test "$@" | task_tap_harness
+}
+
+_task_tap_test()
+{
+       local run_args=
+       local arg
+       local OPTIND=1
+       while getopts ":q" arg "$@"; do
+               case $arg in
+               q)      run_args="$run_args -$arg" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       # Remaining arguments are tests to run.
+
+       local setup_fn="test_setup"
+       local teardown_fn="test_teardown"
+
+       task_is_function "$setup_fn" || setup_fn=":"
+       task_is_function "$teardown_fn" || teardown_fn=":"
+
+       local failures=0
+
+       if [ $# -gt 0 ]; then
+               # Explicit list of tests to run.
+               local max=0
+               local number test_fn
+               for number; do
+                       test_fn="test$number"
+                       task_is_function "$test_fn" || break
+                       max=$(( $max + 1 ))
+               done
+               # Write the TAP plan before the test output.
+               echo "1..$max"
+               # Run the tests.
+               for number; do
+                       _task_tap_line $run_args $number $setup_fn $teardown_fn ||
+                               failures=$(( $failures + 1 ))
+               done
+       else
+               local max=0
+               local number=1
+               local test_fn
+               while : ; do
+                       test_fn="test$number"
+                       task_is_function "$test_fn" || break
+                       max=$number
+                       number=$(( $number + 1 ))
+               done
+               # Write the TAP plan before the test output.
+               echo "1..$max"
+               number=1
+               run_args="$run_args -n"
+               # Run the tests.
+               while [ $number -le $max ]; do
+                       _task_tap_line $run_args $number $setup_fn $teardown_fn ||
+                               failures=$(( $failures + 1 ))
+                       number=$(( $number + 1 ))
+               done
+       fi
+       return $failures
+}
+
+_task_tap_line()
+{
+       : ${RM:=rm}
+
+       local quiet=
+       local write_number=
+       local arg
+       local OPTIND=1
+       while getopts ":nq" arg "$@"; do
+               case $arg in
+               n)      write_number="yes" ;;
+               q)      quiet="yes" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -eq 3 ] || return 127
+       local number="$1"
+       local setup_fn="$2"
+       local teardown_fn="$3"
+       shift 3
+
+       local test_fn="test$number"
+       local TEST_CURDIR=$( task_maketemp -d -t "pkgtasks.$test_fn" )
+       ( # Redirect fd 6 to standard output.
+         exec 6>&1
+         # Close standard output and standard error if quiet.
+         if [ -n "$quiet" ]; then
+               exec 1>&-
+               exec 2>&-
+         fi
+
+         # setup > test > teardown
+         local describe=
+         cd "${TEST_CURDIR}" && eval $setup_fn && eval $test_fn
+         local test_result=$?
+         eval $teardown_fn
+
+         local testline
+
+         # ok or noe ok.
+         case $test_result in
+         0)    testline="ok" ;;
+         *)    testline="not ok"
+         esac
+
+         # Append test number.
+         case $write_number in
+         "")   : "don't append number" ;;
+         *)    testline="$testline $number" ;;
+         esac
+
+         # Put a dash "-" before $describe if it's missing.
+         case $describe in
+         "")   : "testline is unchanged" ;;
+         "- "*|"#"*)
+               testline="$testline $describe" ;;
+         *)    testline="$testline - $describe" ;;
+         esac
+
+         # Write the proper TAP test line.
+         echo 1>&6 "$testline"
+
+         return $test_result )
+       local result=$?
+       ${RM} -fr "${TEST_CURDIR}"
+       return $result
+}
+
+task_tap_harness()
+{
+       local ws="[     ]"
+
+       local count=0
+       local fail=0
+       local pass=0
+       local broken=0
+       local fixed=0
+       local skip=0
+
+       local status=
+       local msgtype="none"
+       local line
+       while IFS= read line; do
+               case $line in
+               1..[0-9]*)
+                       # TAP plan
+                       status="plan"
+                       count=${line#1..}
+                       msgtype="info" ;;
+               "not ok"|"not ok"$ws*)
+                       # failed test
+                       status="not_ok"
+                       fail=$(( $fail + 1 ))
+                       msgtype="error" ;;
+               ok|"ok"$ws*)
+                       # passed test
+                       status="ok"
+                       pass=$(( $pass + 1 ))
+                       msgtype="none" ;;
+               esac
+               case $status in
+               ok|not_ok)
+                       case $line in
+                       *$ws"#"$ws[Ss][Kk][Ii][Pp]|\
+                       *$ws"#"$ws[Ss][Kk][Ii][Pp]$ws*)
+                               # skip directive; consider as passed
+                               pass=$(( $pass + 1 ))
+                               skip=$(( $skip + 1 ))
+                               msgtype="skip" ;;
+                       *$ws"#"$ws[Tt][Oo][Dd][Oo]|\
+                       *$ws"#"$ws[Tt][Oo][Dd][Oo]$ws*)
+                               # todo directive
+                               case $status in
+                               ok)     fixed=$(( $fixed + 1 )) ;;
+                               not_ok) broken=$(( $broken + 1 ))
+                                       fail=$(( fail - 1 )) ;;
+                               esac
+                               msgtype="warn" ;;
+                       esac
+               esac
+               task_say $msgtype "$line"
+       done
+       # summary
+       if [ $skip -gt 0 ]; then
+               task_say skip "# skipped $skip test(s)"
+       fi
+       if [ $fixed -gt 0 ]; then
+               task_say error \
+                       "# $fixed known breakage(s) vanished; please update test(s)"
+       fi
+       if [ $broken -gt 0 ]; then
+               task_say warn "# still have $broken known breakage(s)"
+       fi
+       local msg
+       if [ $broken -eq 0 -a $fixed -eq 0 ]; then
+               msg="$count test(s)"
+       else
+               count=$(( $count - $broken - $fixed ))
+               msg="remaining $count test(s)"
+       fi
+       if [ $fail -gt 0 ]; then
+               task_say error "# failed $fail among $msg"
+       else
+               task_say pass "# passed all $msg"
+       fi
+
+       # return the number of failed tests
+       return $fail
+}
+
+# Static variable for the user ID of the user executing the test.
+__task_uid__=
Index: pkgsrc/pkgtools/pkgtasks/files/usergroup.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/usergroup.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/usergroup.subr       Thu Jun  1 01:58:34 2017
@@ -0,0 +1,130 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      usergroup.subr -- adding users and groups to the system
+#
+# SYNOPSIS
+#      task_addgroup <group> [<groupid>]
+#      task_adduser <user> <group> [<userid> [<descr> [<home> [<shell>]]]]
+#
+# DESCRIPTION
+#      The task_addgroup function adds a group to the system with the
+#      matching group ID if it is given.
+#
+#      The task_adduser function adds a user to the system with the
+#      matching user ID if it is given.  The additional parameters to the
+#      task_adduser function can be used to set the group, description,
+#      home directory, and login shell of the user.
+#
+#      These functions are expected to never write to standard output or
+#      to standard error.  The calling script should capture the return
+#      values of these functions.
+#
+#      These functions assume that platform_groupadd and platform_useradd
+#      functions are defined and accept the following subset of options
+#      supported by the NetBSD/Solaris-compatible versions of groupadd(8)
+#      and useradd(8):
+#
+#          platform_groupadd [-g <gid>] <group>
+#
+#          platform_useradd [-c <descr>] [-d <home>] [-g <group>]
+#              [-s <shell>] [u <uid>] <user>
+#
+# RETURN VALUES
+#      Returns 0 on success, and >0 if an error occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      NOLOGIN
+#              The path to a login shell that is used for accounts that
+#              are not allowed to log in.  The default value is
+#              "/sbin/nologin".
+#
+#      PKGNAME
+#              The name of the package.
+#
+
+__task_usergroup__="yes"
+
+task_load platform
+
+# Load the correct platform_{group,user}add functions.
+case $(task_platform) in
+DragonFly|FreeBSD)
+       task_load usergroup_FreeBSD ;;
+Linux) task_load usergroup_Linux ;;
+MirBSD)        task_load usergroup_MirBSD ;;
+NetBSD|SunOS)
+       task_load usergroup_NetBSD ;;
+*)     task_load usergroup_NetBSD ;;
+esac
+
+task_addgroup()
+{
+       local group="$1"
+       local groupid="$2"
+
+       [ -n "$group" ] || return 1
+
+       case $groupid in
+       "")     platform_groupadd "$group" >/dev/null ;;
+       *)      platform_groupadd -g "$groupid" "$group" >/dev/null ;;
+       esac
+}
+
+task_adduser()
+{
+       : ${PKGNAME:=${0##*/}}
+
+       local user="$1"; local group="$2"; local userid="$3"
+       local descr="$4"; local home="$5"; local shell="$6"
+
+       [ -n "$user" -a -n "$group" ] || return 1
+
+       local pkgbase="${PKGNAME%-[0-9]*}"
+       local descr_default
+       case $user in
+       $pkgbase)
+               descr_default="$user user" ;;
+       *)      descr_default="$pkgbase $user user" ;;
+       esac
+
+       : ${descr:=$descr_default}
+       : ${home:=/nonexistent}
+       : ${shell:=${NOLOGIN:=/sbin/nologin}}
+
+       case $userid in
+       "")     platform_useradd \
+                       -c "$descr" -d "$home" -s "$shell" -g "$group" \
+                       "$user" >/dev/null ;;
+       *)      platform_useradd \
+                       -c "$descr" -d "$home" -s "$shell" -g "$group" \
+                       -u "$userid" "$user" >/dev/null ;;
+       esac
+}
Index: pkgsrc/pkgtools/pkgtasks/files/usergroup_FreeBSD.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/usergroup_FreeBSD.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/usergroup_FreeBSD.subr       Thu Jun  1 01:58:34 2017
@@ -0,0 +1,116 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      usergroup_FreeBSD -- usergroup implementation for FreeBSD
+#
+# SYNOPSIS
+#      platform_groupadd [-g <groupid>] <group>
+#
+#      platform_useradd [-c <descr>] [-d <home>] [-g <group>]
+#              [-s <shell>] [-u <userid>] <user>
+#
+# DESCRIPTION
+#      The functions implement a NetBSD/Solaris-compatible groupadd and
+#      useradd.
+#
+# RETURN VALUES
+#      All functions return 0 on success, and return non-zero otherwise.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      PW      The name or path to the pw(8) utility.
+#
+# COMPATIBILITY
+#      This implementation assumes a FreeBSD-compatible version of pw(8)
+#      is available, and is usable on the following systems:
+#
+#      o DragonFly BSD
+#      o FreeBSD
+#
+
+__task_usergroup_FreeBSD__="yes"
+
+task_load quote
+
+platform_groupadd()
+{
+       : ${PW:=pw}
+
+       local groupadd_args=
+       local arg quoted
+       local OPTIND=1
+       while getopts ":g:" arg "$@"; do
+               case $arg in
+               g)      task_quote "${OPTARG}"
+                       groupadd_args="$groupadd_args -$arg $quoted" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       # A <group> argument is required.
+       [ $# -eq 1 ] || return 127
+       local group="$1"; shift
+
+       [ -n "$group" ] || return 1
+
+       task_quote "$group"
+       groupadd_args="$quoted $groupadd_args"
+
+       eval ${PW} groupadd $groupadd_args
+}
+
+platform_useradd()
+{
+       : ${PW:=pw}
+
+       local useradd_args=
+       local arg quoted
+       local OPTIND=1
+       while getopts ":c:d:g:s:u:" arg "$@"; do
+               case $arg in
+               [cdgsu])
+                       # valid useradd options for pw(8)
+                       task_quote "${OPTARG}"
+                       useradd_args="$useradd_args -$arg $quoted" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       # A <user> argument is required.
+       [ $# -eq 1 ] || return 127
+       local user="$1"; shift
+
+       [ -n "$user" ] || return 1
+
+       task_quote "$user"
+       # The <user> argument precedes the rest for "pw useradd".
+       useradd_args="$quoted $useradd_args"
+
+       eval ${PW} useradd $useradd_args
+}
Index: pkgsrc/pkgtools/pkgtasks/files/usergroup_Linux.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/usergroup_Linux.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/usergroup_Linux.subr Thu Jun  1 01:58:34 2017
@@ -0,0 +1,141 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      usergroup_Linux -- usergroup implementation for Linux
+#
+# SYNOPSIS
+#      platform_groupadd [-g <gid>] <group>
+#
+#      platform_useradd [-c <descr>] [-d <home>] [-g <group>]
+#              [-s <shell>] [-u <uid>] <user>
+#
+# DESCRIPTION
+#      The functions implement a NetBSD/Solaris-compatible groupadd and
+#      useradd.
+#
+# RETURN VALUES
+#      All functions return 0 on success, and return non-zero otherwise.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      GROUPADD
+#              The name or path to the groupadd(8) utility.
+#
+#      USERADD
+#              The name or path to the useradd(8) utility.
+#
+# NOTES
+#      The useradd(8) utility on Linux is a complete mess.  At least Red
+#      Hat derivatives want to create home directories by default.  They
+#      have support for -M, but no --help.  Other Linux distributions lack
+#      -M support, but some at least have --help.  LSB just wants
+#      useradd(8), but doesn't specify any behavior, so it is useless for
+#      writing portable scripts.
+#
+
+__task_usergroup_Linux__="yes"
+
+task_load match
+task_load quote
+
+platform_groupadd()
+{
+       : ${GROUPADD:=groupadd}
+
+       local gid=
+       local groupadd_args=
+       local arg quoted
+       local OPTIND=1
+       while getopts ":g:" arg "$@"; do
+               case $arg in
+               g)      task_quote "${OPTARG}"
+                       groupadd_args="$groupadd_args -$arg $quoted" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       # A <group> argument is required.
+       [ $# -eq 1 ] || return 127
+       local group="$1"; shift
+
+       [ -n "$group" ] || return 1
+
+       # If no GID is specified, then use a GID from the system GID range.
+       if [ -z "$gid" ]; then
+               groupadd_args="$groupadd_args -r"
+       fi
+       task_quote "$group"
+       groupadd_args="$groupadd_args $quoted"
+
+       eval ${GROUPADD} $groupadd_args
+}
+
+platform_useradd()
+{
+       : ${USERADD:=useradd}
+
+       : ${LOGIN_DEFS:=/etc/login.defs}
+
+       local uid=
+       local useradd_args=
+       local arg quoted
+       local OPTIND=1
+       while getopts ":c:d:g:s:u:" arg "$@"; do
+               case $arg in
+               [cdgsu])
+                       # valid useradd options for useradd(8)
+                       case $arg in u) uid=${OPTARG} ;; esac
+                       task_quote "${OPTARG}"
+                       useradd_args="$useradd_args -$arg $quoted" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       # A <user> argument is required.
+       [ $# -eq 1 ] || return 127
+       local user="$1"; shift
+
+       [ -n "$user" ] || return 1
+
+       # Don't create the home directory, even if CREATE_HOME is "yes" in
+       # /etc/login.defs.
+       #
+       if [ -f "${LOGIN_DEFS}" ] &&
+          task_match -qw "CREATE_HOME*[yY][eE][sS]" < ${LOGIN_DEFS}; then
+               useradd_args="$useradd_args -M"
+       fi
+       # If no UID is specified, then use a UID from the system UID range.
+       if [ -z "$uid" ]; then
+               useradd_args="$useradd_args -r"
+       fi
+       task_quote "$user"
+       useradd_args="$useradd_args $quoted"
+
+       eval ${USERADD} $useradd_args
+}
Index: pkgsrc/pkgtools/pkgtasks/files/usergroup_MirBSD.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/usergroup_MirBSD.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/usergroup_MirBSD.subr        Thu Jun  1 01:58:34 2017
@@ -0,0 +1,538 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      usergroup_MirBSD -- usergroup implementation for MirBSD
+#
+# SYNOPSIS
+#      platform_groupadd [-g <gid>] <group>
+#
+#      platform_useradd [-c <descr>] [-d <home>] [-g <group>]
+#              [-s <shell>] [-u <uid>] <user>
+#
+# DESCRIPTION
+#      The functions implement a NetBSD/Solaris-compatible groupadd and
+#      useradd.
+#
+# RETURN VALUES
+#      All functions return 0 on success, and return non-zero otherwise.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set.
+#
+#      CAT     The name or path to the cat(1) utility.
+#
+#      CHMOD   The name or path to the chmod(1) utility.
+#
+#      CHOWN   The name or path to the chown(8) utility.
+#
+#      ETC_GROUP
+#              The path to the system group database text file.  The
+#              default value is "/etc/group".
+#
+#      ETC_PASSWD
+#              The path to the system user/password database text file.
+#              The default value is "/etc/master.passwd".
+#
+#      MKTEMP  The name or path to the mktemp(1) utility.
+#
+#      MV      The name or path to the mv(1) utility.
+#
+#      PWD_MKDB
+#              The name or path to the pwd_mkdb(8) utility that is used
+#              to regenerate the pwd.db and spwd.db binary databases
+#              from ${ETC_PASSWD}.
+#
+#      RM      The name or path to the rm(1) utility.
+#
+#      RMDIR   The name or path to the rmdir(1) utility.
+#
+#      SORT    The name or path to the sort(1) utility.
+#
+
+__task_usergroup_MirBSD__="yes"
+
+task_load echo
+task_load lock
+task_load quote
+
+_platform_group_exists()
+{
+       : ${ETC_GROUP:=/etc/group}
+
+       # parameters
+       local group="$1"
+       local gid="$2"
+       # return values
+       _exists_group=; _exists_gid=; _exists_gid_max=
+
+       local groupfile="${ETC_GROUP}"
+       [ -f "$groupfile" ] || return 1
+
+       local group_to_gid=
+       local gid_found=
+       local gid_max=0
+       local line save_IFS word1 word3
+       while IFS=: read line; do
+               save_IFS=$IFS; IFS=:
+               set -o noglob; set -- $line; set +o noglob
+               word1=$1; word3=$3
+               IFS=$save_IFS
+               if [ "$group" = "$word1" ]; then
+                       group_to_gid=$word3
+               fi
+               if [ "$gid" = "$word3" ]; then
+                       gid_found="yes"
+               fi
+               if [ $gid_max -lt $word3 ]; then
+                       gid_max=$word3
+               fi
+       done < $groupfile
+
+       _exists_gid_max=$gid_max
+       if [ -z "$group_to_gid" ]; then
+               # group not found
+               if [ -z "$gid_found" ]; then
+                       # group not found, and group ID not given
+                       return 1
+               else
+                       # group not found, but group ID found
+                       _exists_gid=$gid
+                       return 2
+               fi
+       else
+               _exists_group=$group
+               _exists_gid=$group_to_gid
+               if [ -z "$gid" ]; then
+                       # group ID not given
+                       return 0
+               elif [ -z "$gid_found" ]; then
+                       # group found, but group ID not found
+                       return 2
+               elif [ "$gid" != "$group_to_gid" ]; then
+                       # group found, but group ID doesn't match
+                       return 2
+               else
+                       # group found, and group ID matches
+                       return 0
+               fi
+       fi
+       return 3
+}
+
+_platform_addgroup()
+{
+       : ${CAT:=cat}
+       : ${CHMOD:=chmod}
+       : ${CHOWN:=chown}
+       : ${MKTEMP:=mktemp}
+       : ${MV:=mv}
+       : ${RM:=rm}
+       : ${RMDIR:=rmdir}
+       : ${SORT:=sort}
+
+       : ${ETC_GROUP:=/etc/group}
+
+       # parameters
+       local group="$1"
+       local gid="$2"
+
+       local groupfile temp tmpdir tmpdir_quoted quoted
+       groupfile="${ETC_GROUP}"
+       tmpdir=$( ${MKTEMP} -d "$groupfile.tmp.XXXXXXXXXX" )
+       case $groupfile in
+       /*)     temp="$tmpdir/${groupfile##*/}" ;;
+       *)      temp="$tmpdir/${groupfile}" ;;
+       esac
+       task_quote "$tmpdir"
+       tmpdir_quoted=$quoted
+       __platform_addgroup_dirs__="$__platform_addgroup_dirs__ $quoted"
+
+       local result=1
+       if [ -n "$tmpdir" -a -d "$tmpdir" ]; then
+               local perms="root:wheel"
+               local mode="0644"
+               if { echo "$group:*:$gid:" &&
+                    [ ! -f "$groupfile" ] || ${CAT} "$groupfile"
+                  } > $temp &&
+                  ${CHOWN} $perms "$temp" &&
+                  ${CHMOD} $mode "$temp" &&
+                  ${SORT} -t: -nk3 -o "$temp" -u "$temp" &&
+                  ${MV} -f "$temp" "$groupfile"; then
+                       result=0
+               else
+                       ${RM} -f "$temp"
+               fi
+               ${RMDIR} "$tmpdir"
+               __platform_addgroup_dirs__=${__platform_addgroup_dirs__% $tmpdir_quoted}
+       fi
+
+       _platform_addgroup_cleanup
+       return $result
+}
+
+platform_groupadd()
+{
+       : ${ETC_GROUP:=/etc/group}
+
+       # Lower bound of GID range for new groups.
+       local lowgid=700
+
+       local gid=
+       local arg
+       local OPTIND=1
+       while getopts ":g:" arg "$@"; do
+               case $arg in
+               g)      gid=${OPTARG} ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+       local group="$1"; shift
+
+       [ -n "$group" ] || return 1
+
+       # Lock ${ETC_GROUP} against other tasks.
+       local groupfile="${ETC_GROUP}"
+       local lock lock_quoted quoted
+       lock="$groupfile.lock"
+       task_quote "$lock"
+       lock_quoted=$quoted
+       __platform_groupadd_locks__="$quoted $__platform_groupadd_locks__"
+       task_lock "$lock" || return 1
+
+       local result=0
+
+       # Check if the group and group ID are already in the database.
+       local _exists_group _exists_gid _exists_gid_max
+       _platform_group_exists "$group" "$gid"
+       case $? in
+       0)      # group already exists with matching group ID.
+               result=1 ;;
+       1)      : "fall through and add missing group" ;;
+       *)      result=1 ;;
+       esac
+       if [ $result -eq 0 ]; then
+               # Set gid to the existing or proposed GID of the group.
+               if [ -z "$gid" ]; then
+                       if [ -n "$_exists_gid" ]; then
+                               gid=$_exists_gid
+                       elif [ $_exists_gid_max -lt $lowgid ]; then
+                               gid=$lowgid
+                       else
+                               gid=$(( $_exists_gid_max + 1 ))
+                       fi
+               fi
+               # Add the group and group ID to the database.
+               _platform_addgroup "$group" "$gid" || result=1
+       fi
+
+       # Release lock on ${ETC_GROUP}.
+       task_lock -r "$lock"
+       __platform_groupadd_locks__=${__platform_groupadd_locks__#$lock_quoted }
+
+       _platform_groupadd_cleanup
+       return $result
+}
+
+_platform_user_exists()
+{
+       : ${ETC_PASSWD:=/etc/master.passwd}
+
+       # parameters
+       local user="$1"
+       local uid="$2"
+       # return values
+       _exists_user=; _exists_uid=; _exists_uid_max=
+
+       local userfile="${ETC_PASSWD}"
+       [ -f "$userfile" ] || return 1
+
+       local user_to_uid=
+       local uid_found=
+       local uid_max=0
+       local line save_IFS word1 word3
+       while read line; do
+               save_IFS=$IFS; IFS=:
+               set -o noglob; set -- $line; set +o noglob
+               word1=$1; word3=$3
+               IFS=$save_IFS
+               if [ "$user" = "$word1" ]; then
+                       user_to_uid=$word3
+               fi
+               if [ "$uid" = "$word3" ]; then
+                       uid_found="yes"
+               fi
+               if [ $uid_max -lt $word3 ]; then
+                       uid_max=$word3
+               fi
+       done < $userfile
+
+       _exists_uid_max=$uid_max
+       if [ -z "$user_to_uid" ]; then
+               # user not found
+               if [ -z "$uid_found" ]; then
+                       # user not found, and user ID not given
+                       return 1
+               else
+                       # user not found, but user ID found
+                       _exists_uid=$uid
+                       return 2
+               fi
+       else
+               _exists_user=$user
+               _exists_uid=$user_to_uid
+               if [ -z "$uid" ]; then
+                       # user ID not given
+                       return 0
+               elif [ -z "$uid_found" ]; then
+                       # user found, but user ID not found
+                       return 2
+               elif [ "$uid" != "$user_to_uid" ]; then
+                       # user found, but user ID doesn't match
+                       return 2
+               else
+                       # user found, and user ID matches
+                       return 0
+               fi
+       fi
+       return 3
+}
+
+_platform_adduser()
+{
+       : ${CAT:=cat}
+       : ${CHMOD:=chmod}
+       : ${CHOWN:=chown}
+       : ${MKTEMP:=mktemp}
+       : ${PWD_MKDB:=pwd_mkdb}
+       : ${RM:=rm}
+       : ${RMDIR:=rmdir}
+       : ${SORT:=sort}
+
+       : ${ETC_PASSWD:=/etc/master.passwd}
+
+       # parameters
+       local user="$1"; local group="$2"; local uid="$3"
+       local descr="$4"; local home="$5"; local shell="$6"
+
+       local userfile temp tmpdir tmpdir_quoted quoted
+       userfile="${ETC_PASSWD}"
+       tmpdir=$( ${MKTEMP} -d "$userfile.tmp.XXXXXXXXXX" ) || return 1
+       case $tmpdir in
+       /*)     temp="$tmpdir/${userfile##*/}" ;;
+       *)      temp="$tmpdir/$userfile" ;;
+       esac
+       task_quote "$tmpdir"
+       tmpdir_quoted=$quoted
+       __platform_adduser_dirs__="$__platform_adduser_dirs__ $quoted"
+
+       local result=1
+       if [ -n "$tmpdir" -a -d "$tmpdir" ]; then
+               local perms="root:wheel"
+               local mode="0600"
+               if { echo "$user:*:$uid:$group::0:0:$descr:$home:$shell" &&
+                    [ ! -f "$userfile" ] || ${CAT} "$userfile"
+                  } > $temp &&
+                  ${CHOWN} $perms "$temp" &&
+                  ${CHMOD} $mode "$temp" &&
+                  ${SORT} -t: -nk3 -o "$temp" -u "$temp" &&
+                  ${PWD_MKDB} -p "$temp"; then
+                       result=0
+               else
+                       ${RM} -f "$temp"
+               fi
+               ${RMDIR} "$tmpdir"
+               __platform_adduser_dirs__=${__platform_adduser_dirs__% $tmpdir_quoted}
+       fi
+
+       _platform_adduser_cleanup
+       return $result
+}
+
+platform_useradd()
+{
+       # Lower bound of UID range for new users.
+       local lowuid=700
+
+       local basedir=
+       local descr=
+       local home=
+       local group=
+       local shell=
+       local uid=
+       local arg
+       local OPTIND=1
+       while getopts ":c:d:g:s:u:" arg "$@"; do
+               case $arg in
+               c)      descr=${OPTARG} ;;
+               d)      home=${OPTARG} ;;
+               g)      group=${OPTARG} ;;
+               s)      shell=${OPTARG} ;;
+               u)      uid=${OPTARG} ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+       local user="$1"; shift
+
+       [ -n "$user" ] || return 1
+
+       : ${basedir:=/home}
+       : ${home:=$basedir/$user}
+       : ${group:=users}
+       : ${shell:=/bin/sh}
+
+       # Lock ${ETC_PASSWD} against other tasks.
+       local userfile="${ETC_PASSWD}"
+       local lock lock_quoted quoted
+       local quoted
+       lock="$userfile.lock"
+       task_quote "$lock"
+       lock_quoted=$quoted
+       __platform_useradd_locks__="$quoted $__platform_useradd_locks__"
+       task_lock "$lock" || return 1
+
+       local result=0
+
+       # Check if the user and user ID are already in the database.
+       local _exists_user _exists_uid _exists_uid_max
+       _platform_user_exists "$user" "$uid"
+       case $? in
+       0)      # user already exists with matching user ID.
+               result=1 ;;
+       1)      : "fall through and add missing user" ;;
+       *)      result=1 ;;
+       esac
+
+       if [ $result -eq 0 ]; then
+               # Set uid to the existing or proposed UID of the user.
+               if [ -z "$uid" ]; then
+                       if [ -n "$_exists_uid" ]; then
+                               uid=$_exists_uid
+                       elif [ $_exists_uid_max -lt $lowuid ]; then
+                               uid=$lowuid
+                       else
+                               uid=$(( $_exists_uid_max + 1 ))
+                       fi
+               fi
+               # Get the group ID of the user to be added.
+               case $group in
+               ""|*[!0-9]*)
+                       # $group is not a GID
+                       platform_groupadd "$group"
+                       _platform_group_exists "$group" || result=1
+                       group=$_exists_gid ;;
+               esac
+       fi
+       if [ $result -eq 0 ]; then
+               # Add the user and user ID to the database.
+               _platform_adduser "$user" "$group" "$uid" \
+                       "$descr" "$home" "$shell" || result=1
+       fi
+
+       # Release lock on ${ETC_PASSWD}.
+       task_lock -r "$lock"
+       __platform_useradd_locks__=${__platform_useradd_locks__#$lock_quoted }
+
+       _platform_useradd_cleanup
+       return $result
+}
+
+_platform_addgroup_cleanup()
+{
+       : ${RM:=rm}
+
+       eval set -- $__platform_addgroup_dirs__
+       local dir
+       for dir; do
+               # Sanity check before blowing away $dir.
+               case ${dir##*/} in
+               *.tmp.*)
+                       ${RM} -fr "$dir" ;;
+               *)      task_echo "!!! WARNING: usergroup: Remove directory $dir" ;;
+               esac
+       done
+       __platform_addgroup_dirs__=
+}
+
+_platform_groupadd_cleanup()
+{
+       eval set -- $__platform_groupadd_locks__
+       local lockfile
+       for lockfile; do
+               task_lock -r "$lockfile"
+       done
+       __platform_groupadd_locks__=
+}
+
+_platform_adduser_cleanup()
+{
+       : ${RM:=rm}
+
+       eval set -- $__platform_adduser_dirs__
+       local dir
+       for dir; do
+               # Sanity check before blowing away $dir.
+               case ${dir##*/} in
+               *.tmp.*)
+                       ${RM} -fr "$dir" ;;
+               *)      task_echo "!!! WARNING: usergroup: Remove directory $dir" ;;
+               esac
+       done
+       __platform_adduser_dirs__=
+}
+
+_platform_useradd_cleanup()
+{
+       eval set -- $__platform_useradd_locks__
+       local lockfile
+       for lockfile; do
+               task_lock -r "$lockfile"
+       done
+       __platform_useradd_locks__=
+}
+
+__install_tasks_platform_usergroup_MirBSD_init__="_platform_usergroup_init"
+_platform_usergroup_init()
+{
+       task_cleanup_add_hook \
+               _platform_addgroup_cleanup _platform_groupadd_cleanup \
+               _platform_adduser_cleanup _platform_useradd_cleanup
+}
+
+# Static variables for temporary directories that should be removed if an
+# error occurs.
+#
+__platform_addgroup_dirs__=
+__platform_adduser_dirs__=
+
+# Static variables for locks that should be released if an error occurs.
+__platform_groupadd_locks__=
+__platform_useradd_locks__=
Index: pkgsrc/pkgtools/pkgtasks/files/usergroup_NetBSD.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/usergroup_NetBSD.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/usergroup_NetBSD.subr        Thu Jun  1 01:58:34 2017
@@ -0,0 +1,121 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      usergroup_NetBSD -- groupadd/useradd for NetBSD
+#
+# SYNOPSIS
+#      platform_groupadd [-g <groupid>] <group>
+#
+#      platform_useradd [-c <descr>] [-d <home>] [-g <group>]
+#              [-s <shell>] [-u <userid>] <user>
+#
+# DESCRIPTION
+#      The functions implement a NetBSD/Solaris-compatible groupadd and
+#      useradd.
+#
+# RETURN VALUES
+#      All functions return 0 on success, and return non-zero otherwise.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      GROUPADD
+#              The name or path to groupadd(8).
+#
+#      USERADD
+#              The name or path to useradd(8).
+#
+# COMPATIBILITY
+#      This implementation assumes NetBSD/Solaris-compatible versions of
+#      groupadd(8) and useradd(8) are available, and is usable on the
+#      following systems:
+#
+#      o NetBSD
+#      o SunOS
+#
+
+__task_usergroup_NetBSD__="yes"
+
+task_load quote
+
+platform_groupadd()
+{
+       : ${GROUPADD:=groupadd}
+
+       local groupadd_args=
+       local arg quoted
+       local OPTIND=1
+       while getopts ":g:" arg "$@"; do
+               case $arg in
+               g)      task_quote "${OPTARG}"
+                       groupadd_args="$groupadd_args -$arg $quoted" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       # A <group> argument is required.
+       [ $# -eq 1 ] || return 127
+       local group="$1"; shift
+
+       [ -n "$group" ] || return 1
+
+       task_quote "$group"
+       groupadd_args="$groupadd_args $quoted"
+
+       eval ${GROUPADD} $groupadd_args
+}
+
+platform_useradd()
+{
+       : ${USERADD:=useradd}
+
+       local useradd_args=
+       local arg quoted
+       local OPTIND=1
+       while getopts ":c:d:g:s:u:" arg "$@"; do
+               case $arg in
+               [cdgsu])
+                       # valid useradd options for pw(8)
+                       task_quote "${OPTARG}"
+                       useradd_args="$useradd_args -$arg $quoted" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       # A <user> argument is required.
+       [ $# -eq 1 ] || return 127
+       local user="$1"; shift
+
+       [ -n "$user" ] || return 1
+
+       task_quote "$user"
+       # The <user> argument precedes the rest for "pw useradd".
+       useradd_args="$useradd_args $quoted"
+
+       eval ${USERADD} $useradd_args
+}
Index: pkgsrc/pkgtools/pkgtasks/files/usergroup_exists.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/usergroup_exists.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/usergroup_exists.subr        Thu Jun  1 01:58:34 2017
@@ -0,0 +1,245 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      usergroup_exists.subr -- check for the existence of users and groups
+#
+# SYNOPSIS
+#      task_group_exists <group> [<groupid>]
+#      task_user_exists <user> [<userid>]
+#
+# DESCRIPTION
+#      The task_group_exists function checks that a group exists on the
+#      system, and also matches the group ID if it is given.
+#
+#      The task_user_exists function checks that a user exists on the
+#      system, and also matches the user ID if it is given.
+#
+# NOTES
+#      These functions test for the presence of groups and users in a
+#      portable manner by using chgrp(1) and chown(1) to change the
+#      ownership of a temporary file and checking the return values.
+#
+# RETURN VALUES
+#      The task_group_exists function has the following return values:
+#
+#          0   if <group> exists, and has gid <groupid> if given
+#          1   if neither <group> nor <groupid> exist
+#          2   if <group> or <groupid> exist but don't match
+#          3   if an error occurs
+#
+#      The task_user_exists function has the following return values:
+#
+#          0   if <user> exists, and has uid <userid> if given
+#          1   if neither <user> nor <userid> exist
+#          2   if <user> or <userid> exist but don't match
+#          3   if an error occurs
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      CHOWN   The name or path to the chown(8) utility.
+#
+#      LS      The name or path to the ls(1) utility.
+#
+#      RM      The name or path to the rm(1) utility.
+#
+
+__task_usergroup_exists__="yes"
+__task_usergroup_exists_init__="_usergroup_exists_init"
+
+task_load cleanup
+task_load createfile
+task_load echo
+task_load maketemp
+
+task_group_exists()
+{
+       : ${CHOWN:=chown}
+       : ${LS:=ls}
+
+       local group="$1"; shift
+       local groupid="$1"; [ $# -eq 0 ] || shift
+
+       [ -n "$group" ] || return 3
+
+       # Check using chown(1) to work properly in an NSS/NIS environment.
+       __group_tmpdir__=$( task_maketemp -dq -t "pkgtasks.group_exists" ) || return 3
+       local testpath="$__group_tmpdir__/group_exists"
+       task_createfile "$testpath"
+
+       local result=0
+       #
+       # Redirect standarrd error below because failing to chgrp(2) is
+       # part of the test and not actually an error.
+       #
+       if ${CHOWN} ":$group" "$testpath" >/dev/null 2>&1; then
+               # group exists
+               if [ -n "$groupid" ]; then
+                       ${LS} -dln "$testpath" 2>/dev/null |
+                       ( read __ __ __ gid __; [ "$groupid" = "$gid" ] )
+                       if [ $? -gt 0 ]; then
+                               # group exists but doesn't match groupid
+                               result=2
+                       else
+                               # group exists and groupid exists and match
+                               result=0
+                       fi
+               else
+                       # group exists and groupid is not set
+                       result=0
+               fi
+       elif [ -z "$groupid" ]; then
+               # group doesn't exist and groupid is not set
+               result=1
+       elif ${CHOWN} ":$groupid" "$testpath" >/dev/null 2>&1; then
+               # group doesn't exist
+               ${LS} -dl "$testpath" 2>/dev/null |
+               ( read __ __ __ name __
+                 #
+                 # If the ls(1) output shows a group name instead of the
+                 # raw GID, then the GID must exist and map to a valid
+                 # group name on the system.
+                 #
+                 [ "$groupid" != "$name" ] )
+               if [ $? -gt 0 ]; then
+                       # group doesn't exist, groupid doesn't exist
+                       result=1
+               else
+                       # group doesn't exist, groupid exists
+                       result=2
+               fi
+       else
+               # group doesn't exist and groupid doesn't exist
+               result=1
+       fi
+       _task_group_exists_cleanup
+       return $result
+}
+
+task_user_exists()
+{
+       : ${CHOWN:=chown}
+       : ${LS:=ls}
+
+       local user="$1"; shift
+       local userid="$1"; [ $# -eq 0 ] || shift
+
+       [ -n "$user" ] || return 3
+
+       # Check using chown(1) to work properly in an NSS/NIS environment.
+       __user_tmpdir__=$( task_maketemp -dq -t "pkgtasks.user_exists" ) || return 3
+       local testpath="$__user_tmpdir__/user_exists"
+       task_createfile "$testpath"
+
+       local result=0
+       #
+       # Redirect standarrd error below because failing to chown(2) is
+       # part of the test and not actually an error.
+       #
+       if ${CHOWN} "$user" "$testpath" >/dev/null 2>&1; then
+               # user exists
+               if [ -n "$userid" ]; then
+                       ${LS} -dln "$testpath" 2>/dev/null |
+                       ( read __ __ uid __; [ "$userid" = "$uid" ] )
+                       if [ $? -gt 0 ]; then
+                               # user exists but doesn't match userid
+                               result=2
+                       else
+                               # user exists and userid exists and match
+                               result=0
+                       fi
+               else
+                       # user exists and userid is not set
+                       result=0
+               fi
+       elif [ -z "$userid" ]; then
+               # user doesn't exist and userid is not set
+               result=1
+       elif ${CHOWN} "$userid" "$testpath" >/dev/null 2>&1; then
+               # user doesn't exist
+               ${LS} -dl "$testpath" 2>/dev/null |
+               ( read __ __ name __
+                 #
+                 # If the ls(1) output shows a username instead of the
+                 # raw UID, then the UID must exist and map to a valid
+                 # username on the system.
+                 #
+                 [ "$userid" != "$name" ] )
+               if [ $? -gt 0 ]; then
+                       # user doesn't exist, userid doesn't exist
+                       result=1
+               else
+                       # user doesn't exist, userid exists
+                       result=2
+               fi
+       else
+               # user doesn't exist and userid doesn't exist
+               result=1
+       fi
+       _task_user_exists_cleanup
+       return $result
+}
+
+_task_group_exists_cleanup()
+{
+       : ${RM:=rm}
+
+       # Sanity check before blowing away $__group_tmpdir__.
+       case $__group_tmpdir__ in
+       /tmp/*) ${RM} -fr "$__group_tmpdir__" ;;
+       "")     : "skip empty tmpdir" ;;
+       *)      task_echo "!!! WARNING: usergroup_exists: Remove directory $__group_tmpdir__" ;;
+       esac
+       __group_tmpdir__=
+}
+
+_task_user_exists_cleanup()
+{
+       : ${RM:=rm}
+
+       # Sanity check before blowing away $__user_tmpdir__.
+       case $__user_tmpdir__ in
+       /tmp/*) ${RM} -fr "$__user_tmpdir__" ;;
+       "")     : "skip empty tmpdir" ;;
+       *)      task_echo "!!! WARNING: usergroup_exists: Remove directory $__user_tmpdir__" ;;
+       esac
+       __user_tmpdir__=
+}
+
+_usergroup_exists_init()
+{
+       task_cleanup_add_hook \
+               _task_group_exists_cleanup \
+               _task_user_exists_cleanup
+}
+
+# Static variables for temporary directories that should be removed if an
+# error occurs.
+#
+__group_tmpdir__=
+__user_tmpdir__=
Index: pkgsrc/pkgtools/pkgtasks/files/usergroup_mock.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/usergroup_mock.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/usergroup_mock.subr  Thu Jun  1 01:58:34 2017
@@ -0,0 +1,317 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      usergroup_mock.subr -- mock user/group functions using text files
+#
+# SYNOPSIS
+#      mock_group_exists <group> [<gid>]
+#      mock_user_exists <user> [<uid>]
+#
+#      mock_groupadd [-g <groupid>] <group>
+#      mock_useradd [-c <descr>] [-d <home>] [-g <group>] [-s <shell>]
+#              [-u <userid>] <user>
+#
+#      mock_usergroup_setup
+#
+# DESCRIPTION
+#      The mock_group_exists and mock_user_exists functions implement the
+#      usergroup-exists API functions with the corresponding names.
+#
+#      The mock_groupadd and mock_useradd functions implement NetBSD- and
+#      Solaris-compatible groupadd(8) and useradd(8) functions with the
+#      corresponding names.
+#
+#      These functions manipulate a group database ${ETC_GROUP} and a
+#      user database ${ETC_PASSWD}, which are plaintext files.
+#
+#      The mock_usergroup_setup function populates ${ETC_GROUP} and
+#      ${ETC_PASSWD} with test data, if those variables are set.  The test
+#      data is:
+#
+#              groupA with GID 100
+#              groupB with GID 105
+#              groupC with GID 110
+#              groupD with GID 190
+#              groupE with GID 200
+#              groupF with GID 205
+#              userA with UID 100 in groupA
+#              userB with UID 105 in groupB
+#              userC with UID 110 in groupC
+#
+# ENVIRONMENT
+#      ETC_GROUP
+#              The path to the group database text file.  This MUST be
+#              set for the group functions to work.
+#
+#      ETC_PASSWD
+#              The path to the user database text file.  This MUST be set
+#              for the user functions to work.
+#
+
+__task_usergroup_mock__="yes"
+
+mock_group_exists()
+{
+       local group="$1"
+       local gid="$2"
+       local groupfile="${ETC_GROUP}"
+
+       [ -n "$group" -a -n "$groupfile" ] || return 3
+       [ -f "$groupfile" ] || return 1
+
+       local line save_IFS word1 word3
+       while read line; do
+               save_IFS=$IFS; IFS=:
+               set -o noglob; set -- $line; set +o noglob
+               word1=$1; word3=$3
+               IFS=$save_IFS
+               if [ -z "$gid" ]; then
+                       # No matching group ID required.
+                       if [ "$group" = "$word1" ]; then
+                               # exact group match
+                               return 0
+                       fi
+               elif [ "$group" = "$word1" ]; then
+                       # exact group match, but exact group ID match required
+                       if [ "$gid" = "$word3" ]; then
+                               # exact group ID match
+                               return 0
+                       else
+                               # group ID doesn't match
+                               return 2
+                       fi
+               elif [ "$gid" = "$word3" ]; then
+                       # exact group ID match, but exact group match required
+                       if [ "$group" = "$word1" ]; then
+                               # exact group match
+                               return 0
+                       else
+                               # group doesn't match
+                               return 2
+                       fi
+               fi
+       done < $groupfile
+       # no matching group or group ID
+       return 1
+}
+
+mock_groupadd()
+{
+       : ${CAT:=cat}
+       : ${MV:=mv}
+       : ${RM:=rm}
+
+       local gid=
+       local arg
+       local OPTIND=1
+       while getopts ":g:" arg "$@"; do
+               case $arg in
+               g)      gid=${OPTARG} ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+       local group="$1"; shift
+
+       [ -n "$group" ] || return 1
+       [ -n "${ETC_GROUP}" ] || return 1
+
+       # Ensure neither $group nor $gid already exist.
+       mock_group_exists "$group" "$gid"
+       [ $? -eq 1 ] || return 1
+
+       local groupfile="${ETC_GROUP}"
+       local groupfile_tmp="$groupfile.tmp.$$"
+
+       # If unset, set $gid to one more than the highest group ID
+       # in the group database.
+       #
+       if [ -z "$gid" -a -f "$groupfile" ]; then
+               gid=0
+               local line save_IFS word3
+               while read line; do
+                       save_IFS=$IFS; IFS=:
+                       set -o noglob; set -- $line; set +o noglob
+                       word3=$3; IFS=$save_IFS
+                       [ $word3 -le $gid ] || gid=$word3
+               done < $groupfile
+               gid=$(( $gid + 1 ))
+       fi
+
+       # Append $group:$gid to the group database.
+       { [ ! -f "$groupfile" ] || ${CAT} "$groupfile"
+         echo "$group:*:$gid:"
+       } > $groupfile_tmp
+       if ${MV} -f "$groupfile_tmp" "$groupfile"; then
+               return 0
+       fi
+       ${RM} -f "$groupfile_tmp"
+       return 1
+}
+
+mock_user_exists()
+{
+       local user="$1"; [ $# -eq 0 ] || shift
+       local uid="$1"; [ $# -eq 0 ] || shift
+
+       [ -n "$user" ] || return 3
+       [ -n "${ETC_PASSWD}" ] || return 3
+
+       local userfile="${ETC_PASSWD}"
+
+       [ -f "$userfile" ] || return 1
+       local line save_IFS word1 word3
+       while read line; do
+               save_IFS=$IFS; IFS=:
+               set -o noglob; set -- $line; set +o noglob
+               word1=$1; word3=$3
+               IFS=$save_IFS
+               if [ -z "$uid" ]; then
+                       # No matching user ID required.
+                       if [ "$user" = "$word1" ]; then
+                               # exact user match
+                               return 0
+                       fi
+               elif [ "$user" = "$word1" ]; then
+                       # exact user match, but exact user ID match required
+                       if [ "$uid" = "$word3" ]; then
+                               # exact user ID match
+                               return 0
+                       else
+                               # user ID doesn't match
+                               return 2
+                       fi
+               elif [ "$uid" = "$word3" ]; then
+                       # exact user ID match, but exact user match required
+                       if [ "$user" = "$word1" ]; then
+                               # exact user match
+                               return 0
+                       else
+                               # user doesn't match
+                               return 2
+                       fi
+               fi
+       done < $userfile
+       # no matching user or user ID
+       return 1
+}
+
+mock_useradd()
+{
+       : ${CAT:=cat}
+       : ${MV:=mv}
+       : ${RM:=rm}
+
+       local descr=
+       local home=
+       local group=
+       local shell=
+       local uid=
+
+       local arg
+       local OPTIND=1
+       while getopts ":c:d:g:s:u:" arg "$@"; do
+               case $arg in
+               c)      descr=${OPTARG} ;;
+               d)      home=${OPTARG} ;;
+               g)      group=${OPTARG} ;;
+               s)      shell=${OPTARG} ;;
+               u)      uid=${OPTARG} ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+       local user="$1"; shift
+
+       [ -n "$user" ] || return 1
+       [ -n "${ETC_PASSWD}" ] || return 1
+
+       : ${home:=/home/$user}
+       : ${group:=users}
+       : ${shell:=/bin/sh}
+
+       # Ensure neither $user nor $uid already exist.
+       mock_user_exists "$user" "$uid"
+       [ $? -eq 1 ] || return 1
+
+       # Ensure group is preexisting.
+       mock_group_exists "$group" || return 1
+
+       local userfile="${ETC_PASSWD}"
+       local userfile_tmp="$userfile.tmp.$$"
+
+       # If unset, set $uid to one more than the highest user ID
+       # in the user database.
+       #
+       if [ -z "$uid" -a -f "$userfile" ]; then
+               uid=0
+               local line save_IFS word3
+               while read line; do
+                       save_IFS=$IFS; IFS=:
+                       set -o noglob; set -- $line; set +o noglob
+                       word3=$3; IFS=$save_IFS
+                       [ $word3 -le $uid ] || uid=$word3
+               done < $userfile
+               uid=$(( $uid + 1 ))
+       fi
+
+       # Append $user:$uid to the user database.
+       { [ ! -f "$userfile" ] || ${CAT} "$userfile"
+         echo "$user:*:$uid:$group:$descr:$home:$shell"
+       } > $userfile_tmp
+       if ${MV} -f "$userfile_tmp" "$userfile"; then
+               return 0
+       fi
+       ${RM} -f "$userfile_tmp"
+       return 1
+}
+
+mock_usergroup_setup()
+{
+       : ${CAT:=cat}
+
+       if [ -n "${ETC_GROUP}" ]; then
+               ${CAT} > ${ETC_GROUP} << EOF
+groupA:*:100:
+groupB:*:105:
+groupC:*:110:
+groupD:*:190:
+groupE:*:200:
+groupF:*:205:
+EOF
+       fi
+       if [ -n "${ETC_PASSWD}" ]; then
+               ${CAT} > ${ETC_PASSWD} << EOF
+userA:*:100:100::0:0:package A user:/nonexistent:/bin/sh
+userB:*:105:105::0:0:package B user:/nonexistent:/bin/sh
+userC:*:110:110::0:0:package C user:/nonexistent:/bin/sh
+EOF
+       fi
+}
Index: pkgsrc/pkgtools/pkgtasks/files/users.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/users.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/users.subr   Thu Jun  1 01:58:34 2017
@@ -0,0 +1,243 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      users.subr -- user management for packages
+#
+# SYNOPSIS
+#      task_users [-s] add | remove
+#      task_users check-add | check-remove
+#
+# DESCRIPTION
+#      The task_users function supports four actions: "add", "remove",
+#      "check-add", and "check-remove".
+#
+#      The available options are as follows:
+#
+#      -s      Silent; don't write to standard output.
+#
+#      The function reads standard input line by line and looks for
+#      lines of the form:
+#
+#          # USER: <name>:<group>[:<userid>[:<descr>[:<home>[:<shell>]]]]
+#
+#      Only the user name and group are required; the remaining fields
+#      are optional.
+#
+#      The "add" action creates the user with the given name if it is
+#      missing, with the given user ID, if ${PKG_CREATE_USERGROUP} is
+#      "yes".  A reference count for the user will be added for the
+#      package.
+#
+#      The "remove" action removes a reference count for the user by
+#      the package.  This function shall not remove any user on the
+#      system.
+#
+#      The "check-add" action will check whether the users exist with
+#      the optional user IDs if they are given, or otherwise writes a
+#      message to standard output noting the missing users.
+#
+#      The "check-remove" action will check whether the users have been
+#      removed, or otherwise writes a message to standard output noting
+#      the users still exists.
+#
+# RETURN VALUES
+#      The "add" and "remove" actions return 0 if they are successful
+#      for all users, and >0 if an error occurs.
+#
+#      The "check-add" and "check-remove" actions return >0 if they
+#      write informative messages, and return 0 otherwise.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      PKGNAME
+#              The name of the package.
+#
+#      PKG_CREATE_USERGROUP
+#              If ${PKG_CREATE_USERGROUP} is a "truthy" value, then the
+#              "add" and "remove" actions are allowed to create and
+#              remove users from the system.
+#
+#      TASK_MSG
+#              String prepended to all normal message written to
+#              standard output.
+#
+
+__task_users__="yes"
+__task_users_init__="_task_users_init"
+
+task_load cleanup
+task_load echo
+task_load quote
+task_load refcount
+task_load truthy
+task_load usergroup
+task_load usergroup_exists
+
+task_users()
+{
+       : ${PKGNAME:=${0##*/}}
+       : ${PKG_CREATE_USERGROUP:=yes}
+       : ${TASK_MSG:=""}
+
+       local arg
+       local echo="task_echo"
+       local OPTIND=1
+       while getopts ":s" arg "$@"; do
+               case $arg in
+               s)      echo=":" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+
+       local action="$1"; shift
+       case $action in
+       add|remove|check-add|check-remove)
+               : "valid action" ;;
+       *)      return 0 ;;
+       esac
+
+       local create="yes"
+       task_is_truthy "${PKG_CREATE_USERGROUP}" || create=
+
+       local result line_result
+       local save_IFS user group uid descr home shell msg
+
+       result=0
+       local hash tag entry
+       while read hash tag entry; do
+               # Filter for "# USER:".
+               case $hash/$tag in
+               "#/USER:")
+                       : "use this line" ;;
+               *)      continue ;;
+               esac
+
+               save_IFS=$IFS; IFS=:
+               set -o noglob; set -- $entry; set +o noglob
+               user=$1; group=$2       # required
+               uid=$3; descr=$4; home=$5; shell=$6
+               IFS=$save_IFS
+               [ -n "$user" -a -n "$group" ] || continue
+
+               if [ -n "$uid" ]; then
+                       msg="$user (uid = $uid)"
+               else
+                       msg="$user"
+               fi
+               msg="$msg: $group"
+               [ -z "$home" ] || msg="$msg, $home"
+               [ -z "$shell" ] || msg="$msg, $shell"
+
+               line_result=0
+               case $action in
+               add)    if task_refcount add users "$user"; then
+                               task_user_exists "$user" "$uid"
+                               case $? in
+                               0)      # $user exists and has uid $uid
+                                       $echo "${TASK_MSG}! user already exists: $msg" ;;
+                               1)      # neither $user nor $uid exist
+                                       if [ -z "$create" ]; then
+                                               $echo "${TASK_MSG}! user creation skipped: $msg"
+                                       elif task_adduser "$user" "$group" "$uid" "$descr" "$home" "$shell"; then
+                                               $echo "${TASK_MSG}> user created: $msg"
+                                               task_quote "$user"
+                                               __task_users_error__="$__task_users_error__ $_quoted"
+                                       else
+                                               $echo "${TASK_MSG}! user not created: $msg"
+                                               line_result=1
+                                       fi ;;
+                               2)      $echo "${TASK_MSG}! user conflict: $msg"
+                                       result=1
+                                       break ;;
+                               *)      $echo "${TASK_MSG}! user not created: $msg"
+                                       line_result=1 ;;
+                               esac
+                       else
+                               # add refcount failed; skip to next line
+                               $echo "${TASK_MSG}! refcount add failure: users $msg"
+                               result=1
+                               continue
+                       fi ;;
+               remove) if task_refcount remove users "$user"; then
+                               if task_refcount exists users "$user"; then
+                                       : "refcount is not zero"
+                               else
+                                       # delete the reference count
+                                       task_refcount delete users "$user"
+                               fi
+                       else
+                               # remove refcount failed
+                               $echo "${TASK_MSG}! refcount remove failure: users $msg"
+                               line_result=1
+                       fi ;;
+               check-add)
+                       if task_user_exists "$user" "$uid"; then
+                               : "user already exists"
+                       else
+                               task_echo "!!! INFO: ${PKGNAME}: Create user: $msg"
+                               line_result=1
+                       fi ;;
+               check-remove)
+                       if task_user_exists "$user" "$uid"; then
+                               task_echo "!!! INFO: ${PKGNAME}: Remove user if unused: $user"
+                               line_result=1
+                       fi ;;
+               esac
+               [ $line_result -eq 0 ] || result=1
+       done
+
+       # Clear users to remove in case of error if all users added
+       # successfully.
+       #
+       [ $result -gt 0 ] || __task_users_error__=
+
+       return $result
+}
+
+_task_users_cleanup()
+{
+       eval set -- $__task_users_error__
+       local user
+       for user; do
+               if task_user_exists "$user"; then
+                       task_echo "!!! ERROR: ${PKGNAME}: User created before error: $user"
+               fi
+       done
+       __task_users_error__=
+}
+
+_task_users_init()
+{
+       task_cleanup_add_hook _task_users_cleanup
+}
+
+# Static variable for users that should be removed if an error occurs.
+__task_users_error__=
Index: pkgsrc/pkgtools/pkgtasks/files/valid_options.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/valid_options.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/valid_options.subr   Thu Jun  1 01:58:34 2017
@@ -0,0 +1,60 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      valid_options.subr -- check validity of an option string
+#
+# SYNOPSIS
+#      task_valid_options <optstr> <validstr>
+#
+# DESCRIPTION
+#      task_valid_options checks whether option string <optstr> is composed
+#      only of characters form <validstr>.  <validstr> MUST NOT contain a
+#      '-' (dash, ASCII 45).
+#
+# RETURN VALUES
+#      Returns 0 if the option string is valid, and >0 otherwise.
+#
+
+__task_valid_options__="yes"
+
+task_valid_options()
+{
+       local optstr="$1"
+       local validstr="$2"
+
+       local arg
+       local OPTIND=1
+       while getopts ":$validstr" arg "-$optstr"; do
+               case $arg in
+               ["$validstr"])
+                       : "valid options" ;;
+               \?)     return 1 ;;
+               esac
+       done
+       return 0
+}
Index: pkgsrc/pkgtools/pkgtasks/files/version.subr.in
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/version.subr.in:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/version.subr.in      Thu Jun  1 01:58:34 2017
@@ -0,0 +1,535 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      version.subr -- compare version strings
+#
+# SYNOPSIS
+#      echo ${TASK_VERSION}
+#
+#      task_version_check <check_version> [* | < | <= | = | => | >] <version> ...
+#
+#      task_version_compare [-v] <version1> <version2>
+#
+# DESCRIPTION
+#      ${TASK_VERSION} is the version number of the installed task modules.
+#
+#      The task_version_check function checks whether <check_version>
+#      satisfies the constraints specified in the remaining parameters.
+#      The remaining parameters are contraints of pairs of an operator and
+#      a version number, and the constraints must all be met for a
+#      successful version check.
+#
+#      The task_version_compare function compares the two version strings.
+#
+#      A version string has the following form:
+#
+#              <swver>[+<pkgver>]
+#
+#      <swver> represents the version of the software and SHOULD be
+#      identical to the version string used by the maintainer of the
+#      software.
+#
+#      <pkgver> is a version that is independent of the version of the
+#      software, and is used to differentiate two version strings with the
+#      same <swver>.
+#
+#      Both <swver> and <pkgver> are an alternating sequence of numeric and
+#      non-numeric components.  Each component MAY contain any
+#      printable-ASCII character except for '/' (slash, ASCII 47), '-'
+#      (dash, ASCII 45), and '+' (plus, ASCII 43).
+#
+#      The magic string "nb" MAY be used as a synonym for '+', used to
+#      separate <swver> and <pkgver> in a version string.
+#
+# ALGORITHM
+#      The comparison algorithm is to compare corresponding components of
+#      the two version strings, beginning with the leftmost components, and
+#      to compare the next pair of components if the current ones match.
+#      If the components are numeric, then do a numeric comparison;
+#      otherwise, do a string comparison.
+#
+#      There are magic strings that may be found in version numbers, listed
+#      below in sorting order from lowest to highest:
+#
+#          ~[string]   Tilde (ASCII 126) string; sorts before a release
+#                      version.  The string after the '~' is optional.
+#
+#          alpha       Equates to "alpha version" and is a synonym for
+#                      "~alpha".
+#
+#          beta        Equates to "beta version" and is a synonym for
+#                      "~beta".
+#
+#          rc          Equates to "release candidate" and is a synonym for
+#                      "~rc".
+#
+#          pre         Equates to "pre-release" and is a synonym for a
+#                      release candidate.
+#
+#          .           Period (ASCII 46); the usual separator between
+#                      numeric components.
+#
+#          _           Underscore (ASCII 95); a synonym for '.' (period).
+#
+#          pl          Equates to "patch level" and is a synonym for '.'
+#                      (period).
+#
+#      Additionally, single alphabetic characters sort in the same place as
+#      their numeric counterparts, so "1.2e" and "1.2.5" are equivalent with
+#      respect to their sorting order.
+#
+#      An empty string for the version number is the "null" version and sorts
+#      as less than all other version numbers.
+#
+# RETURN VALUES
+#      The task_version_check function returns 0 if all of the contraints
+#      are met, and >0 if they are not.
+#
+#      The task_version_compare function has the following return values:
+#
+#          0   if <version1> is less than <version2>
+#          1   if <version1> equals <version2>
+#          2   if <version1> is greater than <version2>
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      AWK     The name or path to the awk(1) utility.
+#
+
+__task_version__="yes"
+
+# The version of the installed task modules.
+TASK_VERSION=@TASK_VERSION@
+
+task_version_check()
+{
+       [ $# -ge 3 ] || return 127
+       local check_version="$1"; shift
+
+       local cmp_result
+       local operator=
+       local version=
+       for version; do
+               if [ -z "$operator" ]; then
+                       operator=$version
+                       continue
+               fi
+               task_version_compare "$check_version" "$version"
+               cmp_result=$?
+               case $operator in
+               "*")    # any
+                       case $cmp_result in
+                       0|1|2)  : "match" ;;
+                       *)      return 1 ;;
+                       esac ;;
+               "<")    # less than
+                       case $cmp_result in
+                       0)      : "match" ;;
+                       *)      return 1 ;;
+                       esac ;;
+               "<=")   # less than or equal to
+                       case $cmp_result in
+                       0|1)    : "match" ;;
+                       *)      return 1 ;;
+                       esac ;;
+               "=")    # equal to
+                       case $cmp_result in
+                       1)      : "match" ;;
+                       *)      return 1 ;;
+                       esac ;;
+               "!=")   # not equal to
+                       case $cmp_result in
+                       0|2)    : "match" ;;
+                       *)      return 1 ;;
+                       esac ;;
+               ">=")   # greater than or equal to
+                       case $cmp_result in
+                       1|2)    : "match" ;;
+                       *)      return 1 ;;
+                       esac ;;
+               ">")    # greater than
+                       case $cmp_result in
+                       2)      : "match" ;;
+                       *)      return 1 ;;
+                       esac ;;
+               esac
+               operator=
+       done
+       [ -z "$operator" ] || return 127
+       return 0
+}
+
+task_version_compare()
+{
+       # Returns 0 if version1 < version2.
+       # Returns 1 if version1 = version2.
+       # Returns 2 if version1 > version2.
+
+       # Decompose each version string into <swver> and <pkgver> components.
+
+       local verbose=
+       local arg
+       local OPTIND=1
+       while getopts ":v" arg "$@"; do
+               case $arg in
+               v)      verbose="-v" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -eq 2 ] || return 127
+       local version1="$1"; shift
+       local version2="$1"; shift
+
+       local swver1 pkgver1
+       local swver2 pkgver2
+
+       case $version1 in
+       *"+"*)  swver1=${version1%+*}
+               pkgver1=${version1#$swver1+} ;;
+       *"nb"*) swver1=${version1%nb*}
+               pkgver1=${version1#${swver1}nb} ;;
+       *)      swver1=$version1
+               pkgver1= ;;
+       esac
+       case $version2 in
+       *"+"*)  swver2=${version2%+*}
+               pkgver2=${version2#$swver2+} ;;
+       *"nb"*) swver2=${version2%nb*}
+               pkgver2=${version2#${swver2}nb} ;;
+       *)      swver2=$version2
+               pkgver2= ;;
+       esac
+
+       [ -z "$verbose" ] || echo "> compare \"$version1\" vs. \"$version2\""
+
+       # Compare $swver1 and $swver2.
+       _task_version_compare $verbose "$swver1" "$swver2"
+       local result=$?
+       case $result in
+       1)      : "fall through to <pkgver> comparison" ;;
+       *)      return $result ;;
+       esac
+
+       # Compare $pkgver1 and $pkgver2.
+       _task_version_compare $verbose "$pkgver1" "$pkgver2"
+}
+
+_task_version_compare()
+{
+       # Returns 0 if version1 < version2.
+       # Returns 1 if version1 = version2.
+       # Returns 2 if version1 > version2.
+       # Returns >2 if an error occurs.
+
+       local echo=":"
+       local arg
+       local OPTIND=1
+       while getopts ":v" arg "$@"; do
+               case $arg in
+               v)      echo="echo" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -eq 2 ] || return 127
+       local version1="$1"; shift
+       local version2="$1"; shift
+
+       # Verify version strings.
+       case $version1 in
+       *"/"*|*"-"*|*"+"*)
+               return 3 ;;
+       esac
+       case $version2 in
+       *"/"*|*"-"*|*"+"*)
+               return 3 ;;
+       esac
+
+       $echo "  > compare: \"$version1\" vs. \"$version2\""
+
+       # Same versions.
+       if [ "$version1" = "$version2" ]; then
+               $echo "    > equal"; return 1
+       fi
+
+       # Null versions.
+       if [ -z "$version1" ]; then
+               $echo "    > less than"; return 0
+       fi
+       if [ -z "$version2" ]; then
+               $echo "    > more than"; return 2
+       fi
+
+       # Break down version numbers for comparisions.
+       #
+       # A version number is a sequence of numbers separated by non-numeric
+       # strings.
+       #
+       # Always start version comparisons with a non-numeric string.
+       case $version1 in
+       [0-9]*) version1=".$version1" ;;
+       *)      version1="$version1" ;;
+       esac
+       case $version2 in
+       [0-9]*) version2=".$version2" ;;
+       *)      version2="$version2" ;;
+       esac
+
+       local number1 str1 value1 tilde1 substr1
+       local number2 str2 value2 tilde2 substr2
+       local mode="string"
+
+       while : ; do
+               case $mode in
+               number) # Set number<n> to the numeric component before the next
+                       # non-numeric string, and set version<n> to the remaining
+                       # version after the leading numeric component.
+                       #
+                       number1=${version1%%[!0-9]*}
+                       case $version1 in
+                       *[!0-9]*)       version1=${version1#$number1} ;;
+                       *)              version1= ;;
+                       esac
+                       number2=${version2%%[!0-9]*}
+                       case $version2 in
+                       *[!0-9]*)       version2=${version2#$number2} ;;
+                       *)              version2= ;;
+                       esac
+                       $echo "    > \"$number1 | $version1\" vs. \"$number2 | $version2\""
+                       if [ -z "$number1" -a -z "$number2" ]; then
+                               # Both version numbers terminate.
+                               break
+                       elif [ -z "$number1" ]; then
+                               $echo "    > less than"; return 0
+                       elif [ -z "$number2" ]; then
+                               $echo "    > more than"; return 2
+                       elif [ $number1 -lt $number2 ]; then
+                               $echo "    > less than"; return 0
+                       elif [ $number1 -gt $number2 ]; then
+                               $echo "    > more than"; return 2
+                       fi
+                       mode="string"
+                       ;;
+               string) # Set str<n> to the non-numeric string before the next
+                       # numeric component, and set version<n> to the remaining
+                       # version after the leading non-numeric string.
+                       #
+                       str1=${version1%%[0-9]*}
+                       case $version1 in
+                       *[0-9]*)        version1=${version1#$str1} ;;
+                       *)              version1= ;;
+                       esac
+                       str2=${version2%%[0-9]*}
+                       case $version2 in
+                       *[0-9]*)        version2=${version2#$str2} ;;
+                       *)              version2= ;;
+                       esac
+                       #
+                       # Alphabetic characters sort in the same place as their
+                       # numeric counterparts, e.g., 1.2e = 1.2.5.  Set str<n>
+                       # to a dot "." and push the numeric counterpart back
+                       # onto the front of version<n>.
+                       #
+                       case $str1 in
+                       [A-Za-z])
+                               case $str1 in
+                               [Aa])   value1=1 ;;     [Nn])   value1=14 ;;
+                               [Bb])   value1=2 ;;     [Oo])   value1=15 ;;
+                               [Cc])   value1=3 ;;     [Pp])   value1=16 ;;
+                               [Dd])   value1=4 ;;     [Qq])   value1=17 ;;
+                               [Ee])   value1=5 ;;     [Rr])   value1=18 ;;
+                               [Ff])   value1=6 ;;     [Ss])   value1=19 ;;
+                               [Gg])   value1=7 ;;     [Tt])   value1=20 ;;
+                               [Hh])   value1=8 ;;     [Uu])   value1=21 ;;
+                               [Ii])   value1=9 ;;     [Vv])   value1=22 ;;
+                               [Jj])   value1=10 ;;    [Ww])   value1=23 ;;
+                               [Kk])   value1=11 ;;    [Xx])   value1=24 ;;
+                               [Ll])   value1=12 ;;    [Yy])   value1=25 ;;
+                               [Mm])   value1=13 ;;    [Zz])   value1=26 ;;
+                               esac
+                               case $version1 in
+                               "")     version1="$value1" ;;
+                               *)      version1="$value1.$version1" ;;
+                               esac
+                               str1="."
+                               ;;
+                       esac
+                       case $str2 in
+                       [A-Za-z])
+                               case $str2 in
+                               [Aa])   value2=1 ;;     [Nn])   value2=14 ;;
+                               [Bb])   value2=2 ;;     [Oo])   value2=15 ;;
+                               [Cc])   value2=3 ;;     [Pp])   value2=16 ;;
+                               [Dd])   value2=4 ;;     [Qq])   value2=17 ;;
+                               [Ee])   value2=5 ;;     [Rr])   value2=18 ;;
+                               [Ff])   value2=6 ;;     [Ss])   value2=19 ;;
+                               [Gg])   value2=7 ;;     [Tt])   value2=20 ;;
+                               [Hh])   value2=8 ;;     [Uu])   value2=21 ;;
+                               [Ii])   value2=9 ;;     [Vv])   value2=22 ;;
+                               [Jj])   value2=10 ;;    [Ww])   value2=23 ;;
+                               [Kk])   value2=11 ;;    [Xx])   value2=24 ;;
+                               [Ll])   value2=12 ;;    [Yy])   value2=25 ;;
+                               [Mm])   value2=13 ;;    [Zz])   value2=26 ;;
+                               esac
+                               case $version2 in
+                               "")     version2="$value2" ;;
+                               *)      version2="$value2.$version2" ;;
+                               esac
+                               str2="."
+                               ;;
+                       esac
+                       #
+                       # Some magic values that sort before a release version.
+                       #
+                       case $str1 in
+                       alpha|beta|rc)
+                               str1="~$str1" ;;
+                       pre)    str1="~rc" ;;   # synonym for "rc"
+                       esac
+                       case $str2 in
+                       alpha|beta|rc)
+                               str2="~$str2" ;;
+                       pre)    str2="~rc" ;;   # synonym for "rc"
+                       esac
+                       #
+                       # Early short-circuit comparisons.
+                       #
+                       case $str1/$str2 in
+                       "~"*/[!~]*)
+                               $echo "    > less than"; return 0 ;;
+                       [!~]*/"~"*)
+                               $echo "    > more than"; return 2 ;;
+                       "~"*/"~"*|[!~]*/[!~]*)
+                               : "fall through to string comparison" ;;
+                       esac
+                       # Compare successive substrings separated by '~'.
+                       while : ; do
+                               # Set substr<n> to the string before the next '~'
+                               # character, and set str<n> to the remaining string
+                               # starting from the next '~' character.
+                               #
+                               case $str1 in
+                               "~"*)   tilde1="~"; str1=${str1#~} ;;
+                               *)      tilde1= ;;
+                               esac
+                               case $str1 in
+                               *"~"*)  substr1=${str1%%~*}
+                                       str1=${str1#$substr1} ;;
+                               *)      substr1=$str1
+                                       str1= ;;
+                               esac
+                               substr1="$tilde1$substr1"
+                               case $str2 in
+                               "~"*)   tilde2="~"; str2=${str2#~} ;;
+                               *)      tilde2= ;;
+                               esac
+                               case $str2 in
+                               *"~"*)  substr2=${str2%%~*}
+                                       str2=${str2#$substr2} ;;
+                               *)      substr2=$str2
+                                       str2= ;;
+                               esac
+                               substr2="$tilde2$substr2"
+                               #
+                               # Assign numerical values to the strings for
+                               # comparison.  We can't do a straight string
+                               # comparison because some of the strings are
+                               # magic tokens.
+                               #
+                               case $substr1 in
+                               ~*)             value1=100 ;;
+                               "")             value1=400 ;;
+                               [.]|_|pl)       value1=500 ;;
+                               *)              value1=1000 ;;
+                               esac
+                               case $substr2 in
+                               ~*)             value2=100 ;;
+                               "")             value2=400 ;;
+                               [.]|_|pl)       value2=500 ;;
+                               *)              value2=1000 ;;
+                               esac
+                               $echo "    > \"$substr1 ($value1) / $str1 | $version1\" vs. \"$substr2 ($value2) / $str2 | $version2\""
+                               if [ $value1 -eq 1000 -a $value2 -eq 1000 ] ||
+                                  [ $value1 -eq 100 -a $value2 -eq 100 ]; then
+                                       # Non-empty string comparisons.
+                                       if _task_string_compare "$substr1" "<" "$substr2"; then
+                                               $echo "    > less than"; return 0
+                                       elif _task_string_compare "$substr1" ">" "$substr2"; then
+                                               $echo "    > more than"; return 2
+                                       fi
+                               elif [ $value1 -eq 400 -a $value2 -eq 400 ]; then
+                                       # Both version numbers terminate.
+                                       break
+                               elif [ $value1 -lt $value2 ]; then
+                                       $echo "    > less than"; return 0
+                               elif [ $value1 -gt $value2 ]; then
+                                       $echo "    > more than"; return 2
+                               fi
+                       done
+                       mode="number"
+                       ;;
+               esac
+       done
+       $echo "    > equal"; return 1
+}
+
+_task_string_compare()
+{
+       : ${AWK:=awk}
+
+       [ $# -eq 3 ] || return 127
+
+       local str1="$1"; shift
+       local op="$1"; shift
+       local str2="$1"; shift
+
+       case $op in
+       '<'|'>'|'='|'!=')
+               test "$str1" "$op" "$str2" 2>/dev/null ;;
+       '<=')   test "$str1" "<" "$str2" 2>/dev/null &&
+               test "$str1" "=" "$str2" 2>/dev/null ;;
+       '>=')   test "$str1" ">" "$str2" 2>/dev/null &&
+               test "$str1" "=" "$str2" 2>/dev/null ;;
+       *)      # invalid operator
+               return 127 ;;
+       esac
+       local result=$?
+       case $result in
+       0|1)    return $result ;;
+       *)      # Fall back to using awk(1) for lexographic comparison.
+               # Convert operator to the AWK-equivalent if needed.
+               case $op in
+               '=')    op="==" ;;
+               *)      : "other operators are the same in AWK" ;;
+               esac
+               ${AWK} -v STR1="$str1" -v STR2="$str2" \
+                       'BEGIN { exit ( (STR1 '"$op"' STR2) ? 0 : 1 ) }' ;;
+       esac
+}
Index: pkgsrc/pkgtools/pkgtasks/files/which.subr
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/which.subr:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/which.subr   Thu Jun  1 01:58:34 2017
@@ -0,0 +1,93 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      which.subr -- locate a program file in the $PATH environment variable
+#
+# SYNOPSIS
+#      task_which name [...]
+#
+# DESCRIPTION
+#      The task_which function takes a list of names and looks for the
+#      files which would be executed had these names been given as
+#      commands.  Each directory in the $PATH is searched, in order,
+#      for each name.
+#
+# RETURN VALUES
+#      The task_which function returns 0 if all commandss are found,
+#      and >0 otherwise.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      PATH    A colon-separated list of directories to search for
+#              commands.
+#
+
+__task_which__="yes"
+
+task_which()
+{
+       local result=0
+       local command
+       for arg; do
+               if [ -n "$arg" ] && _task_which "$arg"; then
+                       echo "$command"
+               else
+                       result=1
+               fi
+       done
+       return $result
+}
+
+_task_which()
+{
+       : ${PATH:=/bin:/sbin:/usr/bin:/usr/sbin}
+
+       # Return path to command in $command.
+       command=
+
+       local result=1
+       local cmd="$1"; shift
+       case $cmd in
+       /*)     if [ -x "$cmd" ]; then
+                       command="$cmd"
+                       result=0
+               fi ;;
+       *)      local save_IFS="$IFS"; IFS=":"; set -- ${PATH}; IFS=$save_IFS
+               for path; do
+                       if [ -x "$path/$cmd" ]; then
+                               command="$path/$cmd"
+                               result=0
+                               break
+                       fi
+               done ;;
+       esac
+       # POST-CONDITION:
+       # $command is set to the string with the full path to the command.
+       return $result
+}

Index: pkgsrc/pkgtools/pkgtasks/files/build-aux/install-sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/build-aux/install-sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/build-aux/install-sh Thu Jun  1 01:58:34 2017
@@ -0,0 +1,301 @@
+#!/bin/sh
+#
+# $NetBSD: install-sh,v 1.1 2017/06/01 01:58:34 jlam Exp $
+# This script now also installs multiple files, but might choke on installing
+# multiple files with spaces in the file names.
+#
+# install - install a program, script, or datafile
+# This comes from X11R5 (mit/util/scripts/install.sh).
+#
+# Copyright 1991 by the Massachusetts Institute of Technology
+#
+# Permission to use, copy, modify, distribute, and sell this software and its
+# documentation for any purpose is hereby granted without fee, provided that
+# the above copyright notice appear in all copies and that both that
+# copyright notice and this permission notice appear in supporting
+# documentation, and that the name of M.I.T. not be used in advertising or
+# publicity pertaining to distribution of the software without specific,
+# written prior permission.  M.I.T. makes no representations about the
+# suitability of this software for any purpose.  It is provided "as is"
+# without express or implied warranty.
+#
+# Calling this script install-sh is preferred over install.sh, to prevent
+# `make' implicit rules from creating a file called install from it
+# when there is no Makefile.
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch.
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit="${DOITPROG-}"
+
+
+# put in absolute paths if you don't have them in your path; or use env. vars.
+
+awkprog="${AWKPROG-awk}"
+mvprog="${MVPROG-mv}"
+cpprog="${CPPROG-cp}"
+chmodprog="${CHMODPROG-chmod}"
+chownprog="${CHOWNPROG-chown}"
+chgrpprog="${CHGRPPROG-chgrp}"
+stripprog="${STRIPPROG-strip}"
+rmprog="${RMPROG-rm}"
+mkdirprog="${MKDIRPROG-mkdir}"
+
+instcmd="$cpprog"
+instflags=""
+pathcompchmodcmd="$chmodprog 755"
+chmodcmd="$chmodprog 755"
+chowncmd=""
+chgrpcmd=""
+stripcmd=""
+stripflags=""
+rmcmd="$rmprog -f"
+mvcmd="$mvprog"
+src=""
+msrc=""
+dst=""
+dir_arg=""
+suffix=""
+suffixfmt=""
+
+while [ x"$1" != x ]; do
+    case $1 in
+       -b) suffix=".old"
+           shift
+           continue;;
+
+       -B) suffixfmt="$2"
+           shift
+           shift
+           continue;;
+
+       -c) instcmd="$cpprog"
+           shift
+           continue;;
+
+       -d) dir_arg=true
+           shift
+           continue;;
+
+       -m) chmodcmd="$chmodprog $2"
+           shift
+           shift
+           continue;;
+
+       -m*)
+           chmodcmd="$chmodprog ${1#-m}"
+           shift
+           continue;;
+
+       -o) chowncmd="$chownprog $2"
+           shift
+           shift
+           continue;;
+
+       -g) chgrpcmd="$chgrpprog $2"
+           shift
+           shift
+           continue;;
+
+       -s) stripcmd="$stripprog"
+           shift
+           continue;;
+
+       -S) stripcmd="$stripprog"
+           stripflags="-S $2 $stripflags"
+           shift
+           shift
+           continue;;
+
+       -p) instflags="-p"
+           shift
+           continue;;
+
+       *)  if [ x"$msrc" = x ]
+           then
+               msrc="$dst"
+           else
+               msrc="$msrc $dst"
+           fi
+           src="$dst"
+           dst="$1"
+           shift
+           continue;;
+    esac
+done
+
+if [ x"$dir_arg" = x ]
+then
+       dstisfile=""
+       if [ ! -d "$dst" ]
+       then
+               if [ x"$msrc" = x"$src" ]
+               then
+                       dstisfile=true
+               else
+                       echo "install: destination is not a directory"
+                       exit 1
+               fi
+       fi
+else
+       msrc="$msrc $dst"
+fi
+
+if [ x"$msrc" = x ]
+then
+       echo "install: no destination specified"
+       exit 1
+fi      
+
+for srcarg in $msrc; do
+
+if [ x"$dir_arg" != x ]; then
+
+       dstarg="$srcarg"
+else
+       dstarg="$dst"
+
+# Waiting for this to be detected by the "$instcmd $srcarg $dsttmp" command
+# might cause directories to be created, which would be especially bad 
+# if $src (and thus $dsttmp) contains '*'.
+
+       if [ -f "$srcarg" ]
+       then
+               doinst="$instcmd $instflags"
+       elif [ -d "$srcarg" ]
+       then
+               echo "install: $srcarg: not a regular file"
+               exit 1
+       elif [ "$srcarg" = "/dev/null" ]
+       then
+               doinst="$cpprog"
+       else
+               echo "install:  $srcarg does not exist"
+               exit 1
+       fi
+       
+# If destination is a directory, append the input filename; if your system
+# does not like double slashes in filenames, you may need to add some logic
+
+       if [ -d "$dstarg" ]
+       then
+               dstarg="$dstarg"/`basename "$srcarg"`
+       fi
+fi
+
+## this sed command emulates the dirname command
+dstdir=`echo "$dstarg" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
+
+# Make sure that the destination directory exists.
+#  this part is taken from Noah Friedman's mkinstalldirs script
+
+# Skip lots of stat calls in the usual case.
+if [ ! -d "$dstdir" ]; then
+defaultIFS='   
+'
+IFS="${IFS-${defaultIFS}}"
+
+oIFS="${IFS}"
+# Some sh's can't handle IFS=/ for some reason.
+IFS='%'
+set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
+IFS="${oIFS}"
+
+pathcomp=''
+
+while [ $# -ne 0 ] ; do
+       pathcomp="${pathcomp}${1}"
+       shift
+
+       if [ ! -d "${pathcomp}" ] ;
+        then
+               $doit $mkdirprog "${pathcomp}"
+               if [ x"$chowncmd" != x ]; then $doit $chowncmd "${pathcomp}"; else true ; fi &&
+               if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "${pathcomp}"; else true ; fi &&
+               if [ x"$pathcompchmodcmd" != x ]; then $doit $pathcompchmodcmd "${pathcomp}"; else true ; fi
+
+       else
+               true
+       fi
+
+       pathcomp="${pathcomp}/"
+done
+fi
+
+       if [ x"$dir_arg" != x ]
+       then
+               if [ -d "$dstarg" ]; then
+                       true
+               else
+                       $doit $mkdirprog "$dstarg" &&
+
+                       if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dstarg"; else true ; fi &&
+                       if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dstarg"; else true ; fi &&
+                       if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dstarg"; else true ; fi
+               fi
+       else
+
+               if [ x"$dstisfile" = x ]
+               then
+                       file=$srcarg
+               else
+                       file=$dst
+               fi
+
+               dstfile=`basename "$file"`
+               dstfinal="$dstdir/$dstfile"
+
+# Make a temp file name in the proper directory.
+
+               dsttmp=$dstdir/#inst.$$#
+
+# Make a backup file name in the proper directory.
+               case x$suffixfmt in
+               *%*)    suffix=`echo x |
+                       $awkprog -v bname="$dstfinal" -v fmt="$suffixfmt" '
+                       { cnt = 0;
+                         do {
+                               sfx = sprintf(fmt, cnt++);
+                               name = bname sfx;
+                         } while (system("test -f " name) == 0);
+                         print sfx; }' -`;;
+               x)      ;;
+               *)      suffix="$suffixfmt";;
+               esac
+               dstbackup="$dstfinal$suffix"
+
+# Move or copy the file name to the temp name
+
+               $doit $doinst $srcarg "$dsttmp" &&
+
+               trap "rm -f ${dsttmp}" 0 &&
+
+# and set any options; do chmod last to preserve setuid bits
+
+# If any of these fail, we abort the whole thing.  If we want to
+# ignore errors from any of these, just make sure not to ignore
+# errors from the above "$doit $instcmd $src $dsttmp" command.
+
+               if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else true;fi &&
+               if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else true;fi &&
+               if [ x"$stripcmd" != x ]; then $doit $stripcmd $stripflags "$dsttmp"; else true;fi &&
+               if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else true;fi &&
+
+# Now rename the file to the real destination.
+
+               if [ x"$suffix" != x ] && [ -f "$dstfinal" ]
+               then
+                       $doit $mvcmd "$dstfinal" "$dstbackup"
+               else
+                       $doit $rmcmd -f "$dstfinal"
+               fi &&
+               $doit $mvcmd "$dsttmp" "$dstfinal"
+       fi
+
+done &&
+
+
+exit 0
Index: pkgsrc/pkgtools/pkgtasks/files/build-aux/missing
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/build-aux/missing:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/build-aux/missing    Thu Jun  1 01:58:34 2017
@@ -0,0 +1,215 @@
+#! /bin/sh
+# Common wrapper for a few potentially missing GNU programs.
+
+scriptversion=2013-10-28.13; # UTC
+
+# Copyright (C) 1996-2014 Free Software Foundation, Inc.
+# Originally written by Fran,cois Pinard <pinard%iro.umontreal.ca@localhost>, 1996.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+if test $# -eq 0; then
+  echo 1>&2 "Try '$0 --help' for more information"
+  exit 1
+fi
+
+case $1 in
+
+  --is-lightweight)
+    # Used by our autoconf macros to check whether the available missing
+    # script is modern enough.
+    exit 0
+    ;;
+
+  --run)
+    # Back-compat with the calling convention used by older automake.
+    shift
+    ;;
+
+  -h|--h|--he|--hel|--help)
+    echo "\
+$0 [OPTION]... PROGRAM [ARGUMENT]...
+
+Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
+to PROGRAM being missing or too old.
+
+Options:
+  -h, --help      display this help and exit
+  -v, --version   output version information and exit
+
+Supported PROGRAM values:
+  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
+  bison     yacc      flex         lex       help2man
+
+Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
+'g' are ignored when checking the name.
+
+Send bug reports to <bug-automake%gnu.org@localhost>."
+    exit $?
+    ;;
+
+  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
+    echo "missing $scriptversion (GNU Automake)"
+    exit $?
+    ;;
+
+  -*)
+    echo 1>&2 "$0: unknown '$1' option"
+    echo 1>&2 "Try '$0 --help' for more information"
+    exit 1
+    ;;
+
+esac
+
+# Run the given program, remember its exit status.
+"$@"; st=$?
+
+# If it succeeded, we are done.
+test $st -eq 0 && exit 0
+
+# Also exit now if we it failed (or wasn't found), and '--version' was
+# passed; such an option is passed most likely to detect whether the
+# program is present and works.
+case $2 in --version|--help) exit $st;; esac
+
+# Exit code 63 means version mismatch.  This often happens when the user
+# tries to use an ancient version of a tool on a file that requires a
+# minimum version.
+if test $st -eq 63; then
+  msg="probably too old"
+elif test $st -eq 127; then
+  # Program was missing.
+  msg="missing on your system"
+else
+  # Program was found and executed, but failed.  Give up.
+  exit $st
+fi
+
+perl_URL=http://www.perl.org/
+flex_URL=http://flex.sourceforge.net/
+gnu_software_URL=http://www.gnu.org/software
+
+program_details ()
+{
+  case $1 in
+    aclocal|automake)
+      echo "The '$1' program is part of the GNU Automake package:"
+      echo "<$gnu_software_URL/automake>"
+      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
+      echo "<$gnu_software_URL/autoconf>"
+      echo "<$gnu_software_URL/m4/>"
+      echo "<$perl_URL>"
+      ;;
+    autoconf|autom4te|autoheader)
+      echo "The '$1' program is part of the GNU Autoconf package:"
+      echo "<$gnu_software_URL/autoconf/>"
+      echo "It also requires GNU m4 and Perl in order to run:"
+      echo "<$gnu_software_URL/m4/>"
+      echo "<$perl_URL>"
+      ;;
+  esac
+}
+
+give_advice ()
+{
+  # Normalize program name to check for.
+  normalized_program=`echo "$1" | sed '
+    s/^gnu-//; t
+    s/^gnu//; t
+    s/^g//; t'`
+
+  printf '%s\n' "'$1' is $msg."
+
+  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
+  case $normalized_program in
+    autoconf*)
+      echo "You should only need it if you modified 'configure.ac',"
+      echo "or m4 files included by it."
+      program_details 'autoconf'
+      ;;
+    autoheader*)
+      echo "You should only need it if you modified 'acconfig.h' or"
+      echo "$configure_deps."
+      program_details 'autoheader'
+      ;;
+    automake*)
+      echo "You should only need it if you modified 'Makefile.am' or"
+      echo "$configure_deps."
+      program_details 'automake'
+      ;;
+    aclocal*)
+      echo "You should only need it if you modified 'acinclude.m4' or"
+      echo "$configure_deps."
+      program_details 'aclocal'
+      ;;
+   autom4te*)
+      echo "You might have modified some maintainer files that require"
+      echo "the 'autom4te' program to be rebuilt."
+      program_details 'autom4te'
+      ;;
+    bison*|yacc*)
+      echo "You should only need it if you modified a '.y' file."
+      echo "You may want to install the GNU Bison package:"
+      echo "<$gnu_software_URL/bison/>"
+      ;;
+    lex*|flex*)
+      echo "You should only need it if you modified a '.l' file."
+      echo "You may want to install the Fast Lexical Analyzer package:"
+      echo "<$flex_URL>"
+      ;;
+    help2man*)
+      echo "You should only need it if you modified a dependency" \
+           "of a man page."
+      echo "You may want to install the GNU Help2man package:"
+      echo "<$gnu_software_URL/help2man/>"
+    ;;
+    makeinfo*)
+      echo "You should only need it if you modified a '.texi' file, or"
+      echo "any other file indirectly affecting the aspect of the manual."
+      echo "You might want to install the Texinfo package:"
+      echo "<$gnu_software_URL/texinfo/>"
+      echo "The spurious makeinfo call might also be the consequence of"
+      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
+      echo "want to install GNU make:"
+      echo "<$gnu_software_URL/make/>"
+      ;;
+    *)
+      echo "You might have modified some files without having the proper"
+      echo "tools for further handling them.  Check the 'README' file, it"
+      echo "often tells you about the needed prerequisites for installing"
+      echo "this package.  You may also peek at any GNU archive site, in"
+      echo "case some other package contains this missing '$1' program."
+      ;;
+  esac
+}
+
+give_advice "$1" | sed -e '1s/^/WARNING: /' \
+                       -e '2,$s/^/         /' >&2
+
+# Propagate the correct exit status (expected to be 127 for a program
+# not found, 63 for a program that failed due to version mismatch).
+exit $st
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:

Index: pkgsrc/pkgtools/pkgtasks/files/t/Kyuafile
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/Kyuafile:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/Kyuafile   Thu Jun  1 01:58:34 2017
@@ -0,0 +1,84 @@
+--[[-----------------------------------------------------------------------
+Copyright (c) 2017 The NetBSD Foundation, Inc.
+All rights reserved.
+
+This code is derived from software contributed to The NetBSD Foundation
+by Johnny C. Lam.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+--]]-----------------------------------------------------------------------
+--[[-----------------------------------------------------------------------
+
+       The following variables will be used if they are set.
+
+       TASK_MODULE_DIR
+               The location where the task modules are found.
+
+       TASK_TESTS_DIR
+               The location where this Kyuafile is found.
+
+--]]-----------------------------------------------------------------------
+
+syntax( 2 )
+
+test_suite( "pkgtasks" )
+
+tap_test_program { name = "t_compare" }
+tap_test_program { name = "t_createfile" }
+tap_test_program { name = "t_directories" }
+tap_test_program { name = "t_dirwalk" }
+tap_test_program { name = "t_echo" }
+tap_test_program { name = "t_files" }
+tap_test_program { name = "t_fonts" }
+tap_test_program { name = "t_groups" }
+tap_test_program { name = "t_info_files" }
+tap_test_program { name = "t_lock" }
+tap_test_program { name = "t_makedir" }
+tap_test_program { name = "t_maketemp" }
+tap_test_program { name = "t_match" }
+tap_test_program { name = "t_ocaml_findlib" }
+tap_test_program { name = "t_permissions" }
+tap_test_program { name = "t_platform" }
+tap_test_program { name = "t_postinstall" }
+tap_test_program { name = "t_postremove" }
+tap_test_program { name = "t_preinstall" }
+tap_test_program { name = "t_preremove" }
+tap_test_program { name = "t_quote" }
+tap_test_program { name = "t_random" }
+tap_test_program { name = "t_refcount" }
+tap_test_program { name = "t_shells" }
+tap_test_program { name = "t_shlibs" }
+tap_test_program { name = "t_sort" }
+tap_test_program { name = "t_taskfunc" }
+tap_test_program { name = "t_tee" }
+tap_test_program { name = "t_truthy" }
+tap_test_program { name = "t_usergroup" }
+tap_test_program { name = "t_usergroup_FreeBSD" }
+tap_test_program { name = "t_usergroup_Linux" }
+tap_test_program { name = "t_usergroup_MirBSD" }
+tap_test_program { name = "t_usergroup_NetBSD" }
+tap_test_program { name = "t_usergroup_exists" }
+tap_test_program { name = "t_usergroup_mock" }
+tap_test_program { name = "t_users" }
+tap_test_program { name = "t_valid_options" }
+tap_test_program { name = "t_version" }
+tap_test_program { name = "t_which" }
Index: pkgsrc/pkgtools/pkgtasks/files/t/build_test.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/build_test.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/build_test.sh      Thu Jun  1 01:58:34 2017
@@ -0,0 +1,134 @@
+#! __POSIX_SHELL__
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      build_test -- build standalone test scripts
+#
+# SYNOPSIS
+#      build_test [-o <target>] <source>
+#
+# DESCRIPTION
+#      build_test takes a script that uses pkgtask modules and generates an
+#      executable script with the necessary boilerplate to run standalone.
+#
+#      The <source> is the path to the file to build.  The built script is
+#      written to the standard output.
+#
+#      The options are as follows:
+#
+#      -o <output>
+#              The path to the output file to write the built script.
+#              If this option is given, then the built script is also made
+#              executable.
+#
+# EXIT STATUS
+#      The script exits with a value of 0 on success, and >0 if an error
+#      occurs.
+#
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      TASK_MODULE_DIR
+#              The location of the pkgtask modules.  The default value is
+#              "__TASK_MODULE_DIR__".
+#
+#      TASK_TESTS_DIR
+#              The location of the pkgtask tests directory.  The default
+#              value is "__TASK_TESTS_DIR__".
+#
+#      POSIX_SHELL
+#              The path of the shell interpreter to add to the shebang
+#              boilerplate of the built script.  The default value is
+#              "__POSIX_SHELL__".
+#
+
+: ${TASK_MODULE_DIR:=__TASK_MODULE_DIR__}
+: ${TASK_TESTS_DIR:=__TASK_TESTS_DIR__}
+: ${POSIX_SHELL:=__POSIX_SHELL__}
+
+. "${TASK_MODULE_DIR}/load.subr"
+
+task_load maketemp
+
+build_test()
+{
+       : ${CAT:=cat}
+       : ${CHMOD:=chmod}
+       : ${MV:=mv}
+
+       local output=
+       local arg
+       local OPTIND=1
+       while getopts ":o:" arg "$@"; do
+               case $arg in
+               o)      output="${OPTARG}" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+
+       # Setting the output file to "-" means to write to standard output.
+       if [ "$output" = "-" ]; then
+               output=
+       fi
+
+       # Use standard input unless source files are given.
+       [ $# -gt 0 ] || set -- "-"
+
+       if [ -n "$output" ]; then
+               local output_tmp
+               output_tmp=$( task_maketemp $output.XXXXXXXXXX ) &&
+               ( _build_test_boilerplate && ${CAT} "$@" ) > $output_tmp &&
+               ${MV} -f "$output_tmp" "$output" &&
+               ${CHMOD} +x "$output"
+       else
+               # Write script to standard output.
+                _build_test_boilerplate && ${CAT} "$@"
+       fi
+}
+
+_build_test_boilerplate()
+{
+       : ${CAT:=cat}
+
+       ${CAT} << EOF
+#! ${POSIX_SHELL}
+
+: \${TASK_MODULE_DIR:=__TASK_MODULE_DIR__}
+: \${TASK_TESTS_DIR:=__TASK_TESTS_DIR__}
+
+[ -f "\${TASK_MODULE_DIR}/load.subr" ] ||
+       echo "\${0##*/}: missing file \`\`\${TASK_MODULE_DIR}/load.subr''"
+
+. "\${TASK_MODULE_DIR}/load.subr"
+
+EOF
+}
+
+build_test "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/run_tests.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/run_tests.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/run_tests.sh       Thu Jun  1 01:58:34 2017
@@ -0,0 +1,167 @@
+#! __POSIX_SHELL__
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# NAME
+#      run_tests -- run all of the test scripts for pkgtasks
+#
+# SYNOPSIS
+#      run_tests [-v] [<script> ...]
+#
+# DESCRIPTION
+#      run_tests runs the test scripts in the ${TASK_TESTS_DIR} directory
+#      and reports a summary of the test results.  By default, all of the
+#      test scripts are run, but a subset may be selected by passing their
+#      names as optional parameters.
+#
+#      The options are as follows:
+#
+#      -v      Verbose; run the tests so they produce output to the
+#              standard output and error.  By default, the tests are run
+#              in quiet mode.
+#
+#      If this script is run with a basename ending in ".sh", then the
+#      tests are assumed to be named also ending in ".sh" and located in
+#      the current directory.  This is to allow the tests to be run from
+#      their source directory.
+#
+# EXIT STATUS
+#      The script exits with a value of the number of failed tests.
+#
+
+case ${0##*/} in
+*.sh)  # Invoked from source directory.
+       : ${TASK_MODULE_DIR:=..}
+       : ${TASK_TESTS_DIR:=.}
+       ;;
+*)     # Invoked from installed tests directory.
+       : ${TASK_MODULE_DIR:=__TASK_MODULE_DIR__}
+       : ${TASK_TESTS_DIR:=__TASK_TESTS_DIR__}
+       ;;
+esac
+
+. ${TASK_MODULE_DIR}/load.subr
+
+# Use the same TASK_MODULE_DIR for all test scripts.
+export TASK_MODULE_DIR="${TASK_MODULE_DIR}"
+
+# Use the same TASK_TEST_DIR for all test scripts.
+export TASK_TESTS_DIR="${TASK_TESTS_DIR}"
+
+task_load say
+
+run_tests()
+{
+       local quiet="-q"
+       local arg
+       local OPTIND=1
+       while getopts ":s:v" arg "$@"; do
+               case $arg in
+               v)      quiet= ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+
+       local suffix
+       case $0 in
+       *.sh)   suffix=".sh" ;;
+       *)      suffix= ;;
+       esac
+
+       # glob pattern to match test scripts
+       local test_pattern="${TASK_TESTS_DIR}/t_*$suffix"
+
+       [ $# -gt 0 ] || set -- $test_pattern
+
+       local count=0
+       local missing=
+       local failures=
+
+       local script
+       local script_args
+       while [ $# -gt 0 ]; do
+               script=$1; shift
+               if ! [ -f "$script" ]; then
+                       missing="$missing $script"
+                       continue
+               fi
+               case $script in
+               */*)    name=${script##*/}
+                       : "script unchanged" ;;
+               *)      name=$script
+                       script="./$script" ;;
+               esac
+
+               # Set up the script parameters.  If the next parameter is
+               # "--", then all remaining arguments are used as parameters
+               # for the script.
+               #
+               script_args="$quiet"
+               if [ "$1" = "--" ]; then
+                       shift
+                       script_args="$@"
+                       # shift away the remaining arguments so the loop will end
+                       shift $#
+               fi
+
+               count=$(( $count + 1 ))
+               task_say info "*** $name ***"
+               #
+               # Run the test scripts by explicitly loading load.subr,
+               # setting up the parameters, and sourcing the script file,
+               # all within a subshell.  This allows the test scripts to be
+               # run without being built.
+               #
+               ( . ${TASK_MODULE_DIR}/load.subr
+                 set -- dummy $script_args; shift
+                 . $script )
+               [ $? -eq 0 ] || failures="$failures $name"
+       done
+
+       set -o noglob; set -- $missing; set +o noglob
+       for script; do
+               task_say warn "# run_tests: missing: $script"
+       done
+
+       set -o noglob; set -- $failures; set +o noglob
+       for script; do
+               task_say error "# run_tests: failed: $script"
+       done
+
+       local msg="$count test script(s)"
+       if [ $# -gt 0 ]; then
+               task_say error "# run_tests: failed $# among $msg"
+       else
+               task_say pass "# run_tests: passed all $msg"
+       fi
+
+       return $#
+}
+
+run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_compare.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_compare.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_compare.sh       Thu Jun  1 01:58:34 2017
@@ -0,0 +1,157 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load compare
+task_load unittest
+
+test_setup()
+{
+       : ${CAT:=cat}
+       : ${CP:=cp}
+}
+
+test1()
+{
+       describe="identical files"
+       ${CAT} > a << EOF
+line1
+line2
+line3
+EOF
+       ${CP} a b
+       if task_compare a b; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="truncated first file"
+       ${CAT} > a << EOF
+line1
+line2
+EOF
+       ${CAT} > b << EOF
+line1
+line2
+line3
+EOF
+       if task_compare a b; then
+               return 1
+       else
+               : "success"
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="truncated second file"
+       ${CAT} > a << EOF
+line1
+line2
+line3
+EOF
+       ${CAT} > b << EOF
+line1
+line2
+EOF
+       if task_compare a b; then
+               return 1
+       else
+               : "success"
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="leading whitespace differences"
+       ${CAT} > a << EOF
+line1
+line2
+line3
+EOF
+       ${CAT} > b << EOF
+line1
+  line2
+    line3
+EOF
+       if task_compare a b; then
+               return 1
+       else
+               : "success"
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="trailing whitespace differences"
+       ${CAT} > a << EOF
+line1
+line2
+line3
+EOF
+       ${CAT} > b << EOF
+line1
+line2 
+line3  
+EOF
+       if task_compare a b; then
+               return 1
+       else
+               : "success"
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="different content"
+       ${CAT} > a << EOF
+line1
+line2
+line3
+EOF
+       ${CAT} > b << EOF
+LINE1
+LINE2
+LINE3
+EOF
+       if task_compare a b; then
+               return 1
+       else
+               : "success"
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_createfile.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_createfile.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_createfile.sh    Thu Jun  1 01:58:34 2017
@@ -0,0 +1,91 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load permissions
+task_load unittest
+
+test_setup()
+{
+       : ${CAT:=cat}
+}
+
+test1()
+{
+       describe="make one file"
+       task_createfile a
+       if [ ! -f "a" ]; then
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="make two files"
+       task_createfile a b
+       if [ ! -f "a" -o ! -f "b" ]; then
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="make file with mode"
+       task_createfile -m 600 a
+       if [ ! -f "a" ]; then
+               return 1
+       fi
+       if task_check_permissions a 600; then
+               : "success"
+       else
+               describe="$describe: wrong mode!"
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="overwrite existing file"
+       ${CAT} > a << 'EOF'
+content
+EOF
+       task_createfile a
+       if [ ! -f "a" ]; then
+               return 1
+       fi
+       local line
+       while read line; do
+               describe="$describe: non-empty file!"
+               return 1
+       done < a
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_directories.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_directories.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_directories.sh   Thu Jun  1 01:58:34 2017
@@ -0,0 +1,386 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load directories
+task_load unittest
+
+test_setup()
+{
+       : ${MKDIR:=mkdir}
+
+       PKGNAME=${0##*/}
+       PKG_PREFIX=${TEST_CURDIR}
+       PKG_DESTDIR=
+
+       PKG_DBDIR="${TEST_CURDIR}/var/db/pkg"
+       PKG_REFCOUNT_DBDIR="${PKG_DBDIR}.refcount"
+       ${MKDIR} -p "${PKG_DBDIR}"
+}
+
+test_destdir_setup()
+{
+       : ${MKDIR:=mkdir}
+       : ${MV:=mv}
+
+       PKG_DESTDIR="${TEST_CURDIR}/destdir"
+       ${MKDIR} -p "${PKG_DESTDIR}${PKG_PREFIX}"
+       ${MV} var "${PKG_DESTDIR}${PKG_PREFIX}"
+}
+
+test1()
+{
+       describe="make dir"
+       if echo "# DIR: etc/pkg1 m" | task_directories add; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# DIR: etc/pkg1 m" | task_directories check-add; then
+               : "success"
+       else
+               describe="$describe: check-add"
+               return 1
+       fi
+       if [ ! -d "${PKG_PREFIX}/etc/pkg1" ]; then
+               describe="$describe: dir missing!"
+               return 1
+       fi
+       if task_refcount exists dirs "${PKG_PREFIX}/etc/pkg1"; then
+               : "success"
+       else
+               describe="$describe: refcount missing!"
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="skip make dir"
+       if echo "# DIR: etc/pkg1 ." | task_directories add; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# DIR: etc/pkg1 ." | task_directories check-add; then
+               : "success"
+       else
+               describe="$describe: check-add"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/etc/pkg1" ]; then
+               describe="$describe: dir exists!"
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="remove make dir"
+       echo "# DIR: etc/pkg1 m" | task_directories add
+       if echo "# DIR: etc/pkg1 m" | task_directories remove; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# DIR: etc/pkg1 m" | task_directories check-remove; then
+               : "success"
+       else
+               describe="$describe: check-remove"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/etc/pkg1" ]; then
+               describe="$describe: dir exists!"
+               return 1
+       fi
+       if task_refcount exists dirs "${PKG_PREFIX}/etc/pkg1"; then
+               describe="$describe: refcount exists!"
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="remove skipped make dir"
+       echo "# DIR: etc/pkg1 ." | task_directories add
+       if echo "# DIR: etc/pkg1 ." | task_directories remove; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# DIR: etc/pkg1 ." | task_directories check-remove; then
+               : "success"
+       else
+               describe="$describe: check-remove"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/etc/pkg1" ]; then
+               describe="$describe: dir exists!"
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="remove skipped made dir"
+       echo "# DIR: etc/pkg1 ." | task_directories add
+       ${MKDIR} -p etc/pkg1
+       if echo "# DIR: etc/pkg1 ." | task_directories remove; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# DIR: etc/pkg1 ." | task_directories check-remove; then
+               : "success"
+       else
+               describe="$describe: check-remove"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/etc/pkg1" ]; then
+               describe="$describe: dir exists!"
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="make dir for 2 packages"
+       ( PKGNAME="package1"
+         echo "# DIR: etc/common m" | task_directories add )
+       ( PKGNAME="package2"
+         echo "# DIR: etc/common m" | task_directories add )
+       if [ ! -d "${PKG_PREFIX}/etc/common" ]; then
+               describe="$describe: dir missing!"
+               return 1
+       fi
+       if task_refcount exists dirs "${PKG_PREFIX}/etc/common"; then
+               : "success"
+       else
+               describe="$describe: refcount missing!"
+               return 1
+       fi
+       return 0
+}
+
+test7()
+{
+       describe="remove after make dir for 2 packages"
+       ( PKGNAME="package1"
+         echo "# DIR: etc/common m" | task_directories add )
+       ( PKGNAME="package2"
+         echo "# DIR: etc/common m" | task_directories add )
+       ( PKGNAME="package1"
+         echo "# DIR: etc/common m" | task_directories remove )
+       if [ ! -d "${PKG_PREFIX}/etc/common" ]; then
+               describe="$describe: dir missing!"
+               return 1
+       fi
+       ( PKGNAME="package2"
+         echo "# DIR: etc/common m" | task_directories remove )
+       if [ -d "${PKG_PREFIX}/etc/common" ]; then
+               describe="$describe: dir exists!"
+               return 1
+       fi
+       return 0
+}
+
+test8()
+{
+       describe="remove owned directory"
+       echo "# DIR: etc/pkg1 mo" | task_directories add
+       echo "# DIR: etc/pkg1 mo" | task_directories remove
+       if [ -d "${PKG_PREFIX}/etc/pkg1" ]; then
+               describe="$describe: dir exists!"
+               return 1
+       fi
+       return 0
+}
+
+test9()
+{
+       describe="conflicting owner"
+       ( PKGNAME="package1"
+         echo "# DIR: etc/common mo" | task_directories add )
+       ( PKGNAME="package2"
+         echo "# DIR: etc/common mo" | task_directories add )
+       if [ $? -eq 0 ]; then
+               return 1
+       fi
+       return 0
+}
+
+test10()
+{
+       describe="remove owned directory used by another package"
+       ( PKGNAME="package1"
+         echo "# DIR: etc/common mo" | task_directories add )
+       ( PKGNAME="package2"
+         echo "# DIR: etc/common m" | task_directories add )
+       ( PKGNAME="package1"
+         echo "# DIR: etc/common mo" | task_directories remove )
+       if [ $? -eq 0 ]; then
+               return 1
+       fi
+       return 0
+}
+
+test11()
+{
+       describe="owned dir with permissions"
+       task_requires_root || return 0
+       if echo "# DIR: etc/pkg1 mo 0700 root wheel" |
+          task_directories add; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# DIR: etc/pkg1 mo 0700 root wheel" |
+          task_directories check-add; then
+               : "success"
+       else
+               describe="$describe: check-add"
+               return 1
+       fi
+       if echo "# DIR: etc/pkg1 mo 0700 root wheel" |
+          task_directories check-perms; then
+               : "success"
+       else
+               describe="$describe: check-perms"
+               return 1
+       fi
+       if [ ! -d "${PKG_PREFIX}/etc/pkg1" ]; then
+               describe="$describe: dir missing!"
+               return 1
+       fi
+}
+
+test12()
+{
+       describe="make dir with PKG_DESTDIR"
+       test_destdir_setup
+       if echo "# DIR: etc/pkg1 m" | task_directories add; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# DIR: etc/pkg1 m" | task_directories check-add; then
+               : "success"
+       else
+               describe="$describe: check-add"
+               return 1
+       fi
+       if [ ! -d "${PKG_DESTDIR}${PKG_PREFIX}/etc/pkg1" ]; then
+               describe="$describe: dir missing!"
+               return 1
+       fi
+       if task_refcount exists dirs "${PKG_PREFIX}/etc/pkg1"; then
+               : "success"
+       else
+               describe="$describe: refcount missing!"
+               return 1
+       fi
+       return 0
+}
+
+test13()
+{
+       describe="skip make dir with PKG_DESTDIR"
+       test_destdir_setup
+       if echo "# DIR: etc/pkg1 ." | task_directories add; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# DIR: etc/pkg1 ." | task_directories check-add; then
+               : "success"
+       else
+               describe="$describe: check-add"
+               return 1
+       fi
+       if [ -d "${PKG_DESTDIR}${PKG_PREFIX}/etc/pkg1" ]; then
+               describe="$describe: dir exists!"
+               return 1
+       fi
+       return 0
+}
+
+test14()
+{
+       describe="remove make dir with PKG_DESTDIR"
+       test_destdir_setup
+       echo "# DIR: etc/pkg1 m" | task_directories add
+       if echo "# DIR: etc/pkg1 m" | task_directories remove; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# DIR: etc/pkg1 m" | task_directories check-remove; then
+               : "success"
+       else
+               describe="$describe: check-remove"
+               return 1
+       fi
+       if [ -d "${PKG_DESTDIR}${PKG_PREFIX}/etc/pkg1" ]; then
+               describe="$describe: dir exists!"
+               return 1
+       fi
+       if task_refcount exists dirs "${PKG_PREFIX}/etc/pkg1"; then
+               describe="$describe: refcount exists!"
+               return 1
+       fi
+       return 0
+}
+
+test15()
+{
+       describe="remove skipped made dir with PKG_DESTDIR"
+       test_destdir_setup
+       echo "# DIR: etc/pkg1 ." | task_directories add
+       ${MKDIR} -p ${PKG_DESTDIR}${PKG_PREFIX}/etc/pkg1
+       if echo "# DIR: etc/pkg1 ." | task_directories remove; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# DIR: etc/pkg1 ." | task_directories check-remove; then
+               : "success"
+       else
+               describe="$describe: check-remove"
+               return 1
+       fi
+       if [ -d "${PKG_DESTDIR}${PKG_PREFIX}/etc/pkg1" ]; then
+               describe="$describe: dir exists!"
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_dirwalk.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_dirwalk.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_dirwalk.sh       Thu Jun  1 01:58:34 2017
@@ -0,0 +1,144 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load dirwalk
+task_load unittest
+
+# Mock a broken utility.
+broken()
+{
+       return 1
+}
+
+test_setup()
+{
+       : ${CAT:=cat}
+       : ${CMP:=cmp}
+       : ${MKDIR:=mkdir}
+
+       # Set FIND to a broken utility to force using the shell code path.
+       FIND=broken
+
+       output="output"
+
+       # ./
+       #   `---root/
+       #        |
+       #        |---dir1/
+       #        |    |---fileA
+       #        |    |---dirB/
+       #        |    |    |---filea
+       #        |    |    `---fileb
+       #        |    `---fileC
+       #        |---file2
+       #        `---dir3/
+       #             |---fileD
+       #             `---fileE
+       #
+       ${MKDIR} root
+       ${MKDIR} root/dir1
+       task_createfile root/dir1/fileA
+       ${MKDIR} root/dir1/dirB
+       task_createfile root/dir1/dirB/filea
+       task_createfile root/dir1/dirB/fileb
+       task_createfile root/dir1/fileC
+       task_createfile root/file2
+       ${MKDIR} root/dir3
+       task_createfile root/dir3/fileD
+       task_createfile root/dir3/fileE
+
+       expected_all="expected_all"
+       ${CAT} > $expected_all << EOF
+root
+root/dir1
+root/dir1/dirB
+root/dir1/dirB/filea
+root/dir1/dirB/fileb
+root/dir1/fileA
+root/dir1/fileC
+root/dir3
+root/dir3/fileD
+root/dir3/fileE
+root/file2
+EOF
+       expected_dirs="expected_dirs"
+       ${CAT} > $expected_dirs << EOF
+root
+root/dir1
+root/dir1/dirB
+root/dir3
+EOF
+       expected_files="expected_files"
+       ${CAT} > $expected_files << EOF
+root/dir1/dirB/filea
+root/dir1/dirB/fileb
+root/dir1/fileA
+root/dir1/fileC
+root/dir3/fileD
+root/dir3/fileE
+root/file2
+EOF
+}
+
+test1()
+{
+       describe="dirwalk root"
+       task_dirwalk root > $output
+       if ${CMP} -s "$expected_all" "$output"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="dirwalk -d root"
+       task_dirwalk -d root > $output
+       if ${CMP} -s "$expected_dirs" "$output"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="dirwalk -f root"
+       task_dirwalk -f root > $output
+       if ${CMP} -s "$expected_files" "$output"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_echo.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_echo.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_echo.sh  Thu Jun  1 01:58:34 2017
@@ -0,0 +1,378 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load echo
+task_load unittest
+
+test_setup()
+{
+       : ${CAT:=cat}
+       : ${CMP:=cmp}
+
+       # Explicitly set TASK_LOGFILE to empty string to prevent unintended
+       # duplicate output.
+       #
+       TASK_LOGFILE=
+}
+
+test1()
+{
+       describe="task_echo -b buffers text"
+       task_echo -bc "line 1"
+       task_echo -b "line 2"
+       task_echo "line 3" > value
+       ${CAT} > expected << 'EOF'
+line 1
+line 2
+line 3
+EOF
+       if ${CMP} -s expected value; then
+               : "success"
+       else
+               return 1
+       fi
+       task_echo "only line" > value
+       echo "only line" > expected
+       if ${CMP} -s expected value; then
+               : "success"
+       else
+               describe="$describe: next write has extra output!"
+               return 1
+       fi
+       for entry in *; do
+               case $entry in
+               expected|value)
+                       : "can exist" ;;
+               *)      describe="$describe: unknown file!"
+                       return 1 ;;
+               esac
+       done
+       return 0
+}
+
+test2()
+{
+       describe="task_echo -c clears buffer"
+       task_echo -bc "line 1"
+       task_echo -b "line 2"
+       task_echo -cn
+       task_echo "only line" > value
+       echo "only line" > expected
+       if ${CMP} -s expected value; then
+               : "success"
+       else
+               return 1
+       fi
+       for entry in *; do
+               case $entry in
+               expected|value)
+                       : "can exist" ;;
+               *)      describe="$describe: unknown file!"
+                       return 1 ;;
+               esac
+       done
+       return 0
+}
+
+test3()
+{
+       describe="task_echo -bc clears buffer"
+       task_echo -bc "line 1"
+       task_echo -b "line 2"
+       task_echo -bc "line 3"
+       task_echo "line 4" > value
+       ${CAT} > expected << 'EOF'
+line 3
+line 4
+EOF
+       if ${CMP} -s expected value; then
+               : "success"
+       else
+               ${CAT} value
+               return 1
+       fi
+       for entry in *; do
+               case $entry in
+               expected|value)
+                       : "can exist" ;;
+               *)      describe="$describe: unknown file!"
+                       return 1 ;;
+               esac
+       done
+       return 0
+}
+
+test4()
+{
+       describe="task_echo -n skips trailing newline"
+       task_echo -bcn "list: 1"
+       task_echo -bn ", 2"
+       task_echo -bn ", 3"
+       task_echo > value
+       echo "list: 1, 2, 3" > expected
+       if ${CMP} -s expected value; then
+               : "success"
+       else
+               ${CAT} value
+               return 1
+       fi
+       for entry in *; do
+               case $entry in
+               expected|value)
+                       : "can exist" ;;
+               *)      describe="$describe: unknown file!"
+                       return 1 ;;
+               esac
+       done
+       return 0
+}
+
+test5()
+{
+       describe="task_echo preserves leading whitespace"
+       task_echo "    1 2 3 4" > value
+       echo      "    1 2 3 4" > expected
+       if ${CMP} -s expected value; then
+               : "success"
+       else
+               ${CAT} value
+               return 1
+       fi
+       for entry in *; do
+               case $entry in
+               expected|value)
+                       : "can exist" ;;
+               *)      describe="$describe: unknown file!"
+                       return 1 ;;
+               esac
+       done
+       return 0
+}
+
+test6()
+{
+       describe="task_echo preserves leading whitespace after buffer output"
+       task_echo -bc "header"
+       task_echo "    1 2 3 4" > value
+       ${CAT} > expected << 'EOF'
+header
+    1 2 3 4
+EOF
+       if ${CMP} -s expected value; then
+               : "success"
+       else
+               ${CAT} value
+               return 1
+       fi
+       for entry in *; do
+               case $entry in
+               expected|value)
+                       : "can exist" ;;
+               *)      describe="$describe: unknown file!"
+                       return 1 ;;
+               esac
+       done
+       return 0
+}
+
+
+test7()
+{
+       describe="task_echo -b buffers text with log"
+       TASK_LOGFILE="${TEST_CURDIR}/log"
+       task_echo -bc "line 1"
+       if [ -f "${TASK_LOGFILE}" ]; then
+               describe="$describe: log exists after first buffered echo!"
+               return 1
+       fi
+       task_echo -b "line 2"
+       if [ -f "${TASK_LOGFILE}" ]; then
+               describe="$describe: log exists after second buffered echo!"
+               return 1
+       fi
+       task_echo "line 3" > value
+       if [ ! -f "${TASK_LOGFILE}" ]; then
+               describe="$describe: log missing!"
+               return 1
+       fi
+       ${CAT} > expected << 'EOF'
+line 1
+line 2
+line 3
+EOF
+       if ${CMP} -s expected value; then
+               : "success"
+       else
+               return 1
+       fi
+       if ${CMP} -s value log; then
+               : "success"
+       else
+               describe="$describe: log doesn't match standard output!"
+               ${CAT} log
+               return 1
+       fi
+       task_echo "only line" > value
+       echo "only line" >> expected
+       if ${CMP} -s expected log; then
+               : "success"
+       else
+               describe="$describe: log doesn't match all writes!"
+               ${CAT} log
+               return 1
+       fi
+       return 0
+}
+
+test8()
+{
+       describe="task_echo -c clears buffer with log"
+       TASK_LOGFILE="${TEST_CURDIR}/log"
+       task_echo -bc "line 1"
+       task_echo -b "line 2"
+       task_echo -cn
+       task_echo "only line" > value
+       echo "only line" > expected
+       if ${CMP} -s expected log; then
+               : "success"
+       else
+               ${CAT} log
+               return 1
+       fi
+       if ${CMP} -s value log; then
+               : "success"
+       else
+               describe="$describe: log doesn't match output"
+               ${CAT} log
+               return 1
+       fi
+       return 0
+}
+
+test9()
+{
+       describe="task_echo -bc clears buffer with log"
+       TASK_LOGFILE="${TEST_CURDIR}/log"
+       task_echo -bc "line 1"
+       task_echo -b "line 2"
+       task_echo -bc "line 3"
+       task_echo "line 4" > value
+       ${CAT} > expected << 'EOF'
+line 3
+line 4
+EOF
+       if ${CMP} -s expected log; then
+               : "success"
+       else
+               ${CAT} log
+               return 1
+       fi
+       if ${CMP} -s value log; then
+               : "success"
+       else
+               describe="$describe: log doesn't match output"
+               ${CAT} log
+               return 1
+       fi
+       return 0
+}
+
+test10()
+{
+       describe="task_echo -n skips trailing newline with log"
+       TASK_LOGFILE="${TEST_CURDIR}/log"
+       task_echo -bcn "list: 1"
+       task_echo -bn ", 2"
+       task_echo -bn ", 3"
+       task_echo > value
+       echo "list: 1, 2, 3" > expected
+       if ${CMP} -s expected log; then
+               : "success"
+       else
+               ${CAT} log
+               return 1
+       fi
+       if ${CMP} -s value log; then
+               : "success"
+       else
+               describe="$describe: log doesn't match output"
+               ${CAT} log
+               return 1
+       fi
+       return 0
+}
+
+test11()
+{
+       describe="task_echo preserves leading whitespace with log"
+       TASK_LOGFILE="${TEST_CURDIR}/log"
+       task_echo "    1 2 3 4" > value
+       echo      "    1 2 3 4" > expected
+       if ${CMP} -s expected log; then
+               : "success"
+       else
+               ${CAT} log
+               return 1
+       fi
+       if ${CMP} -s value log; then
+               : "success"
+       else
+               describe="$describe: log doesn't match output"
+               ${CAT} log
+               return 1
+       fi
+       return 0
+}
+
+test12()
+{
+       describe="task_echo preserves leading whitespace after buffer output with log"
+       TASK_LOGFILE="${TEST_CURDIR}/log"
+       task_echo -bc "header"
+       task_echo "    1 2 3 4" > value
+       ${CAT} > expected << 'EOF'
+header
+    1 2 3 4
+EOF
+       if ${CMP} -s expected log; then
+               : "success"
+       else
+               ${CAT} log
+               return 1
+       fi
+       if ${CMP} -s value log; then
+               : "success"
+       else
+               describe="$describe: log doesn't match output"
+               ${CAT} log
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_files.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_files.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_files.sh Thu Jun  1 01:58:34 2017
@@ -0,0 +1,781 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load files
+task_load unittest
+
+test_setup()
+{
+       : ${CAT:=cat}
+       : ${CHMOD:=chmod}
+       : ${MKDIR:=mkdir}
+
+       PKGNAME=${0##*/}
+       PKG_PREFIX=${TEST_CURDIR}
+       PKG_DESTDIR=
+
+       PKG_DBDIR="${PKG_PREFIX}/var/db/pkg"
+       PKG_REFCOUNT_DBDIR="${PKG_DBDIR}.refcount"
+       ${MKDIR} -p "${PKG_DBDIR}"
+
+       ${MKDIR} -p etc
+       ${MKDIR} -p etc/rc.d
+       ${MKDIR} -p share/examples/pkg1
+       ${MKDIR} -p share/examples/pkg2
+       ${CAT} > share/examples/pkg2/conffile2 << EOF
+line 1
+line 2
+EOF
+       ${MKDIR} -p share/examples/rc.d
+
+       # Unwriteable directory.
+       ${MKDIR} -p unwriteable
+       ${CHMOD} 0400 unwriteable
+
+       # Don't copy rc.d scripts.
+       PKG_INIT_SCRIPTS="no"
+}
+
+test_destdir_setup()
+{
+       : ${MKDIR:=mkdir}
+       : ${MV:=mv}
+
+       PKG_DESTDIR="${TEST_CURDIR}/destdir"
+       ${MKDIR} -p "${PKG_DESTDIR}${PKG_PREFIX}"
+       ${MV} etc share var "${PKG_DESTDIR}${PKG_PREFIX}"
+
+       # Unwriteable directory.
+       ${MKDIR} -p "${PKG_DESTDIR}${PKG_PREFIX}/unwriteable"
+       ${CHMOD} 0400 "${PKG_DESTDIR}${PKG_PREFIX}/unwriteable"
+}
+
+test1()
+{
+       describe="missing example file"
+       if echo "# FILE: \
+               etc/conffile1 c \
+               share/examples/pkg1/conffile1" | task_files add; then
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile1 c \
+               share/examples/pkg1/conffile1" | task_files check-add; then
+               describe="$describe: check-add"
+               return 1
+       fi
+       if [ -f "${PKG_PREFIX}/etc/conffile1" ]; then
+               describe="$describe: copied file exists!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile1"; then
+               : "success"
+       else
+               describe="$describe: refcount missing!"
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="missing target directory"
+       if echo "# FILE: \
+               nonexistent/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files add; then
+               return 1
+       fi
+       if echo "# FILE: \
+               nonexistent/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files check-add; then
+               describe="$describe: check-add"
+               return 1
+       fi
+       if [ -f "${PKG_PREFIX}/nonexistent/conffile2" ]; then
+               describe="$describe: copied file exists!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/nonexistent/conffile2"; then
+               : "success"
+       else
+               describe="$describe: refcount missing!"
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="copy"
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files add; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files check-add; then
+               : "success"
+       else
+               describe="$describe: check-add"
+               return 1
+       fi
+       if [ ! -f "${PKG_PREFIX}/etc/conffile2" ]; then
+               describe="$describe: file missing!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile2"; then
+               : "success"
+       else
+               describe="$describe: refcount missing!"
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="skip copy"
+       if echo "# FILE: \
+               etc/conffile2 . \
+               share/examples/pkg2/conffile2" | task_files add; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile2 . \
+               share/examples/pkg2/conffile2" | task_files check-add; then
+               : "success"
+       else
+               describe="$describe: check-add"
+               return 1
+       fi
+       if [ -f "${PKG_PREFIX}/etc/conffile2" ]; then
+               describe="$describe: file exists!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile2"; then
+               : "success"
+       else
+               describe="$describe: refcount missing!"
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="copy rc.d script"
+       if echo "# FILE: \
+               etc/rc.d/conffile2 cr \
+               share/examples/pkg2/conffile2" | task_files add; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/rc.d/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files check-add; then
+               describe="$describe: check-add"
+               return 1
+       fi
+       if [ -f "${PKG_PREFIX}/etc/rc.d/conffile2" ]; then
+               describe="$describe: file exists!"
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="remove after copy"
+       echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files add
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files remove; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files check-remove; then
+               : "success"
+       else
+               describe="$describe: check-remove"
+               return 1
+       fi
+       if [ -f "${PKG_PREFIX}/etc/conffile2" ]; then
+               describe="$describe: file exists!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile2"; then
+               describe="$describe: refcount exists!"
+               return 1
+       fi
+       return 0
+}
+
+test7()
+{
+       : ${CP:=cp}
+
+       describe="remove after skipped but copied"
+       echo "# FILE: \
+               etc/conffile2 . \
+               share/examples/pkg2/conffile2" | task_files add
+       ${CP} share/examples/pkg2/conffile2 etc/conffile2
+       if echo "# FILE: \
+               etc/conffile2 . \
+               share/examples/pkg2/conffile2" | task_files remove; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile2 . \
+               share/examples/pkg2/conffile2" | task_files check-remove; then
+               : "success"
+       else
+               describe="$describe: check-remove"
+               return 1
+       fi
+       if [ -f "${PKG_PREFIX}/etc/conffile2" ]; then
+               describe="$describe: file exists!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile2"; then
+               describe="$describe: refcount exists!"
+               return 1
+       fi
+       return 0
+}
+
+test8()
+{
+       describe="remove after modification"
+       echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files add
+       echo "extra line" >> "${PKG_PREFIX}/etc/conffile2"
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files remove; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files check-remove; then
+               describe="$describe: check-remove"
+               return 1
+       fi
+       if [ ! -f "${PKG_PREFIX}/etc/conffile2" ]; then
+               describe="$describe: file missing!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile2"; then
+               describe="$describe: refcount exists!"
+               return 1
+       fi
+       return 0
+}
+
+test9()
+{
+       : ${CP:=cp}
+
+       describe="remove after skipped but copied and modification"
+       echo "# FILE: \
+               etc/conffile2 . \
+               share/examples/pkg2/conffile2" | task_files add
+       ${CP} share/examples/pkg2/conffile2 etc/conffile2
+       echo "extra line" >> "${PKG_PREFIX}/etc/conffile2"
+       if echo "# FILE: \
+               etc/conffile2 . \
+               share/examples/pkg2/conffile2" | task_files remove; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile2 . \
+               share/examples/pkg2/conffile2" | task_files check-remove; then
+               describe="$describe: check-remove"
+               return 1
+       fi
+       if [ ! -f "${PKG_PREFIX}/etc/conffile2" ]; then
+               describe="$describe: file missing!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile2"; then
+               describe="$describe: refcount exists!"
+               return 1
+       fi
+       return 0
+}
+
+test10()
+{
+       describe="copy with preexisting"
+       task_createfile etc/conffile2
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files add; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files check-add; then
+               : "success"
+       else
+               describe="$describe: check-add"
+               return 1
+       fi
+       if [ ! -f "${PKG_PREFIX}/etc/conffile2" ]; then
+               describe="$describe: file missing!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile2"; then
+               : "success"
+       else
+               describe="$describe: refcount missing!"
+               return 1
+       fi
+       if task_refcount prop_exists files "${PKG_PREFIX}/etc/conffile2" preexist; then
+               : "success"
+       else
+               describe="$describe: property missing!"
+               return 1
+       fi
+       return 0
+}
+
+test11()
+{
+       describe="remove after copy with preexisting"
+       task_createfile etc/conffile2
+       echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files add
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files remove; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files check-remove; then
+               describe="$describe: check-remove"
+               return 1
+       fi
+       if [ ! -f "${PKG_PREFIX}/etc/conffile2" ]; then
+               describe="$describe: file missing!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile2"; then
+               describe="$describe: refcount exists!"
+               return 1
+       fi
+       return 0
+}
+
+test12()
+{
+       describe="copy with permissions"
+       task_requires_root || return 0
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2 \
+               0400 root wheel" | task_files add; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2 \
+               0400 root wheel" | task_files check-add; then
+               : "success"
+       else
+               describe="$describe: check-add"
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2 \
+               0400 root wheel" | task_files check-perms; then
+               : "success"
+       else
+               describe="$describe: check-perms"
+               return 1
+       fi
+       if [ ! -f "${PKG_PREFIX}/etc/conffile2" ]; then
+               describe="$describe: file missing!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile2"; then
+               : "success"
+       else
+               describe="$describe: refcount missing!"
+               return 1
+       fi
+}
+
+test13()
+{
+       describe="missing example file with PKG_DESTDIR"
+       test_destdir_setup
+       if echo "# FILE: \
+               etc/conffile1 c \
+               share/examples/pkg1/conffile1" | task_files add; then
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile1 c \
+               share/examples/pkg1/conffile1" | task_files check-add; then
+               describe="$describe: check-add"
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/etc/conffile1" ]; then
+               describe="$describe: copied file exists!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile1"; then
+               : "success"
+       else
+               describe="$describe: refcount missing!"
+               return 1
+       fi
+       return 0
+}
+
+test14()
+{
+       describe="missing target directory with PKG_DESTDIR"
+       test_destdir_setup
+       if echo "# FILE: \
+               nonexistent/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files add; then
+               return 1
+       fi
+       if echo "# FILE: \
+               nonexistent/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files check-add; then
+               describe="$describe: check-add"
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/nonexistent/conffile2" ]; then
+               describe="$describe: copied file exists!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/nonexistent/conffile2"; then
+               : "success"
+       else
+               describe="$describe: refcount missing!"
+               return 1
+       fi
+       return 0
+}
+
+test15()
+{
+       describe="copy with PKG_DESTDIR"
+       test_destdir_setup
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files add; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files check-add; then
+               : "success"
+       else
+               describe="$describe: check-add"
+               return 1
+       fi
+       if [ ! -f "${PKG_DESTDIR}${PKG_PREFIX}/etc/conffile2" ]; then
+               describe="$describe: file missing!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile2"; then
+               : "success"
+       else
+               describe="$describe: refcount missing!"
+               return 1
+       fi
+       return 0
+}
+
+test16()
+{
+       describe="skip copy with PKG_DESTDIR"
+       test_destdir_setup
+       if echo "# FILE: \
+               etc/conffile2 . \
+               share/examples/pkg2/conffile2" | task_files add; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile2 . \
+               share/examples/pkg2/conffile2" | task_files check-add; then
+               : "success"
+       else
+               describe="$describe: check-add"
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/etc/conffile2" ]; then
+               describe="$describe: file exists!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile2"; then
+               : "success"
+       else
+               describe="$describe: refcount missing!"
+               return 1
+       fi
+       return 0
+}
+
+test17()
+{
+       describe="copy rc.d script with PKG_DESTDIR"
+       test_destdir_setup
+       if echo "# FILE: \
+               etc/rc.d/conffile2 cr \
+               share/examples/pkg2/conffile2" | task_files add; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/rc.d/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files check-add; then
+               describe="$describe: check-add"
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/etc/rc.d/conffile2" ]; then
+               describe="$describe: file exists!"
+               return 1
+       fi
+       return 0
+}
+
+test18()
+{
+       describe="remove after copy with PKG_DESTDIR"
+       test_destdir_setup
+       echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files add
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files remove; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files check-remove; then
+               : "success"
+       else
+               describe="$describe: check-remove"
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/etc/conffile2" ]; then
+               describe="$describe: file exists!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile2"; then
+               describe="$describe: refcount exists!"
+               return 1
+       fi
+       return 0
+}
+
+test19()
+{
+       : ${CP:=cp}
+
+       describe="remove after skipped but copied with PKG_DESTDIR"
+       test_destdir_setup
+       echo "# FILE: \
+               etc/conffile2 . \
+               share/examples/pkg2/conffile2" | task_files add
+       ${CP} ${PKG_DESTDIR}${PKG_PREFIX}/share/examples/pkg2/conffile2 \
+               ${PKG_DESTDIR}${PKG_PREFIX}/etc/conffile2
+       if echo "# FILE: \
+               etc/conffile2 . \
+               share/examples/pkg2/conffile2" | task_files remove; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile2 . \
+               share/examples/pkg2/conffile2" | task_files check-remove; then
+               : "success"
+       else
+               describe="$describe: check-remove"
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/etc/conffile2" ]; then
+               describe="$describe: file exists!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile2"; then
+               describe="$describe: refcount exists!"
+               return 1
+       fi
+       return 0
+}
+
+test20()
+{
+       describe="remove after modification with PKG_DESTDIR"
+       test_destdir_setup
+       echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files add
+       echo "extra line" >> "${PKG_DESTDIR}${PKG_PREFIX}/etc/conffile2"
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files remove; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files check-remove; then
+               describe="$describe: check-remove"
+               return 1
+       fi
+       if [ ! -f "${PKG_DESTDIR}${PKG_PREFIX}/etc/conffile2" ]; then
+               describe="$describe: file missing!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile2"; then
+               describe="$describe: refcount exists!"
+               return 1
+       fi
+       return 0
+}
+
+test21()
+{
+       : ${CP:=cp}
+
+       describe="remove after skipped but copied and modification with PKG_DESTDIR"
+       test_destdir_setup
+       echo "# FILE: \
+               etc/conffile2 . \
+               share/examples/pkg2/conffile2" | task_files add
+       ${CP} ${PKG_DESTDIR}${PKG_PREFIX}/share/examples/pkg2/conffile2 \
+               ${PKG_DESTDIR}${PKG_PREFIX}/etc/conffile2
+       echo "extra line" >> "${PKG_DESTDIR}${PKG_PREFIX}/etc/conffile2"
+       if echo "# FILE: \
+               etc/conffile2 . \
+               share/examples/pkg2/conffile2" | task_files remove; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile2 . \
+               share/examples/pkg2/conffile2" | task_files check-remove; then
+               describe="$describe: check-remove"
+               return 1
+       fi
+       if [ ! -f "${PKG_DESTDIR}${PKG_PREFIX}/etc/conffile2" ]; then
+               describe="$describe: file missing!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile2"; then
+               describe="$describe: refcount exists!"
+               return 1
+       fi
+       return 0
+}
+
+test22()
+{
+       describe="copy with preexisting with PKG_DESTDIR"
+       test_destdir_setup
+       task_createfile "${PKG_DESTDIR}${PKG_PREFIX}/etc/conffile2"
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files add; then
+               : "success"
+       else
+               return 1
+       fi
+       if echo "# FILE: \
+               etc/conffile2 c \
+               share/examples/pkg2/conffile2" | task_files check-add; then
+               : "success"
+       else
+               describe="$describe: check-add"
+               return 1
+       fi
+       if [ ! -f "${PKG_DESTDIR}${PKG_PREFIX}/etc/conffile2" ]; then
+               describe="$describe: file missing!"
+               return 1
+       fi
+       if task_refcount exists files "${PKG_PREFIX}/etc/conffile2"; then
+               : "success"
+       else
+               describe="$describe: refcount missing!"
+               return 1
+       fi
+       if task_refcount prop_exists files "${PKG_PREFIX}/etc/conffile2" preexist; then
+               : "success"
+       else
+               describe="$describe: property missing!"
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_fonts.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_fonts.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_fonts.sh Thu Jun  1 01:58:34 2017
@@ -0,0 +1,347 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load fonts
+task_load unittest
+
+test_setup()
+{
+       PKG_PREFIX="${TEST_CURDIR}"
+       PKG_DESTDIR=
+
+       fontdir_ttf="share/fonts/ttf"
+       fontdir_type1="share/fonts/type1"
+       fontdir_x11="share/fonts/x11"
+
+       # Prevent current directory from being auto-removed because it's empty.
+       task_createfile non-empty
+
+       MKFONTDIR="mock_mkfontdir"
+       MKFONTSCALE="mock_mkfontscale"
+       TTMKFDIR="mock_ttmkfdir"
+       TYPE1INST="mock_type1inst"
+}
+
+test_destdir_setup()
+{
+       : ${MKDIR:=mkdir}
+       : ${MV:=mv}
+
+       PKG_DESTDIR="${TEST_CURDIR}/destdir"
+       ${MKDIR} -p "${PKG_DESTDIR}${PKG_DESTDIR}"
+       ${MV} non-empty "${PKG_DESTDIR}${PKG_DESTDIR}"
+}
+
+# Mock font index generator utilities.
+mock_mkfontdir()
+{
+       task_createfile encodings.dir
+}
+
+mock_mkfontscale()
+{
+       task_createfile fonts.scale
+}
+
+mock_ttmkfdir()
+{
+       task_createfile fonts.dir
+       task_createfile fonts.scale
+}
+
+mock_type1inst()
+{
+       task_createfile type1inst.log
+       task_createfile Fontmap.1
+       task_createfile Fontmap.2
+       task_createfile Fontmap.3
+}
+
+test1()
+{
+       : ${MKDIR:=mkdir}
+
+       describe="empty ttf fonts dir"
+       ${MKDIR} -p "$fontdir_ttf"
+       echo "# FONTS: $fontdir_ttf ttf" | task_fonts add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$fontdir_ttf" ]; then
+               describe="$describe: ${PKG_PREFIX}/$fontdir_ttf exists!"
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       : ${MKDIR:=mkdir}
+
+       describe="non-empty ttf fonts dir"
+       ${MKDIR} -p "$fontdir_ttf"
+       task_createfile "${PKG_PREFIX}/$fontdir_ttf/font1"
+       echo "# FONTS: $fontdir_ttf ttf" | task_fonts add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -d "${PKG_PREFIX}/$fontdir_ttf" ]; then
+               describe="$describe: ${PKG_PREFIX}/$fontdir_ttf missing!"
+               return 1
+       fi
+       if [ ! -f "${PKG_PREFIX}/$fontdir_ttf/encodings.dir" ]; then
+               describe="$describe: x11 encodings missing!"
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       : ${MKDIR:=mkdir}
+
+       describe="empty type1 fonts dir"
+       ${MKDIR} -p "$fontdir_type1"
+       echo "# FONTS: $fontdir_type1 type1" | task_fonts add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$fontdir_type1" ]; then
+               describe="$describe: ${PKG_PREFIX}/$fontdir_type1 exists!"
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       : ${MKDIR:=mkdir}
+
+       describe="non-empty type1 fonts dir"
+       ${MKDIR} -p "$fontdir_type1"
+       task_createfile "${PKG_PREFIX}/$fontdir_type1/font1"
+       echo "# FONTS: $fontdir_type1 type1" | task_fonts add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -d "${PKG_PREFIX}/$fontdir_type1" ]; then
+               describe="$describe: ${PKG_PREFIX}/$fontdir_type1 missing!"
+               return 1
+       fi
+       if [ ! -f "${PKG_PREFIX}/$fontdir_type1/encodings.dir" ]; then
+               describe="$describe: x11 encodings missing!"
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       : ${MKDIR:=mkdir}
+
+       describe="empty x11 fonts dir"
+       ${MKDIR} -p "$fontdir_x11"
+       echo "# FONTS: $fontdir_x11 x11" | task_fonts add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$fontdir_x11" ]; then
+               describe="$describe: ${PKG_PREFIX}/$fontdir_x11 exists!"
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       : ${MKDIR:=mkdir}
+
+       describe="non-empty x11 fonts dir"
+       ${MKDIR} -p "$fontdir_x11"
+       task_createfile "${PKG_PREFIX}/$fontdir_x11/font1"
+       echo "# FONTS: $fontdir_x11 x11" | task_fonts add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -d "${PKG_PREFIX}/$fontdir_x11" ]; then
+               describe="$describe: ${PKG_PREFIX}/$fontdir_x11 missing!"
+               return 1
+       fi
+       return 0
+}
+
+test7()
+{
+       : ${MKDIR:=mkdir}
+
+       describe="empty ttf fonts dir with PKG_DESTDIR"
+       test_destdir_setup
+       local fontdir="${PKG_DESTDIR}${PKG_PREFIX}/$fontdir_ttf"
+       ${MKDIR} -p "$fontdir"
+       echo "# FONTS: $fontdir_ttf ttf" | task_fonts add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ -d "$fontdir" ]; then
+               describe="$describe: $fontdir exists!"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$fontdir_ttf" ]; then
+               describe="$describe: ${PKG_PREFIX}/$fontdir_ttf exists!"
+               return 1
+       fi
+       return 0
+}
+
+test8()
+{
+       : ${MKDIR:=mkdir}
+
+       describe="non-empty ttf fonts dir with PKG_DESTDIR"
+       test_destdir_setup
+       local fontdir="${PKG_DESTDIR}${PKG_PREFIX}/$fontdir_ttf"
+       ${MKDIR} -p "$fontdir"
+       task_createfile "$fontdir/font1"
+       echo "# FONTS: $fontdir_ttf ttf" | task_fonts add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -d "$fontdir" ]; then
+               describe="$describe: $fontdir missing!"
+               return 1
+       fi
+       if [ ! -f "$fontdir/encodings.dir" ]; then
+               describe="$describe: x11 encodings missing!"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$fontdir_ttf" ]; then
+               describe="$describe: ${PKG_PREFIX}/$fontdir_ttf exists!"
+               return 1
+       fi
+       return 0
+}
+
+test9()
+{
+       : ${MKDIR:=mkdir}
+
+       describe="empty type1 fonts dir with PKG_DESTDIR"
+       test_destdir_setup
+       local fontdir="${PKG_DESTDIR}${PKG_PREFIX}/$fontdir_type1"
+       ${MKDIR} -p "$fontdir"
+       echo "# FONTS: $fontdir_type1 type1" | task_fonts add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ -d "$fontdir" ]; then
+               describe="$describe: $fontdir exists!"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$fontdir_type1" ]; then
+               describe="$describe: ${PKG_PREFIX}/$fontdir_type1 exists!"
+               return 1
+       fi
+       return 0
+}
+
+test10()
+{
+       : ${MKDIR:=mkdir}
+
+       describe="non-empty type1 fonts dir with PKG_DESTDIR"
+       test_destdir_setup
+       local fontdir="${PKG_DESTDIR}${PKG_PREFIX}/$fontdir_type1"
+       ${MKDIR} -p "$fontdir"
+       task_createfile "$fontdir/font1"
+       echo "# FONTS: $fontdir_type1 type1" | task_fonts add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -d "$fontdir" ]; then
+               describe="$describe: $fontdir missing!"
+               return 1
+       fi
+       if [ ! -f "$fontdir/encodings.dir" ]; then
+               describe="$describe: x11 encodings missing!"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$fontdir_type1" ]; then
+               describe="$describe: ${PKG_PREFIX}/$fontdir_type1 exists!"
+               return 1
+       fi
+       return 0
+}
+
+test11()
+{
+       : ${MKDIR:=mkdir}
+
+       describe="empty x11 fonts dir with PKG_DESTDIR"
+       test_destdir_setup
+       local fontdir="${PKG_DESTDIR}${PKG_PREFIX}/$fontdir_x11"
+       ${MKDIR} -p "$fontdir"
+       echo "# FONTS: $fontdir_x11 x11" | task_fonts add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ -d "$fontdir" ]; then
+               describe="$describe: $fontdir exists!"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$fontdir_x11" ]; then
+               describe="$describe: ${PKG_PREFIX}/$fontdir_x11 exists!"
+               return 1
+       fi
+       return 0
+}
+
+test12()
+{
+       : ${MKDIR:=mkdir}
+
+       describe="non-empty x11 fonts dir with PKG_DESTDIR"
+       test_destdir_setup
+       local fontdir="${PKG_DESTDIR}${PKG_PREFIX}/$fontdir_x11"
+       ${MKDIR} -p "$fontdir"
+       task_createfile "$fontdir/font1"
+       echo "# FONTS: $fontdir_x11 x11" | task_fonts add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -d "$fontdir" ]; then
+               describe="$describe: $fontdir missing!"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$fontdir_x11" ]; then
+               describe="$describe: ${PKG_PREFIX}/$fontdir_x11 exists!"
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_groups.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_groups.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_groups.sh        Thu Jun  1 01:58:34 2017
@@ -0,0 +1,193 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load groups
+task_load unittest
+task_load usergroup_mock
+
+# Mock platform_groupadd() needed by usergroup.subr, and task_group_exists()
+# needed by groups.subr.
+#
+platform_groupadd()
+{
+       mock_groupadd "$@"
+}
+
+task_group_exists()
+{
+       mock_group_exists "$@"
+}
+
+test_setup()
+{
+       : ${CAT:=cat}
+       : ${MKDIR:=mkdir}
+
+       PKG_DBDIR="${TEST_CURDIR}/var/db/pkg"
+       PKG_REFCOUNT_DBDIR="${PKG_DBDIR}.refcount"
+       ${MKDIR} -p "${PKG_DBDIR}"
+
+       ETC_GROUP="${TEST_CURDIR}/etc.group"
+       mock_usergroup_setup
+
+       datafile="datafile"
+       ${CAT} > $datafile << EOF
+# GROUP: groupG
+# GROUP: groupH:300
+# GROUP: groupI:305
+EOF
+}
+
+test1()
+{
+       describe="check-add missing groups"
+       if task_groups check-add < $datafile; then
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="add nonexistent groups"
+       if task_groups add < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       local name
+       for name in groupG groupH groupI; do
+               if task_group_exists "$name"; then
+                       : "success"
+               else
+                       describe="$describe: missing $name!"
+                       return 1
+               fi
+       done
+       return 0
+}
+
+test3()
+{
+       describe="add existent and nonexistent groups"
+       task_addgroup groupH 300
+       if task_groups add < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       local name
+       for name in groupG groupH groupI; do
+               if task_group_exists "$name"; then
+                       : "success"
+               else
+                       describe="$describe: missing $name!"
+                       return 1
+               fi
+       done
+       return 0
+}
+
+test4()
+{
+       describe="add conflicting group"
+       task_addgroup groupH 3000
+       if task_groups add < $datafile; then
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="check-add groups with all groups added"
+       task_groups add < $datafile
+       if task_groups check-add < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="check-remove groups with no groups removed"
+       task_groups add < $datafile
+       if task_groups check-remove < $datafile; then
+               return 1
+       fi
+       return 0
+}
+
+test7()
+{
+       describe="remove existent groups"
+       task_groups add < $datafile
+       # This always returns 0 because no groups are ever removed.
+       if task_groups remove < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       local name
+       for name in groupG groupH groupI; do
+               # No groups should have been removed.
+               if task_group_exists "$name"; then
+                       : "success"
+               else
+                       describe="$describe: $name remains!"
+                       return 1
+               fi
+       done
+       return 0
+}
+
+test8()
+{
+       describe="remove nonexistent groups"
+       # This always returns 0 because no groups are ever removed.
+       if task_groups remove < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test9()
+{
+       describe="check-remove groups with groups already removed"
+       if task_groups check-remove < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_info_files.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_info_files.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_info_files.sh    Thu Jun  1 01:58:34 2017
@@ -0,0 +1,411 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load info_files
+task_load unittest
+
+test_setup()
+{
+       : ${CAT:=cat}
+       : ${GREP:=grep}
+       : ${MKDIR:=mkdir}
+
+       PKG_PREFIX=${TEST_CURDIR}
+       PKG_DESTDIR=
+
+       infodir="info"
+       testinfo="$infodir/test.info"
+       dirfile="$infodir/dir"
+
+       ${MKDIR} "$infodir"
+       ${CAT} > "$testinfo" << 'EOF'
+INFO-DIR-SECTION Test section
+START-INFO-DIR-ENTRY
+* t_info-files: (test).                Test info-files.sh.
+END-INFO-DIR-ENTRY
+EOF
+}
+
+test_destdir_setup()
+
+{
+       : ${MKDIR:=mkdir}
+       : ${MV:=mv}
+
+       PKG_DESTDIR="${TEST_CURDIR}/destdir"
+       ${MKDIR} -p "${PKG_DESTDIR}${PKG_PREFIX}"
+       ${MV} info "${PKG_DESTDIR}${PKG_PREFIX}"
+}
+
+test1()
+{
+       describe="missing dir file on remove"
+       echo "# INFO: $testinfo $infodir" | task_info_files remove
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ -f "${PKG_PREFIX}/$dirfile" ]; then
+               describe="$describe: ${PKG_PREFIX}/$dirfile exists!"
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="missing dir file on add"
+       echo "# INFO: $testinfo $infodir" | task_info_files add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -f "${PKG_PREFIX}/$dirfile" ]; then
+               describe="$describe: ${PKG_PREFIX}/$dirfile missing!"
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="empty dir file on remove"
+       task_createfile "$dirfile"
+       echo "# INFO: $testinfo $infodir" | task_info_files remove
+       if [ $? -eq 0 ]; then
+               return 1
+       fi
+       if [ -f "${PKG_PREFIX}/$dirfile" ]; then
+               describe="$describe: ${PKG_PREFIX}/$dirfile exists!"
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="empty dir file on add"
+       task_createfile "$dirfile"
+       echo "# INFO: $testinfo $infodir" | task_info_files add
+       if [ $? -eq 0 ]; then
+               return 1
+       fi
+       if [ -f "${PKG_PREFIX}/$dirfile" ]; then
+               describe="$describe: ${PKG_PREFIX}/$dirfile exists!"
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="invalid dir file on remove"
+       echo "asdf" > $dirfile
+       echo "# INFO: $testinfo $infodir" | task_info_files remove
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ -f "${PKG_PREFIX}/$dirfile" ]; then
+               describe="$describe: ${PKG_PREFIX}/$dirfile exists!"
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="invalid dir file on add"
+       echo "asdf" > $dirfile
+       echo "# INFO: $testinfo $infodir" | task_info_files add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ -f "${PKG_PREFIX}/$dirfile" ]; then
+               describe="$describe: ${PKG_PREFIX}/$dirfile exists!"
+               return 1
+       fi
+       return 0
+}
+
+test7()
+{
+       describe="remove nonexistent info file from missing dir file"
+       echo "# INFO: /nonexistent.info $infodir" | task_info_files remove
+       if [ $? -eq 0 ]; then
+               return 1
+       fi
+       return 0
+}
+
+test8()
+{
+       describe="add info file to missing dir file"
+       echo "# INFO: $testinfo $infodir" | task_info_files add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -f "${PKG_PREFIX}/$dirfile" ]; then
+               describe="$describe: no dir!"
+               return 1
+       fi
+       return 0
+}
+
+test9()
+{
+       describe="remove info file after successful add"
+       echo "# INFO: $testinfo $infodir" | task_info_files add
+       echo "# INFO: $testinfo $infodir" | task_info_files remove
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ -f "${PKG_PREFIX}/$dirfile" ]; then
+               describe="$describe: ${PKG_PREFIX}/$dirfile exists!"
+               return 1
+       fi
+       return 0
+}
+
+test10()
+{
+       describe="add info file more than once"
+       task_info_files add << EOF
+# INFO: $testinfo $infodir
+# INFO: $testinfo $infodir
+# INFO: $testinfo $infodir
+# INFO: $testinfo $infodir
+EOF
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       local count
+       count=$( ${GREP} -c '^\* t_info-files:' "$dirfile" )
+       if [ $count -gt 1 ]; then
+               describe="$describe: $count"
+               return 1
+       fi
+       return 0
+}
+
+test11()
+{
+       describe="missing dir file on remove with PKG_DESTDIR"
+       test_destdir_setup
+       echo "# INFO: $testinfo $infodir" | task_info_files remove
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$dirfile" ]; then
+               describe="$describe: ${PKG_DESTDIR}${PKG_PREFIX}/$dirfile exists!"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$infodir" ]; then
+               describe="$describe: ${PKG_PREFIX}/$infodir exists!"
+               return 1
+       fi
+       return 0
+}
+
+test12()
+{
+       describe="missing dir file on add with PKG_DESTDIR"
+       test_destdir_setup
+       echo "# INFO: $testinfo $infodir" | task_info_files add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -f "${PKG_DESTDIR}${PKG_PREFIX}/$dirfile" ]; then
+               describe="$describe: ${PKG_DESTDIR}${PKG_PREFIX}/$dirfile missing!"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$infodir" ]; then
+               describe="$describe: ${PKG_PREFIX}/$infodir exists!"
+               return 1
+       fi
+       return 0
+}
+
+test13()
+{
+       describe="empty dir file on remove with PKG_DESTDIR"
+       test_destdir_setup
+       task_createfile "${PKG_DESTDIR}${PKG_PREFIX}/$dirfile"
+       echo "# INFO: $testinfo $infodir" | task_info_files remove
+       if [ $? -eq 0 ]; then
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$dirfile" ]; then
+               describe="$describe: ${PKG_DESTDIR}${PKG_PREFIX}/$dirfile exists!"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$infodir" ]; then
+               describe="$describe: ${PKG_PREFIX}/$infodir exists!"
+               return 1
+       fi
+       return 0
+}
+
+test14()
+{
+       describe="empty dir file on add with PKG_DESTDIR"
+       test_destdir_setup
+       task_createfile "${PKG_DESTDIR}${PKG_PREFIX}/$dirfile"
+       echo "# INFO: $testinfo $infodir" | task_info_files add
+       if [ $? -eq 0 ]; then
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$dirfile" ]; then
+               describe="$describe: ${PKG_DESTDIR}${PKG_PREFIX}/$dirfile exists!"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$infodir" ]; then
+               describe="$describe: ${PKG_PREFIX}/$infodir exists!"
+               return 1
+       fi
+       return 0
+}
+
+test15()
+{
+       describe="invalid dir file on remove with PKG_DESTDIR"
+       test_destdir_setup
+       echo "asdf" > "${PKG_DESTDIR}${PKG_PREFIX}/$dirfile"
+       echo "# INFO: $testinfo $infodir" | task_info_files remove
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$dirfile" ]; then
+               describe="$describe: ${PKG_DESTDIR}${PKG_PREFIX}/$dirfile exists!"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$infodir" ]; then
+               describe="$describe: ${PKG_PREFIX}/$infodir exists!"
+               return 1
+       fi
+       return 0
+}
+
+test16()
+{
+       describe="invalid dir file on add with PKG_DESTDIR"
+       test_destdir_setup
+       echo "asdf" > "${PKG_DESTDIR}${PKG_PREFIX}/$dirfile"
+       echo "# INFO: $testinfo $infodir" | task_info_files add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$dirfile" ]; then
+               describe="$describe: ${PKG_DESTDIR}${PKG_PREFIX}/$dirfile exists!"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$infodir" ]; then
+               describe="$describe: ${PKG_PREFIX}/$infodir exists!"
+               return 1
+       fi
+       return 0
+}
+
+test17()
+{
+       describe="remove nonexistent info file from missing dir file with PKG_DESTDIR"
+       test_destdir_setup
+       echo "# INFO: /nonexistent.info $infodir" | task_info_files remove
+       if [ $? -eq 0 ]; then
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$infodir" ]; then
+               describe="$describe: ${PKG_PREFIX}/$infodir exists!"
+               return 1
+       fi
+       return 0
+}
+
+test18()
+{
+       describe="add info file to missing dir file with PKG_DESTDIR"
+       test_destdir_setup
+       echo "# INFO: $testinfo $infodir" | task_info_files add
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -f "${PKG_DESTDIR}${PKG_PREFIX}/$dirfile" ]; then
+               describe="$describe: no dir!"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$infodir" ]; then
+               describe="$describe: ${PKG_PREFIX}/$infodir exists!"
+               return 1
+       fi
+       return 0
+}
+
+test19()
+{
+       describe="remove info file after successful add with PKG_DESTDIR"
+       test_destdir_setup
+       echo "# INFO: $testinfo $infodir" | task_info_files add
+       echo "# INFO: $testinfo $infodir" | task_info_files remove
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$dirfile" ]; then
+               describe="$describe: ${PKG_DESTDIR}${PKG_PREFIX}/$dirfile exists!"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$infodir" ]; then
+               describe="$describe: ${PKG_PREFIX}/$infodir exists!"
+               return 1
+       fi
+       return 0
+}
+
+test20()
+{
+       describe="add info file more than once with PKG_DESTDIR"
+       test_destdir_setup
+       task_info_files add << EOF
+# INFO: $testinfo $infodir
+# INFO: $testinfo $infodir
+# INFO: $testinfo $infodir
+# INFO: $testinfo $infodir
+EOF
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       local count
+       count=$( ${GREP} -c '^\* t_info-files:' "${PKG_DESTDIR}${PKG_PREFIX}/$dirfile" )
+       if [ $count -gt 1 ]; then
+               describe="$describe: $count"
+               return 1
+       fi
+       if [ -d "${PKG_PREFIX}/$infodir" ]; then
+               describe="$describe: ${PKG_PREFIX}/$infodir exists!"
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_lock.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_lock.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_lock.sh  Thu Jun  1 01:58:34 2017
@@ -0,0 +1,120 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load lock
+task_load unittest
+
+test_setup()
+{
+       : ${CAT:=cat}
+       : ${CMP:=cmp}
+       : ${SLEEP:=sleep}
+
+       lockfile="lock"
+}
+
+test1()
+{
+       describe="create lock"
+       if task_lock "$lockfile"; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ ! -f "$lockfile" ]; then
+               describe="$describe: $lockfile missing!"
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="create nonblocking lock, pre-existing lock file"
+       task_createfile "$lockfile"
+       if task_lock -n "$lockfile"; then
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="release lock"
+       task_lock "$lockfile"
+       if task_lock -r "$lockfile"; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ -f "$lockfile" ]; then
+               describe="$describe: $lockfile exists!"
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="create lock, competing processes"
+       local timeout=3
+       # Create a child process that writes to "value".
+       ( if task_lock "$lockfile"; then
+               echo "child" >> value
+               ${SLEEP} $timeout
+               task_lock -r "$lockfile"
+         fi ) &
+       #
+       # Wait for up to $timeout seconds for the child to write to the
+       # datefile.
+       #
+       while [ $timeout -gt 0 ]; do
+               [ ! -f value ] || break
+               ${SLEEP} 1
+               timeout=$(( $timeout - 1 ))
+       done
+       # Block waiting for background process to unlock.
+       if task_lock "$lockfile"; then
+               echo "parent" >> value
+               task_lock -r "$lockfile"
+       fi
+       # Check that the writes were serialized: child, then parent.
+       ${CAT} > expected << 'EOF'
+child
+parent
+EOF
+       if ${CMP} -s expected value; then
+               : "success"
+       else
+               describe="$describe: child after parent!"
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_makedir.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_makedir.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_makedir.sh       Thu Jun  1 01:58:34 2017
@@ -0,0 +1,70 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load makedir
+task_load permissions
+task_load unittest
+
+test1()
+{
+       describe="makedir a/b/c"
+       task_makedir a/b/c
+       if [ ! -d "a/b/c" ]; then
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="makedir -i a/b/c"
+       task_makedir -in a/b/c
+       task_makedir -i a/b/c
+       if [ ! -d "a/b/c" ]; then
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="makedir -i -m 700 a/b/c"
+       task_makedir -in -m 700 a/b/c
+       task_makedir -i -m 700 a/b/c
+       if [ ! -d "a/b/c" ]; then
+               return 1
+       fi
+       if task_check_permissions a/b/c 700; then
+               : "success"
+       else
+               describe="$describe: wrong mode!"
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_maketemp.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_maketemp.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_maketemp.sh      Thu Jun  1 01:58:34 2017
@@ -0,0 +1,215 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load maketemp
+task_load unittest
+
+# Mock a broken utility.
+broken()
+{
+       return 1
+}
+
+test_setup()
+{
+       : ${MKDIR:=mkdir}
+
+       # Set MKTEMP to a broken utility to force following the shell code path.
+       MKTEMP=broken
+
+       etcdir="${TEST_CURDIR}/etc"
+       TMPDIR="${TEST_CURDIR}/tmp"
+
+       ${MKDIR} -p "$etcdir"
+       ${MKDIR} -p "${TMPDIR}"
+}
+
+test1()
+{
+       describe="maketemp"
+       local temp
+       temp=$( task_maketemp )
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -f "$temp" ]; then
+               describe="$describe: $temp missing!"
+               return 1
+       fi
+       local temp_dirname="${temp%/*}"
+       if [ "$temp_dirname" != "${TMPDIR}" ]; then
+               describe="$describe: $temp_dirname is wrong parent!"
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="maketemp -p $etcdir"
+       local temp
+       temp=$( task_maketemp -p "$etcdir" )
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -f "$temp" ]; then
+               describe="$describe: $temp missing!"
+               return 1
+       fi
+       local temp_dirname="${temp%/*}"
+       if [ "$temp_dirname" != "$etcdir" ]; then
+               describe="$describe: $temp_dirname is wrong parent!"
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="maketemp -t foobar"
+       local temp
+       temp=$( task_maketemp -t foobar )
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -f "$temp" ]; then
+               describe="$describe: $temp missing!"
+               return 1
+       fi
+       case $temp in
+       ${TMPDIR}/foobar.*)
+               : "success" ;;
+       *)      describe="$describe: $temp doesn't match template!"
+               return 1 ;;
+       esac
+       return 0
+}
+
+test4()
+{
+       describe="maketemp $etcdir/group.XXX"
+       local temp
+       temp=$( task_maketemp "$etcdir/group.XXX" )
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -f "$temp" ]; then
+               describe="$describe: $temp missing!"
+               return 1
+       fi
+       case $temp in
+       $etcdir/group.???)
+               : "success" ;;
+       *)      describe="$describe: $temp doesn't match template!"
+               return 1 ;;
+       esac
+       return 0
+}
+
+test5()
+{
+       describe="maketemp -d"
+       local temp
+       temp=$( task_maketemp -d )
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -d "$temp" ]; then
+               describe="$describe: $temp missing!"
+               return 1
+       fi
+       local temp_dirname="${temp%/*}"
+       if [ "$temp_dirname" != "${TMPDIR}" ]; then
+               describe="$describe: $temp_dirname is the wrong parent!"
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="maketemp -d -p $etcdir"
+       local temp
+       temp=$( task_maketemp -d -p "$etcdir" )
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -d "$temp" ]; then
+               describe="$describe: $temp missing!"
+               return 1
+       fi
+       local temp_dirname="${temp%/*}"
+       if [ "$temp_dirname" != "$etcdir" ]; then
+               describe="$describe: $temp_dirname is the wrong prefix!"
+               return 1
+       fi
+       return 0
+}
+
+test7()
+{
+       describe="maketemp -d -t foobar"
+       local temp
+       temp=$( task_maketemp -d -t foobar )
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -d "$temp" ]; then
+               describe="$describe: $temp missing!"
+               return 1
+       fi
+       case $temp in
+       ${TMPDIR}/foobar.*)
+               : "success" ;;
+       *)      describe="$describe: $temp doesn't match template!"
+               return 1 ;;
+       esac
+       return 0
+}
+
+test8()
+{
+       describe="maketemp -d $etcdir/group.XXX"
+       local temp
+       temp=$( task_maketemp -d "$etcdir/group.XXX" )
+       if [ $? -gt 0 ]; then
+               return 1
+       fi
+       if [ ! -d "$temp" ]; then
+               describe="$describe: $temp missing!"
+               return 1
+       fi
+       case $temp in
+       $etcdir/group.???)
+               : "success" ;;
+       *)      describe="$describe: $temp doesn't match template!"
+               return 1 ;;
+       esac
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_match.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_match.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_match.sh Thu Jun  1 01:58:34 2017
@@ -0,0 +1,175 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load match
+task_load unittest
+
+test_setup()
+{
+       : ${CAT:=cat}
+
+       data="data"
+       newline="
+"
+
+       ${CAT} > $data << EOF
+aaa
+bbb ccc
+bbbccc
+
+ddd aaa
+
+aaa eee
+* Menu:
+EOF
+}
+
+test1()
+{
+       describe="exact plain match one line"
+       local expected value
+       expected="bbb ccc"
+       value=$( task_match "bbb ccc" < $data )
+       if [ "$value" != "$expected" ]; then
+               task_match "bbb ccc" < $data
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="word plain match one line"
+       local expected value
+       expected="bbb ccc"
+       value=$( task_match -w bbb < $data )
+       if [ "$value" != "$expected" ]; then
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="word plain match multiple lines"
+       local expected value
+       value=$( task_match -w aaa < $data )
+       expected="aaa${newline}aaa eee"
+       if [ "$value" != "$expected" ]; then
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="word reverse match one line"
+       local expected value
+       value=$( task_match -vw bbb < $data )
+       expected="aaa${newline}bbbccc${newline}${newline}ddd aaa${newline}${newline}aaa eee${newline}* Menu:"
+       if [ "$value" != "$expected" ]; then
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="word reverse match multiple lines"
+       local expected value
+       value=$( task_match -vw aaa < $data )
+       expected="bbb ccc${newline}bbbccc${newline}${newline}ddd aaa${newline}${newline}* Menu:"
+       if [ "$value" != "$expected" ]; then
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="exact plain match no lines"
+       local value
+       value=$( task_match ccc < $data )
+       if [ -n "$value" ]; then
+               return 1
+       fi
+       return 0
+}
+
+test7()
+{
+       describe="word plain match silent"
+       if task_match -qw aaa < $data; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test8()
+{
+       describe="word reverse match silent"
+       if task_match -qvw aaa < $data; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test9()
+{
+       describe="exact plain match no lines silent"
+       if task_match -q ccc < $data; then
+               return 1
+       fi
+       return 0
+}
+
+test10()
+{
+       describe="exact reverse match no lines silent"
+       if task_match -qv ccc < $data; then
+               return 1
+       fi
+       return 0
+}
+
+test11()
+{
+       describe="plain glob match one line"
+       local expected value
+       value=$( task_match "[*][       ][mM]enu:*" < $data )
+       expected="* Menu:"
+       if [ "$value" != "$expected" ]; then
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_ocaml_findlib.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_ocaml_findlib.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_ocaml_findlib.sh Thu Jun  1 01:58:34 2017
@@ -0,0 +1,346 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load ocaml_findlib
+task_load unittest
+
+test_setup()
+{
+       : ${CAT:=cat}
+
+       PKG_PREFIX=${TEST_CURDIR}
+       PKG_DESTDIR=
+
+       ldconf="ld.conf"
+       ldconf_lock="$ldconf.lock"
+
+       datafile="datafile"
+       ${CAT} > $datafile << EOF
+# FINDLIB: pcre $ldconf
+# FINDLIB: base64 $ldconf
+# FINDLIB: expat $ldconf
+# FINDLIB: pcre $ldconf
+EOF
+}
+
+test_destdir_setup()
+{
+       : ${MKDIR:=mkdir}
+       : ${MV:=mv}
+
+       PKG_DESTDIR="${TEST_CURDIR}/destdir"
+       ${MKDIR} -p "${PKG_DESTDIR}${PKG_PREFIX}"
+}
+
+test1()
+{
+       describe="check-add findlib dirs with empty ld.conf"
+       if task_ocaml_findlib check-add < $datafile; then
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="add findlib dirs"
+       if task_ocaml_findlib add < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ ! -f "$ldconf" ]; then
+               describe="$describe: $ldconf missing!"
+               return 1
+       fi
+       if [ -f "$ldconf_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="verify uniqueness"
+       task_ocaml_findlib add < $datafile
+       local count=0
+       local line
+       while read line; do
+               case $line in
+               */pcre) count="$count + 1" ;;
+               esac
+       done < $ldconf
+       count=$(( $count ))
+       if [ $count -gt 1 ]; then
+               describe="$describe: too many pcre!"
+               return 1
+       fi
+       if [ -f "$ldconf_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="check-add findlib dirs with all dirs added"
+       task_ocaml_findlib add < $datafile
+       if task_ocaml_findlib check-add < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ -f "$ldconf_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="check-remove findlib dirs with no dirs removed"
+       task_ocaml_findlib add < $datafile
+       if task_ocaml_findlib check-remove < $datafile; then
+               return 1
+       fi
+       if [ -f "$ldconf_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="remove findlib dirs"
+       task_ocaml_findlib add < $datafile
+       if task_ocaml_findlib remove < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ -f "$ldconf_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       return 0
+}
+
+test7()
+{
+       describe="verify empty ld.conf"
+       task_ocaml_findlib add < $datafile
+       task_ocaml_findlib remove < $datafile
+       local count=0
+       local line
+       while read line; do
+               count="$count + 1"
+       done < $ldconf
+       count=$(( $count ))
+       if [ $count -gt 0 ]; then
+               return 1
+       fi
+       return 0
+}
+
+test8()
+{
+       describe="check-remove findlib dirs with empty ld.conf"
+       task_createfile "$ldconf"
+       if task_ocaml_findlib check-remove < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ -f "$ldconf_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       return 0
+}
+
+test9()
+{
+       describe="add findlib dirs with PKG_DESTDIR"
+       test_destdir_setup
+       if task_ocaml_findlib add < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ ! -f "${PKG_DESTDIR}${PKG_PREFIX}/$ldconf" ]; then
+               describe="$describe: ${PKG_DESTDIR}${PKG_PREFIX}/$ldconf missing!"
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$ldconf_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       if [ -f "$ldconf" ]; then
+               describe="$describe: $ldconf exists!"
+               return 1
+       fi
+       return 0
+}
+
+test10()
+{
+       describe="verify uniqueness with PKG_DESTDIR"
+       test_destdir_setup
+       task_ocaml_findlib add < $datafile
+       local count=0
+       local line
+       while read line; do
+               case $line in
+               */pcre) count="$count + 1" ;;
+               esac
+       done < ${PKG_DESTDIR}${PKG_PREFIX}/$ldconf
+       count=$(( $count ))
+       if [ $count -gt 1 ]; then
+               describe="$describe: too many pcre!"
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$ldconf_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       if [ -f "$ldconf" ]; then
+               describe="$describe: $ldconf exists!"
+               return 1
+       fi
+       return 0
+}
+
+test11()
+{
+       describe="check-add findlib dirs with all dirs added with PKG_DESTDIR"
+       test_destdir_setup
+       task_ocaml_findlib add < $datafile
+       if task_ocaml_findlib check-add < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$ldconf_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       if [ -f "$ldconf" ]; then
+               describe="$describe: $ldconf exists!"
+               return 1
+       fi
+       return 0
+}
+
+test12()
+{
+       describe="check-remove findlib dirs with no dirs removed with PKG_DESTDIR"
+       test_destdir_setup
+       task_ocaml_findlib add < $datafile
+       if task_ocaml_findlib check-remove < $datafile; then
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$ldconf_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       if [ -f "$ldconf" ]; then
+               describe="$describe: $ldconf exists!"
+               return 1
+       fi
+       return 0
+}
+
+test13()
+{
+       describe="remove findlib dirs with PKG_DESTDIR"
+       test_destdir_setup
+       task_ocaml_findlib add < $datafile
+       if task_ocaml_findlib remove < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$ldconf_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       if [ -f "$ldconf" ]; then
+               describe="$describe: $ldconf exists!"
+               return 1
+       fi
+       return 0
+}
+
+test14()
+{
+       describe="verify empty ld.conf with PKG_DESTDIR"
+       test_destdir_setup
+       task_ocaml_findlib add < $datafile
+       task_ocaml_findlib remove < $datafile
+       local count=0
+       local line
+       while read line; do
+               count="$count + 1"
+       done < ${PKG_DESTDIR}${PKG_PREFIX}/$ldconf
+       count=$(( $count ))
+       if [ $count -gt 0 ]; then
+               return 1
+       fi
+       if [ -f "$ldconf" ]; then
+               describe="$describe: $ldconf exists!"
+               return 1
+       fi
+       return 0
+}
+
+test15()
+{
+       describe="check-remove findlib dirs with empty ld.conf with PKG_DESTDIR"
+       test_destdir_setup
+       task_createfile "${PKG_DESTDIR}${PKG_PREFIX}/$ldconf"
+       if task_ocaml_findlib check-remove < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$ldconf_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       if [ -f "$ldconf" ]; then
+               describe="$describe: $ldconf exists!"
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_permissions.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_permissions.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_permissions.sh   Thu Jun  1 01:58:34 2017
@@ -0,0 +1,172 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load permissions
+task_load unittest
+
+test_setup()
+{
+       : ${LS:=ls}
+
+       PKG_PREFIX=${TEST_CURDIR}
+       PKG_DESTDIR=
+}
+
+test_destdir_setup()
+{
+       : ${MKDIR:=mkdir}
+       : ${MV:=mv}
+
+       PKG_DESTDIR="${TEST_CURDIR}/destdir"
+       ${MKDIR} -p "${PKG_DESTDIR}${PKG_PREFIX}"
+}
+
+test1()
+{
+       describe="missing file"
+       echo "# PERMS: file1 0444" | task_permissions check-add
+       if echo "# PERMS: file1 0444" | task_permissions add; then
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="change only file mode"
+       task_createfile file1
+       echo "# PERMS: file1 0444" | task_permissions add
+       echo "# PERMS: file1 0444" | task_permissions check-add
+       if task_check_permissions file1 0444; then
+               : "success"
+       else
+               describe="$describe: file1"
+               ${LS} -ln file1 |
+               ( read mode
+                 if [ "$mode" != "-r--r--r--" ]; then
+                       describe="$describe: wrong mode \`$mode'"
+                       return 1
+                 fi ) || return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="change to root/wheel"
+       task_requires_root || return 0
+       task_createfile file1
+       echo "# PERMS: file1 0600 root wheel" | task_permissions add
+       echo "# PERMS: file1 0600 root wheel" | task_permissions check-add
+       if task_check_permissions file1 0600 root wheel; then
+               : "success"
+       else
+               describe="$describe: file1"
+               ${LS} -ln file1 |
+               ( read mode x owner group x;
+                 if [ "$mode" != "-rw-------" ]; then
+                       describe="$describe: wrong mode \`$mode'"
+                       return 1
+                 fi
+                 if [ "$owner" != 0 ]; then
+                       describe="$describe: wrong owner \`$owner'"
+                       return 1
+                 fi
+                 if [ "$group" != 0 ]; then
+                       describe="$describe: wrong group \`$group'"
+                       return 1
+                 fi ) || return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="missing file with PKG_DESTDIR"
+       test_destdir_setup
+       echo "# PERMS: file1 0444" | task_permissions check-add
+       if echo "# PERMS: file1 0444" | task_permissions add; then
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="change only file mode with PKG_DESTDIR"
+       test_destdir_setup
+       local file="${PKG_DESTDIR}${PKG_PREFIX}/file1"
+       task_createfile $file
+       echo "# PERMS: file1 0444" | task_permissions add
+       echo "# PERMS: file1 0444" | task_permissions check-add
+       if task_check_permissions "$file" 0444; then
+               : "success"
+       else
+               describe="$describe: $file"
+               ${LS} -ln "$file" |
+               ( read mode
+                 if [ "$mode" != "-r--r--r--" ]; then
+                       describe="$describe: wrong mode \`$mode'"
+                       return 1
+                 fi ) || return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="change to root/wheel with PKG_DESTDIR"
+       task_requires_root || return 0
+       test_destdir_setup
+       local file="${PKG_DESTDIR}${PKG_PREFIX}/file1"
+       task_createfile "$file"
+       echo "# PERMS: file1 0600 root wheel" | task_permissions add
+       echo "# PERMS: file1 0600 root wheel" | task_permissions check-add
+       if task_check_permissions "$file" 0600 root wheel; then
+               : "success"
+       else
+               describe="$describe: $file"
+               ${LS} -ln "$file" |
+               ( read mode x owner group x;
+                 if [ "$mode" != "-rw-------" ]; then
+                       describe="$describe: wrong mode \`$mode'"
+                       return 1
+                 fi
+                 if [ "$owner" != 0 ]; then
+                       describe="$describe: wrong owner \`$owner'"
+                       return 1
+                 fi
+                 if [ "$group" != 0 ]; then
+                       describe="$describe: wrong group \`$group'"
+                       return 1
+                 fi ) || return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_platform.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_platform.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_platform.sh      Thu Jun  1 01:58:34 2017
@@ -0,0 +1,68 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load platform
+task_load unittest
+
+# Mock uname() needed by platform.subr.
+mock_uname()
+{
+       echo "N-e-t/B-S-D"
+}
+
+mock_uname_cygwin()
+{
+       echo "CYGWIN"
+}
+
+test1()
+{
+       describe="uname with dashes and slashes"
+       local expected value
+       expected="NetBSD"
+       value=$( UNAME=mock_uname task_platform )
+       if [ "$value" != "$expected" ]; then
+               echo "$value"
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="cygwin"
+       local expected value
+       expected="Cygwin"
+       value=$( UNAME=mock_uname_cygwin task_platform )
+       if [ "$value" != "$expected" ]; then
+               echo "$value"
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_postinstall.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_postinstall.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_postinstall.sh   Thu Jun  1 01:58:34 2017
@@ -0,0 +1,199 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load postinstall
+task_load unittest
+
+test_setup()
+{
+       datafile="empty"
+       task_createfile "$datafile"
+
+       TASK_DIRECTORIES_SUCCESS="yes"
+       TASK_FILES_SUCCESS="yes"
+       TASK_FONTS_SUCCESS="yes"
+       TASK_FUNCTION_SUCCESS="yes"
+       TASK_INFO_FILES_SUCCESS="yes"
+       TASK_OCAML_FINDLIB_SUCCESS="yes"
+       TASK_PERMISSIONS_SUCCESS="yes"
+       TASK_SHELLS_SUCCESS="yes"
+       TASK_SHLIBS_SUCCESS="yes"
+}
+
+# Mock actions that return the truthiness of environment variables.
+task_directories()
+{
+       [ "${TASK_DIRECTORIES_SUCCESS}" = "yes" ]
+}
+
+task_files()
+{
+       [ "${TASK_FILES_SUCCESS}" = "yes" ]
+}
+
+task_fonts()
+{
+       [ "${TASK_FONTS_SUCCESS}" = "yes" ]
+}
+
+task_function()
+{
+       [ "${TASK_FUNCTION_SUCCESS}" = "yes" ]
+}
+
+task_info_files()
+{
+       [ "${TASK_INFO_FILES_SUCCESS}" = "yes" ]
+}
+
+task_ocaml_findlib()
+{
+       [ "${TASK_OCAML_FINDLIB_SUCCESS}" = "yes" ]
+}
+
+task_permissions()
+{
+       [ "${TASK_PERMISSIONS_SUCCESS}" = "yes" ]
+}
+
+task_shells()
+{
+       [ "${TASK_SHELLS_SUCCESS}" = "yes" ]
+}
+
+task_shlibs()
+{
+       [ "${TASK_SHLIBS_SUCCESS}" = "yes" ]
+}
+
+# Only succeed if all of the actions were successful.
+
+test1()
+{
+       describe="dirs fail"
+       TASK_DIRECTORIES_SUCCESS="no"
+       if task_postinstall "$datafile"; then
+               : "dirs should only be used to check"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="files fail"
+       TASK_FILES_SUCCESS="no"
+       if task_postinstall "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="fonts fail"
+       TASK_FONTS_SUCCESS="no"
+       if task_postinstall "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="function fail"
+       TASK_FUNCTION_SUCCESS="no"
+       if task_postinstall "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="info_files fail"
+       TASK_INFO_FILES_SUCCESS="no"
+       if task_postinstall "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="ocaml_findlib fail"
+       TASK_OCAML_FINDLIB_SUCCESS="no"
+       if task_postinstall "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test7()
+{
+       describe="permissions fail"
+       TASK_PERMISSIONS_SUCCESS="no"
+       if task_postinstall "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test8()
+{
+       describe="shells fail"
+       TASK_SHELLS_SUCCESS="no"
+       if task_postinstall "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test9()
+{
+       describe="shlibs fail"
+       TASK_SHLIBS_SUCCESS="no"
+       if task_postinstall "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test10()
+{
+       describe="all succeed"
+       if task_postinstall "$datafile"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_postremove.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_postremove.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_postremove.sh    Thu Jun  1 01:58:34 2017
@@ -0,0 +1,217 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load postremove
+task_load unittest
+
+test_setup()
+{
+       datafile="empty"
+       task_createfile "$datafile"
+
+       TASK_DIRECTORIES_SUCCESS="yes"
+       TASK_FILES_SUCCESS="yes"
+       TASK_FONTS_SUCCESS="yes"
+       TASK_FUNCTION_SUCCESS="yes"
+       TASK_GROUPS_SUCCESS="yes"
+       TASK_INFO_FILES_SUCCESS="yes"
+       TASK_OCAML_FINDLIB_SUCCESS="yes"
+       TASK_SHELLS_SUCCESS="yes"
+       TASK_SHLIBS_SUCCESS="yes"
+       TASK_USERS_SUCCESS="yes"
+}
+
+# Mock actions that return the truthiness of environment variables.
+task_directories()
+{
+       [ "${TASK_DIRECTORIES_SUCCESS}" = "yes" ]
+}
+
+task_files()
+{
+       [ "${TASK_FILES_SUCCESS}" = "yes" ]
+}
+
+task_fonts()
+{
+       [ "${TASK_FONTS_SUCCESS}" = "yes" ]
+}
+
+task_function()
+{
+       [ "${TASK_FUNCTION_SUCCESS}" = "yes" ]
+}
+
+task_groups()
+{
+       [ "${TASK_GROUPS_SUCCESS}" = "yes" ]
+}
+
+task_info_files()
+{
+       [ "${TASK_INFO_FILES_SUCCESS}" = "yes" ]
+}
+
+task_ocaml_findlib()
+{
+       [ "${TASK_OCAML_FINDLIB_SUCCESS}" = "yes" ]
+}
+
+task_shells()
+{
+       [ "${TASK_SHELLS_SUCCESS}" = "yes" ]
+}
+
+task_shlibs()
+{
+       [ "${TASK_SHLIBS_SUCCESS}" = "yes" ]
+}
+
+task_users()
+{
+       [ "${TASK_USERS_SUCCESS}" = "yes" ]
+}
+
+# Only succeed if all of the actions were successful.
+
+test1()
+{
+       describe="dirs fail"
+       TASK_DIRECTORIES_SUCCESS="no"
+       if task_postremove "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="files fail"
+       TASK_FILES_SUCCESS="no"
+       if task_postremove "$datafile"; then
+               : "files should only be used to check"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="fonts fail"
+       TASK_FONTS_SUCCESS="no"
+       if task_postremove "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="function fail"
+       TASK_FUNCTION_SUCCESS="no"
+       if task_postremove "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="groups fail"
+       TASK_GROUPS_SUCCESS="no"
+       if task_postremove "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="info_files fail"
+       TASK_INFO_FILES_SUCCESS="no"
+       if task_postremove "$datafile"; then
+               : "info_files should only be used to check"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test7()
+{
+       describe="ocaml_findlib fail"
+       TASK_OCAML_FINDLIB_SUCCESS="no"
+       if task_postremove "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test8()
+{
+       describe="shells fail"
+       TASK_SHELLS_SUCCESS="no"
+       if task_postremove "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test9()
+{
+       describe="shlibs fail"
+       TASK_SHLIBS_SUCCESS="no"
+       if task_postremove "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test10()
+{
+       describe="users fail"
+       TASK_USERS_SUCCESS="no"
+       if task_postremove "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test11()
+{
+       describe="all succeed"
+       if task_postremove "$datafile"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_preinstall.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_preinstall.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_preinstall.sh    Thu Jun  1 01:58:34 2017
@@ -0,0 +1,117 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load preinstall
+task_load unittest
+
+test_setup()
+{
+       datafile="empty"
+       task_createfile "$datafile"
+
+       TASK_DIRECTORIES_SUCCESS="yes"
+       TASK_FUNCTION_SUCCESS="yes"
+       TASK_GROUPS_SUCCESS="yes"
+       TASK_USERS_SUCCESS="yes"
+}
+
+# Mock actions that return the truthiness of environment variables.
+task_directories()
+{
+       [ "${TASK_DIRECTORIES_SUCCESS}" = "yes" ]
+}
+
+task_function()
+{
+       [ "${TASK_FUNCTION_SUCCESS}" = "yes" ]
+}
+
+task_groups()
+{
+       [ "${TASK_GROUPS_SUCCESS}" = "yes" ]
+}
+
+task_users()
+{
+       [ "${TASK_USERS_SUCCESS}" = "yes" ]
+}
+
+test1()
+{
+       describe="dirs fail"
+       TASK_DIRECTORIES_SUCCESS="no"
+       if task_preinstall "$datafile"; then
+               : "dirs errors in preinstall are non-fatal"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="function fail"
+       TASK_FUNCTION_SUCCESS="no"
+       if task_preinstall "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="groups fail"
+       TASK_GROUPS_SUCCESS="no"
+       if task_preinstall "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="users fail"
+       TASK_USERS_SUCCESS="no"
+       if task_preinstall "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="all succeed"
+       if task_preinstall "$datafile"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_preremove.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_preremove.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_preremove.sh     Thu Jun  1 01:58:34 2017
@@ -0,0 +1,105 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load preremove
+task_load unittest
+
+test_setup()
+{
+       datafile="empty"
+       task_createfile "$datafile"
+
+       TASK_FILES_SUCCESS="yes"
+       TASK_FUNCTION_SUCCESS="yes"
+       TASK_INFO_FILES_SUCCESS="yes"
+}
+
+# Mock actions whose return values are ignored.
+task_files()
+{
+       [ "${TASK_FILES_SUCCESS}" = "yes" ]
+}
+
+task_function()
+{
+       [ "${TASK_FUNCTION_SUCCESS}" = "yes" ]
+}
+
+task_info_files()
+{
+       [ "${TASK_INFO_FILES_SUCCESS}" = "yes" ]
+}
+
+# Always succeed.
+
+test1()
+{
+       describe="files fail"
+       TASK_FILES_SUCCESS="no"
+       if task_preremove "$datafile"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="function fail"
+       TASK_FUNCTION_SUCCESS="no"
+       if task_preremove "$datafile"; then
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="info_files fail"
+       TASK_INFO_FILES_SUCCESS="no"
+       if task_preremove "$datafile"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="all succeed"
+       if task_preremove "$datafile"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_quote.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_quote.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_quote.sh Thu Jun  1 01:58:34 2017
@@ -0,0 +1,118 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load quote
+task_load unittest
+
+test_setup()
+{
+       # Create files in the test directory to catch wildcard expansion.
+       task_createfile a b c
+}
+
+test1()
+{
+       describe="6 words"
+       local quoted
+       task_quote "1 *" "2 *" "3 *"
+       set -- $quoted
+       if [ $# -eq 6 ]; then
+               : "success"
+       else
+               return 1
+       fi
+}
+
+test2()
+{
+       describe="1 word"
+       local quoted
+       task_quote "1 *" "2 *" "3 *"
+       set -- "$quoted"
+       if [ $# -eq 1 ]; then
+               : "success"
+       else
+               return 1
+       fi
+}
+
+test3()
+{
+       describe="3 words (correct quoting)"
+       local quoted
+       task_quote "1 *" "2 *" "3 *"
+       eval set -- $quoted
+       if [ $# -eq 3 ]; then
+               : "success"
+       else
+               return 1
+       fi
+}
+
+test4()
+{
+       describe="3 words, extraneous quotes (correct quoting)"
+       local quoted
+       task_quote "1 *" "2 *" "3 *"
+       eval set -- "$quoted"
+       if [ $# -eq 3 ]; then
+               : "success"
+       else
+               return 1
+       fi
+}
+
+test5()
+{
+       describe="1 word (correct quoting)"
+       local quoted
+       task_quote "*"
+       eval set -- $quoted
+       local arg; for arg; do echo "$arg"; done
+       if [ $# -eq 1 ]; then
+               : "success"
+       else
+               return 1
+       fi
+}
+
+test6()
+{
+       describe="1 word, extraneous quotes (correct quoting)"
+       local quoted
+       task_quote "*"
+       eval set -- "$quoted"
+       local arg; for arg; do echo "$arg"; done
+       if [ $# -eq 1 ]; then
+               : "success"
+       else
+               return 1
+       fi
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_random.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_random.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_random.sh        Thu Jun  1 01:58:34 2017
@@ -0,0 +1,61 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load random
+task_load unittest
+
+test1()
+{
+       describe="each \$RANDOM is different"
+       local rand1 rand2 rand3
+       task_random && rand1=$RANDOM
+       task_random && rand2=$RANDOM
+       task_random && rand3=$RANDOM
+       [ "$rand1" != "$rand2" ] &&
+       [ "$rand1" != "$rand3" ] &&
+       [ "$rand2" != "$rand3" ]
+}
+
+test2()
+{
+       describe="task_random -i yields reproducible \$RANDOM"
+       local first1 first2 first3
+       task_random -i "12345"
+       task_random && rand1=$RANDOM
+       task_random && rand2=$RANDOM
+       task_random && rand3=$RANDOM
+       local second1 second2 second3
+       task_random -i "12345"
+       task_random && rand1=$RANDOM
+       task_random && rand2=$RANDOM
+       task_random && rand3=$RANDOM
+       [ "$first1" = "$second1" ] &&
+       [ "$first2" = "$second2" ] &&
+       [ "$first3" = "$second3" ]
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_refcount.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_refcount.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_refcount.sh      Thu Jun  1 01:58:34 2017
@@ -0,0 +1,397 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load refcount
+task_load unittest
+
+test_setup()
+{
+       PKG_REFCOUNT_DBDIR="${TEST_CURDIR}/refcount"
+       PKG_DESTDIR=
+
+       nonexistent="${TEST_CURDIR}/nonexistent"
+}
+
+test_destdir_setup()
+{
+       : ${MKDIR:=mkdir}
+       : ${MV:=mv}
+
+       PKG_DESTDIR="${TEST_CURDIR}/destdir"
+       ${MKDIR} -p "${PKG_DESTDIR}${TEST_CURDIR}"
+}
+
+test1()
+{
+       describe="add nonexistent file"
+       if task_refcount add refs "$nonexistent"; then
+               : "success"
+       else
+               return 1
+       fi
+       if task_refcount exists refs "$nonexistent"; then
+               : "success"
+       else
+               describe="$describe: reference missing!"
+               return 1
+       fi
+       if task_refcount prop_exists refs "$nonexistent" permissions; then
+               describe="$describe: permissions found!"
+               return 1
+       fi
+       if task_refcount prop_exists refs "$nonexistent" preexist; then
+               describe="$describe: preexist found!"
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="put permissions"
+       local permissions="0400 root wheel"
+       task_refcount add refs "$nonexistent"
+       if task_refcount prop_put refs "$nonexistent" permissions $permissions; then
+               : "success"
+       else
+               return 1
+       fi
+       if task_refcount prop_match refs "$nonexistent" permissions $permissions; then
+               : "success"
+       else
+               describe="$describe: permissions not matching!"
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="put preexist"
+       task_refcount add refs "$nonexistent"
+       if task_refcount prop_put refs "$nonexistent" preexist; then
+               : "success"
+       else
+               return 1
+       fi
+       if task_refcount prop_exists refs "$nonexistent" preexist; then
+               : "success"
+       else
+               describe="$describe: preexist not found!"
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="remove after add twice"
+       task_refcount add refs "$nonexistent"
+       task_refcount add refs "$nonexistent"
+       if task_refcount remove refs "$nonexistent"; then
+               : "success"
+       else
+               return 1
+       fi
+       if task_refcount exists refs "$nonexistent"; then
+               describe="$describe: reference found!"
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="remove pkg1 after add pkg1 and pkg2"
+       ( PKGNAME="package1"; task_refcount add refs "$nonexistent" )
+       ( PKGNAME="package2"; task_refcount add refs "$nonexistent" )
+       ( PKGNAME="package1"; task_refcount remove refs "$nonexistent" )
+       if task_refcount exists refs "$nonexistent"; then
+               : "success"
+       else
+               return 1
+       fi
+}
+
+test6()
+{
+       describe="put property with no refcount"
+       local permissions="0400 root wheel"
+       if task_refcount prop_put refs "$nonexistent" permissions $permissions; then
+               : "success"
+       else
+               return 1
+       fi
+       if task_refcount exists refs "$nonexistent"; then
+               describe="$describe: refcount exists!"
+               return 1
+       fi
+}
+
+test7()
+{
+       describe="delete refcount"
+       task_refcount add refs "$nonexistent"
+       task_refcount prop_put refs "$nonexistent" owner
+       if task_refcount delete refs "$nonexistent"; then
+               : "success"
+       else
+               return 1
+       fi
+       if task_refcount exists refs "$nonexistent"; then
+               describe="$describe: reference found!"
+               return 1
+       fi
+}
+
+test8()
+{
+       describe="remove refcount after putting property"
+       task_refcount add refs "$nonexistent"
+       task_refcount prop_put refs "$nonexistent" owner
+       if task_refcount remove refs "$nonexistent"; then
+               : "success"
+       else
+               return 1
+       fi
+       if task_refcount exists refs "$nonexistent"; then
+               describe="$describe: reference found!"
+               return 1
+       fi
+       if task_refcount prop_exists refs "$nonexistent" owner; then
+               : "success"
+       else
+               describe="$describe: property not found!"
+               return 1
+       fi
+}
+
+test9()
+{
+       describe="delete property"
+       task_refcount prop_put refs "$nonexistent" owner
+       if task_refcount prop_delete refs "$nonexistent" owner; then
+               : "success"
+       else
+               return 1
+       fi
+       if task_refcount prop_exists refs "$nonexistent" owner; then
+               describe="$describe: property found!"
+               return 1
+       fi
+}
+
+test10()
+{
+       describe="add nonexistent file with PKG_DESTDIR"
+       test_destdir_setup
+       if task_refcount add refs "$nonexistent"; then
+               : "success"
+       else
+               return 1
+       fi
+       if task_refcount exists refs "$nonexistent"; then
+               : "success"
+       else
+               describe="$describe: reference missing!"
+               return 1
+       fi
+       if task_refcount prop_exists refs "$nonexistent" permissions; then
+               describe="$describe: permissions found!"
+               return 1
+       fi
+       if task_refcount prop_exists refs "$nonexistent" preexist; then
+               describe="$describe: preexist found!"
+               return 1
+       fi
+       if [ -d "${PKG_REFCOUNT_DBDIR}" ]; then
+               describe="$describe: wrong refcount directory!"
+               return 1
+       fi
+       return 0
+}
+
+test11()
+{
+       describe="put permissions with PKG_DESTDIR"
+       test_destdir_setup
+       local permissions="0400 root wheel"
+       task_refcount add refs "$nonexistent"
+       if task_refcount prop_put refs "$nonexistent" permissions $permissions; then
+               : "success"
+       else
+               return 1
+       fi
+       if task_refcount prop_match refs "$nonexistent" permissions $permissions; then
+               : "success"
+       else
+               describe="$describe: permissions not matching!"
+               return 1
+       fi
+       if [ -d "${PKG_REFCOUNT_DBDIR}" ]; then
+               describe="$describe: wrong refcount directory!"
+               return 1
+       fi
+       return 0
+}
+
+test12()
+{
+       describe="put preexist with DESTDIR"
+       test_destdir_setup
+       task_refcount add refs "$nonexistent"
+       if task_refcount prop_put refs "$nonexistent" preexist; then
+               : "success"
+       else
+               return 1
+       fi
+       if task_refcount prop_exists refs "$nonexistent" preexist; then
+               : "success"
+       else
+               describe="$describe: preexist not found!"
+               return 1
+       fi
+       if [ -d "${PKG_REFCOUNT_DBDIR}" ]; then
+               describe="$describe: wrong refcount directory!"
+               return 1
+       fi
+       return 0
+}
+
+test13()
+{
+       describe="remove after add twice with PKG_DESTDIR"
+       test_destdir_setup
+       task_refcount add refs "$nonexistent"
+       task_refcount add refs "$nonexistent"
+       if task_refcount remove refs "$nonexistent"; then
+               : "success"
+       else
+               return 1
+       fi
+       if task_refcount exists refs "$nonexistent"; then
+               describe="$describe: reference found!"
+               return 1
+       fi
+       return 0
+}
+
+test14()
+{
+       describe="remove pkg1 after add pkg1 and pkg2 with PKG_DESTDIR"
+       test_destdir_setup
+       ( PKGNAME="package1"; task_refcount add refs "$nonexistent" )
+       ( PKGNAME="package2"; task_refcount add refs "$nonexistent" )
+       ( PKGNAME="package1"; task_refcount remove refs "$nonexistent" )
+       if task_refcount exists refs "$nonexistent"; then
+               : "success"
+       else
+               return 1
+       fi
+}
+
+test15()
+{
+       describe="put property with no refcount with PKG_DESTDIR"
+       test_destdir_setup
+       local permissions="0400 root wheel"
+       if task_refcount prop_put refs "$nonexistent" permissions $permissions; then
+               : "success"
+       else
+               return 1
+       fi
+       if task_refcount exists refs "$nonexistent"; then
+               describe="$describe: refcount exists!"
+               return 1
+       fi
+       if [ -d "${PKG_REFCOUNT_DBDIR}" ]; then
+               describe="$describe: wrong refcount directory!"
+               return 1
+       fi
+}
+
+test16()
+{
+       describe="delete refcount with PKG_DESTDIR"
+       test_destdir_setup
+       task_refcount add refs "$nonexistent"
+       task_refcount prop_put refs "$nonexistent" owner
+       if task_refcount delete refs "$nonexistent"; then
+               : "success"
+       else
+               return 1
+       fi
+       if task_refcount exists refs "$nonexistent"; then
+               describe="$describe: reference found!"
+               return 1
+       fi
+}
+
+test17()
+{
+       describe="remove refcount after putting property with PKG_DESTDIR"
+       test_destdir_setup
+       task_refcount add refs "$nonexistent"
+       task_refcount prop_put refs "$nonexistent" owner
+       if task_refcount remove refs "$nonexistent"; then
+               : "success"
+       else
+               return 1
+       fi
+       if task_refcount exists refs "$nonexistent"; then
+               describe="$describe: reference found!"
+               return 1
+       fi
+       if task_refcount prop_exists refs "$nonexistent" owner; then
+               : "success"
+       else
+               describe="$describe: property not found!"
+               return 1
+       fi
+       if [ -d "${PKG_REFCOUNT_DBDIR}" ]; then
+               describe="$describe: wrong refcount directory!"
+               return 1
+       fi
+}
+
+test18()
+{
+       describe="delete property with PKG_DESTDIR"
+       test_destdir_setup
+       task_refcount prop_put refs "$nonexistent" owner
+       if task_refcount prop_delete refs "$nonexistent" owner; then
+               : "success"
+       else
+               return 1
+       fi
+       if task_refcount prop_exists refs "$nonexistent" owner; then
+               describe="$describe: property found!"
+               return 1
+       fi
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_shells.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_shells.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_shells.sh        Thu Jun  1 01:58:34 2017
@@ -0,0 +1,339 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load shells
+task_load unittest
+
+test_setup()
+{
+       : ${CAT:=cat}
+       : ${MKDIR:=mkdir}
+
+       PKG_PREFIX="${TEST_CURDIR}"
+       PKG_DESTDIR=
+
+       shelldb="etc/shells"
+       shelldb_lock="$shelldb.lock"
+
+       datafile="datafile"
+       ${CAT} > $datafile << EOF
+# SHELL: bin/pdksh $shelldb
+# SHELL: bin/bash $shelldb
+# SHELL: ${PKG_PREFIX}/bin/pdksh $shelldb
+EOF
+
+       ${MKDIR} -p etc
+}
+
+test_destdir_setup()
+{
+       : ${MKDIR:=mkdir}
+       : ${MV:=mv}
+
+       PKG_DESTDIR="${TEST_CURDIR}/destdir"
+       ${MKDIR} -p "${PKG_DESTDIR}${PKG_PREFIX}"
+       ${MV} etc "${PKG_DESTDIR}${PKG_PREFIX}"
+}
+
+test1()
+{
+       describe="check-add shells with empty shell database"
+       if task_shells check-add < $datafile; then
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="add shells"
+       if task_shells add < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ -f "$shelldb_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="verify uniqueness"
+       task_shells add < $datafile
+       local count=0
+       local line
+       while read line; do
+               case $line in
+               */pdksh*) count="$count + 1" ;;
+               esac
+       done < $shelldb
+       count=$(( $count ))
+       if [ $count -gt 1 ]; then
+               describe="$describe: too many pdksh!"
+               return 1
+       fi
+       if [ -f "$shelldb_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="check-add shells with all shells added"
+       task_shells add < $datafile
+       if task_shells check-add < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ -f "$shelldb_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="check-remove shells with no shells removed"
+       task_shells add < $datafile
+       if task_shells check-remove < $datafile; then
+               return 1
+       fi
+       if [ -f "$shelldb_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="remove shells"
+       task_shells add < $datafile
+       if task_shells remove < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ -f "$shelldb_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       return 0
+}
+
+test7()
+{
+       describe="verify empty shell database"
+       task_shells add < $datafile
+       task_shells remove < $datafile
+       local count=0
+       while read line; do
+               count="$count + 1"
+       done < $shelldb
+       count=$(( $count ))
+       if [ $count -gt 0 ]; then
+               return 1
+       fi
+       return 0
+}
+
+test8()
+{
+       describe="check-remove shells with empty shell database"
+       task_createfile "$shelldb"
+       if task_shells check-remove < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ -f "$shelldb_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       return 0
+}
+
+test9()
+{
+       describe="add shells with PKG_DESTDIR"
+       test_destdir_setup
+       if task_shells add < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$shelldb_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       if [ -f "$shelldb" ]; then
+               describe="$describe: $shelldb exists!"
+               return 1
+       fi
+       return 0
+}
+
+test10()
+{
+       describe="verify uniqueness with PKG_DESTDIR"
+       test_destdir_setup
+       task_shells add < $datafile
+       local count=0
+       local line
+       while read line; do
+               case $line in
+               */pdksh*) count="$count + 1" ;;
+               esac
+       done < "${PKG_DESTDIR}${PKG_PREFIX}/$shelldb"
+       count=$(( $count ))
+       if [ $count -gt 1 ]; then
+               describe="$describe: too many pdksh!"
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$shelldb_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       if [ -f "$shelldb" ]; then
+               describe="$describe: $shelldb exists!"
+               return 1
+       fi
+       return 0
+}
+
+test11()
+{
+       describe="check-add shells with all shells added with PKG_DESTDIR"
+       test_destdir_setup
+       task_shells add < $datafile
+       if task_shells check-add < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$shelldb_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       if [ -f "$shelldb" ]; then
+               describe="$describe: $shelldb exists!"
+               return 1
+       fi
+       return 0
+}
+
+test12()
+{
+       describe="check-remove shells with no shells removed with PKG_DESTDIR"
+       test_destdir_setup
+       task_shells add < $datafile
+       if task_shells check-remove < $datafile; then
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$shelldb_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       if [ -f "$shelldb" ]; then
+               describe="$describe: $shelldb exists!"
+               return 1
+       fi
+       return 0
+}
+
+test13()
+{
+       describe="remove shells with PKG_DESTDIR"
+       test_destdir_setup
+       task_shells add < $datafile
+       if task_shells remove < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$shelldb_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       if [ -f "$shelldb" ]; then
+               describe="$describe: $shelldb exists!"
+               return 1
+       fi
+       return 0
+}
+
+test14()
+{
+       describe="verify empty shell database"
+       test_destdir_setup
+       task_shells add < $datafile
+       task_shells remove < $datafile
+       local count=0
+       while read line; do
+               count="$count + 1"
+       done < "${PKG_DESTDIR}${PKG_PREFIX}/$shelldb"
+       count=$(( $count ))
+       if [ $count -gt 0 ]; then
+               return 1
+       fi
+       if [ -f "$shelldb" ]; then
+               describe="$describe: $shelldb exists!"
+               return 1
+       fi
+       return 0
+}
+
+test15()
+{
+       describe="check-remove shells with empty shell database"
+       test_destdir_setup
+       task_createfile "${PKG_DESTDIR}${PKG_PREFIX}/$shelldb"
+       if task_shells check-remove < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if [ -f "${PKG_DESTDIR}${PKG_PREFIX}/$shelldb_lock" ]; then
+               describe="$describe: lock exists!"
+               return 1
+       fi
+       if [ -f "$shelldb" ]; then
+               describe="$describe: $shelldb exists!"
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_shlibs.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_shlibs.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_shlibs.sh        Thu Jun  1 01:58:34 2017
@@ -0,0 +1,106 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load shlibs
+task_load unittest
+
+test_setup()
+{
+       : ${CAT:=cat}
+       : ${GREP:=grep}
+       : ${MV:=mv}
+
+       : ${PKGNAME:=${0##*/}}
+
+       PKG_PREFIX="${TEST_CURDIR}"
+       PKG_DESTDIR=
+
+       datafile="datafile"
+       ${CAT} > $datafile << EOF
+# SHLIB: lib
+EOF
+
+       dbfile="shlibs"
+       dbfile_tmp="$dbfile.tmp.$$"
+       task_createfile "$dbfile"
+}
+
+# Mock ldconfig that just toggles between adding and removing paths
+# from a flat text file.
+#
+ldconfig()
+{
+       : ${GREP:=grep}
+       : ${MV:=mv}
+
+       [ $# -gt 0 ] || set -- ${PKG_PREFIX}/lib
+       for path; do
+               if ${GREP} -q '^'"$path"'$' < $dbfile; then
+                       ${GREP} -v '^'"$path"'$' < $dbfile > $dbfile_tmp
+                       ${MV} -f "$dbfile_tmp" "$dbfile"
+               else
+                       echo "$path" >> $dbfile
+               fi
+       done
+       return 0
+}
+
+test1()
+{
+       describe="add with empty cache"
+       if task_shlibs add < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if ${GREP} -cq "^" "$dbfile"; then
+               : "success"
+       else
+               describe="$describe: not in $dbfile!"
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="remove after adding to cache"
+       task_shlibs add < $datafile
+       if task_shlibs remove < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       if ${GREP} -cq "^" "$dbfile"; then
+               describe="$describe: still in $dbfile!"
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_sort.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_sort.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_sort.sh  Thu Jun  1 01:58:34 2017
@@ -0,0 +1,155 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load sort
+task_load unittest
+
+test_setup()
+{
+       : ${CAT:=cat}
+       : ${CMP:=cmp}
+
+       ${CAT} > data << EOF
+c
+e
+d
+a
+d
+b
+c
+b
+e
+a
+EOF
+       ${CAT} > sorted << EOF
+a
+a
+b
+b
+c
+c
+d
+d
+e
+e
+EOF
+       ${CAT} > reversed << EOF
+e
+e
+d
+d
+c
+c
+b
+b
+a
+a
+EOF
+       ${CAT} > unique-sorted << EOF
+a
+b
+c
+d
+e
+EOF
+       ${CAT} > unique-reversed << EOF
+e
+d
+c
+b
+a
+EOF
+}
+
+test1()
+{
+       describe="sort"
+       task_sort < data > output
+       if ${CMP} -s output sorted; then
+               : "success"
+       else
+               ${CAT} output
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="reverse sort"
+       task_sort -r < data > output
+       if ${CMP} -s output reversed; then
+               : "success"
+       else
+               ${CAT} output
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="empty input"
+       task_createfile empty
+       task_sort < empty > output
+       if ${CMP} -s output empty; then
+               : "success"
+       else
+               ${CAT} output
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="unique sort"
+       task_sort -u < data > output
+       if ${CMP} -s output unique-sorted; then
+               : "success"
+       else
+               ${CAT} output
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="unique reverse-sort"
+       task_sort -ru < data > output
+       if ${CMP} -s output unique-reversed; then
+               : "success"
+       else
+               ${CAT} output
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_taskfunc.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_taskfunc.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_taskfunc.sh      Thu Jun  1 01:58:34 2017
@@ -0,0 +1,173 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load taskfunc
+task_load unittest
+
+test_setup()
+{
+       : ${CAT:=cat}
+       : ${CMP:=cmp}
+
+       ${CAT} > data << EOF
+# ( ) junk
+# TASK: hello  # GREET: world one
+# TASK: bye    # FAREWELL: dear one
+# TASK: hello  # GREET: world two
+# TASK: bye    # FAREWELL: dear two
+# TASK: hello  # GREET: world three
+# TASK: bye    # FAREWELL: dear three
+EOF
+       ${CAT} > expected-add << EOF
+hello add: world one
+hello add: world two
+hello add: world three
+bye add: dear one
+bye add: dear two
+bye add: dear three
+EOF
+       ${CAT} > expected-remove << EOF
+hello remove: world one
+hello remove: world two
+hello remove: world three
+bye remove: dear one
+bye remove: dear two
+bye remove: dear three
+EOF
+}
+
+mock_function()
+{
+       local name="$1"; shift
+       local nametag="$1"; shift
+       local action="$1"; shift
+       local stage="$1"
+
+       case $action in
+       add|remove|check-add|check-remove)
+               : "valid action" ;;
+       *)      return 0 ;;
+       esac
+       case $stage in
+       postinstall|"")
+               : "valid stage" ;;
+       *)      return 0 ;;
+       esac
+
+       local hash tag line
+       while read hash tag line; do
+               case $hash/$tag in
+               "#/$nametag")
+                       case $line in FAIL) return 1 ;; esac
+                       echo "$name $action: $line" ;;
+               esac
+       done
+}
+
+hello()
+{
+       mock_function hello "GREET:" "$@"
+}
+
+bye()
+{
+       mock_function bye "FAREWELL:" "$@"
+}
+
+test1()
+{
+       describe="missing function"
+       if echo "# TASK: missing arg1 arg2 arg3" | task_function add; then
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="add"
+       task_function add < data > value
+       if ${CMP} -s expected-add value; then
+               : "success"
+       else
+               ${CAT} value
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="remove"
+       task_function remove < data > value
+       if ${CMP} -s expected-remove value; then
+               : "success"
+       else
+               ${CAT} value
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="add fail"
+       if echo "# TASK: hello # GREET: FAIL" | task_function add; then
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="wrong stage"
+       task_function add preinstall < data > value
+       task_createfile expected
+       if ${CMP} -s expected value; then
+               : "success"
+       else
+               ${CAT} value
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="correct stage"
+       task_function add postinstall < data > value
+       if ${CMP} -s expected-add value; then
+               : "success"
+       else
+               ${CAT} value
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_tee.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_tee.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_tee.sh   Thu Jun  1 01:58:34 2017
@@ -0,0 +1,133 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load tee
+task_load unittest
+
+test_setup()
+{
+       : ${CAT:=cat}
+       : ${CMP:=cmp}
+       : ${CP:=cp}
+
+       ${CAT} > data << EOF
+line 1
+line 2
+line 3
+line 4
+line 5
+EOF
+}
+
+test1()
+{
+       describe="no files"
+       ${CP} data expected
+       task_tee < data > value
+       if ${CMP} -s expected value; then
+               : "success"
+       else
+               ${CAT} value
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="output files"
+       ${CP} data expected
+       task_tee out1 out2 < data > value
+       if ${CMP} -s expected value; then
+               : "success"
+       else
+               ${CAT} value
+               return 1
+       fi
+       if ${CMP} -s expected out1; then
+               : "success"
+       else
+               describe="$describe: out1"
+               ${CAT} out1
+               return 1
+       fi
+       if ${CMP} -s expected out2; then
+               : "success"
+       else
+               describe="$describe: out2"
+               ${CAT} out2
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="overwrite existing files"
+       ${CP} data expected
+       echo "overwritten" > out
+       task_tee out < data > value
+       if ${CMP} -s expected value; then
+               : "success"
+       else
+               ${CAT} value
+               return 1
+       fi
+       if ${CMP} -s expected out; then
+               : "success"
+       else
+               describe="$describe: out"
+               ${CAT} out
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="append existing files"
+       echo "append" > out
+       ${CP} out expected
+       ${CAT} data >> expected
+       task_tee -a out < data > value
+       if ${CMP} -s data value; then
+               : "success"
+       else
+               ${CAT} value
+               return 1
+       fi
+       if ${CMP} -s expected out; then
+               : "success"
+       else
+               describe="$describe: out"
+               ${CAT} out
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_truthy.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_truthy.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_truthy.sh        Thu Jun  1 01:58:34 2017
@@ -0,0 +1,72 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load truthy
+task_load unittest
+
+test1()
+{
+       describe="task_is_truthy yes"
+       task_is_truthy yes
+}
+
+test2()
+{
+       describe="task_is_truthy true"
+       task_is_truthy true
+}
+
+test3()
+{
+       describe="task_is_truthy on"
+       task_is_truthy on
+}
+
+test4()
+{
+       describe="task_is_truthy 1"
+       task_is_truthy 1
+}
+
+test5()
+{
+       describe="task_is_truthy case-insensitive"
+       task_is_truthy YES
+}
+
+test6()
+{
+       describe="task_is_truthy no"
+       if task_is_truthy no; then
+               return 1
+       else
+               : "success"
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup.sh     Thu Jun  1 01:58:34 2017
@@ -0,0 +1,194 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load unittest
+task_load usergroup
+task_load usergroup_mock
+
+# If this script is not directly included by another script, then define
+# mock platform_groupadd() and platform_useradd() functions needed by
+# usergroup.subr.
+#
+if [ -z "$__platform_usergroup__" ]; then
+       platform_groupadd()
+       {
+               mock_groupadd "$@"
+       }
+
+       platform_useradd()
+       {
+               mock_useradd "$@"
+       }
+fi
+
+test_setup()
+{
+       ETC_GROUP="${TEST_CURDIR}/etc.group"
+       ETC_PASSWD="${TEST_CURDIR}/etc.master.passwd"
+       mock_usergroup_setup
+
+       existent_gid=110
+       existent_group="groupB"
+       nonexistent_gid=300
+       nonexistent_group="groupG"
+
+       existent_uid=110
+       existent_user="userB"
+       nonexistent_uid=300
+       nonexistent_user="userG"
+
+       # Run any platform-specific setup.
+       if task_is_function platform_test_setup; then
+               platform_test_setup
+       fi
+}
+
+test_teardown()
+{
+       # Run any platform-specific teardown.
+       if task_is_function platform_test_teardown; then
+               platform_test_teardown
+       fi
+}
+
+test1()
+{
+       describe="nonexistent group, no groupid"
+       if task_addgroup "$nonexistent_group"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="nonexistent group, nonexistent groupid"
+       if task_addgroup "$nonexistent_group" "$nonexistent_gid"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="nonexistent group, existent groupid"
+       if task_addgroup "$nonexistent_group" "$existent_gid"; then
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="existent group, no groupid"
+       if task_addgroup "$existent_group"; then
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="existent group, nonexistent groupid"
+       if task_addgroup "$existent_group" "$nonexistent_gid"; then
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="existent group, existent groupid"
+       if task_addgroup "$existent_group" "$existent_gid"; then
+               return 1
+       fi
+       return 0
+}
+
+test7()
+{
+       describe="nonexistent user, no userid"
+       if task_adduser "$nonexistent_user" "$existent_group"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test8()
+{
+       describe="nonexistent user, nonexistent userid"
+       if task_adduser "$nonexistent_user" "$existent_group" "$nonexistent_uid"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test9()
+{
+       describe="nonexistent user, existent userid"
+       if task_adduser "$nonexistent_user" "$existent_group" "$existent_uid"; then
+               return 1
+       fi
+       return 0
+}
+
+test10()
+{
+       describe="existent user, no userid"
+       if task_adduser "$existent_user" "$existent_group"; then
+               return 1
+       fi
+       return 0
+}
+
+test11()
+{
+       describe="existent user, nonexistent userid"
+       if task_adduser "$existent_user" "$existent_group" "$nonexistent_uid"; then
+               return 1
+       fi
+       return 0
+}
+
+test12()
+{
+       describe="existent user, existent userid"
+       if task_adduser "$existent_user" "$existent_group" "$existent_uid"; then
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_FreeBSD.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_FreeBSD.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_FreeBSD.sh     Thu Jun  1 01:58:34 2017
@@ -0,0 +1,53 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load unittest
+task_load usergroup_mock
+
+# Mock uname to select usergroup_FreeBSD.subr.
+uname()
+{
+       # DragonFly also uses usergroup_FreeBSD.subr.
+       echo "DragonFly"
+}
+
+# Mock pw needed for usergroup_FreeBSD.subr.
+pw()
+{
+       case $1 in
+       groupadd)
+               local group="$2"; shift 2
+               mock_groupadd "$@" "$group" ;;
+       useradd)
+               local user="$2"; shift 2
+               mock_useradd "$@" "$user" ;;
+       esac
+}
+
+__platform_usergroup__="yes"
+
+task_load_test t_usergroup "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_Linux.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_Linux.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_Linux.sh       Thu Jun  1 01:58:34 2017
@@ -0,0 +1,102 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load quote
+task_load unittest
+task_load usergroup_mock
+
+# Mock uname() to select usergroup_Linux.subr.
+uname()
+{
+       echo "Linux"
+}
+
+# Mock groupadd and useradd needed for usergroup_Linux.subr.
+groupadd()
+{
+       # Skip "-r" and pass all other options through to mock_groupadd().
+       local groupadd_args=
+       local quoted
+       local arg
+       local OPTIND=1
+       while getopts ":g:r" arg "$@"; do
+               case $arg in
+               g)      task_quote "${OPTARG}"
+                       groupadd_args="$groupadd_args -$arg $quoted" ;;
+               r)      : "silently accept" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -eq 1 ] || return 127
+       local group="$1"; shift
+
+       [ -n "$group" ] || return 1
+       task_quote "$group"
+       groupadd_args="$groupadd_args $quoted"
+
+       eval mock_groupadd $groupadd_args
+}
+
+useradd()
+{
+       # Skip "-M" and "-r" and pass all other options through to
+       # mock_useradd().
+       #
+       local useradd_args=
+       local quoted
+       local arg
+       local OPTIND=1
+       while getopts ":c:d:g:Mrs:u:" arg "$@"; do
+               case $arg in
+               [Mr])   : "silently accept" ;;
+               [cdgsu])
+                       task_quote "${OPTARG}"
+                       useradd_args="$useradd_args -$arg $quoted" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -eq 1 ] || return 127
+       local user="$1"; shift
+
+       [ -n "$user" ] || return 1
+       task_quote "$user"
+       useradd_args="$useradd_args $quoted"
+
+       eval mock_useradd $useradd_args
+}
+
+platform_test_setup()
+{
+       LOGIN_DEFS="${TEST_CURDIR}/etc.login.defs"
+       echo "CREATE_HOME       yes" > ${LOGIN_DEFS}
+}
+
+__platform_usergroup__="yes"
+
+task_load_test t_usergroup "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_MirBSD.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_MirBSD.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_MirBSD.sh      Thu Jun  1 01:58:34 2017
@@ -0,0 +1,378 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# Mock uname() to select usergroup_MirBSD.subr.
+uname()
+{
+       echo "MirBSD"
+}
+
+task_load unittest
+task_load usergroup
+
+test_setup()
+{
+       : ${CAT:=cat}
+       : ${GREP:=grep}
+       : ${MV:=mv}
+
+       ETC_GROUP="${TEST_CURDIR}/etc.group"
+       ${CAT} > ${ETC_GROUP} << EOF
+groupA:*:100:
+groupB:*:105:
+groupC:*:110:
+EOF
+       existent_gid=110
+       existent_group="groupB"
+       matching_gid=105
+       nonexistent_gid=300
+       nonexistent_group="groupG"
+
+       ETC_PASSWD="${TEST_CURDIR}/etc.master.passwd"
+       ${CAT} > ${ETC_PASSWD} << EOF
+userA:*:100:100::0:0:package A user:/nonexistent:/bin/sh
+userB:*:105:105::0:0:package B user:/nonexistent:/bin/sh
+userC:*:110:110::0:0:package C user:/nonexistent:/bin/sh
+EOF
+       existent_uid=110
+       existent_user="userB"
+       nonexistent_uid=300
+       nonexistent_user="userG"
+
+       # Set CHOWN and PWD_MKDB to "working" mocks.
+       CHOWN="chown"
+       PWD_MKDB="pwd_mkdb"
+}
+
+# Mock utilities needed by MirBSD platform_groupadd() and platform_useradd().
+chown()
+{
+       return 0
+}
+
+mock_false()
+{
+       return 1
+}
+
+pwd_mkdb()
+{
+       local arg
+       local OPTIND=1
+       while getopts ":cd:psu:" arg "$@"; do
+               case $arg in
+               [cpsdu])
+                       : "silently ignore" ;;
+               *)      return 127 ;;
+               esac
+       done
+       shift $(( ${OPTIND} - 1 ))
+       [ $# -gt 0 ] || return 127
+
+       ${MV} -f "$1" "${ETC_PASSWD}"
+}
+
+test1()
+{
+       describe="nonexistent group, no groupid"
+       if task_addgroup "$nonexistent_group"; then
+               : "success"
+       else
+               return 1
+       fi
+       if ${GREP} -q "^$nonexistent_group:" "${ETC_GROUP}"; then
+               : "success"
+       else
+               describe="$describe: group missing!"
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="nonexistent group, nonexistent groupid"
+       if task_addgroup "$nonexistent_group" "$nonexistent_gid"; then
+               : "success"
+       else
+               return 1
+       fi
+       if ${GREP} -q "^$nonexistent_group:[^:]*:$nonexistent_gid:" "${ETC_GROUP}"; then
+               : "success"
+       else
+               describe="$describe: group missing!"
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="nonexistent group, existent groupid"
+       if task_addgroup "$nonexistent_group" "$existent_gid"; then
+               return 1
+       fi
+       if ${GREP} -q "^$nonexistent_group:" "${ETC_GROUP}"; then
+               describe="$describe: group exists!"
+               return 1
+       fi
+       if ${GREP} -q "^[^:]*:[^:]*:$existent_gid:" "${ETC_GROUP}"; then
+               : "success"
+       else
+               describe="$describe: group ID missing!"
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="existent group, no groupid"
+       if task_addgroup "$existent_group"; then
+               return 1
+       fi
+       if ${GREP} -q "^$existent_group:" "${ETC_GROUP}"; then
+               : "success"
+       else
+               describe="$describe: group missing!"
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="existent group, nonexistent groupid"
+       if task_addgroup "$existent_group" "$nonexistent_gid"; then
+               return 1
+       fi
+       if ${GREP} -q "^$existent_group:" "${ETC_GROUP}"; then
+               : "success"
+       else
+               describe="$describe: group missing!"
+               return 1
+       fi
+       if ${GREP} -q "^[^:]*:[^:]*:$nonexistent_gid:" "${ETC_GROUP}"; then
+               describe="$describe: group ID exists!"
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="existent group, existent groupid"
+       if task_addgroup "$existent_group" "$existent_gid"; then
+               return 1
+       fi
+       if ${GREP} -q "^$existent_group:" "${ETC_GROUP}"; then
+               : "success"
+       else
+               describe="$describe: group missing!"
+               return 1
+       fi
+       if ${GREP} -q "^[^:]*:[^:]*:$existent_gid:" "${ETC_GROUP}"; then
+               : "success"
+       else
+               describe="$describe: group ID missing!"
+               return 1
+       fi
+       return 0
+}
+
+test7()
+{
+       describe="broken chown(8) when adding group"
+       CHOWN="mock_false"
+       if task_addgroup "$nonexistent_group"; then
+               return 1
+       fi
+       if ${GREP} -q "^$nonexistent_group:" "${ETC_GROUP}"; then
+               describe="$describe: group exists!"
+               return 1
+       fi
+       set -- ${ETC_GROUP}.tmp.*
+       case $1 in
+       "${ETC_GROUP}.tmp.*")
+               : "group tmpdir not found" ;;
+       *)      describe="$describe: group tmpdir exists!"
+               return 1 ;;
+       esac
+       return 0
+}
+
+test8()
+{
+       describe="nonexistent user, no userid"
+       if task_adduser "$nonexistent_user" "$existent_group"; then
+               : "success"
+       else
+               return 1
+       fi
+       if ${GREP} -q "^$nonexistent_user:[^:]*:[^:]*:$matching_gid:" "${ETC_PASSWD}"; then
+               : "success"
+       else
+               describe="$describe: user missing!"
+               return 1
+       fi
+       return 0
+}
+
+test9()
+{
+       describe="nonexistent user, nonexistent userid"
+       if task_adduser "$nonexistent_user" "$existent_group" "$nonexistent_uid"; then
+               : "success"
+       else
+               return 1
+       fi
+       if ${GREP} -q "^$nonexistent_user:[^:]*:$nonexistent_uid:$matching_gid:" "${ETC_PASSWD}"; then
+               : "success"
+       else
+               describe="$describe: user missing!"
+               return 1
+       fi
+       return 0
+}
+
+test10()
+{
+       describe="nonexistent user, existent userid"
+       if task_adduser "$nonexistent_user" "$existent_group" "$existent_uid"; then
+               return 1
+       fi
+       if ${GREP} -q "^$nonexistent_user:" "${ETC_PASSWD}"; then
+               describe="$describe: user exists!"
+               return 1
+       fi
+       if ${GREP} -q "^[^:]*:[^:]*:[^:]*:$existent_uid:" "${ETC_PASSWD}"; then
+               : "success"
+       else
+               describe="$describe: user ID missing!"
+               return 1
+       fi
+       return 0
+}
+
+test11()
+{
+       describe="existent user, no userid"
+       if task_adduser "$existent_user" "$existent_group"; then
+               return 1
+       fi
+       if ${GREP} -q "^$existent_user:" "${ETC_PASSWD}"; then
+               : "success"
+       else
+               describe="$describe: user missing!"
+               return 1
+       fi
+       return 0
+}
+
+test12()
+{
+       describe="existent user, nonexistent userid"
+       if task_adduser "$existent_user" "$existent_group" "$nonexistent_uid"; then
+               return 1
+       fi
+       if ${GREP} -q "^$existent_user:" "${ETC_PASSWD}"; then
+               : "success"
+       else
+               describe="$describe: user missing!"
+               return 1
+       fi
+       if ${GREP} -q "^[^:]*:[^:]*:[^:]*:$nonexistent_uid:" "${ETC_PASSWD}"; then
+               describe="$describe: user ID exists!"
+               return 1
+       fi
+       return 0
+}
+
+test13()
+{
+       describe="existent user, existent userid"
+       if task_adduser "$existent_user" "$existent_group" "$existent_uid"; then
+               return 1
+       fi
+       if ${GREP} -q "^$existent_user:" "${ETC_PASSWD}"; then
+               : "success"
+       else
+               describe="$describe: user missing!"
+               return 1
+       fi
+       if ${GREP} -q "^[^:]*:[^:]*:[^:]*:$existent_uid:" "${ETC_PASSWD}"; then
+               : "success"
+       else
+               describe="$describe: user ID missing!"
+               return 1
+       fi
+       return 0
+}
+
+test14()
+{
+       describe="broken chown(8) when adding user"
+       CHOWN="mock_false"
+       if task_adduser "$nonexistent_user" "$existent_group"; then
+               return 1
+       fi
+       if ${GREP} -q "^$nonexistent_user:" "${ETC_PASSWD}"; then
+               describe="$describe: user exists!"
+               return 1
+       fi
+       set -- ${ETC_PASSWD}.tmp.*
+       case $1 in
+       "${ETC_PASSWD}.tmp.*")
+               : "user tmpdir not found" ;;
+       *)      describe="$describe: user tmpdir exists!"
+               return 1 ;;
+       esac
+       return 0
+}
+
+test15()
+{
+       describe="broken pwd_mkdb(8) when adding user"
+       PWD_MKDB="mock_false"
+       if task_adduser "$nonexistent_user" "$existent_group"; then
+               return 1
+       fi
+       if ${GREP} -q "^$nonexistent_user:" "${ETC_PASSWD}"; then
+               describe="$describe: user exists!"
+               return 1
+       fi
+       set -- ${ETC_PASSWD}.tmp.*
+       case $1 in
+       "${ETC_PASSWD}.tmp.*")
+               : "user tmpdir not found" ;;
+       *)      describe="$describe: user tmpdir exists!"
+               return 1 ;;
+       esac
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_NetBSD.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_NetBSD.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_NetBSD.sh      Thu Jun  1 01:58:34 2017
@@ -0,0 +1,51 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load unittest
+task_load usergroup_mock
+
+# Mock uname() to select usergroup_NetBSD.subr.
+uname()
+{
+       # SunOS also uses usergroup_NetBSD.subr.
+       echo "SunOS"
+}
+
+# Mock groupadd and useradd needed for usergroup_NetBSD.subr
+groupadd()
+{
+       mock_groupadd "$@"
+}
+
+useradd()
+{
+       mock_useradd "$@"
+}
+
+__platform_usergroup__="yes"
+
+task_load_test t_usergroup "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_exists.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_exists.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_exists.sh      Thu Jun  1 01:58:34 2017
@@ -0,0 +1,206 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load unittest
+task_load usergroup_exists
+
+test_setup()
+{
+       : ${MKDIR:=mkdir}
+
+       TMPDIR="${TEST_CURDIR}/tmp"
+       ${MKDIR} -p "${TMPDIR}"
+
+       # These values may need to be corrected.
+       existent_gid=32766
+       existent_group="nogroup"
+       nonexistent_gid=27777
+       nonexistent_group="nonexistent_group"
+
+       existent_uid=32767
+       existent_user="nobody"
+       nonexistent_uid=27777
+       nonexistent_user="nonexistent_user"
+}
+
+test1()
+{
+       describe="nonexistent group, no groupid"
+       task_requires_root || return 0
+       task_group_exists $nonexistent_group
+       local result=$?
+       if [ $result -ne 1 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="nonexistent group, nonexistent groupid"
+       task_requires_root || return 0
+       task_group_exists $nonexistent_group $nonexistent_gid
+       local result=$?
+       if [ $result -ne 1 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="nonexistent group, existent groupid"
+       task_requires_root || return 0
+       task_group_exists $nonexistent_group $existent_gid
+       local result=$?
+       if [ $result -ne 2 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="existent group, no groupid"
+       task_requires_root || return 0
+       task_group_exists $existent_group
+       local result=$?
+       if [ $result -ne 0 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="existent group, nonexistent groupid"
+       task_requires_root || return 0
+       task_group_exists $existent_group $nonexistent_gid
+       local result=$?
+       if [ $result -ne 2 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="existent group, existent groupid"
+       task_requires_root || return 0
+       task_group_exists $existent_group $existent_gid
+       local result=$?
+       if [ $result -ne 0 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test7()
+{
+       describe="nonexistent user, no userid"
+       task_requires_root || return 0
+       task_user_exists $nonexistent_user
+       local result=$?
+       if [ $result -ne 1 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test8()
+{
+       describe="nonexistent user, nonexistent userid"
+       task_requires_root || return 0
+       task_user_exists $nonexistent_user $nonexistent_uid
+       local result=$?
+       if [ $result -ne 1 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test9()
+{
+       describe="nonexistent user, existent userid"
+       task_requires_root || return 0
+       task_user_exists $nonexistent_user $existent_uid
+       local result=$?
+       if [ $result -ne 2 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test10()
+{
+       describe="existent user, no userid"
+       task_requires_root || return 0
+       task_user_exists $existent_user
+       local result=$?
+       if [ $result -ne 0 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test11()
+{
+       describe="existent user, nonexistent userid"
+       task_requires_root || return 0
+       task_user_exists $existent_user $nonexistent_uid
+       local result=$?
+       if [ $result -ne 2 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test12()
+{
+       describe="existent user, existent userid"
+       task_requires_root || return 0
+       task_user_exists $existent_user $existent_uid
+       local result=$?
+       if [ $result -ne 0 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_mock.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_mock.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_usergroup_mock.sh        Thu Jun  1 01:58:34 2017
@@ -0,0 +1,334 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load unittest
+task_load usergroup_mock
+
+test_setup()
+{
+       ETC_GROUP="${TEST_CURDIR}/etc.group"
+       ETC_PASSWD="${TEST_CURDIR}/etc.passwd"
+       mock_usergroup_setup
+
+       existent_gid=110
+       existent_group="groupB"
+       matching_gid=105
+       nonexistent_gid=300
+       nonexistent_group="groupG"
+
+       existent_uid=110
+       existent_user="userB"
+       matching_gid=105
+       nonexistent_uid=200
+       nonexistent_user="userD"
+}
+
+test1()
+{
+       describe="exists: nonexistent group, no groupid"
+       mock_group_exists $nonexistent_group
+       local result=$?
+       if [ $result -ne 1 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="exists: nonexistent group, nonexistent groupid"
+       mock_group_exists $nonexistent_group $nonexistent_gid
+       local result=$?
+       if [ $result -ne 1 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="exists: nonexistent group, existent groupid"
+       mock_group_exists $nonexistent_group $existent_gid
+       local result=$?
+       if [ $result -ne 2 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="exists: existent group, no groupid"
+       mock_group_exists $existent_group
+       local result=$?
+       if [ $result -ne 0 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="exists: existent group, nonexistent groupid"
+       mock_group_exists $existent_group $nonexistent_gid
+       local result=$?
+       if [ $result -ne 2 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="exists: existent group, existent groupid"
+       mock_group_exists $existent_group $existent_gid
+       local result=$?
+       if [ $result -ne 2 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test7()
+{
+       describe="exists: existent group, matching groupid"
+       mock_group_exists $existent_group $matching_gid
+       local result=$?
+       if [ $result -ne 0 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test8()
+{
+       describe="exists: nonexistent user, no userid"
+       mock_user_exists $nonexistent_user
+       local result=$?
+       if [ $result -ne 1 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test9()
+{
+       describe="exists: nonexistent user, nonexistent userid"
+       mock_user_exists $nonexistent_user $nonexistent_uid
+       local result=$?
+       if [ $result -ne 1 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test10()
+{
+       describe="exists: nonexistent user, existent userid"
+       mock_user_exists $nonexistent_user $existent_uid
+       local result=$?
+       if [ $result -ne 2 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test11()
+{
+       describe="exists: existent user, no userid"
+       mock_user_exists $existent_user
+       local result=$?
+       if [ $result -ne 0 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test12()
+{
+       describe="exists: existent user, nonexistent userid"
+       mock_user_exists $existent_user $nonexistent_uid
+       local result=$?
+       if [ $result -ne 2 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test13()
+{
+       describe="exists: existent user, existent userid"
+       mock_user_exists $existent_user $existent_uid
+       local result=$?
+       if [ $result -ne 2 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test14()
+{
+       describe="exists: existent user, matching userid"
+       mock_user_exists $existent_user $matching_uid
+       local result=$?
+       if [ $result -ne 0 ]; then
+               describe="$describe: $result"
+               return 1
+       fi
+       return 0
+}
+
+test15()
+{
+       describe="add: nonexistent group, no groupid"
+       if mock_groupadd "$nonexistent_group"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test16()
+{
+       describe="add: nonexistent group, nonexistent groupid"
+       if mock_groupadd -g "$nonexistent_gid" "$nonexistent_group"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test17()
+{
+       describe="add: nonexistent group, existent groupid"
+       if mock_groupadd -g "$existent_gid" "$nonexistent_group"; then
+               return 1
+       fi
+       return 0
+}
+
+test18()
+{
+       describe="add: existent group, no groupid"
+       if mock_groupadd "$existent_group"; then
+               return 1
+       fi
+       return 0
+}
+
+test19()
+{
+       describe="add: existent group, nonexistent groupid"
+       if mock_groupadd -g "$nonexistent_gid" "$existent_group"; then
+               return 1
+       fi
+       return 0
+}
+
+test20()
+{
+       describe="add: existent group, existent groupid"
+       if mock_groupadd -g "$existent_gid" "$existent_group"; then
+               return 1
+       fi
+       return 0
+}
+
+test21()
+{
+       describe="add: nonexistent user, no userid"
+       if mock_useradd -g "$existent_group" "$nonexistent_user"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test22()
+{
+       describe="add: nonexistent user, nonexistent userid"
+       if mock_useradd -g "$existent_group" -u "$nonexistent_uid" "$nonexistent_user"; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test23()
+{
+       describe="add: nonexistent user, existent userid"
+       if mock_useradd -g "$existent_group" -u "$existent_uid" "$nonexistent_user"; then
+               return 1
+       fi
+       return 0
+}
+
+test24()
+{
+       describe="add: existent user, no userid"
+       if mock_useradd -g "$existent_group" "$existent_user"; then
+               return 1
+       fi
+       return 0
+}
+
+test25()
+{
+       describe="add: existent user, nonexistent userid"
+       if mock_useradd -g "$existent_group" -u "$nonexistent_uid" "$existent_user"; then
+               return 1
+       fi
+       return 0
+}
+
+test26()
+{
+       describe="add: existent user, existent userid"
+       if mock_useradd -g "$existent_group" -u "$existent_uid" "$existent_user"; then
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_users.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_users.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_users.sh Thu Jun  1 01:58:34 2017
@@ -0,0 +1,194 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load unittest
+task_load usergroup_mock
+task_load users
+
+# Mock platform_useradd() needed by usergroup.subr, and task_user_exists()
+# needed by users.subr.
+#
+platform_useradd()
+{
+       mock_useradd "$@"
+}
+
+task_user_exists()
+{
+       mock_user_exists "$@"
+}
+
+test_setup()
+{
+       : ${CAT:=cat}
+       : ${MKDIR:=mkdir}
+
+       PKG_DBDIR="${TEST_CURDIR}/var/db/pkg"
+       PKG_REFCOUNT_DBDIR="${PKG_DBDIR}.refcount"
+       ${MKDIR} -p "${PKG_DBDIR}"
+
+       ETC_GROUP="${TEST_CURDIR}/etc.group"
+       ETC_PASSWD="${TEST_CURDIR}/etc.passwd"
+       mock_usergroup_setup
+
+       datafile="datafile"
+       ${CAT} > $datafile << EOF
+# USER: userD:groupD
+# USER: userE:groupE:200
+# USER: userF:groupF:205
+EOF
+}
+
+test1()
+{
+       describe="check-add missing users"
+       if task_users check-add < $datafile; then
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="add nonexistent users"
+       if task_users add < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       local name
+       for name in userD userE userF; do
+               if task_user_exists "$name"; then
+                       : "success"
+               else
+                       describe="$describe: missing $name"
+                       return 1
+               fi
+       done
+       return 0
+}
+
+test3()
+{
+       describe="add existent and nonexistent users"
+       task_adduser userE groupE 200
+       if task_users add < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       local name
+       for name in userD userE userF; do
+               if task_user_exists "$name"; then
+                       : "success"
+               else
+                       describe="$describe: missing $name"
+                       return 1
+               fi
+       done
+       return 0
+}
+
+test4()
+{
+       describe="add conflicting user"
+       task_adduser userE groupE 300
+       if task_users add < $datafile; then
+               return 1
+       fi
+       return 0
+}
+
+test5()
+{
+       describe="check-add users with all users added"
+       task_users add < $datafile
+       if task_users check-add < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test6()
+{
+       describe="check-remove users with no users removed"
+       task_users add < $datafile
+       if task_users check-remove < $datafile; then
+               return 1
+       fi
+       return 0
+}
+
+test7()
+{
+       describe="remove existent users"
+       task_users add < $datafile
+       # This always returns 0 because no users are ever removed.
+       if task_users remove < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       local name
+       for name in userD userE userF; do
+               # No users should have been removed.
+               if task_user_exists "$name"; then
+                       : "success"
+               else
+                       describe="$describe: missing $name"
+                       return 1
+               fi
+       done
+       return 0
+}
+
+test8()
+{
+       describe="remove nonexistent users"
+       # This always returns 0 because no users are ever removed.
+       if task_users remove < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+test9()
+{
+       describe="check-remove users with users already removed"
+       if task_users check-remove < $datafile; then
+               : "success"
+       else
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_valid_options.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_valid_options.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_valid_options.sh Thu Jun  1 01:58:34 2017
@@ -0,0 +1,95 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load valid_options
+task_load unittest
+
+test1()
+{
+       describe="valid substring"
+       task_valid_options "ab" "abcd."
+}
+
+test2()
+{
+       describe="valid first character"
+       task_valid_options "a" "abcd."
+}
+
+test3()
+{
+       describe="valid middle character"
+       task_valid_options "b" "abcd."
+}
+
+test4()
+{
+       describe="valid last character"
+       task_valid_options "." "abcd."
+}
+
+test5()
+{
+       describe="invalid substring"
+       if task_valid_options "abCD" "abcd."; then
+               return 1
+       fi
+}
+
+test6()
+{
+       describe="invalid first character"
+       if task_valid_options "Abc" "abcd."; then
+               return 1
+       fi
+}
+
+test7()
+{
+       describe="invalid middle character"
+       if task_valid_options "aBc" "abcd."; then
+               return 1
+       fi
+}
+
+test8()
+{
+       describe="invalid last character"
+       if task_valid_options "abD" "abcd."; then
+               return 1
+       fi
+}
+
+test9()
+{
+       describe="invalid only"
+       if task_valid_options "C" "abcd."; then
+               return 1
+       fi
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_version.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_version.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_version.sh       Thu Jun  1 01:58:34 2017
@@ -0,0 +1,322 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load unittest
+task_load version 2>/dev/null || task_load -s ".subr.in" version
+
+test1()
+{
+       describe="1 < 1+1"
+       task_version_compare -v 1 1+1
+}
+
+test2()
+{
+       describe="1.0 < 1.0.1"
+       task_version_compare -v 1.0 1.0.1
+}
+
+test3()
+{
+       describe="1.23.2 < 1.23.11"
+       task_version_compare -v 1.23.2 1.23.11
+}
+
+test4()
+{
+       describe="1.2alpha < 1.2"
+       task_version_compare -v 1.2alpha 1.2
+}
+
+test5()
+{
+       describe="1.2alpha < 1.2alpha1"
+       task_version_compare -v 1.2alpha 1.2alpha1
+}
+
+test6()
+{
+       describe="1.2alpha2 < 1.2alpha11"
+       task_version_compare -v 1.2alpha2 1.2alpha11
+}
+
+test7()
+{
+       describe="1.2alpha < 1.2beta"
+       task_version_compare -v 1.2alpha 1.2beta
+}
+
+test8()
+{
+       describe="1.2alpha < 1.2rc"
+       task_version_compare -v 1.2alpha 1.2rc
+}
+
+test9()
+{
+       describe="1.2beta < 1.2rc"
+       task_version_compare -v 1.2beta 1.2rc
+}
+
+test10()
+{
+       describe="1.2alpha < 1.2e"
+       task_version_compare -v 1.2alpha 1.2e
+}
+
+test11()
+{
+       describe="1.2a < 1.2b"
+       task_version_compare -v 1.2a 1.2b
+}
+
+test12()
+{
+       describe="1.2a2 < 1.2a11"
+       task_version_compare -v 1.2a2 1.2a11
+}
+
+test13()
+{
+       describe="1.2rc1 < 1.2a"
+       task_version_compare -v 1.2rc1 1.2a
+}
+
+test14()
+{
+       describe="1.2 < 1.2+1"
+       task_version_compare -v 1.2 1.2+1
+}
+
+test15()
+{
+       describe="1.2alpha99 < 1.2+1"
+       task_version_compare -v 1.2alpha99 1.2+1
+}
+
+test16()
+{
+       describe="1.2+2 < 1.2+11"
+       task_version_compare -v 1.2+2 1.2+11
+}
+
+test17()
+{
+       describe="(null) < 1.0"
+       task_version_compare -v "" "1.0"
+}
+
+test18()
+{
+       describe="1.2.5 = 1.2e"
+       task_version_compare -v 1.2.5 1.2e
+       [ $? -eq 1 ]
+}
+
+test19()
+{
+       describe="1.0.0 = 1.0.0"
+       task_version_compare -v 1.0.0 1.0.0
+       [ $? -eq 1 ]
+}
+
+test20()
+{
+       describe="1.2.3 < 1abc2.3"
+       task_version_compare -v 1.2.3 1abc2.3
+}
+
+test21()
+{
+       describe="Bravo < Charlie"
+       task_version_compare -v Bravo Charlie
+}
+
+test22()
+{
+       describe="1.2+1 < 1.2.1"
+       task_version_compare -v 1.2+1 1.2.1
+}
+
+test23()
+{
+       describe="1_2_0 = 1.2.0"
+       task_version_compare -v 1_2_0 1.2.0
+       [ $? -eq 1 ]
+}
+
+test24()
+{
+       describe="1.2alpha < 1.2alpha+1"
+       task_version_compare -v 1.2alpha 1.2alpha+1
+}
+
+test25()
+{
+       describe="1.2~ < 1.2"
+       task_version_compare -v 1.2~ 1.2
+}
+
+test26()
+{
+       describe="1.2~alpha1 = 1.2alpha1"
+       task_version_compare -v 1.2~alpha1 1.2alpha1
+       [ $? -eq 1 ]
+}
+
+test27()
+{
+       describe="1.2~a1 < 1.2alpha1"
+       task_version_compare -v 1.2~a1 1.2alpha1
+}
+
+test28()
+{      describe="1.2~a~b < 1.2~a"
+       task_version_compare -v 1.2~a~b 1.2~a
+}
+
+test29()
+{
+       describe="1.2alpha1 < 1.2~b1"
+       task_version_compare -v 1.2alpha1 1.2~b1
+}
+
+test30()
+{
+       describe="~~ < ~"
+       task_version_compare -v "~~" "~"
+}
+
+test31()
+{
+       describe="~ < ~a"
+       task_version_compare -v "~" "~a"
+}
+
+test32()
+{
+       describe="version_check 1.2 >= 1.0"
+       task_version_check 1.2 ">=" 1.0
+}
+
+test33()
+{
+       describe="version_check 1.2 >= 2.0 is false"
+       if task_version_check 1.2 ">=" 2.0; then
+               return 1
+       fi
+}
+
+test34()
+{
+       describe="version_check 1.2 > 1.0"
+       task_version_check 1.2 ">" 1.0
+}
+
+test35()
+{
+       describe="version_check 1.2 > 2.0 is false"
+       if task_version_check 1.2 ">" 2.0; then
+               return 1
+       fi
+}
+
+test36()
+{
+       describe="version_check 1.2 = 1.2"
+       task_version_check 1.2 "=" 1.2
+}
+
+test37()
+{
+       describe="version_check 1.2 = 2.0 is false"
+       if task_version_check 1.2 "=" 2.0; then
+               return 1
+       fi
+}
+
+test38()
+{
+       describe="version_check 1.2 < 2.0"
+       task_version_check 1.2 "<" 2.0
+}
+
+test39()
+{
+       describe="version_check 1.2 < 1.0 is false"
+       if task_version_check 1.2 "<" 1.0; then
+               return 1
+       fi
+}
+
+test40()
+{
+       describe="version_check 1.2 <= 2.0"
+       task_version_check 1.2 "<=" 2.0
+}
+
+test41()
+{
+       describe="version_check 1.2 <= 1.0 is false"
+       if task_version_check 1.2 "<=" 1.0; then
+               return 1
+       fi
+}
+
+test42()
+{
+       describe="version_check 1.2 *"
+       task_version_check 1.2 "*" ""
+}
+
+test43()
+{
+       describe="version_check 1.2 >= 1.0 < 2.0"
+       task_version_check 1.2 ">=" 1.0 "<" 2.0
+}
+
+test44()
+{
+       describe="version_check 1.2 >= 1.0 < 1.1 is false"
+       if task_version_check 1.2 ">=" 1.0 "<" 1.1; then
+               return 1
+       fi
+}
+
+test45()
+{
+       describe="version_check Charlie < Delta"
+       task_version_check Charlie "<" Delta
+}
+
+test46()
+{
+       describe="version_check Delta > Charlie"
+       task_version_check Delta ">" Charlie
+}
+
+task_run_tests "$@"
Index: pkgsrc/pkgtools/pkgtasks/files/t/t_which.sh
diff -u /dev/null pkgsrc/pkgtools/pkgtasks/files/t/t_which.sh:1.1
--- /dev/null   Thu Jun  1 01:58:34 2017
+++ pkgsrc/pkgtools/pkgtasks/files/t/t_which.sh Thu Jun  1 01:58:34 2017
@@ -0,0 +1,96 @@
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+task_load createfile
+task_load makedir
+task_load which
+task_load unittest
+
+test_setup()
+{
+       : ${CHMOD:=chmod}
+
+       task_makedir bin usr/bin
+       task_createfile bin/cmd1 usr/bin/cmd2
+       ${CHMOD} +x bin/cmd1 usr/bin/cmd2
+
+       TEST_PATH="${TEST_CURDIR}/bin:${TEST_CURDIR}/usr/bin"
+}
+
+test1()
+{
+       describe="cmd in first directory"
+       local expected value
+       expected="${TEST_CURDIR}/bin/cmd1"
+       value=$( PATH="${TEST_PATH}" task_which cmd1 )
+       if [ "$value" != "$expected" ]; then
+               echo "$value"
+               return 1
+       fi
+       return 0
+}
+
+test2()
+{
+       describe="cmd in second directory"
+       local expected value
+       expected="${TEST_CURDIR}/usr/bin/cmd2"
+       value=$( PATH="${TEST_PATH}" task_which cmd2 )
+       if [ "$value" != "$expected" ]; then
+               echo "$value"
+               return 1
+       fi
+       return 0
+}
+
+test3()
+{
+       describe="cmd in no directories"
+       local expected value
+       expected=""
+       value=$( PATH="${TEST_PATH}" task_which cmd3 )
+       if [ "$value" != "$expected" ]; then
+               echo "$value"
+               return 1
+       fi
+       return 0
+}
+
+test4()
+{
+       describe="empty cmd"
+       local expected value
+       expected=""
+       value="$( task_which '' )"
+       if [ "$value" != "$expected" ]; then
+               echo "$value"
+               return 1
+       fi
+       return 0
+}
+
+task_run_tests "$@"



Home | Main Index | Thread Index | Old Index