summaryrefslogtreecommitdiff
path: root/sys-freebsd
diff options
context:
space:
mode:
authorV3n3RiX <venerix@redcorelinux.org>2019-10-13 22:11:03 +0100
committerV3n3RiX <venerix@redcorelinux.org>2019-10-13 22:11:03 +0100
commit2929788def9a92c1eb237eed93fbdb0c02838bbf (patch)
tree166b01591366d3479084ea774c888bc84aaa8d4f /sys-freebsd
parentab499d7cfb9ad23e83cf7a4f5052bdf1b4c42030 (diff)
Revert "gentoo resync : 13.10.2019"
This reverts commit ab499d7cfb9ad23e83cf7a4f5052bdf1b4c42030.
Diffstat (limited to 'sys-freebsd')
-rw-r--r--sys-freebsd/Manifest.gzbin0 -> 2710 bytes
-rw-r--r--sys-freebsd/boot0/Manifest5
-rw-r--r--sys-freebsd/boot0/boot0-11.1.ebuild86
-rw-r--r--sys-freebsd/boot0/files/boot0-11.0-gcc46.patch14
-rw-r--r--sys-freebsd/boot0/files/boot0-add-nossp-cflags.patch11
-rw-r--r--sys-freebsd/boot0/metadata.xml12
-rw-r--r--sys-freebsd/freebsd-bin/Manifest3
-rw-r--r--sys-freebsd/freebsd-bin/freebsd-bin-11.1.ebuild41
-rw-r--r--sys-freebsd/freebsd-bin/metadata.xml8
-rw-r--r--sys-freebsd/freebsd-cddl/Manifest18
-rw-r--r--sys-freebsd/freebsd-cddl/files/freebsd-cddl-11.0-add-libs.patch87
-rw-r--r--sys-freebsd/freebsd-cddl/files/freebsd-cddl-11.0-workaround.patch12
-rw-r--r--sys-freebsd/freebsd-cddl/files/freebsd-cddl-9.0-bsdxml.patch28
-rw-r--r--sys-freebsd/freebsd-cddl/files/freebsd-cddl-9.0-libpaths.patch167
-rw-r--r--sys-freebsd/freebsd-cddl/files/freebsd-cddl-9.0-underlink.patch22
-rw-r--r--sys-freebsd/freebsd-cddl/files/zfs.initd23
-rw-r--r--sys-freebsd/freebsd-cddl/files/zvol.initd-9.044
-rw-r--r--sys-freebsd/freebsd-cddl/freebsd-cddl-11.1.ebuild77
-rw-r--r--sys-freebsd/freebsd-cddl/freebsd-cddl-9.1.ebuild60
-rw-r--r--sys-freebsd/freebsd-cddl/metadata.xml8
-rw-r--r--sys-freebsd/freebsd-lib/Manifest45
-rw-r--r--sys-freebsd/freebsd-lib/files/bootpd.confd7
-rw-r--r--sys-freebsd/freebsd-lib/files/bootpd.initd27
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-11.0-bsdxml2expat.patch39
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-11.0-libproc-libcxx.patch13
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-11.0-workaround.patch12
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-11.1-elf-nhdr.patch10
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-11.1-liblink.patch142
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-6.0-flex-2.5.31.patch13
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-6.0-pmc.patch13
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-6.1-csu.patch20
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-7.1-types.h-fix.patch15
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-8.0-gcc45.patch28
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-bluetooth.patch12
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-cve-2010-2632.patch215
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-liblink.patch21
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-netware.patch11
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-opieincludes.patch122
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-9.1-.eh_frame_hdr-fix.patch17
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-9.1-aligned_alloc.patch51
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-9.1-rmgssapi.patch16
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-add-nossp-cflags.patch30
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-bsdxml2expat.patch26
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-lib-includes.patch13
-rw-r--r--sys-freebsd/freebsd-lib/files/freebsd-sources-9.0-sysctluint.patch13
-rw-r--r--sys-freebsd/freebsd-lib/files/libusb-1.0.pc.in11
-rw-r--r--sys-freebsd/freebsd-lib/files/libusb.pc.in11
-rw-r--r--sys-freebsd/freebsd-lib/files/rquotad.xinetd11
-rw-r--r--sys-freebsd/freebsd-lib/files/rstatd.xinetd11
-rw-r--r--sys-freebsd/freebsd-lib/files/rusersd.xinetd11
-rw-r--r--sys-freebsd/freebsd-lib/files/sprayd.xinetd11
-rw-r--r--sys-freebsd/freebsd-lib/files/walld.xinetd11
-rw-r--r--sys-freebsd/freebsd-lib/freebsd-lib-11.1-r1.ebuild708
-rw-r--r--sys-freebsd/freebsd-lib/freebsd-lib-9.1-r11.ebuild616
-rw-r--r--sys-freebsd/freebsd-lib/metadata.xml15
-rw-r--r--sys-freebsd/freebsd-libexec/Manifest16
-rw-r--r--sys-freebsd/freebsd-libexec/files/bootpd.confd7
-rw-r--r--sys-freebsd/freebsd-libexec/files/bootpd.initd27
-rw-r--r--sys-freebsd/freebsd-libexec/files/rquotad.xinetd11
-rw-r--r--sys-freebsd/freebsd-libexec/files/rstatd.xinetd11
-rw-r--r--sys-freebsd/freebsd-libexec/files/rusersd.xinetd11
-rw-r--r--sys-freebsd/freebsd-libexec/files/sprayd.xinetd11
-rw-r--r--sys-freebsd/freebsd-libexec/files/walld.xinetd11
-rw-r--r--sys-freebsd/freebsd-libexec/freebsd-libexec-9.1-r2.ebuild80
-rw-r--r--sys-freebsd/freebsd-libexec/metadata.xml8
-rw-r--r--sys-freebsd/freebsd-mk-defs/Manifest8
-rw-r--r--sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.0-drop-unsupport-cflags.patch13
-rw-r--r--sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.0-gnu.patch63
-rw-r--r--sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.0-libproc-libcxx.patch13
-rw-r--r--sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.0-rename-libs.patch16
-rw-r--r--sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.1-gentoo.patch343
-rw-r--r--sys-freebsd/freebsd-mk-defs/freebsd-mk-defs-11.1.ebuild54
-rw-r--r--sys-freebsd/freebsd-mk-defs/metadata.xml8
-rw-r--r--sys-freebsd/freebsd-pam-modules/Manifest4
-rw-r--r--sys-freebsd/freebsd-pam-modules/files/README.pamd61
-rw-r--r--sys-freebsd/freebsd-pam-modules/freebsd-pam-modules-11.1.ebuild45
-rw-r--r--sys-freebsd/freebsd-pam-modules/metadata.xml8
-rw-r--r--sys-freebsd/freebsd-pf/Manifest9
-rw-r--r--sys-freebsd/freebsd-pf/files/freebsd-pf-11.1-libevent.patch13
-rw-r--r--sys-freebsd/freebsd-pf/files/freebsd-pf-11.1-pflogd.patch14
-rw-r--r--sys-freebsd/freebsd-pf/files/freebsd-pf-9.0-bpf.patch10
-rw-r--r--sys-freebsd/freebsd-pf/files/freebsd-pf-9.0-pcap_pollution.patch17
-rw-r--r--sys-freebsd/freebsd-pf/files/pf.confd9
-rw-r--r--sys-freebsd/freebsd-pf/files/pf.initd49
-rw-r--r--sys-freebsd/freebsd-pf/freebsd-pf-11.1.ebuild70
-rw-r--r--sys-freebsd/freebsd-pf/metadata.xml8
-rw-r--r--sys-freebsd/freebsd-rescue/Manifest6
-rw-r--r--sys-freebsd/freebsd-rescue/files/freebsd-rescue-10.0-zlib.patch22
-rw-r--r--sys-freebsd/freebsd-rescue/files/freebsd-rescue-11.0-rename-libs.patch22
-rw-r--r--sys-freebsd/freebsd-rescue/files/freebsd-ubin-10.2-bsdxml.patch13
-rw-r--r--sys-freebsd/freebsd-rescue/freebsd-rescue-11.1.ebuild83
-rw-r--r--sys-freebsd/freebsd-rescue/metadata.xml12
-rw-r--r--sys-freebsd/freebsd-sbin/Manifest8
-rw-r--r--sys-freebsd/freebsd-sbin/files/adjkerntz-crontab4
-rw-r--r--sys-freebsd/freebsd-sbin/files/freebsd-sbin-10.0-zlib.patch22
-rw-r--r--sys-freebsd/freebsd-sbin/files/freebsd-sbin-6.1-pr102701.patch17
-rw-r--r--sys-freebsd/freebsd-sbin/files/freebsd-sbin-6.2-ldconfig.patch13
-rw-r--r--sys-freebsd/freebsd-sbin/files/freebsd-sbin-setXid.patch20
-rw-r--r--sys-freebsd/freebsd-sbin/freebsd-sbin-11.1.ebuild102
-rw-r--r--sys-freebsd/freebsd-sbin/metadata.xml21
-rw-r--r--sys-freebsd/freebsd-share/Manifest9
-rw-r--r--sys-freebsd/freebsd-share/files/freebsd-share-10.0-gentoo-eapi3.patch17
-rw-r--r--sys-freebsd/freebsd-share/files/freebsd-share-10.2-gnu-miscfiles.patch30
-rw-r--r--sys-freebsd/freebsd-share/files/freebsd-share-10.3-gentoo-skel.patch20
-rw-r--r--sys-freebsd/freebsd-share/files/freebsd-share-SA-1808-tcp-11.patch23
-rw-r--r--sys-freebsd/freebsd-share/files/freebsd-share-SA-1810-ip.patch113
-rw-r--r--sys-freebsd/freebsd-share/freebsd-share-11.1.ebuild118
-rw-r--r--sys-freebsd/freebsd-share/freebsd-share-11.1_p1.ebuild122
-rw-r--r--sys-freebsd/freebsd-share/metadata.xml11
-rw-r--r--sys-freebsd/freebsd-sources/Manifest27
-rw-r--r--sys-freebsd/freebsd-sources/files/config-GENTOO4
-rw-r--r--sys-freebsd/freebsd-sources/files/freebsd-sources-10.1-gcc48.patch18
-rw-r--r--sys-freebsd/freebsd-sources/files/freebsd-sources-11.0-gentoo-gcc.patch13
-rw-r--r--sys-freebsd/freebsd-sources/files/freebsd-sources-11.0-gentoo.patch22
-rw-r--r--sys-freebsd/freebsd-sources/files/freebsd-sources-6.0-flex-2.5.31.patch22
-rw-r--r--sys-freebsd/freebsd-sources/files/freebsd-sources-7.1-includes.patch13
-rw-r--r--sys-freebsd/freebsd-sources/files/freebsd-sources-8.0-subnet-route-pr40133.patch21
-rw-r--r--sys-freebsd/freebsd-sources/files/freebsd-sources-9.0-disable-optimization.patch32
-rw-r--r--sys-freebsd/freebsd-sources/files/freebsd-sources-9.0-sysctluint.patch13
-rw-r--r--sys-freebsd/freebsd-sources/freebsd-sources-11.1_p2.ebuild159
-rw-r--r--sys-freebsd/freebsd-sources/freebsd-sources-11.1_p3.ebuild188
-rw-r--r--sys-freebsd/freebsd-sources/metadata.xml13
-rw-r--r--sys-freebsd/freebsd-ubin/Manifest33
-rw-r--r--sys-freebsd/freebsd-ubin/files/freebsd-ubin-10.2-bsdxml.patch13
-rw-r--r--sys-freebsd/freebsd-ubin/files/freebsd-ubin-10.2-talk-workaround.patch12
-rw-r--r--sys-freebsd/freebsd-ubin/files/freebsd-ubin-11.0-setXid.patch147
-rw-r--r--sys-freebsd/freebsd-ubin/files/freebsd-ubin-11.1-fixmakefiles.patch12
-rw-r--r--sys-freebsd/freebsd-ubin/files/freebsd-ubin-11.1-man-paths.patch40
-rw-r--r--sys-freebsd/freebsd-ubin/files/freebsd-ubin-6.0-bsdcmp.patch13
-rw-r--r--sys-freebsd/freebsd-ubin/files/freebsd-ubin-8.0-xinstall.patch26
-rw-r--r--sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.0-fixmakefiles.patch11
-rw-r--r--sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-ar-libarchive3.patch19
-rw-r--r--sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-bsdar.patch25
-rw-r--r--sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-grep.patch17
-rw-r--r--sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-kdump-ioctl.patch24
-rw-r--r--sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-minigzip.patch10
-rw-r--r--sys-freebsd/freebsd-ubin/files/freebsd-ubin-lint-stdarg.patch24
-rw-r--r--sys-freebsd/freebsd-ubin/files/freebsd-ubin-setXid.patch129
-rw-r--r--sys-freebsd/freebsd-ubin/files/locate-updatedb-cron6
-rw-r--r--sys-freebsd/freebsd-ubin/files/login.1.pamd4
-rw-r--r--sys-freebsd/freebsd-ubin/files/passwd.1.pamd7
-rw-r--r--sys-freebsd/freebsd-ubin/files/su.1.pamd15
-rw-r--r--sys-freebsd/freebsd-ubin/freebsd-ubin-11.1-r1.ebuild214
-rw-r--r--sys-freebsd/freebsd-ubin/freebsd-ubin-11.1.ebuild211
-rw-r--r--sys-freebsd/freebsd-ubin/freebsd-ubin-9.1-r2.ebuild180
-rw-r--r--sys-freebsd/freebsd-ubin/freebsd-ubin-9.1-r3.ebuild180
-rw-r--r--sys-freebsd/freebsd-ubin/metadata.xml19
-rw-r--r--sys-freebsd/freebsd-usbin/Manifest18
-rw-r--r--sys-freebsd/freebsd-usbin/files/freebsd-usbin-10.3-bsdxml2expat.patch13
-rw-r--r--sys-freebsd/freebsd-usbin/files/freebsd-usbin-11.0-workaround.patch13
-rw-r--r--sys-freebsd/freebsd-usbin/files/freebsd-usbin-11.1-bsdxml2expat.patch26
-rw-r--r--sys-freebsd/freebsd-usbin/files/freebsd-usbin-9.0-newsyslog.patch12
-rw-r--r--sys-freebsd/freebsd-usbin/files/freebsd-usbin-SA-1803-speculative_execution-amd64-11.patch189
-rw-r--r--sys-freebsd/freebsd-usbin/files/freebsd-usbin-adduser.patch20
-rw-r--r--sys-freebsd/freebsd-usbin/files/iscsid.initd20
-rw-r--r--sys-freebsd/freebsd-usbin/files/nfs.confd10
-rw-r--r--sys-freebsd/freebsd-usbin/files/nfs.initd54
-rw-r--r--sys-freebsd/freebsd-usbin/files/nfsuserd.confd5
-rw-r--r--sys-freebsd/freebsd-usbin/files/nfsuserd.initd20
-rw-r--r--sys-freebsd/freebsd-usbin/files/pw.conf5
-rw-r--r--sys-freebsd/freebsd-usbin/files/rpc.lockd.initd20
-rw-r--r--sys-freebsd/freebsd-usbin/files/rpc.statd.initd20
-rw-r--r--sys-freebsd/freebsd-usbin/freebsd-usbin-11.1.ebuild189
-rw-r--r--sys-freebsd/freebsd-usbin/freebsd-usbin-11.1_p1.ebuild191
-rw-r--r--sys-freebsd/freebsd-usbin/metadata.xml19
-rw-r--r--sys-freebsd/metadata.xml14
-rw-r--r--sys-freebsd/ubin-wrappers/Manifest2
-rw-r--r--sys-freebsd/ubin-wrappers/metadata.xml5
-rw-r--r--sys-freebsd/ubin-wrappers/ubin-wrappers-0.ebuild36
169 files changed, 7766 insertions, 0 deletions
diff --git a/sys-freebsd/Manifest.gz b/sys-freebsd/Manifest.gz
new file mode 100644
index 000000000000..92d9b51a5e0f
--- /dev/null
+++ b/sys-freebsd/Manifest.gz
Binary files differ
diff --git a/sys-freebsd/boot0/Manifest b/sys-freebsd/boot0/Manifest
new file mode 100644
index 000000000000..fefa03a93960
--- /dev/null
+++ b/sys-freebsd/boot0/Manifest
@@ -0,0 +1,5 @@
+AUX boot0-11.0-gcc46.patch 481 BLAKE2B 32b905518fbb8c4016afe4296715369b344ab0397d4df7c3255d5b64d2600d1b1715a071ff720de74f44bb89bd623b850f0e11d7f7acd587c550b30d4dfe704c SHA512 114580260572d03ae145f38d9e7552e18d1d9eace430c102dbc73de055e453fdff9fd81e1ee6f4237d36b87800ff1da63b78ecdd17208ecf8969919fa245cf01
+AUX boot0-add-nossp-cflags.patch 341 BLAKE2B 71eecc9af36e07b331ef842d1cd52688d5c8e152b54a44c7598253bc7078ab8f84a5b8aaa54a796ae88aae9d262546a65a86a35445f41ea1772b4434bf194e0d SHA512 980a6b8f247f0d51724f409627c81e5e089e4b2a7b11732bc3cf569f87a5c308e7c2e5985ce3ba32c61c489a5a1e16596bde43ef3c260b0730ec67e50f42e9bb
+DIST freebsd-src-11.1.tar.xz 147661560 BLAKE2B a9e6ba9d0e12c8b56ac58575d5f02931edbb6a3545d9dccae78810d2d0470a29b29dd7f724b03b8afafbca23717a71346e4cfbd3530e0f40118a23609c3f414e SHA512 b97707ec7a601ca6bcb682c45f6d94a38484301ac24630d7285eff6f88b027ce6900c93fc62f8ce36e0cf32c91f73a9d1c999db397b7f8782fd74a8551a03aca
+EBUILD boot0-11.1.ebuild 1928 BLAKE2B bcec8c212cbf66cb521010b5a91e6f5c3189c69821ba98139f90aba64efde512e9890803ad6ce9798a754bb39ca1b08e37154d1e520758183cdb6fc745c0ce72 SHA512 d68766eaeae64385bbc4d241704f8099b7a81bd38c56f63b2b9302666874f3876f4958d23b43d3046fedbfbb126e1aed7f09af13f05c346045c58f952ce7a135
+MISC metadata.xml 385 BLAKE2B d91b401fe4cbcbe6eeb2e0621e7dc26f0c5a26e11219828fd0df652231d7ccf809b2824eb995463cac8e14056e3065a189667f2351d24510fe0980ca6b2a77f8 SHA512 b65045bfb5e261f1a26102c00ff576065570701658bc643ded73761de269e72fb8843ce38231e92def5c7823720e1ec687b8cce575307097847d10dd35b8a808
diff --git a/sys-freebsd/boot0/boot0-11.1.ebuild b/sys-freebsd/boot0/boot0-11.1.ebuild
new file mode 100644
index 000000000000..6b33a6891f7a
--- /dev/null
+++ b/sys-freebsd/boot0/boot0-11.1.ebuild
@@ -0,0 +1,86 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd flag-o-matic toolchain-funcs
+
+DESCRIPTION="FreeBSD's bootloader"
+SLOT="0"
+
+IUSE="bzip2 ieee1394 tftp zfs"
+
+# Security Advisory and Errata patches.
+# UPSTREAM_PATCHES=()
+
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64-fbsd ~x86-fbsd"
+ SRC_URI="${SRC_URI}
+ $(freebsd_upstream_patches)"
+fi
+
+EXTRACTONLY="
+ sys/
+ lib/
+ contrib/bzip2/
+ contrib/zlib/
+"
+
+RDEPEND=""
+DEPEND="=sys-freebsd/freebsd-mk-defs-${RV}*
+ =sys-freebsd/freebsd-lib-${RV}*"
+
+S="${WORKDIR}/sys/boot"
+
+PATCHES=( "${FILESDIR}/${PN}-11.0-gcc46.patch"
+ "${FILESDIR}/${PN}-add-nossp-cflags.patch" )
+
+boot0_use_enable() {
+ use ${1} && mymakeopts="${mymakeopts} LOADER_${2}_SUPPORT=\"yes\""
+ use ${1} || mymakeopts="${mymakeopts} WITHOUT_${2}= "
+}
+
+pkg_setup() {
+ boot0_use_enable ieee1394 FIREWIRE
+ boot0_use_enable zfs ZFS
+ boot0_use_enable tftp TFTP
+ boot0_use_enable bzip2 BZIP2
+}
+
+src_prepare() {
+ sed -e '/-mno-align-long-strings/d' \
+ -i "${S}"/i386/boot2/Makefile \
+ -i "${S}"/i386/gptboot/Makefile \
+ -i "${S}"/i386/gptzfsboot/Makefile \
+ -i "${S}"/i386/zfsboot/Makefile || die
+
+ mymakeopts="${mymakeopts} LOADER_NO_GELI_SUPPORT=yes"
+ export MAKEOBJDIRPREFIX="${WORKDIR}/build"
+}
+
+src_compile() {
+ strip-flags
+ append-flags "-fno-strict-aliasing"
+
+ cd "${WORKDIR}/lib/libstand" || die
+ freebsd_src_compile
+
+ CFLAGS="${CFLAGS} -I${WORKDIR}/lib/libstand"
+ LDFLAGS="${LDFLAGS} -L${MAKEOBJDIRPREFIX}/${WORKDIR}/lib/libstand"
+ export LIBSTAND="${MAKEOBJDIRPREFIX}/${WORKDIR}/lib/libstand/libstand.a"
+
+ cd "${S}" || die
+ NOFLAGSTRIP="yes" freebsd_src_compile
+}
+
+src_install() {
+ dodir /boot/defaults
+ freebsd_src_install FILESDIR=/boot
+
+ cd "${WORKDIR}/sys/$(tc-arch-kernel)/conf" || die
+ insinto /boot
+ newins GENERIC.hints device.hints
+
+ echo 'CONFIG_PROTECT="/boot/device.hints"' > "${T}"/50boot0
+ doenvd "${T}"/50boot0
+}
diff --git a/sys-freebsd/boot0/files/boot0-11.0-gcc46.patch b/sys-freebsd/boot0/files/boot0-11.0-gcc46.patch
new file mode 100644
index 000000000000..ec17d92b5790
--- /dev/null
+++ b/sys-freebsd/boot0/files/boot0-11.0-gcc46.patch
@@ -0,0 +1,14 @@
+diff --git a/sys/boot/i386/boot2/Makefile b/sys/boot/i386/boot2/Makefile
+index ead9ad1..af5e021 100644
+--- a/sys/boot/i386/boot2/Makefile
++++ b/sys/boot/i386/boot2/Makefile
+@@ -45,6 +45,9 @@ CFLAGS.gcc+= -Os \
+ .if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} <= 40201
+ CFLAGS.gcc+= -mno-align-long-strings
+ .endif
++.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 40600
++CFLAGS.gcc+= -fno-asynchronous-unwind-tables
++.endif
+
+ CFLAGS.clang+= -Oz ${CLANG_OPT_SMALL}
+
diff --git a/sys-freebsd/boot0/files/boot0-add-nossp-cflags.patch b/sys-freebsd/boot0/files/boot0-add-nossp-cflags.patch
new file mode 100644
index 000000000000..abc6a57bf4b0
--- /dev/null
+++ b/sys-freebsd/boot0/files/boot0-add-nossp-cflags.patch
@@ -0,0 +1,11 @@
+https://bugs.gentoo.org/show_bug.cgi?id=511698
+
+diff --git a/sys/boot/Makefile.inc b/sys/boot/Makefile.inc
+index e0039b9..533dea0 100644
+--- a/sys/boot/Makefile.inc
++++ b/sys/boot/Makefile.inc
+@@ -1,3 +1,3 @@
+ # $FreeBSD: release/10.0.0/sys/boot/Makefile.inc 188895 2009-02-21 15:04:31Z ru $
+
+-SSP_CFLAGS=
++SSP_CFLAGS= -fno-stack-protector
diff --git a/sys-freebsd/boot0/metadata.xml b/sys-freebsd/boot0/metadata.xml
new file mode 100644
index 000000000000..d9f0c8324191
--- /dev/null
+++ b/sys-freebsd/boot0/metadata.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+<maintainer type="project">
+ <email>bsd@gentoo.org</email>
+ <name>BSD Project</name>
+ </maintainer>
+ <use>
+ <flag name="tftp">Enable PXE/TFTP boot support.</flag>
+ <flag name="zfs">Enable booting on ZFS filesystems.</flag>
+ </use>
+</pkgmetadata>
diff --git a/sys-freebsd/freebsd-bin/Manifest b/sys-freebsd/freebsd-bin/Manifest
new file mode 100644
index 000000000000..f1cc0adc25eb
--- /dev/null
+++ b/sys-freebsd/freebsd-bin/Manifest
@@ -0,0 +1,3 @@
+DIST freebsd-src-11.1.tar.xz 147661560 BLAKE2B a9e6ba9d0e12c8b56ac58575d5f02931edbb6a3545d9dccae78810d2d0470a29b29dd7f724b03b8afafbca23717a71346e4cfbd3530e0f40118a23609c3f414e SHA512 b97707ec7a601ca6bcb682c45f6d94a38484301ac24630d7285eff6f88b027ce6900c93fc62f8ce36e0cf32c91f73a9d1c999db397b7f8782fd74a8551a03aca
+EBUILD freebsd-bin-11.1.ebuild 781 BLAKE2B b64305d2287a2c6bf2068b7d593ae23689f3ecd6b0398c72ba13c216f94d4259ca61613017bb061168c35d932ba3dcc739fd507fefb5f2852f21dc3dda119e3e SHA512 66d2e50f2573749f76886ff09622cad56d2ecd6ca442ba20b587fedadbbf2a88ce0e57e2ed18f493f8288fb1b10222a90771c1c8292e762e45ac3cae2c3c1c3f
+MISC metadata.xml 238 BLAKE2B 5d18b211ca67cdae4e0f4d6e1598b20b39a471aa07326791c53bb4e1013607b85bac28a64c1939e53b01228d0c9b7814314b95c0f76928de265d95ef7ee6cd45 SHA512 173efaa53a514acf1e2f0c6681c82a48ec16d505844f551d2cc823ee8685b27837c7461f7956c12182059ee7e83023e2f0bcd5d1afab74beeaf998487193656d
diff --git a/sys-freebsd/freebsd-bin/freebsd-bin-11.1.ebuild b/sys-freebsd/freebsd-bin/freebsd-bin-11.1.ebuild
new file mode 100644
index 000000000000..6451fb41815c
--- /dev/null
+++ b/sys-freebsd/freebsd-bin/freebsd-bin-11.1.ebuild
@@ -0,0 +1,41 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd
+
+DESCRIPTION="FreeBSD /bin tools"
+SLOT="0"
+
+IUSE=""
+
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64-fbsd ~x86-fbsd"
+fi
+
+EXTRACTONLY="
+ bin/
+ usr.bin/
+ sbin/
+ lib/
+"
+
+RDEPEND="=sys-freebsd/freebsd-lib-${RV}*
+ >=dev-libs/libedit-20120311.3.0-r1
+ sys-libs/ncurses:0=
+ sys-apps/ed
+ !app-misc/realpath
+ !<sys-freebsd/freebsd-ubin-8"
+DEPEND="${RDEPEND}
+ =sys-freebsd/freebsd-mk-defs-${RV}*
+ >=sys-devel/flex-2.5.31-r2"
+
+S=${WORKDIR}/bin
+
+# csh and tcsh are provided by tcsh package, rmail is sendmail stuff.
+REMOVE_SUBDIRS="csh rmail ed freebsd-version"
+
+pkg_setup() {
+ mymakeopts="${mymakeopts} WITHOUT_TCSH= WITHOUT_SENDMAIL= WITHOUT_RCMDS= "
+}
diff --git a/sys-freebsd/freebsd-bin/metadata.xml b/sys-freebsd/freebsd-bin/metadata.xml
new file mode 100644
index 000000000000..a00f3aeb1f81
--- /dev/null
+++ b/sys-freebsd/freebsd-bin/metadata.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+<maintainer type="project">
+ <email>bsd@gentoo.org</email>
+ <name>BSD Project</name>
+</maintainer>
+</pkgmetadata>
diff --git a/sys-freebsd/freebsd-cddl/Manifest b/sys-freebsd/freebsd-cddl/Manifest
new file mode 100644
index 000000000000..2162ad05c285
--- /dev/null
+++ b/sys-freebsd/freebsd-cddl/Manifest
@@ -0,0 +1,18 @@
+AUX freebsd-cddl-11.0-add-libs.patch 3401 BLAKE2B b0928c729f7a95d7cb7e33718917d5b021e2ae782a43b6ab68e5de61781f9f5292d48da7850f9a2188c28f271fea74344d6bfa10e7655b79435ed3db569fa9b4 SHA512 7a3da3a57bde26a79784dcb023961ed0a292da4945c49e07c4a69035fe6cd0773e09cec25eab638a64c6ccc54bb775c169b1553743f7a9b4af60ce49f1fee54c
+AUX freebsd-cddl-11.0-workaround.patch 576 BLAKE2B e1b7fa79a82812ba5543245c1051f7ef287dfd68fdd99a8808e5def821c640f258f0a9405641b853e874a4ee31ec2e1caf948bbd6de36327678ce4c28ef2629a SHA512 0a2280caeb23622454351657d61e8e465c597b82bf49cb534a924758844cd7da2df330434ba6282e159d9bc2e6ade27c2a9db41980ada6370bcab59c6a57da22
+AUX freebsd-cddl-9.0-bsdxml.patch 1419 BLAKE2B 435e028205fbbdc0aa46763cb4de491aebab62459f485a9a5fe6d4e12319a5674453bf37fa33aef5a04194402fee9ec78e9eccd255fdd55f833309265b784853 SHA512 8ea86f6918b2629c33286c2396226bb4944e373069a423104d96f65e387162e0da94707458fd5caebcab08b9305b435ac66f4207aa6b15ce9571a5fa5878f3c5
+AUX freebsd-cddl-9.0-libpaths.patch 7621 BLAKE2B 1d743118005f6e92d960a782e633e1d8095fa1cc38c5c9dba9176b07ec188653140e2ec4e7ace83c80968e35109f77e588e2042273ea81d8ce12008f3b349911 SHA512 87e56647a41262363900ab4ecc6aabd1b4ba4f0d7d5b5011dc2eb9ec312c640bed5aa931495f208110277b2baf6c3625d20d59e62c19a70e7625a6b36b61a278
+AUX freebsd-cddl-9.0-underlink.patch 755 BLAKE2B 6d9987c6a0f491ad0afc47d169e10fe9fbe088bcb287bbc40d1707763856ae9ff936ffe54ddd5fb2f1304d3d46c4d93832b628802ead75a663b80f7cbda74225 SHA512 002c9e6a389140455f9a698dbe47197d795d36ff08e4e5fb096d38525b8cf017672de7f511b2495fdea6f536e07a426e299e0a056cbdd8dae64677299376d2f9
+AUX zfs.initd 368 BLAKE2B 932c990c341246aadc23702d107591195ebd5bbcbda9001c36fb16d7a354f33f4afbae2f54660f6fc0a621ab7c97447532009a3d9a8080639c181ec216960b4c SHA512 6b1c0342cbd4dd7e84df58240be3ef8bdc9924a32abe9258d76c87b187be5cb5776125c5989b9dc9bd1210f46216b8f478d2ecb8cc9d165a960157fadc9b5ff8
+AUX zvol.initd-9.0 812 BLAKE2B c7aaa3d415cd59f403ed520831b10433f2ec2ddce420642b84bca33566244360b641f87760ea0276ccd281b2b946200cd7c9a592e3c67615d00a5a7fdc7c085b SHA512 dbd113cb8f072b001e5f696ddb142df063f12b29a5b16af99f3b00b8c511af87a6094bd210f384ad03a300c2afd7af249cdf278a6179a3f53edc439c3a80f566
+DIST freebsd-cddl-9.1.tar.bz2 899348 BLAKE2B 419e475b4c3debacd0d0fbbad4d1b13685c1c5ac741cc8cfb53dadce9d30cf9ddd7132ef8ab897787be538028d34bb9603eb76caf7650f4f50bb3295f19bf035 SHA512 ae0a969e710785bbcf36a2ec22cc5b1dcdb25398be951e047a1237d0c977e38fc9e05504db51f8bf9ed83bc1f68b04fc88ce18fc48a93f785b8a3f8ef481bacd
+DIST freebsd-contrib-9.1.tar.bz2 54751432 BLAKE2B 8a30e78021e6388d679637d2dbe0ed3f4896d3902064baaafa79de9c328171cbcb895b0ffd3d0d0cd3ca25c93a73584ed4900b45bd672a73b15b75721de59de5 SHA512 71be13049258c6e6b5e4f63cc16da5d349a89d68f04d87446e4ad33ae8bf2a93ea67d9c256b7bec60b61e65db0487268070cfb77a484c3ac0f8ba368b48c2438
+DIST freebsd-include-9.1.tar.bz2 146881 BLAKE2B 3db8570a8c841ec1c9ceff479bd0ef9b146b2a343d6596892c9d8a9f9193404f6c62712cb96d7416c6e5cc4c46e7fb942421c47e1bc2c707dde534e2050be442 SHA512 779c8315ce2b10b343bb62e331525d510b0d68ce5d665a1672bd6f4d1eff6445bc6b7a0f178b319828aa203c4e4c04c561ce793052703f4f936ce9711280a0c9
+DIST freebsd-lib-9.1.tar.bz2 3206685 BLAKE2B 67f93b7951fc03e877ee525d53b81ba49c8c1a70041c30aac97665d5dab7b3f2817fdb3bbb1475be66c33a7f996309e9020f1a3d1154fab8e2f6789f5ae0bb18 SHA512 40d0c36b6b889c404fa0e0afa38ba4e84a55bc88ffa2f98a70afbd7a32c4f32c158617ba770567d082a986d62c09b3ec8db3dc5ab853ee1c9bbe0b90bb82396e
+DIST freebsd-sbin-9.1.tar.bz2 1273913 BLAKE2B c00fea446a19311020ae081ba00d6c7d0b3b0365ab2046ec24252c2b02d4b4079fb7bbbf0d17432e2a1efb0788b552d684b1b91bbbb05d2c1712a93380a89b49 SHA512 9f186602b7de96f268c352ca386986652fddf5570e7eca1afa8c0d2bdc83b57df1198efe47f36dd5c7a6abf4f9c935f1c8207a4a12a6b2153bd6c3c6292719dc
+DIST freebsd-src-11.1.tar.xz 147661560 BLAKE2B a9e6ba9d0e12c8b56ac58575d5f02931edbb6a3545d9dccae78810d2d0470a29b29dd7f724b03b8afafbca23717a71346e4cfbd3530e0f40118a23609c3f414e SHA512 b97707ec7a601ca6bcb682c45f6d94a38484301ac24630d7285eff6f88b027ce6900c93fc62f8ce36e0cf32c91f73a9d1c999db397b7f8782fd74a8551a03aca
+DIST freebsd-sys-9.1.tar.bz2 32588103 BLAKE2B 7f94a4735c6a17b39a86fa0fda0682924b18e4b466dc6319a5df889522aaeaffaa87e1b76582c48ae034df8c20169c8cea93bbd3d6e7abd0526716686f88dfe8 SHA512 7dc9d9e00dde8f592bb171f4386d02b655b73cb4f153fe5ec063d010a148ef0639eae0dcdb3eeb09ecd1e3653c69e49a2d261329fa6d0381d2ddabe258ddde6d
+DIST freebsd-ubin-9.1.tar.bz2 1910472 BLAKE2B 4bab770072543d9eb25ce7ce450084e0eb9ca603deb58886a26495a92a05373f4f8f5821c65dc76365bf325a7291e6b630b00af5ba895784093d450163637504 SHA512 74ae0aceec8597aa66c3f1ab313f0685a3c63d7273c36ae7baf8794275ad9bca241c60c3f6281cccf6d531d250d7611099977d3b1a27279cef3586401b6af05e
+EBUILD freebsd-cddl-11.1.ebuild 1677 BLAKE2B 0cbc7e66559a7e078d497fd67b7ec83dec27df50d605fd8f177c69ad3f483b58e85f0ed6a0c160492936ce47161a6bdad32a7db6f11ec463c58d76faba69cf6c SHA512 6594f3af2fdb9ccd4414c7c2cf83ce32bf7359b511adacace969fe13aef1e294b562d5a6b184269c70f66688b7e4529edce9448eb6892c2e1dab8408a54befc7
+EBUILD freebsd-cddl-9.1.ebuild 1490 BLAKE2B d6b5e924034f17f6adf6bf7aedce5567b6b99b48f48bcb8de49b77bc31beba512249b7e2fc856fa73ab81f41951882dd88800c382a3ad5d3f7f903af434ac191 SHA512 805bf092f6a4c98158f224bcf68da9e57e839cb3e2057297d02bc05090d580e35d9759dad76eb49cb526684fe01b4e6fdbba9e0a472b339c55d073456d07c51f
+MISC metadata.xml 238 BLAKE2B 5d18b211ca67cdae4e0f4d6e1598b20b39a471aa07326791c53bb4e1013607b85bac28a64c1939e53b01228d0c9b7814314b95c0f76928de265d95ef7ee6cd45 SHA512 173efaa53a514acf1e2f0c6681c82a48ec16d505844f551d2cc823ee8685b27837c7461f7956c12182059ee7e83023e2f0bcd5d1afab74beeaf998487193656d
diff --git a/sys-freebsd/freebsd-cddl/files/freebsd-cddl-11.0-add-libs.patch b/sys-freebsd/freebsd-cddl/files/freebsd-cddl-11.0-add-libs.patch
new file mode 100644
index 000000000000..46f25217bdac
--- /dev/null
+++ b/sys-freebsd/freebsd-cddl/files/freebsd-cddl-11.0-add-libs.patch
@@ -0,0 +1,87 @@
+diff --git a/cddl/sbin/zfs/Makefile b/cddl/sbin/zfs/Makefile
+index 1e386e5..a4c08ee 100644
+--- a/cddl/sbin/zfs/Makefile
++++ b/cddl/sbin/zfs/Makefile
+@@ -22,6 +22,6 @@ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/contrib/opensolaris/uts/common/fs/zfs
+ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/contrib/opensolaris/uts/common/sys
+ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/contrib/opensolaris/common/zfs
+
+-LIBADD= jail nvpair uutil zfs_core zfs
++LIBADD= jail nvpair uutil zfs_core zfs umem avl
+
+ .include <bsd.prog.mk>
+diff --git a/cddl/sbin/zpool/Makefile b/cddl/sbin/zpool/Makefile
+index ebf0f90..c70a3c4 100644
+--- a/cddl/sbin/zpool/Makefile
++++ b/cddl/sbin/zpool/Makefile
+@@ -27,6 +27,6 @@ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/contrib/opensolaris/uts/common/sys
+ CFLAGS+= -I${.CURDIR}/../../../cddl/contrib/opensolaris/lib/libzpool/common
+ CFLAGS+= -I${.CURDIR}/../../../cddl/contrib/opensolaris/cmd/stat/common
+
+-LIBADD= geom nvpair uutil zfs
++LIBADD= geom nvpair uutil zfs umem avl zfs_core
+
+ .include <bsd.prog.mk>
+diff --git a/cddl/usr.sbin/lockstat/Makefile b/cddl/usr.sbin/lockstat/Makefile
+index fc68904..9af6ff2 100644
+--- a/cddl/usr.sbin/lockstat/Makefile
++++ b/cddl/usr.sbin/lockstat/Makefile
+@@ -21,6 +21,6 @@ CFLAGS+= -DNEED_ERRLOC -g
+
+ #YFLAGS+= -d
+
+-LIBADD= elf dtrace rt
++LIBADD= elf dtrace rt ctf
+
+ .include <bsd.prog.mk>
+diff --git a/cddl/usr.sbin/plockstat/Makefile b/cddl/usr.sbin/plockstat/Makefile
+index 77b6139..7737efd 100644
+--- a/cddl/usr.sbin/plockstat/Makefile
++++ b/cddl/usr.sbin/plockstat/Makefile
+@@ -18,6 +18,6 @@ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/compat/opensolaris \
+ -I${.CURDIR}/../../../cddl/lib/libdtrace \
+ -I${.CURDIR}/../../../sys
+
+-LIBADD= dtrace proc
++LIBADD= dtrace proc ctf
+
+ .include <bsd.prog.mk>
+diff --git a/cddl/usr.sbin/zdb/Makefile b/cddl/usr.sbin/zdb/Makefile
+index 3609502..71526f7 100644
+--- a/cddl/usr.sbin/zdb/Makefile
++++ b/cddl/usr.sbin/zdb/Makefile
+@@ -24,7 +24,7 @@ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/contrib/opensolaris/common/zfs
+ CFLAGS+= -I${.CURDIR}/../../../cddl/contrib/opensolaris/head
+ CFLAGS+= -I${.CURDIR}/../../lib/libumem
+
+-LIBADD= nvpair umem uutil zfs zpool
++LIBADD= nvpair umem uutil zfs zpool avl zfs_core
+
+ # Since there are many asserts in this program, it makes no sense to compile
+ # it without debugging.
+diff --git a/cddl/usr.sbin/zfsd/Makefile.common b/cddl/usr.sbin/zfsd/Makefile.common
+index a545609..034d418 100644
+--- a/cddl/usr.sbin/zfsd/Makefile.common
++++ b/cddl/usr.sbin/zfsd/Makefile.common
+@@ -35,7 +35,7 @@ CXXFLAGS= -g -DNEED_SOLARIS_BOOLEAN ${INCFLAGS}
+
+ DPADD= ${LIBDEVDCTL} ${LIBZFS} ${LIBZFS_CORE} ${LIBUTIL} ${LIBGEOM} \
+ ${LIBBSDXML} ${LIBSBUF} ${LIBNVPAIR} ${LIBUUTIL}
+-LIBADD= devdctl zfs zfs_core util geom bsdxml sbuf nvpair uutil
++LIBADD= devdctl zfs zfs_core util geom bsdxml sbuf nvpair uutil umem avl
+
+ cscope:
+ find ${.CURDIR} -type f -a \( -name "*.[ch]" -o -name "*.cc" \) \
+diff --git a/cddl/usr.sbin/zhack/Makefile b/cddl/usr.sbin/zhack/Makefile
+index 02c51ac..d9b79a9 100644
+--- a/cddl/usr.sbin/zhack/Makefile
++++ b/cddl/usr.sbin/zhack/Makefile
+@@ -23,7 +23,7 @@ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/contrib/opensolaris/common/zfs
+ CFLAGS+= -I${.CURDIR}/../../../cddl/contrib/opensolaris/head
+ CFLAGS+= -I${.CURDIR}/../../lib/libumem
+
+-LIBADD= nvpair zfs zpool
++LIBADD= nvpair zfs zpool umem uutil avl zfs_core
+
+ CFLAGS+= -DDEBUG=1
+ #DEBUG_FLAGS+= -g
diff --git a/sys-freebsd/freebsd-cddl/files/freebsd-cddl-11.0-workaround.patch b/sys-freebsd/freebsd-cddl/files/freebsd-cddl-11.0-workaround.patch
new file mode 100644
index 000000000000..839b6b5a7924
--- /dev/null
+++ b/sys-freebsd/freebsd-cddl/files/freebsd-cddl-11.0-workaround.patch
@@ -0,0 +1,12 @@
+diff --git a/cddl/usr.sbin/zfsd/Makefile.common b/cddl/usr.sbin/zfsd/Makefile.common
+index 6c71bdf..6b71908 100644
+--- a/cddl/usr.sbin/zfsd/Makefile.common
++++ b/cddl/usr.sbin/zfsd/Makefile.common
+@@ -31,6 +31,7 @@ INCFLAGS+= -I${SRCDIR}/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
+ INCFLAGS+= -I${SRCDIR}/sys/cddl/contrib/opensolaris/uts/common/sys
+
+ CFLAGS= -g -DNEED_SOLARIS_BOOLEAN ${INCFLAGS}
++CXXFLAGS= -g -DNEED_SOLARIS_BOOLEAN ${INCFLAGS}
+
+ DPADD= ${LIBDEVDCTL} ${LIBZFS} ${LIBZFS_CORE} ${LIBUTIL} ${LIBGEOM} \
+ ${LIBBSDXML} ${LIBSBUF} ${LIBNVPAIR} ${LIBUUTIL}
diff --git a/sys-freebsd/freebsd-cddl/files/freebsd-cddl-9.0-bsdxml.patch b/sys-freebsd/freebsd-cddl/files/freebsd-cddl-9.0-bsdxml.patch
new file mode 100644
index 000000000000..b3d95bb7741e
--- /dev/null
+++ b/sys-freebsd/freebsd-cddl/files/freebsd-cddl-9.0-bsdxml.patch
@@ -0,0 +1,28 @@
+diff -ur cddl.old/sbin/zfs/Makefile cddl/sbin/zfs/Makefile
+--- cddl.old/sbin/zfs/Makefile 2011-11-04 10:01:46.000000000 +0000
++++ cddl/sbin/zfs/Makefile 2011-11-04 10:07:15.000000000 +0000
+@@ -21,8 +21,8 @@
+ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/contrib/opensolaris/uts/common/sys
+ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/contrib/opensolaris/common/zfs
+
+-DPADD= ${LIBBSDXML} ${LIBGEOM} ${LIBM} ${LIBNVPAIR} ${LIBSBUF} ${LIBUMEM} \
++DPADD= ${LIBGEOM} ${LIBM} ${LIBNVPAIR} ${LIBSBUF} ${LIBUMEM} \
+ ${LIBUTIL} ${LIBUUTIL} ${LIBZFS}
+-LDADD= -lbsdxml -lgeom -lm -lnvpair -lsbuf -lumem -lutil -luutil -lzfs
++LDADD= -lgeom -lm -lnvpair -lsbuf -lumem -lutil -luutil -lzfs
+
+ .include <bsd.prog.mk>
+diff -ur cddl.old/sbin/zpool/Makefile cddl/sbin/zpool/Makefile
+--- cddl.old/sbin/zpool/Makefile 2011-11-04 10:01:46.000000000 +0000
++++ cddl/sbin/zpool/Makefile 2011-11-04 10:06:38.000000000 +0000
+@@ -26,8 +26,8 @@
+ CFLAGS+= -I${.CURDIR}/../../../cddl/contrib/opensolaris/lib/libzpool/common
+ CFLAGS+= -I${.CURDIR}/../../../cddl/contrib/opensolaris/cmd/stat/common
+
+-DPADD= ${LIBAVL} ${LIBBSDXML} ${LIBGEOM} ${LIBM} ${LIBNVPAIR} ${LIBSBUF} \
++DPADD= ${LIBAVL} ${LIBGEOM} ${LIBM} ${LIBNVPAIR} ${LIBSBUF} \
+ ${LIBUMEM} ${LIBUTIL} ${LIBUUTIL} ${LIBZFS}
+-LDADD= -lavl -lbsdxml -lgeom -lm -lnvpair -lsbuf -lumem -lutil -luutil -lzfs
++LDADD= -lavl -lgeom -lm -lnvpair -lsbuf -lumem -lutil -luutil -lzfs
+
+ .include <bsd.prog.mk>
diff --git a/sys-freebsd/freebsd-cddl/files/freebsd-cddl-9.0-libpaths.patch b/sys-freebsd/freebsd-cddl/files/freebsd-cddl-9.0-libpaths.patch
new file mode 100644
index 000000000000..c81a2c3a9cdf
--- /dev/null
+++ b/sys-freebsd/freebsd-cddl/files/freebsd-cddl-9.0-libpaths.patch
@@ -0,0 +1,167 @@
+diff -upNr a/cddl/lib/libzfs/Makefile b/cddl/lib/libzfs/Makefile
+--- a/cddl/lib/libzfs/Makefile 2012-03-30 18:58:53.174771000 +0000
++++ b/cddl/lib/libzfs/Makefile 2012-03-30 19:04:39.904906253 +0000
+@@ -54,4 +54,8 @@ CFLAGS+= -I${.CURDIR}/../../../cddl/cont
+ CFLAGS+= -I${.CURDIR}/../../../cddl/contrib/opensolaris/lib/libuutil/common
+ CFLAGS+= -I${.CURDIR}/../../../cddl/contrib/opensolaris/lib/libzfs/common
+
++LDFLAGS+= -L${.CURDIR}/../../lib/libnvpair
++LDFLAGS+= -L${.CURDIR}/../../lib/libumem
++LDFLAGS+= -L${.CURDIR}/../../lib/libuutil
++
+ .include <bsd.lib.mk>
+diff -upNr a/cddl/lib/libzpool/Makefile b/cddl/lib/libzpool/Makefile
+--- a/cddl/lib/libzpool/Makefile 2012-03-30 18:58:53.174771000 +0000
++++ b/cddl/lib/libzpool/Makefile 2012-03-30 19:04:55.839233753 +0000
+@@ -56,6 +56,10 @@ CFLAGS+= -I${.CURDIR}/../../../lib/libpt
+ CFLAGS+= -I${.CURDIR}/../../../lib/libpthread/sys
+ CFLAGS+= -I${.CURDIR}/../../../lib/libthr/arch/${MACHINE_CPUARCH}/include
+
++LDFLAGS+= -L${.CURDIR}/../../lib/libavl
++LDFLAGS+= -L${.CURDIR}/../../lib/libnvpair
++LDFLAGS+= -L${.CURDIR}/../../lib/libumem
++
+ DPADD= ${LIBMD} ${LIBPTHREAD} ${LIBZ}
+ LDADD= -lmd -lpthread -lz -lumem -lnvpair -lavl
+
+diff -upNr a/cddl/sbin/zfs/Makefile b/cddl/sbin/zfs/Makefile
+--- a/cddl/sbin/zfs/Makefile 2012-03-30 18:58:53.174771000 +0000
++++ b/cddl/sbin/zfs/Makefile 2012-03-30 19:05:11.094859502 +0000
+@@ -21,6 +21,11 @@ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/
+ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/contrib/opensolaris/uts/common/sys
+ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/contrib/opensolaris/common/zfs
+
++LDFLAGS+= -L${.CURDIR}/../../lib/libnvpair
++LDFLAGS+= -L${.CURDIR}/../../lib/libumem
++LDFLAGS+= -L${.CURDIR}/../../lib/libuutil
++LDFLAGS+= -L${.CURDIR}/../../lib/libzfs
++
+ DPADD= ${LIBGEOM} ${LIBM} ${LIBNVPAIR} ${LIBSBUF} ${LIBUMEM} \
+ ${LIBUTIL} ${LIBUUTIL} ${LIBZFS}
+ LDADD= -lgeom -lm -lnvpair -lsbuf -lumem -lutil -luutil -lzfs
+diff -upNr a/cddl/sbin/zpool/Makefile b/cddl/sbin/zpool/Makefile
+--- a/cddl/sbin/zpool/Makefile 2012-03-30 18:58:53.174771000 +0000
++++ b/cddl/sbin/zpool/Makefile 2012-03-30 19:05:24.830721002 +0000
+@@ -26,6 +26,12 @@ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/
+ CFLAGS+= -I${.CURDIR}/../../../cddl/contrib/opensolaris/lib/libzpool/common
+ CFLAGS+= -I${.CURDIR}/../../../cddl/contrib/opensolaris/cmd/stat/common
+
++LDFLAGS+= -L${.CURDIR}/../../lib/libavl
++LDFLAGS+= -L${.CURDIR}/../../lib/libnvpair
++LDFLAGS+= -L${.CURDIR}/../../lib/libumem
++LDFLAGS+= -L${.CURDIR}/../../lib/libuutil
++LDFLAGS+= -L${.CURDIR}/../../lib/libzfs
++
+ DPADD= ${LIBAVL} ${LIBGEOM} ${LIBM} ${LIBNVPAIR} ${LIBSBUF} \
+ ${LIBUMEM} ${LIBUTIL} ${LIBUUTIL} ${LIBZFS}
+ LDADD= -lavl -lgeom -lm -lnvpair -lsbuf -lumem -lutil -luutil -lzfs
+diff -upNr a/cddl/usr.bin/ctfconvert/Makefile b/cddl/usr.bin/ctfconvert/Makefile
+--- a/cddl/usr.bin/ctfconvert/Makefile 2012-03-30 18:58:53.174771000 +0000
++++ b/cddl/usr.bin/ctfconvert/Makefile 2012-03-30 19:05:49.454897012 +0000
+@@ -36,6 +36,8 @@ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/
+ -I${OPENSOLARIS_USR_DISTDIR}/tools/ctf/cvt \
+ -I${OPENSOLARIS_SYS_DISTDIR}/uts/common
+
++LDFLAGS+= -L${.CURDIR}/../../lib/libctf
++
+ DPADD= ${LIBCTF} ${LIBDWARF} ${LIBELF} ${LIBZ} ${LIBPTHREAD}
+ LDADD= -lctf -ldwarf -lelf -lz -lpthread
+
+diff -upNr a/cddl/usr.bin/ctfmerge/Makefile b/cddl/usr.bin/ctfmerge/Makefile
+--- a/cddl/usr.bin/ctfmerge/Makefile 2012-03-30 18:58:53.174771000 +0000
++++ b/cddl/usr.bin/ctfmerge/Makefile 2012-03-30 19:06:08.084858412 +0000
+@@ -33,6 +33,8 @@ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/
+ -I${OPENSOLARIS_USR_DISTDIR}/tools/ctf/cvt \
+ -I${OPENSOLARIS_SYS_DISTDIR}/uts/common
+
++LDFLAGS+= -L${.CURDIR}/../../lib/libctf
++
+ DPADD= ${LIBCTF} ${LIBDWARF} ${LIBELF} ${LIBZ} ${LIBPTHREAD}
+ LDADD= -lctf -ldwarf -lelf -lz -lpthread
+
+diff -upNr a/cddl/usr.bin/zinject/Makefile b/cddl/usr.bin/zinject/Makefile
+--- a/cddl/usr.bin/zinject/Makefile 2012-03-30 18:58:53.174771000 +0000
++++ b/cddl/usr.bin/zinject/Makefile 2012-03-30 19:06:25.084865592 +0000
+@@ -19,6 +19,13 @@ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/
+ CFLAGS+= -I${.CURDIR}/../../contrib/opensolaris/head
+ CFLAGS+= -I${.CURDIR}/../../lib/libumem
+
++LDFLAGS+= -L${.CURDIR}/../../lib/libavl
++LDFLAGS+= -L${.CURDIR}/../../lib/libnvpair
++LDFLAGS+= -L${.CURDIR}/../../lib/libumem
++LDFLAGS+= -L${.CURDIR}/../../lib/libuutil
++LDFLAGS+= -L${.CURDIR}/../../lib/libzfs
++LDFLAGS+= -L${.CURDIR}/../../lib/libzpool
++
+ DPADD= ${LIBAVL} ${LIBGEOM} ${LIBM} ${LIBNVPAIR} ${LIBUMEM} ${LIBUUTIL} \
+ ${LIBZFS} ${LIBZPOOL}
+ LDADD= -lavl -lgeom -lm -lnvpair -lumem -luutil -lzfs -lzpool
+diff -upNr a/cddl/usr.bin/zstreamdump/Makefile b/cddl/usr.bin/zstreamdump/Makefile
+--- a/cddl/usr.bin/zstreamdump/Makefile 2012-03-30 18:58:53.174771000 +0000
++++ b/cddl/usr.bin/zstreamdump/Makefile 2012-03-30 19:06:44.544860132 +0000
+@@ -18,6 +18,11 @@ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/
+ CFLAGS+= -I${.CURDIR}/../../contrib/opensolaris/head
+ CFLAGS+= -I${.CURDIR}/../../lib/libumem
+
++LDFLAGS+= -L${.CURDIR}/../../lib/libavl
++LDFLAGS+= -L${.CURDIR}/../../lib/libnvpair
++LDFLAGS+= -L${.CURDIR}/../../lib/libumem
++LDFLAGS+= -L${.CURDIR}/../../lib/libzpool
++
+ DPADD= ${LIBM} ${LIBNVPAIR} ${LIBUMEM} ${LIBZPOOL} \
+ ${LIBPTHREAD} ${LIBZ} ${LIBAVL}
+ LDADD= -lm -lnvpair -lumem -lzpool -lpthread -lz -lavl
+diff -upNr a/cddl/usr.bin/ztest/Makefile b/cddl/usr.bin/ztest/Makefile
+--- a/cddl/usr.bin/ztest/Makefile 2012-03-30 18:58:53.174771000 +0000
++++ b/cddl/usr.bin/ztest/Makefile 2012-03-30 19:06:58.344895642 +0000
+@@ -17,6 +17,11 @@ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/
+ CFLAGS+= -I${.CURDIR}/../../contrib/opensolaris/head
+ CFLAGS+= -I${.CURDIR}/../../lib/libumem
+
++LDFLAGS+= -L${.CURDIR}/../../lib/libavl
++LDFLAGS+= -L${.CURDIR}/../../lib/libnvpair
++LDFLAGS+= -L${.CURDIR}/../../lib/libumem
++LDFLAGS+= -L${.CURDIR}/../../lib/libzpool
++
+ DPADD= ${LIBM} ${LIBNVPAIR} ${LIBUMEM} ${LIBZPOOL} \
+ ${LIBPTHREAD} ${LIBZ} ${LIBAVL}
+ LDADD= -lm -lnvpair -lumem -lzpool -lpthread -lz -lavl
+diff -upNr a/cddl/usr.sbin/zdb/Makefile b/cddl/usr.sbin/zdb/Makefile
+--- a/cddl/usr.sbin/zdb/Makefile 2012-03-30 18:58:53.164736000 +0000
++++ b/cddl/usr.sbin/zdb/Makefile 2012-03-30 19:07:17.454861002 +0000
+@@ -23,6 +23,13 @@ CFLAGS+= -I${.CURDIR}/../../../sys/cddl/
+ CFLAGS+= -I${.CURDIR}/../../../cddl/contrib/opensolaris/head
+ CFLAGS+= -I${.CURDIR}/../../lib/libumem
+
++LDFLAGS+= -L${.CURDIR}/../../lib/libavl
++LDFLAGS+= -L${.CURDIR}/../../lib/libnvpair
++LDFLAGS+= -L${.CURDIR}/../../lib/libumem
++LDFLAGS+= -L${.CURDIR}/../../lib/libuutil
++LDFLAGS+= -L${.CURDIR}/../../lib/libzfs
++LDFLAGS+= -L${.CURDIR}/../../lib/libzpool
++
+ DPADD= ${LIBAVL} ${LIBGEOM} ${LIBM} ${LIBNVPAIR} ${LIBPTHREAD} ${LIBUMEM} \
+ ${LIBUUTIL} ${LIBZ} ${LIBZFS} ${LIBZPOOL}
+ LDADD= -lavl -lgeom -lm -lnvpair -lpthread -lumem -luutil -lz -lzfs -lzpool
+--- a/cddl/usr.sbin/dtrace/Makefile.old 2011-07-06 00:09:01.000000000 +0000
++++ b/cddl/usr.sbin/dtrace/Makefile 2011-07-06 00:09:48.000000000 +0000
+@@ -24,6 +24,8 @@
+ #CFLAGS+= -DNEED_ERRLOC
+ #YFLAGS+= -d
+
++LDFLAGS+= -L${.CURDIR}/../../lib/libdtrace -L${.CURDIR}/../../lib/libctf
++
+ DPADD= ${LIBPTHREAD} ${LIBDTRACE} ${LIBY} ${LIBL} ${LIBPROC} \
+ ${LIBCTF} ${LIBELF} ${LIBZ} ${LIBUTIL} ${LIBRTLD_DB}
+ LDADD= -lpthread -ldtrace -ly -lfl -lproc -lctf -lelf -lz -lutil \
+--- a/cddl/usr.sbin/lockstat/Makefile.old 2011-07-06 00:10:33.000000000 +0000
++++ b/cddl/usr.sbin/lockstat/Makefile 2011-07-06 00:10:57.000000000 +0000
+@@ -23,6 +23,8 @@
+
+ CFLAGS+= -DNEED_ERRLOC -g
+
++LDFLAGS+=-L${.CURDIR}/../../lib/libdtrace -L${.CURDIR}/../../lib/libctf
++
+ #YFLAGS+= -d
+
+ DPADD= ${LIBPTHREAD} ${LIBDTRACE} ${LIBY} ${LIBL} ${LIBPROC} \
diff --git a/sys-freebsd/freebsd-cddl/files/freebsd-cddl-9.0-underlink.patch b/sys-freebsd/freebsd-cddl/files/freebsd-cddl-9.0-underlink.patch
new file mode 100644
index 000000000000..ff87d2c6ef9b
--- /dev/null
+++ b/sys-freebsd/freebsd-cddl/files/freebsd-cddl-9.0-underlink.patch
@@ -0,0 +1,22 @@
+--- cddl/lib/libzfs/Makefile.old 2011-11-04 10:27:30.000000000 +0000
++++ cddl/lib/libzfs/Makefile 2011-11-04 10:28:59.000000000 +0000
+@@ -7,7 +7,7 @@
+
+ LIB= zfs
+ DPADD= ${LIBMD} ${LIBPTHREAD} ${LIBUMEM} ${LIBUTIL}
+-LDADD= -lmd -lpthread -lumem -lutil
++LDADD= -lmd -lpthread -lumem -lutil -luutil -lnvpair -lm -lgeom
+
+ SRCS= deviceid.c \
+ fsshare.c \
+--- cddl/lib/libzpool/Makefile.old 2011-11-04 18:22:28.000000000 +0000
++++ cddl/lib/libzpool/Makefile 2011-11-04 18:24:01.000000000 +0000
+@@ -57,7 +57,7 @@
+ CFLAGS+= -I${.CURDIR}/../../../lib/libthr/arch/${MACHINE_CPUARCH}/include
+
+ DPADD= ${LIBMD} ${LIBPTHREAD} ${LIBZ}
+-LDADD= -lmd -lpthread -lz
++LDADD= -lmd -lpthread -lz -lumem -lnvpair -lavl
+
+ # atomic.S doesn't like profiling.
+ NO_PROFILE=
diff --git a/sys-freebsd/freebsd-cddl/files/zfs.initd b/sys-freebsd/freebsd-cddl/files/zfs.initd
new file mode 100644
index 000000000000..a62d7fbeb1c2
--- /dev/null
+++ b/sys-freebsd/freebsd-cddl/files/zfs.initd
@@ -0,0 +1,23 @@
+#!/sbin/openrc-run
+# Copyright 1999-2012 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+depend() {
+ need hostid
+ before fsck
+}
+
+start() {
+ einfo "Starting zfs ..."
+ zfs mount -a
+ zfs share -a
+ if [ ! -r /etc/zfs/exports ]; then
+ touch /etc/zfs/exports
+ fi
+}
+
+stop() {
+ einfo "Stopping zfs ..."
+ zfs unshare -a
+ zfs unmount -a
+}
diff --git a/sys-freebsd/freebsd-cddl/files/zvol.initd-9.0 b/sys-freebsd/freebsd-cddl/files/zvol.initd-9.0
new file mode 100644
index 000000000000..c4071474fc2f
--- /dev/null
+++ b/sys-freebsd/freebsd-cddl/files/zvol.initd-9.0
@@ -0,0 +1,44 @@
+#!/sbin/openrc-run
+# Copyright 1999-2012 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+depend() {
+ need hostid
+ before fsck
+}
+
+start() {
+ einfo "Starting zfs volumes..."
+ eend $?
+ # Enable swap on ZVOLs that have org.freebsd:swap=on.
+ zfs list -H -o org.freebsd:swap,name -t volume | \
+ while read state name; do
+ case "${state}" in
+ [oO][nN])
+ einfo "Enabling swap on zvol ${name}"
+ swapon /dev/zvol/${name}
+ eend $?
+ ;;
+ esac
+ done
+}
+
+stop() {
+ # Disable what we had enabled before.
+ zfs list -H -o org.freebsd:swap,name -t volume | \
+ while read state name; do
+ case "${state}" in
+ [oO][nN])
+ einfo "Disabling swap on zvol ${name}"
+ swapoff /dev/zvol/${name}
+ eend $?
+ ;;
+ esac
+ done
+ einfo "Stopping zfs volumes..."
+ eend $?
+}
+
+restart() {
+ :
+}
diff --git a/sys-freebsd/freebsd-cddl/freebsd-cddl-11.1.ebuild b/sys-freebsd/freebsd-cddl/freebsd-cddl-11.1.ebuild
new file mode 100644
index 000000000000..06a875225fed
--- /dev/null
+++ b/sys-freebsd/freebsd-cddl/freebsd-cddl-11.1.ebuild
@@ -0,0 +1,77 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd toolchain-funcs multilib usr-ldscript
+
+DESCRIPTION="FreeBSD CDDL (opensolaris/zfs) extra software"
+SLOT="0"
+
+IUSE="build"
+LICENSE="CDDL GPL-2"
+
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64-fbsd ~x86-fbsd"
+fi
+
+# sys is required.
+EXTRACTONLY="
+ cddl/
+ contrib/
+ usr.bin/
+ lib/
+ sbin/
+ sys/
+"
+
+RDEPEND="=sys-freebsd/freebsd-lib-${RV}*
+ build? ( sys-apps/baselayout )"
+
+DEPEND="${RDEPEND}
+ =sys-freebsd/freebsd-mk-defs-${RV}*
+ !build? ( =sys-freebsd/freebsd-sources-${RV}* )"
+
+S="${WORKDIR}/cddl"
+
+PATCHES=( "${FILESDIR}/${PN}-11.0-workaround.patch"
+ "${FILESDIR}/${PN}-11.0-add-libs.patch" )
+
+pkg_setup() {
+ # Add the required source files.
+ use build && EXTRACTONLY+="include/ "
+ [[ $(tc-getCXX) != *clang++* ]] && REMOVE_SUBDIRS="usr.sbin/zfsd"
+}
+
+src_prepare() {
+ if [[ ! -e "${WORKDIR}/include" ]]; then
+ # Link in include headers.
+ ln -s "/usr/include" "${WORKDIR}/include" || die "Symlinking /usr/include.."
+ fi
+ for d in libavl libctf libdtrace libnvpair libumem libuutil libzfs libzfs_core libzpool; do
+ LDFLAGS="${LDFLAGS} -L${S}/lib/${d}"
+ done
+}
+
+src_compile() {
+ cd "${S}"/lib || die
+ freebsd_src_compile
+ cd "${S}" || die
+ freebsd_src_compile
+}
+
+src_install() {
+ # Install libraries proper place
+ local mylibdir=$(get_libdir)
+ freebsd_src_install SHLIBDIR="/usr/${mylibdir}" LIBDIR="/usr/${mylibdir}"
+
+ gen_usr_ldscript -a avl nvpair umem uutil zfs zpool zfs_core
+
+ # Install zfs volinit script.
+ newinitd "${FILESDIR}"/zvol.initd-9.0 zvol
+
+ # Install zfs script
+ newinitd "${FILESDIR}"/zfs.initd zfs
+
+ keepdir /etc/zfs
+}
diff --git a/sys-freebsd/freebsd-cddl/freebsd-cddl-9.1.ebuild b/sys-freebsd/freebsd-cddl/freebsd-cddl-9.1.ebuild
new file mode 100644
index 000000000000..517b17da8e2c
--- /dev/null
+++ b/sys-freebsd/freebsd-cddl/freebsd-cddl-9.1.ebuild
@@ -0,0 +1,60 @@
+# Copyright 1999-2013 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=4
+
+inherit bsdmk freebsd toolchain-funcs multilib usr-ldscript
+
+DESCRIPTION="FreeBSD CDDL (opensolaris/zfs) extra software"
+SLOT="0"
+KEYWORDS="~amd64-fbsd ~x86-fbsd"
+
+IUSE="build"
+LICENSE="CDDL GPL-2"
+
+SRC_URI="mirror://gentoo/${P}.tar.bz2
+ mirror://gentoo/${CONTRIB}.tar.bz2
+ mirror://gentoo/${UBIN}.tar.bz2
+ mirror://gentoo/${LIB}.tar.bz2
+ mirror://gentoo/${SBIN}.tar.bz2
+ mirror://gentoo/${SYS}.tar.bz2
+ build? ( mirror://gentoo/${INCLUDE}.tar.bz2 )"
+
+# sys is required.
+
+RDEPEND="=sys-freebsd/freebsd-lib-${RV}*
+ =sys-freebsd/freebsd-libexec-${RV}*
+ build? ( sys-apps/baselayout )
+ dev-libs/libelf"
+
+DEPEND="${RDEPEND}
+ =sys-freebsd/freebsd-mk-defs-${RV}*
+ !build? ( =sys-freebsd/freebsd-sources-${RV}* )"
+
+S="${WORKDIR}/cddl"
+
+PATCHES=( "${FILESDIR}/${PN}-9.0-bsdxml.patch"
+ "${FILESDIR}/${PN}-9.0-underlink.patch"
+ "${FILESDIR}/${PN}-9.0-libpaths.patch" )
+
+src_unpack() {
+ freebsd_src_unpack
+ # Link in include headers.
+ ln -s "/usr/include" "${WORKDIR}/include" || die "Symlinking /usr/include.."
+}
+
+src_install() {
+ # Install libraries proper place
+ local mylibdir=$(get_libdir)
+ mkinstall SHLIBDIR="/usr/${mylibdir}" LIBDIR="/usr/${mylibdir}" || die
+
+ gen_usr_ldscript -a avl nvpair umem uutil zfs zpool
+
+ # Install zfs volinit script.
+ newinitd "${FILESDIR}"/zvol.initd-9.0 zvol
+
+ # Install zfs script
+ newinitd "${FILESDIR}"/zfs.initd zfs
+
+ keepdir /etc/zfs
+}
diff --git a/sys-freebsd/freebsd-cddl/metadata.xml b/sys-freebsd/freebsd-cddl/metadata.xml
new file mode 100644
index 000000000000..a00f3aeb1f81
--- /dev/null
+++ b/sys-freebsd/freebsd-cddl/metadata.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+<maintainer type="project">
+ <email>bsd@gentoo.org</email>
+ <name>BSD Project</name>
+</maintainer>
+</pkgmetadata>
diff --git a/sys-freebsd/freebsd-lib/Manifest b/sys-freebsd/freebsd-lib/Manifest
new file mode 100644
index 000000000000..9beed09e413a
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/Manifest
@@ -0,0 +1,45 @@
+AUX bootpd.confd 183 BLAKE2B 76fb1b41204f2b3d07cc974ec996ff9127945dc638796b176cd8809ca46fb69fa307f3fa313d48d79a7deb532d393ab58839ed7ae53927280f0178c20c4df3c4 SHA512 3f097c1acb5547add8d12fcee0b4b55b03896cb3ba473214d1634804f3683e0dea4b3c9559b61b2366b7f264d7a3d878695e16f29acff076b8060ca1fd79757f
+AUX bootpd.initd 554 BLAKE2B 86c2128a8f17a1d8eb57ef935a6e5a2b04f5c8c6654ecf40b10559912f30effb189f55e7f34ef37b496d8f9f8eb8726ab6af2ca179cb215809d76d1293ffb338 SHA512 69bc8dc708d955e41d3e0cfb997f96b589e8a3d33b11b2728541082fc5ab0844d753ca036a6c70ddd23a2a0085c39a89340b0f7d332b1384c94671cf3fe09b66
+AUX freebsd-lib-11.0-bsdxml2expat.patch 1103 BLAKE2B 7dd06eca9f528b2cbd7741c6f977b3580eb6231395be376d0bcdbcc767d9ff9bb585eb2579d65e6ad851eb68c77ccb71af95e8aeef58fa2a757f559c07c7f79f SHA512 a0e9d99ff47ce813a98a5c1fd3605dd757ceb6c4f68e3784f1b48192c9f0966cbf1c769387a808ae4511f004b00242fc47f7fd3a2971e371de587cac6827533e
+AUX freebsd-lib-11.0-libproc-libcxx.patch 350 BLAKE2B 0b0a9886567b9c81c8159266eba2f5957d81b90b816e76b21cd2a5c90e9eeb008acda1f7d2338167d20ee8a4b57e45ddd92ab978dd472e0752bbc8c055332240 SHA512 c9ace882ac2fb2a077839a02a4307ce7df1dd0699cef081e6a99f12f9c2b443e4a4e4f85415a59d208859442dc665d7b9cae22de8d61f80ab8a5875d423c5795
+AUX freebsd-lib-11.0-workaround.patch 295 BLAKE2B 3e0fa9e7c981caeb11c75e5c7ccfef597a6129c0ea098f2d6945aac4439cfc9f937463b989078f4148e995efeee28cfc81de77e8a1acd7da9a3d913c5dfe82e5 SHA512 5c7559dc1876e833f440bc85e23e601eaa5dd26484b1905a5a59e29345f83438208770671c248b4dfb5138c4dded1f08234c77070afadb5c6b54e2b6dc35e24a
+AUX freebsd-lib-11.1-elf-nhdr.patch 287 BLAKE2B 76f5c3b448ceb62b67eb5973201e59b61dc1fa5e3f06d3cec28377b803421f99c207f93d9b1d3963a3b6a3dbfa1132bab1637ea5b1986cad9f85db7b2ae786a7 SHA512 24adf537a277e5bb10e3701cdf37bf9be69b8fe57b88b947b04a57bdcd8e26f67e912ea812eccc8ba88df71076a9c4edeec7f709808d5835b44c210e905784c5
+AUX freebsd-lib-11.1-liblink.patch 4233 BLAKE2B e088abc8f738475e09793cf59cb41257e2143a8daf7dbbdeb81190aec95e6d15b800862033353e556d87f757be43693e6b0895a6900fd58fff580ef8e6f1279a SHA512 23a875fa84685c7a98ddb08b1bcf831613239a6079c1711362bbbd19f27b67e61eb203bafc48c9ad06b9344258005e4d04756d4f8caba7c9545f3f86dcb52830
+AUX freebsd-lib-6.0-flex-2.5.31.patch 421 BLAKE2B df851549b6978ab7b59585fbaec7c3bcea19f8eb6b1a2882343618c21ef2533fb8a56f9c8a362b7c188c97e5d0091b02288a457fe114b8e2e6dbe4b69bfad62d SHA512 c16a99b85e7908e77915796245741cbfcfb30ab1f4f0a8d565c28256b25d1532209ed27328d8b1571f61677251830f1fb6bbec17a8104686f56afd87f3226dec
+AUX freebsd-lib-6.0-pmc.patch 338 BLAKE2B 8c587f716fba0237e114af0c1860493c2aff046447f4469ba813a67e44779caa58f5b45108dc12634b7303401725006bed3b254459993972894a242737bb08bf SHA512 33187ec853ddf0c39680af60b669e60d3e213eba20a2e1ba995c991f04c053c5adcc5169b92c5d1d4cfbc7e03b72af2df4a5349361b41c56ca4a9b91e81bb327
+AUX freebsd-lib-6.1-csu.patch 655 BLAKE2B acd7ed7144a59494d656c66e823c884f4cf5c112ac1ec55add9c25745ce737ed1c6e56c82e8a0718c8c1ac3b8ab7b2e8edd51a1aedaa5f6684d6ba4e30771722 SHA512 926d8aafd6f517a0fb97af61746d53bafab7fe7003f71181c43b4f9b31e7652624d060a350cc23d83ca7da7c1be2dcc048bb00a581c3524f0f2b7b06de6100b4
+AUX freebsd-lib-7.1-types.h-fix.patch 371 BLAKE2B 358a52999cd48561beb41e051829e0d47aba07d73b8852c0e164debfeeaa22e8dd04249897f807192239be3be673f1a51df98f8ee63529ceca5d469fd6cfc5e5 SHA512 133ab13e98c3f2dc5f96cd5e45cd11c4da9757f4ea64831a6e17b309bc4692e4213b48c7ab6dd634f1feb069ca2dfc3a8afe1585d0d1425b5304fd7494cd342f
+AUX freebsd-lib-8.0-gcc45.patch 1264 BLAKE2B ad0884780b17fd02a6347e85654feadc0a496f4463ce2e8e796c74213f5554c0d61e595dc1e9b1bfb30a431f3fda5863ff0a2dda046bfb0f01e7bfce7ad991e8 SHA512 12b81def4e7690cf5b910f31466b06c3fdf58f38a41f63dd359582d8f480e8081b54fd4997c6595e9e1a8912f991ba1b8d04989e270f242dd547d72c9ad5ea57
+AUX freebsd-lib-9.0-bluetooth.patch 318 BLAKE2B d86b2c48ca86bd3415073f03c311444eb3adc32f7990754396fb6383c63ccd66b3aa562d75c1817941c59497fcb709f59df1e49186f6a59a437416f8bbbcbc41 SHA512 71cba168c1530407840dde9e25ce374abb7e0d69800e85bf6f5aff28d1a777ff31f47a84ab763e1518d3492f604d1c09ca95cf8ec5b4e05e8bd5b85267ca4488
+AUX freebsd-lib-9.0-cve-2010-2632.patch 6963 BLAKE2B c8e49014e253306abac9752cc3e308da48f76ac02d96888848645d98bc2e9aa8159e56710f7e6df1d6722d25463aa8c3827151565f30e33d31a8fde1abb46f44 SHA512 bb7090a0acbf8ab431334245b1e767da60dcf8f2d23de97a4690e879ae5d528065f5462e2ad3647313662a906f139cfff04f15bce80efede2d2174f74792a07b
+AUX freebsd-lib-9.0-liblink.patch 627 BLAKE2B cbd14d69fc854e60d32882050ef5e035e51688a3f5b426488d2d3c58e45f956cbc62a4d76345d99e9857370094d969cd6f50a9a0c1ae8e04711de5d6f68bcb80 SHA512 0c570fea9cc386afe4b742985cf7de4d49370be3f34b2059dee76869d8e64bd52db0a07e61fac8924848d12d0e6d510ad6a266ce8ef76e2be885d81d909ab616
+AUX freebsd-lib-9.0-netware.patch 400 BLAKE2B b9e6c14739e7547b9c053a2143afc413b112908fdbab0b40bd5e8d025331ad13796c4be5c7fcaa25a8b2b1f7a38bf9b80cd615fa7b6345843f7089f22dd4cbdf SHA512 07ebde5797480f37502e60db2a8c9ce9459bd55b176e79c0f20a859cf737f619559cb27706fb0e83fb501493677a3ffeaa9a98d45db3c0c539b71d2f18140246
+AUX freebsd-lib-9.0-opieincludes.patch 4495 BLAKE2B 31508eb84ac06e6cbceec5b65d46f566f0cdfb5cbd344530b8d9ddc8984f572bfce6371098f33698c16fc459d51727286f318de5af508de7878b46c33e03782a SHA512 a3828985f7da9e72ad44d88640952d56079693024bc11b4e3cca86b6f455a9e4756ba76f9e6d4c15960898f39e1dac7bc833e3241082f532c7fbd6d7d6f9418b
+AUX freebsd-lib-9.1-.eh_frame_hdr-fix.patch 695 BLAKE2B 94c43f89d54cf01e7c2095615ee4913dabc81824c19fbfcc2e58f357e2254cca3a972d4beae303ac51c579339a8d97e7fa5abc7eb21bed16e0291a975193ed35 SHA512 c40270e8890a1152a6f2e705461ac64f8cc44e6d0306d895a0d146017d4fe3553853de88178e0744fc1be4197a4eb35b578c68593c80467dd8cf15c35720413d
+AUX freebsd-lib-9.1-aligned_alloc.patch 1355 BLAKE2B c2d7a867aabbfd72d888e374f8f45fba263eb1358ebce70989149bf7a10d736bb88723e6bd2eafdec22e31d928299493d7ddcb758ab4a4507316dba72a48c82a SHA512 d9ac6008650efcd02ff1a0f64ac486e413c926681082d4ab9c1cb5abfbf1070e44b723e685a0b5b0e7159ab9071d85c5ee08c9063c9dcda470dfaa06a29391bc
+AUX freebsd-lib-9.1-rmgssapi.patch 699 BLAKE2B 2ac005efd364e4a64ffe0d1fc88bcf9d56ce449f5d22037afb54fa7b2bd1fbfdb959ef23fda2b7fa291c9d893d22529d3000fd17d600deee5b26654110e15641 SHA512 cb0b292cca0c321ed72b1a792a3975be239303b3990efc6665b0c960dfe17fdbb4529405286c0a956c4b4711462d2ee9d7d1c9d343ad3246b43c49edfc87dae0
+AUX freebsd-lib-add-nossp-cflags.patch 1193 BLAKE2B da7842da17bddf59d7eac48da7d3283ea742afcb07d962f6876ff19b5a2731d9ecd62d704ad7c5b7c5d019dd683dba52004db8596419a23569c2ada121450dac SHA512 fcb290527381df5b91355ca7f36bb4c770378b014890e7a4d129b7cc28e7c18cb1f87ef9e1b308e0de61b54d767677865969c77a9877d8874f2bec223331f9f8
+AUX freebsd-lib-bsdxml2expat.patch 708 BLAKE2B bb35aa6343b6af82e42296b1e94c5420609c67fa2970b7b34de9518234219e913a5f00828cb859f308b742354db9a0557e57c43eb341ca9b8c03a9c2e14583e3 SHA512 d3b321062886ee636a09af4b8714ae90317c17eb954a3d491cd21ca90605e26491033df4d6f02a517eda423783db74dad16adf7ee1bdc5557392cc70218ee9c7
+AUX freebsd-lib-includes.patch 316 BLAKE2B 60a6260437b95b74ec6fb54ad1d9f29bda9122f2407f0368d8e07abecac9e4217fe28f534b6dcd6a782962a980ff4ccbe055eb105e46c93bcc6966190ac43a91 SHA512 31b7f368a4d3998e42486cb944a001a8371c365276eac94fa8712e29dbe9a13a7756a2fd77fbff87a1f7f4c19b32721c74bbb099f611d46a8c78b73f92d9255e
+AUX freebsd-sources-9.0-sysctluint.patch 403 BLAKE2B 3860821b308a75dcad8fa5910cb6c287ca2013269d21b588d0abbb1a79197366eac7eb733c87136f77ba2556913f36784842ac5f089d5c9bdb59bdb836748049 SHA512 f3a87cb187858bc6fd1bafda3c3bd7bbda52b07239a50a7c1aa201df2c52a58d4809e196b8799b1949c8ca1a556519d454ad1789358540e3a96cd480fc0a504c
+AUX libusb-1.0.pc.in 207 BLAKE2B c875ca3dbd083dab223906e3f162e744477c8b2630da79803639c841e2162ff3bebcd5fbdf679e091cec835d0d324de8ae32a316049f39802700cca2c2fd1281 SHA512 93289cecfc298a31fd4fd0848bf25a63048a7549bd81792d7bd158731246221c24ec9f469a918430da56873a0936fb2b372cedaaa32a38ccd5323de0f9a89b93
+AUX libusb.pc.in 208 BLAKE2B 2995d5f059679bf7c246917fdbb10e2cc81ed3de0c6e6884069f4fa37459652a5363fbca52e3dde8153aefa208d2a04df387fd4987dedff640e051edbd3ed6db SHA512 e9c6d5f04057cf8c13f69a3d8e07bdd517fdb01d572a69a1beb397766311b3c53894b108caaaea740bfc27b227a9620621dac5846bff1a367fbf9954f38bb40c
+AUX rquotad.xinetd 162 BLAKE2B 87633efa7d9732c498de807976fdc65e3ec15eaef596f7f3f52e3a065fd0b6a9d592c3823a3c84cb9d363df5870f81f00d4a140a6df6e54cbfe239157af05c6b SHA512 2cf16514f18abe2aeaa273fabc2dc94b09f31d02001ece5c82d9336c02d921e03dff6f82a613a4bffe57b5e415add2b82ef883a306907dd20ffe1bbe332b011f
+AUX rstatd.xinetd 218 BLAKE2B a998b50e4f3a49582529d0d1751a4111b0705f03e53e677395043db38b743a5d017799d4dbfa26eeb107d5d657d82af88198d6477452976b59458ce5f7912417 SHA512 febca8ab8248b1c103dd7be0806e3d678c5b5cf165a7b3bd0305bc905da228bf92392d65d44a765b7692f772befeedcbc3df205d32bb62ad5aa307f71a1c1011
+AUX rusersd.xinetd 220 BLAKE2B 60590eb0a4115ab0cdc3248beb4940f7cc6526967963e1e1791dee53a08b2ada06d2f740246bcf4e5c2a9665f612e7b613e5f437576df468ec6fd29712cb0d0f SHA512 fdf4ef4e0b0dd11c64fb38d32c9fca2d378a69e4cff87523127089d7dc0db12b26f6399c7a61fc43d62ca8083b116440f6fffff9e3329f0548bf54f0f26699cd
+AUX sprayd.xinetd 216 BLAKE2B 8e154d0eb67616b6245a002d95b260c32243c8f230861b31a51f67b84d6b56627f2328b58db5cc6d6df85c8831d0c1996ea707ff0058a059b7b5b77a81b6e59d SHA512 a49824ab0421560699901f54d9faf3f38fb6f8d8f63f05e33eb11da053278838e80eaabf5963b1c2a7292ba2d2118e1efd90954b2f3b2dc01b945fbadc6ce101
+AUX walld.xinetd 215 BLAKE2B dbf0093f41762c8e493e34bd52e52f61961fcd2dfeeae981c275c983f3ce4f85283c6e81ca379f827088b1274dff9a1f9dd9dffd714a33021b34c12ca07ccfe1 SHA512 ab78d32e48d660649d3415a4432a5f3e98f8a6a8854791d1d828b0dc678f58e9f24532c264c5f5b039ccd706e0bb70c369ba9fb55fc9af9d3ed9b28e10b9e830
+DIST freebsd-cddl-9.1.tar.bz2 899348 BLAKE2B 419e475b4c3debacd0d0fbbad4d1b13685c1c5ac741cc8cfb53dadce9d30cf9ddd7132ef8ab897787be538028d34bb9603eb76caf7650f4f50bb3295f19bf035 SHA512 ae0a969e710785bbcf36a2ec22cc5b1dcdb25398be951e047a1237d0c977e38fc9e05504db51f8bf9ed83bc1f68b04fc88ce18fc48a93f785b8a3f8ef481bacd
+DIST freebsd-contrib-9.1.tar.bz2 54751432 BLAKE2B 8a30e78021e6388d679637d2dbe0ed3f4896d3902064baaafa79de9c328171cbcb895b0ffd3d0d0cd3ca25c93a73584ed4900b45bd672a73b15b75721de59de5 SHA512 71be13049258c6e6b5e4f63cc16da5d349a89d68f04d87446e4ad33ae8bf2a93ea67d9c256b7bec60b61e65db0487268070cfb77a484c3ac0f8ba368b48c2438
+DIST freebsd-crypto-9.1.tar.bz2 5682828 BLAKE2B f6b14f5319932b8680a79abab41ff6b447045464992ad8a22ebc0a6bf89f60559881ed34a26639d5d09af7b66972d2105181186c4cb42c5d6fdbf65b342ae38a SHA512 40c7a8150fb3ddd93488502a976ce03e992e6f4fb28aa3e5e102d4915f8ff49fe9085995ccfecacefc3b665e23c85cc3a0cdeec20a32c79e04458f7cc88630d9
+DIST freebsd-etc-9.1.tar.bz2 207776 BLAKE2B 61fbfa11dfcd24c007c20940a4b7cc802dfb9a991e41433840c57f113eaaa9e2b833a15f48d60c706e55d941b0a999baabd0c33197cffd522b67c57eaa9460f1 SHA512 4fbe56fde519cf2f44e39a8869efa26c34f703cf540f4a83389da8d170873d7c6fb18e4010e643b8d793cfc5c55d15eeb198057a5b2a8da9d9e8f791801bf314
+DIST freebsd-gnu-9.1.tar.bz2 795778 BLAKE2B a922a8bd2c8a7ddbac757e7db900109918bf214a34988adb45bdb11e5c829445cac9b13b0ed27ec62603aeae1e3230af362682182494db0ec95ff47cbfd7d927 SHA512 b05f2a5a10bdaeef19dfd0e962bc09f1571288a831e9345f404b920037f47db5c0ca3d620d1cbdd138b18bca1c3feab5b211b57e3041727341e5238cb9feb4fd
+DIST freebsd-include-9.1.tar.bz2 146881 BLAKE2B 3db8570a8c841ec1c9ceff479bd0ef9b146b2a343d6596892c9d8a9f9193404f6c62712cb96d7416c6e5cc4c46e7fb942421c47e1bc2c707dde534e2050be442 SHA512 779c8315ce2b10b343bb62e331525d510b0d68ce5d665a1672bd6f4d1eff6445bc6b7a0f178b319828aa203c4e4c04c561ce793052703f4f936ce9711280a0c9
+DIST freebsd-lib-9.1.tar.bz2 3206685 BLAKE2B 67f93b7951fc03e877ee525d53b81ba49c8c1a70041c30aac97665d5dab7b3f2817fdb3bbb1475be66c33a7f996309e9020f1a3d1154fab8e2f6789f5ae0bb18 SHA512 40d0c36b6b889c404fa0e0afa38ba4e84a55bc88ffa2f98a70afbd7a32c4f32c158617ba770567d082a986d62c09b3ec8db3dc5ab853ee1c9bbe0b90bb82396e
+DIST freebsd-libexec-9.1.tar.bz2 304592 BLAKE2B 994543ac910e4703d36682f6c0550596e340605754b9386770660f0ed0e70f8d437185f2010e6be795a8cc508aa7d69c90cc0a0df968c5dd8de4c5c4bb38e8c2 SHA512 7baa4160dda2610250dd52f445e24478e0f1ea10bce21fcd0e5d1b856f399b896adc334114de0c7f61a5637e4349bb1688fdbe5c72798d8568ae791114710b92
+DIST freebsd-src-11.1.tar.xz 147661560 BLAKE2B a9e6ba9d0e12c8b56ac58575d5f02931edbb6a3545d9dccae78810d2d0470a29b29dd7f724b03b8afafbca23717a71346e4cfbd3530e0f40118a23609c3f414e SHA512 b97707ec7a601ca6bcb682c45f6d94a38484301ac24630d7285eff6f88b027ce6900c93fc62f8ce36e0cf32c91f73a9d1c999db397b7f8782fd74a8551a03aca
+DIST freebsd-sys-9.1.tar.bz2 32588103 BLAKE2B 7f94a4735c6a17b39a86fa0fda0682924b18e4b466dc6319a5df889522aaeaffaa87e1b76582c48ae034df8c20169c8cea93bbd3d6e7abd0526716686f88dfe8 SHA512 7dc9d9e00dde8f592bb171f4386d02b655b73cb4f153fe5ec063d010a148ef0639eae0dcdb3eeb09ecd1e3653c69e49a2d261329fa6d0381d2ddabe258ddde6d
+DIST freebsd-usbin-9.1.tar.bz2 2670916 BLAKE2B 353c7e641c0cccf25b99cb454368bd3001cd6b85a15956b1ee2de1ab240c420602e04bf6d0389aca0bdd4f7d1206a6848516e58a17eda4881d849f078b71a139 SHA512 21c234312f70eb35cd2926519efc1f61592892f5d0940786dbeb959c3c5ec7819a51ae95c6e8a1a06aa01f669350fe0fd3dd7c4ec8a84dd6b90f24cb192356ca
+EBUILD freebsd-lib-11.1-r1.ebuild 21724 BLAKE2B 68edc92625bd55e2fa821407400225aca1d1f1c1c4c88206b991513f16b00ec5aa2650d1d86e5d4eaf67d3a1f2b3b8c22bb2707c1a67342c75110626af59c13a SHA512 5432e62e686fb7d42f4eb5138900a42e72d13ebc24ed7f0166a20fc67b143f0ed10e884a82d4ffcaa303891b08779b40aa21f7e981bedd16d3461745983c1d7e
+EBUILD freebsd-lib-9.1-r11.ebuild 18728 BLAKE2B 51adae6ab935fc4c521090b1431aa86fb9e2469733a118479040c6dc14326614ebbca80ea08f6407efb675b57edc4751141aafcb60cf09b172ecd2707efbc9a5 SHA512 d3c4578d4297cdad219959c40a31576d1aaafe53c95adcda88fe946b221adb409e359ae60697ed0888d93cf3f65d66db5cc4630f443fa52014fad29c54bf9919
+MISC metadata.xml 435 BLAKE2B a3a4660e1e514808dc3798a4903fd90da26772e8265845ab2b70b8a00239c603493f1fef46b4e095f6fa4f3cbc039bde045d1e8a34f6d7ccf6aedad2df8a56c6 SHA512 6764bb11f73e8717651797e909a02af0aaed5f61537db85290efa52be10fa7d1be6c13e69f27230daa9a2ace0b3cab4109156b523adcca62ac3d298e491e63a3
diff --git a/sys-freebsd/freebsd-lib/files/bootpd.confd b/sys-freebsd/freebsd-lib/files/bootpd.confd
new file mode 100644
index 000000000000..6d238e4d4853
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/bootpd.confd
@@ -0,0 +1,7 @@
+# Configuration file for /etc/init.d/bootpd
+
+# Name of the configuration file for bootpd
+# bootptab_file="/etc/bootptab"
+
+# Options to pass to bootpd. See bootpd(8).
+# bootpd_opts=""
diff --git a/sys-freebsd/freebsd-lib/files/bootpd.initd b/sys-freebsd/freebsd-lib/files/bootpd.initd
new file mode 100644
index 000000000000..82288ebf19c3
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/bootpd.initd
@@ -0,0 +1,27 @@
+#!/sbin/openrc-run
+# Copyright 2008 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+depend() {
+ need net
+}
+
+start() {
+ local bootptab=${bootptab_file:-/etc/bootptab}
+
+ if ! [ -f "${bootptab}" ]; then
+ eerror "Unable to find the bootptab file: ${bootptab}"
+ eend 1
+ return 1
+ fi
+
+ ebegin "Starting BOOTP server"
+ start-stop-daemon --start --exec /usr/libexec/bootpd -- ${bootpd_opts} ${bootptab}
+ eend $?
+}
+
+stop() {
+ ebegin "Stopping BOOTP server"
+ start-stop-daemon --stop --exec /usr/libexec/bootpd
+ eend $?
+}
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-11.0-bsdxml2expat.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-11.0-bsdxml2expat.patch
new file mode 100644
index 000000000000..41a394b815a0
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-11.0-bsdxml2expat.patch
@@ -0,0 +1,39 @@
+diff --git a/lib/libgeom/geom_xml2tree.c b/lib/libgeom/geom_xml2tree.c
+index 9dedb8e..d96420c 100644
+--- a/lib/libgeom/geom_xml2tree.c
++++ b/lib/libgeom/geom_xml2tree.c
+@@ -43,7 +43,7 @@
+ #include <sys/sbuf.h>
+ #include <sys/sysctl.h>
+ #include <err.h>
+-#include <bsdxml.h>
++#include <expat.h>
+ #include <libgeom.h>
+
+ struct mystate {
+diff --git a/lib/libmt/mtlib.c b/lib/libmt/mtlib.c
+index d1fc0b1..89ac55e 100644
+--- a/lib/libmt/mtlib.c
++++ b/lib/libmt/mtlib.c
+@@ -48,7 +48,7 @@ __FBSDID("$FreeBSD: stable/10/lib/libmt/mtlib.c 280438 2015-03-24 14:36:10Z ken
+ #include <unistd.h>
+ #include <stdint.h>
+ #include <errno.h>
+-#include <bsdxml.h>
++#include <expat.h>
+ #include <mtlib.h>
+
+ /*
+diff --git a/lib/lib80211/lib80211_regdomain.c b/lib/lib80211/lib80211_regdomain.c
+index c500d3f..fe1d37e 100644
+--- a/lib/lib80211/lib80211_regdomain.c
++++ b/lib/lib80211/lib80211_regdomain.c
+@@ -40,7 +40,7 @@ static const char rcsid[] = "$FreeBSD: stable/11/lib/lib80211/lib80211_regdomain
+ #include <err.h>
+ #include <unistd.h>
+
+-#include <bsdxml.h>
++#include <expat.h>
+
+ #include "lib80211_regdomain.h"
+
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-11.0-libproc-libcxx.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-11.0-libproc-libcxx.patch
new file mode 100644
index 000000000000..013ad20619e5
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-11.0-libproc-libcxx.patch
@@ -0,0 +1,13 @@
+diff --git a/lib/libproc/Makefile b/lib/libproc/Makefile
+index e3b2578..acd76e8 100644
+--- a/lib/libproc/Makefile
++++ b/lib/libproc/Makefile
+@@ -18,7 +18,7 @@ CFLAGS+= -I${.CURDIR}
+
+ .if ${MK_CXX} == "no"
+ CFLAGS+= -DNO_CXA_DEMANGLE
+-.elif ${MK_LIBCPLUSPLUS} != "no"
++.elif ${COMPILER_TYPE} == "clang"
+ LIBADD+= cxxrt
+ .else
+ LIBADD+= supcplusplus
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-11.0-workaround.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-11.0-workaround.patch
new file mode 100644
index 000000000000..05f817eeb032
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-11.0-workaround.patch
@@ -0,0 +1,12 @@
+diff --git a/lib/libdevdctl/event.cc b/lib/libdevdctl/event.cc
+index a8cb447..d56df2e 100644
+--- a/lib/libdevdctl/event.cc
++++ b/lib/libdevdctl/event.cc
+@@ -50,6 +50,7 @@
+ #include <syslog.h>
+ #include <unistd.h>
+
++#include <cstdio>
+ #include <cstdarg>
+ #include <cstring>
+ #include <iostream>
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-11.1-elf-nhdr.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-11.1-elf-nhdr.patch
new file mode 100644
index 000000000000..a00df5f66f12
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-11.1-elf-nhdr.patch
@@ -0,0 +1,10 @@
+--- a/sys/sys/elf_common.h 2018/01/18 20:45:41 328136
++++ b/sys/sys/elf_common.h 2018/01/18 21:19:57 328137
+@@ -51,6 +51,7 @@
+ u_int32_t n_descsz; /* Length of descriptor. */
+ u_int32_t n_type; /* Type of this note. */
+ } Elf_Note;
++typedef Elf_Note Elf_Nhdr;
+
+ /*
+ * Option kinds.
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-11.1-liblink.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-11.1-liblink.patch
new file mode 100644
index 000000000000..b1fe7035b120
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-11.1-liblink.patch
@@ -0,0 +1,142 @@
+diff --git a/lib/libmt/Makefile b/lib/libmt/Makefile
+index a6efe28..f60919a 100644
+--- a/lib/libmt/Makefile
++++ b/lib/libmt/Makefile
+@@ -6,6 +6,7 @@ SHLIBDIR?= /lib
+ SRCS= mtlib.c
+ INCS= mtlib.h
+
++CFLAGS+= -I${.CURDIR}
+ LIBADD= sbuf bsdxml
+
+ MAN= mt.3
+diff --git a/lib/libsysdecode/Makefile b/lib/libsysdecode/Makefile
+index ce89201..ba78ae4 100644
+--- a/lib/libsysdecode/Makefile
++++ b/lib/libsysdecode/Makefile
+@@ -9,7 +9,7 @@ SRCS= errno.c flags.c ioctl.c signal.c syscallnames.c utrace.c
+ INCS= sysdecode.h
+
+ CFLAGS+= -I${.OBJDIR}
+-CFLAGS+= -I${SRCTOP}/sys
++CFLAGS+= -I${SRCTOP}/sys -I${.CURDIR}
+ CFLAGS+= -I${SRCTOP}/libexec/rtld-elf
+
+ MAN= sysdecode.3 \
+
+diff --git a/lib/libdpv/Makefile b/lib/libdpv/Makefile
+index 280f7de..d0663b0 100644
+--- a/lib/libdpv/Makefile
++++ b/lib/libdpv/Makefile
+@@ -11,6 +11,7 @@ LIBADD= dialog figpar util ncursesw
+
+ SRCS= dialog_util.c dialogrc.c dprompt.c dpv.c status.c util.c
+
+-CFLAGS+= -I${.CURDIR}
++CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../libfigpar
++LDFLAGS+= -L${.OBJDIR}/../libfigpar
+
+ .include <bsd.lib.mk>
+diff --git a/lib/libcasper/libcasper/Makefile b/lib/libcasper/libcasper/Makefile
+index 1064ada..32a2e66 100644
+--- a/lib/libcasper/libcasper/Makefile
++++ b/lib/libcasper/libcasper/Makefile
+@@ -18,6 +18,7 @@ INCS+= libcasper_service.h
+ LIBADD= nv
+
+ CFLAGS+=-I${.CURDIR}
++LDFLAGS+=-L${.OBJDIR}/../../libnv
+
+ MAN+= libcasper.3
+
+diff --git a/lib/libcasper/services/cap_dns/Makefile b/lib/libcasper/services/cap_dns/Makefile
+index bf6bed5..baeecbe 100644
+--- a/lib/libcasper/services/cap_dns/Makefile
++++ b/lib/libcasper/services/cap_dns/Makefile
+@@ -14,5 +14,6 @@ INCS= cap_dns.h
+ LIBADD= nv
+
+ CFLAGS+=-I${.CURDIR}
++LDFLAGS+=-L${.OBJDIR}/../../../libnv
+
+ .include <bsd.lib.mk>
+diff --git a/lib/libcasper/services/cap_grp/Makefile b/lib/libcasper/services/cap_grp/Makefile
+index 78a860a..dfb4911 100644
+--- a/lib/libcasper/services/cap_grp/Makefile
++++ b/lib/libcasper/services/cap_grp/Makefile
+@@ -14,5 +14,6 @@ INCS= cap_grp.h
+ LIBADD= nv
+
+ CFLAGS+=-I${.CURDIR}
++LDFLAGS+=-L${.OBJDIR}/../../../libnv
+
+ .include <bsd.lib.mk>
+diff --git a/lib/libcasper/services/cap_pwd/Makefile b/lib/libcasper/services/cap_pwd/Makefile
+index e4df38b..64d7709 100644
+--- a/lib/libcasper/services/cap_pwd/Makefile
++++ b/lib/libcasper/services/cap_pwd/Makefile
+@@ -14,5 +14,6 @@ INCS= cap_pwd.h
+ LIBADD= nv
+
+ CFLAGS+=-I${.CURDIR}
++LDFLAGS+=-L${.OBJDIR}/../../../libnv
+
+ .include <bsd.lib.mk>
+diff --git a/lib/libcasper/services/cap_random/Makefile b/lib/libcasper/services/cap_random/Makefile
+index d69c160..658be9c 100644
+--- a/lib/libcasper/services/cap_random/Makefile
++++ b/lib/libcasper/services/cap_random/Makefile
+@@ -14,5 +14,6 @@ INCS= cap_random.h
+ LIBADD= nv
+
+ CFLAGS+=-I${.CURDIR}
++LDFLAGS+=-L${.OBJDIR}/../../../libnv
+
+ .include <bsd.lib.mk>
+diff --git a/lib/libcasper/services/cap_sysctl/Makefile b/lib/libcasper/services/cap_sysctl/Makefile
+index 2471e65..b20a342 100644
+--- a/lib/libcasper/services/cap_sysctl/Makefile
++++ b/lib/libcasper/services/cap_sysctl/Makefile
+@@ -14,5 +14,6 @@ INCS= cap_sysctl.h
+ LIBADD= nv
+
+ CFLAGS+=-I${.CURDIR}
++LDFLAGS+=-L${.OBJDIR}/../../../libnv
+
+ .include <bsd.lib.mk>
+diff --git a/lib/libc/Makefile b/lib/libc/Makefile
+index 1cf73a7..f1c2bc8 100644
+--- a/lib/libc/Makefile
++++ b/lib/libc/Makefile
+@@ -51,6 +51,7 @@ CFLAGS+=${CANCELPOINTS_CFLAGS}
+ #
+ LDFLAGS+= -nodefaultlibs
+ LIBADD+= compiler_rt
++LDFLAGS+= -L${.OBJDIR}/../libcompiler_rt
+
+ .if ${MK_SSP} != "no"
+ LIBADD+= ssp_nonshared
+diff --git a/lib/libcompiler_rt/Makefile b/lib/libcompiler_rt/Makefile
+index 4da1166..b34297a 100644
+--- a/lib/libcompiler_rt/Makefile
++++ b/lib/libcompiler_rt/Makefile
+@@ -11,6 +11,7 @@ CFLAGS+= ${PICFLAG}
+ CFLAGS+= -fvisibility=hidden
+ CFLAGS+= -DVISIBILITY_HIDDEN
+ CFLAGS+= -I${SRCTOP}/contrib/libcxxrt
++LDFLAGS+= -L${.OBJDIR}/../libc
+
+ .if ${COMPILER_TYPE} == "clang"
+ CWARNFLAGS.gcc_personality_v0.c+= -Wno-typedef-redefinition
+diff --git a/lib/libcam/Makefile b/lib/libcam/Makefile
+index 310c9a2..86a5e8c 100644
+--- a/lib/libcam/Makefile
++++ b/lib/libcam/Makefile
+@@ -40,6 +40,7 @@ MLINKS+= cam.3 cam_open_device.3 \
+ ${SRCTOP}/sys/cam
+
+ CFLAGS+= -I${.CURDIR} -I${SRCTOP}/sys
++LDFLAGS+= -L${.OBJDIR}/../libsbuf
+
+ SHLIB_MAJOR= 7
+
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-6.0-flex-2.5.31.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-6.0-flex-2.5.31.patch
new file mode 100644
index 000000000000..00de8a6debb8
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-6.0-flex-2.5.31.patch
@@ -0,0 +1,13 @@
+Index: fbsd-6/lib/libipsec/policy_token.l
+===================================================================
+--- fbsd-6.orig/lib/libipsec/policy_token.l
++++ fbsd-6/lib/libipsec/policy_token.l
+@@ -138,8 +138,6 @@ void
+ __policy__strbuffer__init__(msg)
+ char *msg;
+ {
+- if (yy_current_buffer)
+- yy_delete_buffer(yy_current_buffer);
+ strbuffer = (YY_BUFFER_STATE)yy_scan_string(msg);
+ yy_switch_to_buffer(strbuffer);
+
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-6.0-pmc.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-6.0-pmc.patch
new file mode 100644
index 000000000000..2f6de4652822
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-6.0-pmc.patch
@@ -0,0 +1,13 @@
+Index: freebsd-6.0_beta4/lib/libpmc/Makefile
+===================================================================
+--- freebsd-6.0_beta4.orig/lib/libpmc/Makefile
++++ freebsd-6.0_beta4/lib/libpmc/Makefile
+@@ -9,6 +9,8 @@ WARNS?= 6
+
+ MAN= pmc.3 pmclog.3
+
++CFLAGS+= -I${.CURDIR}
++
+ MLINKS+= \
+ pmc.3 pmc_allocate.3 \
+ pmc.3 pmc_attach.3 \
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-6.1-csu.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-6.1-csu.patch
new file mode 100644
index 000000000000..075f2780e693
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-6.1-csu.patch
@@ -0,0 +1,20 @@
+--- lib/csu/amd64/Makefile.orig 2006-07-04 07:49:58 -0300
++++ lib/csu/amd64/Makefile 2006-07-04 07:50:15 -0300
+@@ -16,6 +16,7 @@
+ ${CC} ${CFLAGS} -DGCRT -c -o gcrt1.o ${.CURDIR}/crt1.c
+
+ realinstall:
++ ${INSTALL} -d ${DESTDIR}${LIBDIR}
+ ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${OBJS} ${DESTDIR}${LIBDIR}
+
+--- lib/csu/sparc64/Makefile.orig 2006-10-06 15:13:55 +0100
++++ lib/csu/sparc64/Makefile 2006-10-06 15:15:06 +0100
+@@ -15,6 +15,7 @@
+ ${CC} ${CFLAGS} -DGCRT -c -o gcrt1.o ${.ALLSRC}
+
+ realinstall:
++ ${INSTALL} -d ${DESTDIR}${LIBDIR}
+ ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${OBJS} ${DESTDIR}${LIBDIR}
+
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-7.1-types.h-fix.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-7.1-types.h-fix.patch
new file mode 100644
index 000000000000..8de5df2d16a6
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-7.1-types.h-fix.patch
@@ -0,0 +1,15 @@
+Fixes a compile error if XOPEN_SOURCE 600 is defined.
+
+See: http://www.mailinglistarchive.com/freebsd-current@freebsd.org/msg15011.html
+
+--- sys/sys/types.h.orig
++++ sys/sys/types.h
+@@ -46,7 +46,7 @@
+
+ #include <sys/_pthreadtypes.h>
+
+-#if __BSD_VISIBLE
++#ifndef _POSIX_SOURCE
+ typedef unsigned char u_char;
+ typedef unsigned short u_short;
+ typedef unsigned int u_int;
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-8.0-gcc45.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-8.0-gcc45.patch
new file mode 100644
index 000000000000..2ddb9eadb909
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-8.0-gcc45.patch
@@ -0,0 +1,28 @@
+diff -Nur work.orig/include/rpcsvc/nis.x work/include/rpcsvc/nis.x
+--- work.orig/include/rpcsvc/nis.x 2009-10-25 10:10:29.000000000 +0900
++++ work/include/rpcsvc/nis.x 2011-04-13 21:25:13.000000000 +0900
+@@ -399,10 +399,7 @@
+ %#define OARIGHTS(d, n) (((d)->do_armask.do_armask_val+n)->oa_rights)
+ %#define WORLD_DEFAULT (NIS_READ_ACC)
+ %#define GROUP_DEFAULT (NIS_READ_ACC << 8)
+-%#define OWNER_DEFAULT ((NIS_READ_ACC +\
+- NIS_MODIFY_ACC +\
+- NIS_CREATE_ACC +\
+- NIS_DESTROY_ACC) << 16)
++%#define OWNER_DEFAULT ((NIS_READ_ACC + NIS_MODIFY_ACC + NIS_CREATE_ACC + NIS_DESTROY_ACC) << 16)
+ %#define DEFAULT_RIGHTS (WORLD_DEFAULT | GROUP_DEFAULT | OWNER_DEFAULT)
+ %
+ %/* Result manipulation defines ... */
+@@ -431,10 +428,8 @@
+ % * these definitions they take an nis_object *, and an int and return
+ % * a u_char * for Value, and an int for length.
+ % */
+-%#define ENTRY_VAL(obj, col) \
+- (obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val
+-%#define ENTRY_LEN(obj, col) \
+- (obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len
++%#define ENTRY_VAL(obj, col) (obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val
++%#define ENTRY_LEN(obj, col) (obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len
+ %
+ %#ifdef __cplusplus
+ %}
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-bluetooth.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-bluetooth.patch
new file mode 100644
index 000000000000..cf1172ab6335
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-bluetooth.patch
@@ -0,0 +1,12 @@
+diff -Nur lib.orig/libsdp/Makefile lib/libsdp/Makefile
+--- lib.orig/libsdp/Makefile 2012-12-25 20:28:50.000000000 +0900
++++ lib/libsdp/Makefile 2012-12-25 20:31:19.000000000 +0900
+@@ -5,7 +5,7 @@
+ MAN= sdp.3
+
+ WARNS?= 2
+-CFLAGS+= -I${.CURDIR}
++CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../libbluetooth
+
+ SHLIB_MAJOR= 4
+
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-cve-2010-2632.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-cve-2010-2632.patch
new file mode 100644
index 000000000000..ad9b9608f42c
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-cve-2010-2632.patch
@@ -0,0 +1,215 @@
+Index: lib/libc/gen/glob.c
+===================================================================
+--- lib/libc/gen/glob.c (revision 246357)
++++ lib/libc/gen/glob.c (working copy)
+@@ -94,6 +94,25 @@ __FBSDID("$FreeBSD$");
+
+ #include "collate.h"
+
++/*
++ * glob(3) expansion limits. Stop the expansion if any of these limits
++ * is reached. This caps the runtime in the face of DoS attacks. See
++ * also CVE-2010-2632
++ */
++#define GLOB_LIMIT_BRACE 128 /* number of brace calls */
++#define GLOB_LIMIT_PATH 65536 /* number of path elements */
++#define GLOB_LIMIT_READDIR 16384 /* number of readdirs */
++#define GLOB_LIMIT_STAT 1024 /* number of stat system calls */
++#define GLOB_LIMIT_STRING ARG_MAX /* maximum total size for paths */
++
++struct glob_limit {
++ size_t l_brace_cnt;
++ size_t l_path_lim;
++ size_t l_readdir_cnt;
++ size_t l_stat_cnt;
++ size_t l_string_cnt;
++};
++
+ #define DOLLAR '$'
+ #define DOT '.'
+ #define EOS '\0'
+@@ -153,15 +172,18 @@ static const Char *g_strchr(const Char *, wchar_t)
+ static Char *g_strcat(Char *, const Char *);
+ #endif
+ static int g_stat(Char *, struct stat *, glob_t *);
+-static int glob0(const Char *, glob_t *, size_t *);
+-static int glob1(Char *, glob_t *, size_t *);
+-static int glob2(Char *, Char *, Char *, Char *, glob_t *, size_t *);
+-static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, size_t *);
+-static int globextend(const Char *, glob_t *, size_t *);
+-static const Char *
++static int glob0(const Char *, glob_t *, struct glob_limit *);
++static int glob1(Char *, glob_t *, struct glob_limit *);
++static int glob2(Char *, Char *, Char *, Char *, glob_t *,
++ struct glob_limit *);
++static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *,
++ struct glob_limit *);
++static int globextend(const Char *, glob_t *, struct glob_limit *);
++static const Char *
+ globtilde(const Char *, Char *, size_t, glob_t *);
+-static int globexp1(const Char *, glob_t *, size_t *);
+-static int globexp2(const Char *, const Char *, glob_t *, int *, size_t *);
++static int globexp1(const Char *, glob_t *, struct glob_limit *);
++static int globexp2(const Char *, const Char *, glob_t *, int *,
++ struct glob_limit *);
+ static int match(Char *, Char *, Char *);
+ #ifdef DEBUG
+ static void qprintf(const char *, Char *);
+@@ -171,8 +193,8 @@ int
+ glob(const char * __restrict pattern, int flags,
+ int (*errfunc)(const char *, int), glob_t * __restrict pglob)
+ {
++ struct glob_limit limit = { 0, 0, 0, 0, 0 };
+ const char *patnext;
+- size_t limit;
+ Char *bufnext, *bufend, patbuf[MAXPATHLEN], prot;
+ mbstate_t mbs;
+ wchar_t wc;
+@@ -186,11 +208,10 @@ glob(const char * __restrict pattern, int flags,
+ pglob->gl_offs = 0;
+ }
+ if (flags & GLOB_LIMIT) {
+- limit = pglob->gl_matchc;
+- if (limit == 0)
+- limit = ARG_MAX;
+- } else
+- limit = 0;
++ limit.l_path_lim = pglob->gl_matchc;
++ if (limit.l_path_lim == 0)
++ limit.l_path_lim = GLOB_LIMIT_PATH;
++ }
+ pglob->gl_flags = flags & ~GLOB_MAGCHAR;
+ pglob->gl_errfunc = errfunc;
+ pglob->gl_matchc = 0;
+@@ -243,11 +264,17 @@ glob(const char * __restrict pattern, int flags,
+ * characters
+ */
+ static int
+-globexp1(const Char *pattern, glob_t *pglob, size_t *limit)
++globexp1(const Char *pattern, glob_t *pglob, struct glob_limit *limit)
+ {
+ const Char* ptr = pattern;
+ int rv;
+
++ if ((pglob->gl_flags & GLOB_LIMIT) &&
++ limit->l_brace_cnt++ >= GLOB_LIMIT_BRACE) {
++ errno = 0;
++ return (GLOB_NOSPACE);
++ }
++
+ /* Protect a single {}, for find(1), like csh */
+ if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)
+ return glob0(pattern, pglob, limit);
+@@ -266,7 +293,8 @@ static int
+ * If it fails then it tries to glob the rest of the pattern and returns.
+ */
+ static int
+-globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv, size_t *limit)
++globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv,
++ struct glob_limit *limit)
+ {
+ int i;
+ Char *lm, *ls;
+@@ -436,7 +464,7 @@ globtilde(const Char *pattern, Char *patbuf, size_
+ * if things went well, nonzero if errors occurred.
+ */
+ static int
+-glob0(const Char *pattern, glob_t *pglob, size_t *limit)
++glob0(const Char *pattern, glob_t *pglob, struct glob_limit *limit)
+ {
+ const Char *qpatnext;
+ int err;
+@@ -529,7 +557,7 @@ compare(const void *p, const void *q)
+ }
+
+ static int
+-glob1(Char *pattern, glob_t *pglob, size_t *limit)
++glob1(Char *pattern, glob_t *pglob, struct glob_limit *limit)
+ {
+ Char pathbuf[MAXPATHLEN];
+
+@@ -547,7 +575,7 @@ static int
+ */
+ static int
+ glob2(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern,
+- glob_t *pglob, size_t *limit)
++ glob_t *pglob, struct glob_limit *limit)
+ {
+ struct stat sb;
+ Char *p, *q;
+@@ -563,6 +591,15 @@ glob2(Char *pathbuf, Char *pathend, Char *pathend_
+ if (g_lstat(pathbuf, &sb, pglob))
+ return(0);
+
++ if ((pglob->gl_flags & GLOB_LIMIT) &&
++ limit->l_stat_cnt++ >= GLOB_LIMIT_STAT) {
++ errno = 0;
++ if (pathend + 1 > pathend_last)
++ return (GLOB_ABORTED);
++ *pathend++ = SEP;
++ *pathend = EOS;
++ return (GLOB_NOSPACE);
++ }
+ if (((pglob->gl_flags & GLOB_MARK) &&
+ pathend[-1] != SEP) && (S_ISDIR(sb.st_mode)
+ || (S_ISLNK(sb.st_mode) &&
+@@ -606,7 +643,7 @@ glob2(Char *pathbuf, Char *pathend, Char *pathend_
+ static int
+ glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
+ Char *pattern, Char *restpattern,
+- glob_t *pglob, size_t *limit)
++ glob_t *pglob, struct glob_limit *limit)
+ {
+ struct dirent *dp;
+ DIR *dirp;
+@@ -652,6 +689,19 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_
+ size_t clen;
+ mbstate_t mbs;
+
++ if ((pglob->gl_flags & GLOB_LIMIT) &&
++ limit->l_readdir_cnt++ >= GLOB_LIMIT_READDIR) {
++ errno = 0;
++ if (pathend + 1 > pathend_last)
++ err = GLOB_ABORTED;
++ else {
++ *pathend++ = SEP;
++ *pathend = EOS;
++ err = GLOB_NOSPACE;
++ }
++ break;
++ }
++
+ /* Initial DOT must be matched literally. */
+ if (dp->d_name[0] == DOT && *pattern != DOT)
+ continue;
+@@ -702,14 +752,15 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_
+ * gl_pathv points to (gl_offs + gl_pathc + 1) items.
+ */
+ static int
+-globextend(const Char *path, glob_t *pglob, size_t *limit)
++globextend(const Char *path, glob_t *pglob, struct glob_limit *limit)
+ {
+ char **pathv;
+ size_t i, newsize, len;
+ char *copy;
+ const Char *p;
+
+- if (*limit && pglob->gl_pathc > *limit) {
++ if ((pglob->gl_flags & GLOB_LIMIT) &&
++ pglob->gl_matchc > limit->l_path_lim) {
+ errno = 0;
+ return (GLOB_NOSPACE);
+ }
+@@ -737,6 +788,12 @@ static int
+ for (p = path; *p++;)
+ continue;
+ len = MB_CUR_MAX * (size_t)(p - path); /* XXX overallocation */
++ limit->l_string_cnt += len;
++ if ((pglob->gl_flags & GLOB_LIMIT) &&
++ limit->l_string_cnt >= GLOB_LIMIT_STRING) {
++ errno = 0;
++ return (GLOB_NOSPACE);
++ }
+ if ((copy = malloc(len)) != NULL) {
+ if (g_Ctoc(path, copy, len)) {
+ free(copy);
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-liblink.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-liblink.patch
new file mode 100644
index 000000000000..f8e470736c64
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-liblink.patch
@@ -0,0 +1,21 @@
+diff -uNr lib.ol/libproc/Makefile lib/libproc/Makefile
+--- lib.ol/libproc/Makefile 2011-11-02 14:02:17.000000000 +0000
++++ lib/libproc/Makefile 2011-11-02 14:03:09.000000000 +0000
+@@ -16,5 +16,6 @@
+ SHLIB_MAJOR= 2
+
+ WITHOUT_MAN=
++LDADD+=-lelf
+
+ .include <bsd.lib.mk>
+diff -uNr lib.ol/librtld_db/Makefile lib/librtld_db/Makefile
+--- lib.ol/librtld_db/Makefile 2011-11-02 14:02:13.000000000 +0000
++++ lib/librtld_db/Makefile 2011-11-02 14:04:00.000000000 +0000
+@@ -10,5 +10,7 @@
+ INCS= rtld_db.h
+
+ CFLAGS+= -I${.CURDIR}
++LDADD+=-lutil -lproc
++LDFLAGS+=-L${.OBJDIR}/../libutil -L${.OBJDIR}/../libproc
+
+ .include <bsd.lib.mk>
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-netware.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-netware.patch
new file mode 100644
index 000000000000..c1c2a0e04560
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-netware.patch
@@ -0,0 +1,11 @@
+diff -Nur lib.orig/libncp/Makefile lib/libncp/Makefile
+--- lib.orig/libncp/Makefile 2012-12-25 20:35:16.000000000 +0900
++++ lib/libncp/Makefile 2012-12-25 20:36:23.000000000 +0900
+@@ -6,6 +6,7 @@
+
+ DPADD= ${LIBIPX}
+ LDADD= -lipx
++LDFLAGS+=-L${.OBJDIR}/../libipx
+
+ SRCS= ncpl_subr.c ncpl_bind.c ncpl_queue.c ncpl_file.c ncpl_misc.c \
+ ncpl_net.c ncpl_rcfile.c ncpl_conn.c ncpl_nls.c ncpl_msg.c \
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-opieincludes.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-opieincludes.patch
new file mode 100644
index 000000000000..bf77a0a5219f
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-9.0-opieincludes.patch
@@ -0,0 +1,122 @@
+Fixes warnings like:
+/var/tmp/portage/sys-freebsd/freebsd-lib-9.0-r2/work/lib/libopie/../../contrib/opie/libopie/randomchallenge.c:43:5:
+warning: incompatible implicit declaration of built-in function ‘strcpy’
+
+diff -uNr contrib.old/opie/libopie/accessfile.c contrib/opie/libopie/accessfile.c
+--- contrib.old/opie/libopie/accessfile.c 2012-05-25 08:54:33.000000000 -0400
++++ contrib/opie/libopie/accessfile.c 2012-05-25 09:12:34.000000000 -0400
+@@ -46,6 +46,7 @@
+ #ifdef DEBUG
+ #include <syslog.h>
+ #endif /* DEBUG */
++#include <ctype.h>
+
+ #include "opie.h"
+
+diff -uNr contrib.old/opie/libopie/generator.c contrib/opie/libopie/generator.c
+--- contrib.old/opie/libopie/generator.c 2012-05-25 08:54:33.000000000 -0400
++++ contrib/opie/libopie/generator.c 2012-05-25 08:58:10.000000000 -0400
+@@ -50,6 +50,7 @@
+ #include <syslog.h>
+ #endif /* DEBUG */
+ #include "opie.h"
++#include <stdio.h>
+
+ static char *algids[] = { NULL, NULL, NULL, "sha1", "md4", "md5" };
+
+diff -uNr contrib.old/opie/libopie/lookup.c contrib/opie/libopie/lookup.c
+--- contrib.old/opie/libopie/lookup.c 2012-05-25 08:54:33.000000000 -0400
++++ contrib/opie/libopie/lookup.c 2012-05-25 09:15:08.000000000 -0400
+@@ -14,6 +14,7 @@
+ #include "opie_cfg.h"
+ #include <stdio.h>
+ #include "opie.h"
++#include <string.h>
+
+ int opielookup FUNCTION((opie, principal), struct opie *opie AND char *principal)
+ {
+diff -uNr contrib.old/opie/libopie/newseed.c contrib/opie/libopie/newseed.c
+--- contrib.old/opie/libopie/newseed.c 2012-05-25 08:54:33.000000000 -0400
++++ contrib/opie/libopie/newseed.c 2012-05-25 09:14:37.000000000 -0400
+@@ -36,6 +36,9 @@
+ #include <syslog.h>
+ #endif /* DEBUG */
+ #include "opie.h"
++#include <stdio.h>
++#include <stdlib.h>
++#include <time.h>
+
+ int opienewseed FUNCTION((seed), char *seed)
+ {
+diff -uNr contrib.old/opie/libopie/parsechallenge.c contrib/opie/libopie/parsechallenge.c
+--- contrib.old/opie/libopie/parsechallenge.c 2012-05-25 08:54:33.000000000 -0400
++++ contrib/opie/libopie/parsechallenge.c 2012-05-25 09:15:54.000000000 -0400
+@@ -20,6 +20,8 @@
+ #include <string.h>
+ #endif /* HAVE_STRING_H */
+ #include "opie.h"
++#include <stdlib.h>
++#include <ctype.h>
+
+ struct algorithm {
+ char *name;
+diff -uNr contrib.old/opie/libopie/passwd.c contrib/opie/libopie/passwd.c
+--- contrib.old/opie/libopie/passwd.c 2012-05-25 08:54:33.000000000 -0400
++++ contrib/opie/libopie/passwd.c 2012-05-25 09:13:45.000000000 -0400
+@@ -22,6 +22,7 @@
+
+ #include "opie_cfg.h"
+ #include "opie.h"
++#include <string.h>
+
+ int opiepasswd FUNCTION((old, flags, principal, n, seed, ks), struct opie *old AND int flags AND char *principal AND int n AND char *seed AND char *ks)
+ {
+diff -uNr contrib.old/opie/libopie/randomchallenge.c contrib/opie/libopie/randomchallenge.c
+--- contrib.old/opie/libopie/randomchallenge.c 2012-05-25 08:54:33.000000000 -0400
++++ contrib/opie/libopie/randomchallenge.c 2012-05-25 09:00:27.000000000 -0400
+@@ -28,6 +28,9 @@
+
+ #include "opie_cfg.h"
+ #include "opie.h"
++#include <stdio.h>
++#include <string.h>
++#include <stdlib.h>
+
+ static char *algids[] = { 0, 0, 0, "sha1", "md4", "md5" };
+
+diff -uNr contrib.old/opie/libopie/verify.c contrib/opie/libopie/verify.c
+--- contrib.old/opie/libopie/verify.c 2012-05-25 08:54:33.000000000 -0400
++++ contrib/opie/libopie/verify.c 2012-05-25 09:12:09.000000000 -0400
+@@ -25,6 +25,7 @@
+ #include <string.h>
+ #endif /* HAVE_STRING_H */
+ #include "opie.h"
++#include <ctype.h>
+
+ #define RESPONSE_STANDARD 0
+ #define RESPONSE_WORD 1
+diff -uNr contrib.old/opie/libopie/version.c contrib/opie/libopie/version.c
+--- contrib.old/opie/libopie/version.c 2012-05-25 08:54:33.000000000 -0400
++++ contrib/opie/libopie/version.c 2012-05-25 09:13:15.000000000 -0400
+@@ -19,6 +19,8 @@
+ */
+ #include "opie_cfg.h"
+ #include "opie.h"
++#include <stdio.h>
++#include <stdlib.h>
+
+ VOIDRET opieversion FUNCTION_NOARGS
+ {
+diff -uNr contrib.old/opie/opie.h contrib/opie/opie.h
+--- contrib.old/opie/opie.h 2012-05-25 08:54:33.000000000 -0400
++++ contrib/opie/opie.h 2012-05-25 09:21:28.000000000 -0400
+@@ -158,6 +158,9 @@
+ int __opiereadrec __P((struct opie *));
+ int __opiewriterec __P((struct opie *));
+ int __opieparsechallenge __P((char *buffer, int *algorithm, int *sequence, char **seed, int *exts));
++VOIDRET opiehashlen FUNCTION((algorithm, in, out, n), int algorithm AND VOIDPTR in AND struct opie_otpkey *out AND int n);
++int opieinsecure FUNCTION_NOARGS;
++int opienewseed FUNCTION((seed), char *seed);
+ __END_DECLS
+
+ #define opiestrncpy(dst, src, n) \
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-9.1-.eh_frame_hdr-fix.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-9.1-.eh_frame_hdr-fix.patch
new file mode 100644
index 000000000000..fdb7e16f6e08
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-9.1-.eh_frame_hdr-fix.patch
@@ -0,0 +1,17 @@
+Fix "no .eh_frame_hdr table will be created" error.
+
+http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47829
+http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/4a0e0cd7377c45dc21d5c71bcab931b5e5727e74
+
+diff -Nur lib.orig/csu/i386-elf/Makefile lib/csu/i386-elf/Makefile
+--- lib.orig/csu/i386-elf/Makefile 2013-03-06 01:07:57.000000000 +0900
++++ lib/csu/i386-elf/Makefile 2013-03-06 01:10:09.000000000 +0900
+@@ -10,6 +10,8 @@
+ FILESDIR= ${LIBDIR}
+ CFLAGS+= -I${.CURDIR}/../common \
+ -I${.CURDIR}/../../libc/include
++CFLAGS+= -fno-omit-frame-pointer
++CFLAGS+= -fno-asynchronous-unwind-tables
+ CLEANFILES= ${FILES} crt1_c.o crt1_s.o gcrt1_c.o Scrt1_c.o
+ CLEANFILES+= crt1_c.s gcrt1_c.s Scrt1_c.s
+
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-9.1-aligned_alloc.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-9.1-aligned_alloc.patch
new file mode 100644
index 000000000000..97ac14160b87
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-9.1-aligned_alloc.patch
@@ -0,0 +1,51 @@
+Backport aligned_alloc for C++11 support.
+
+http://lists.freebsd.org/pipermail/svn-src-stable-9/2012-November/003313.html
+
+diff -uNr lib.old/libc/stdlib/Symbol.map lib/libc/stdlib/Symbol.map
+--- lib.old/libc/stdlib/Symbol.map 2013-05-24 17:03:55.000000000 -0400
++++ lib/libc/stdlib/Symbol.map 2013-05-24 17:06:03.000000000 -0400
+@@ -97,6 +97,7 @@
+ atoi_l;
+ atol_l;
+ atoll_l;
++ aligned_alloc;
+ at_quick_exit;
+ quick_exit;
+ strtod_l;
+diff -uNr lib.old/libc/stdlib/malloc.c lib/libc/stdlib/malloc.c
+--- lib.old/libc/stdlib/malloc.c 2013-05-24 17:03:55.000000000 -0400
++++ lib/libc/stdlib/malloc.c 2013-05-24 17:05:40.000000000 -0400
+@@ -6046,6 +6046,21 @@
+ }
+
+ void *
++aligned_alloc(size_t alignment, size_t size)
++{
++ void *memptr;
++ int ret;
++
++ ret = posix_memalign(&memptr, alignment, size);
++ if (ret != 0) {
++ errno = ret;
++ return (NULL);
++ }
++ return (memptr);
++}
++
++
++void *
+ calloc(size_t num, size_t size)
+ {
+ void *ret;
+diff -uNr includeold/stdlib.h include/stdlib.h
+--- includeold/stdlib.h 2013-05-24 17:03:46.000000000 -0400
++++ include/stdlib.h 2013-05-24 17:04:46.000000000 -0400
+@@ -155,6 +155,7 @@
+ * If we're in a mode greater than C99, expose C1x functions.
+ */
+ #if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L
++void * aligned_alloc(size_t, size_t);
+ _Noreturn void
+ quick_exit(int);
+ int at_quick_exit(void (*)(void));
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-9.1-rmgssapi.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-9.1-rmgssapi.patch
new file mode 100644
index 000000000000..62357e0830db
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-9.1-rmgssapi.patch
@@ -0,0 +1,16 @@
+--- include/Makefile.orig 2013-06-16 10:47:52.000000000 +0200
++++ include/Makefile 2013-06-16 10:47:37.000000000 +0200
+@@ -6,11 +6,11 @@
+ .include <bsd.own.mk>
+
+ CLEANFILES= osreldate.h version vers.c
++SUBDIR= arpa protocols rpcsvc rpc xlocale
+-SUBDIR= arpa gssapi protocols rpcsvc rpc xlocale
+ INCS= a.out.h ar.h assert.h bitstring.h complex.h cpio.h _ctype.h ctype.h \
+ db.h \
+ dirent.h dlfcn.h elf.h elf-hints.h err.h fmtmsg.h fnmatch.h fstab.h \
++ fts.h ftw.h getopt.h glob.h grp.h \
+- fts.h ftw.h getopt.h glob.h grp.h gssapi.h \
+ ieeefp.h ifaddrs.h \
+ inttypes.h iso646.h kenv.h langinfo.h libgen.h limits.h link.h \
+ locale.h malloc.h malloc_np.h memory.h monetary.h mpool.h mqueue.h \
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-add-nossp-cflags.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-add-nossp-cflags.patch
new file mode 100644
index 000000000000..00b39f750ec1
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-add-nossp-cflags.patch
@@ -0,0 +1,30 @@
+Please do not disable this patch.
+All commands will be non-executable.
+Abort trap: 6 (core dumped) is displayed...
+
+Details see Gentoo Bug #511698.
+https://bugs.gentoo.org/show_bug.cgi?id=511698
+
+diff --git a/lib/libc/Makefile b/lib/libc/Makefile
+index 1cc23b7..7dd458e 100644
+--- a/lib/libc/Makefile
++++ b/lib/libc/Makefile
+@@ -149,6 +149,6 @@ CWARNFLAGS:= ${.IMPSRC:Ngdtoa_*.c:C/^.+$/${CWARNFLAGS}/:C/^$/-w/}
+ # in the future to circumvent this.
+ SSP_CFLAGS:= ${SSP_CFLAGS:S/^-fstack-protector-all$/-fstack-protector/}
+ # Disable stack protection for SSP symbols.
+-SSP_CFLAGS:= ${.IMPSRC:N*/stack_protector.c:C/^.+$/${SSP_CFLAGS}/}
++SSP_CFLAGS:= ${.IMPSRC:N*/stack_protector.c:C/^.+$/${SSP_CFLAGS}/:C/^$/-fno-stack-protector/}
+ # Generate stack unwinding tables for cancellation points
+ CANCELPOINTS_CFLAGS:= ${.IMPSRC:Mcancelpoints_*:C/^.+$/${CANCELPOINTS_CFLAGS}/:C/^$//}
+diff --git a/lib/csu/Makefile.inc b/lib/csu/Makefile.inc
+index f92d87d..7a3a2f3 100644
+--- a/lib/csu/Makefile.inc
++++ b/lib/csu/Makefile.inc
+@@ -1,5 +1,5 @@
+ # $FreeBSD: release/9.1.0/lib/csu/Makefile.inc 204757 2010-03-05 13:29:05Z uqs $
+
+-SSP_CFLAGS=
++SSP_CFLAGS= -fno-stack-protector
+
+ .include "../Makefile.inc"
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-bsdxml2expat.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-bsdxml2expat.patch
new file mode 100644
index 000000000000..1b4e79129bfc
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-bsdxml2expat.patch
@@ -0,0 +1,26 @@
+diff -ur lib/libgeom.old/Makefile lib/libgeom/Makefile
+--- lib/libgeom.old/Makefile 2011-07-10 14:23:51.000000000 +0000
++++ lib/libgeom/Makefile 2011-07-10 15:12:39.000000000 +0000
+@@ -13,8 +13,8 @@
+
+ WARNS?= 3
+
+-DPADD= ${LIBBSDXML} ${LIBSBUF}
+-LDADD= -lbsdxml -lsbuf
++DPADD= ${LIBSBUF}
++LDADD= -lexpat -lsbuf
+
+ MAN= libgeom.3
+
+diff -ur lib/libgeom.old/geom_xml2tree.c lib/libgeom/geom_xml2tree.c
+--- lib/libgeom.old/geom_xml2tree.c 2010-12-21 17:09:25.000000000 +0000
++++ lib/libgeom/geom_xml2tree.c 2011-07-10 15:12:52.000000000 +0000
+@@ -43,7 +43,7 @@
+ #include <sys/sbuf.h>
+ #include <sys/sysctl.h>
+ #include <err.h>
+-#include <bsdxml.h>
++#include <expat.h>
+ #include <libgeom.h>
+
+ struct mystate {
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-lib-includes.patch b/sys-freebsd/freebsd-lib/files/freebsd-lib-includes.patch
new file mode 100644
index 000000000000..c2cf1421ea9e
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-lib-includes.patch
@@ -0,0 +1,13 @@
+Fix headers dependencies so that they can be included alone.
+
+--- include/ifaddrs.h.old 2009-05-15 13:50:10 +0000
++++ include/ifaddrs.h 2009-05-15 13:50:23 +0000
+@@ -28,6 +28,8 @@
+ #ifndef _IFADDRS_H_
+ #define _IFADDRS_H_
+
++#include <sys/types.h>
++
+ struct ifaddrs {
+ struct ifaddrs *ifa_next;
+ char *ifa_name;
diff --git a/sys-freebsd/freebsd-lib/files/freebsd-sources-9.0-sysctluint.patch b/sys-freebsd/freebsd-lib/files/freebsd-sources-9.0-sysctluint.patch
new file mode 100644
index 000000000000..751a77c843bb
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/freebsd-sources-9.0-sysctluint.patch
@@ -0,0 +1,13 @@
+u_int is defined in sys/types.h
+makes header usable alone.
+
+--- sys/sys/sysctl.h.old 2012-05-25 11:08:53.000000000 -0400
++++ sys/sys/sysctl.h 2012-05-25 11:09:16.000000000 -0400
+@@ -788,6 +788,7 @@
+ struct sysctl_req *);
+ #else /* !_KERNEL */
+ #include <sys/cdefs.h>
++#include <sys/types.h> /* for u_int */
+
+ __BEGIN_DECLS
+ int sysctl(const int *, u_int, void *, size_t *, const void *, size_t);
diff --git a/sys-freebsd/freebsd-lib/files/libusb-1.0.pc.in b/sys-freebsd/freebsd-lib/files/libusb-1.0.pc.in
new file mode 100644
index 000000000000..058ecb4384a3
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/libusb-1.0.pc.in
@@ -0,0 +1,11 @@
+prefix=/usr
+exec_prefix=${prefix}
+libdir=@LIBDIR@
+includedir=${prefix}/include
+
+Name: libusb
+Description: USB access library (FreeBSD version)
+Version: 1.0.1
+Libs: -L${libdir} -lusb
+Cflags: -I${includedir}
+
diff --git a/sys-freebsd/freebsd-lib/files/libusb.pc.in b/sys-freebsd/freebsd-lib/files/libusb.pc.in
new file mode 100644
index 000000000000..f63c6e399816
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/libusb.pc.in
@@ -0,0 +1,11 @@
+prefix=/usr
+exec_prefix=${prefix}
+libdir=@LIBDIR@
+includedir=${prefix}/include
+
+Name: libusb
+Description: USB access library (FreeBSD version)
+Version: 0.1.12
+Libs: -L${libdir} -lusb
+Cflags: -I${includedir}
+
diff --git a/sys-freebsd/freebsd-lib/files/rquotad.xinetd b/sys-freebsd/freebsd-lib/files/rquotad.xinetd
new file mode 100644
index 000000000000..876cd16c53c2
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/rquotad.xinetd
@@ -0,0 +1,11 @@
+service rquotad
+{
+ type = rpc
+ socket_type = dgram
+ protocol = udp
+ wait = yes
+ user = root
+ server = /usr/libexec/rpc.rquotad
+ rpc_version = 1
+ disabled = yes
+}
diff --git a/sys-freebsd/freebsd-lib/files/rstatd.xinetd b/sys-freebsd/freebsd-lib/files/rstatd.xinetd
new file mode 100644
index 000000000000..ba1b819851eb
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/rstatd.xinetd
@@ -0,0 +1,11 @@
+service rstatd
+{
+ type = rpc
+ socket_type = dgram
+ protocol = udp
+ wait = yes
+ user = root
+ server = /usr/libexec/rpc.rstatd
+ rpc_version = 1-3
+ disabled = yes
+}
diff --git a/sys-freebsd/freebsd-lib/files/rusersd.xinetd b/sys-freebsd/freebsd-lib/files/rusersd.xinetd
new file mode 100644
index 000000000000..5cbe091881e8
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/rusersd.xinetd
@@ -0,0 +1,11 @@
+service rusersd
+{
+ type = rpc
+ socket_type = dgram
+ protocol = udp
+ wait = yes
+ user = root
+ server = /usr/libexec/rpc.rusersd
+ rpc_version = 1-2
+ disabled = yes
+}
diff --git a/sys-freebsd/freebsd-lib/files/sprayd.xinetd b/sys-freebsd/freebsd-lib/files/sprayd.xinetd
new file mode 100644
index 000000000000..7be55771ac22
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/sprayd.xinetd
@@ -0,0 +1,11 @@
+service sprayd
+{
+ type = rpc
+ socket_type = dgram
+ protocol = udp
+ wait = yes
+ user = root
+ server = /usr/libexec/rpc.sprayd
+ rpc_version = 1
+ disabled = yes
+}
diff --git a/sys-freebsd/freebsd-lib/files/walld.xinetd b/sys-freebsd/freebsd-lib/files/walld.xinetd
new file mode 100644
index 000000000000..800b84fa21e6
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/files/walld.xinetd
@@ -0,0 +1,11 @@
+service walld
+{
+ type = rpc
+ socket_type = dgram
+ protocol = udp
+ wait = yes
+ user = root
+ server = /usr/libexec/rpc.rwalld
+ rpc_version = 1
+ disabled = yes
+}
diff --git a/sys-freebsd/freebsd-lib/freebsd-lib-11.1-r1.ebuild b/sys-freebsd/freebsd-lib/freebsd-lib-11.1-r1.ebuild
new file mode 100644
index 000000000000..68bc1432a8a3
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/freebsd-lib-11.1-r1.ebuild
@@ -0,0 +1,708 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd flag-o-matic multilib toolchain-funcs eutils multibuild multilib-build usr-ldscript
+
+DESCRIPTION="FreeBSD's base system libraries"
+SLOT="0"
+LICENSE="BSD GPL-2 zfs? ( CDDL )"
+
+# Security Advisory and Errata patches.
+# UPSTREAM_PATCHES=()
+
+# Crypto is needed to have an internal OpenSSL header
+# sys is needed for libalias, probably we can just extract that instead of
+# extracting the whole tarball
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64-fbsd ~x86-fbsd"
+ SRC_URI="${SRC_URI}
+ $(freebsd_upstream_patches)"
+fi
+
+EXTRACTONLY="
+ lib/
+ contrib/
+ crypto/
+ libexec/
+ etc/
+ include/
+ usr.bin/
+ usr.sbin/
+ gnu/
+ secure/
+"
+
+if [ "${CATEGORY#*cross-}" = "${CATEGORY}" ]; then
+ RDEPEND="ssl? ( dev-libs/openssl:0= )
+ kerberos? ( app-crypt/heimdal )
+ pam? ( virtual/pam )
+ usb? ( !dev-libs/libusb )
+ zfs? ( =sys-freebsd/freebsd-cddl-${RV}* )
+ >=dev-libs/expat-2.0.1
+ >=dev-util/dialog-1.2.20150225
+ !sys-freebsd/freebsd-libexec
+ !sys-libs/libutempter
+ !dev-libs/libelf
+ !dev-libs/libexecinfo
+ !dev-libs/libiconv
+ !sys-freebsd/freebsd-headers"
+ DEPEND="${RDEPEND}
+ >=sys-devel/flex-2.5.31-r2
+ =sys-freebsd/freebsd-sources-${RV}*"
+ RDEPEND="${RDEPEND}
+ =sys-freebsd/freebsd-share-${RV}*
+ xinetd? ( sys-apps/xinetd )
+ >=virtual/libiconv-0-r2"
+else
+ EXTRACTONLY+="sys/ "
+fi
+
+DEPEND="${DEPEND}
+ userland_GNU? ( sys-apps/mtree )
+ =sys-freebsd/freebsd-mk-defs-${RV}*"
+
+S="${WORKDIR}/lib"
+
+export CTARGET=${CTARGET:-${CHOST}}
+if [ "${CTARGET}" = "${CHOST}" -a "${CATEGORY#*cross-}" != "${CATEGORY}" ]; then
+ export CTARGET=${CATEGORY/cross-}
+fi
+
+IUSE="atm bluetooth ssl ipv6 kerberos usb netware
+ build headers-only zfs pam xinetd
+ userland_GNU userland_BSD"
+
+QA_DT_NEEDED="lib/libc.so.7 usr/lib32/libc.so.7"
+
+pkg_setup() {
+ # Add the required source files.
+ use build && EXTRACTONLY+="sys/ "
+ use zfs && EXTRACTONLY+="cddl/ "
+
+ [ -c /dev/zero ] || \
+ die "You forgot to mount /dev; the compiled libc would break."
+
+ if ! use ssl && use kerberos; then
+ eerror "If you want kerberos support you need to enable ssl support, too."
+ fi
+
+ use atm || mymakeopts="${mymakeopts} WITHOUT_ATM= "
+ use bluetooth || mymakeopts="${mymakeopts} WITHOUT_BLUETOOTH= "
+ mymakeopts="${mymakeopts} WITHOUT_HESIOD= "
+ use ipv6 || mymakeopts="${mymakeopts} WITHOUT_INET6_SUPPORT= "
+ use kerberos || mymakeopts="${mymakeopts} WITHOUT_KERBEROS_SUPPORT= WITHOUT_GSSAPI= "
+ use netware || mymakeopts="${mymakeopts} WITHOUT_IPX= WITHOUT_IPX_SUPPORT= WITHOUT_NCP= "
+ use ssl || mymakeopts="${mymakeopts} WITHOUT_OPENSSL= "
+ use usb || mymakeopts="${mymakeopts} WITHOUT_USB= "
+ use zfs || mymakeopts="${mymakeopts} WITHOUT_CDDL= "
+
+ mymakeopts="${mymakeopts} WITHOUT_SENDMAIL= WITHOUT_CLANG= WITHOUT_LIBCPLUSPLUS= WITHOUT_LDNS= WITHOUT_UNBOUND= WITHOUT_BSNMP= "
+
+ if [ "${CTARGET}" != "${CHOST}" ]; then
+ mymakeopts="${mymakeopts} MACHINE=$(tc-arch-kernel ${CTARGET})"
+ mymakeopts="${mymakeopts} MACHINE_ARCH=$(tc-arch-kernel ${CTARGET})"
+ fi
+
+ # Taken from freebsd-libexec.
+ use pam || mymakeopts="${mymakeopts} WITHOUT_PAM_SUPPORT= "
+ if has_version "<sys-freebsd/freebsd-ubin-11.0"; then
+ mymakeopts="${mymakeopts} WITHOUT_MAN_UTILS= "
+ fi
+}
+
+PATCHES=(
+ "${FILESDIR}/${PN}-6.0-pmc.patch"
+ "${FILESDIR}/${PN}-9.0-bluetooth.patch"
+ "${FILESDIR}/${PN}-11.0-workaround.patch"
+ "${FILESDIR}/${PN}-11.0-bsdxml2expat.patch"
+ "${FILESDIR}/${PN}-11.0-libproc-libcxx.patch"
+ "${FILESDIR}/${PN}-11.1-liblink.patch"
+ "${FILESDIR}/${PN}-add-nossp-cflags.patch"
+ )
+# Here we disable and remove source which we don't need or want
+# In order:
+# - ncurses stuff
+# - libexpat creates a bsdxml library which is the same as expat
+# - archiving libraries (have their own ebuild)
+# - sendmail libraries (they are installed by sendmail)
+# - SNMP library and dependency (have their own ebuilds)
+# - libstand: static library, 32bits on amd64 used for boot0, we build it from
+# boot0 instead.
+#
+# The rest are libraries we already have somewhere else because
+# they are contribution.
+REMOVE_SUBDIRS="ncurses \
+ libexpat \
+ libz libbz2 libarchive liblzma \
+ libsm libsmdb libsmutil \
+ libbegemot libbsnmp \
+ libpam libpcap libwrap libmagic \
+ libcom_err
+ libedit
+ libstand
+ libgssapi"
+
+# Are we building a cross-compiler?
+is_crosscompile() {
+ [ "${CATEGORY#*cross-}" != "${CATEGORY}" ]
+}
+
+src_prepare() {
+ # If gcc-5.0 or later, apply a workaround to fix a critical issue. bug 573358
+ [[ "$(gcc-major-version)" -ge 5 ]] && replace-flags -O? -O1
+
+ sed -i.bak -e 's:-o/dev/stdout:-t:' "${S}/libc/net/Makefile.inc"
+
+ # Upstream Display Managers default to using VT7
+ # We should make FreeBSD allow this by default
+ local x=
+ for x in "${WORKDIR}"/etc/etc.*/ttys ; do
+ sed -i.bak \
+ -e '/ttyv5[[:space:]]/ a\
+# Display Managers default to VT7.\
+# If you use the xdm init script, keep ttyv6 commented out\
+# unless you force a different VT for the DM being used.' \
+ -e '/^ttyv[678][[:space:]]/ s/^/# /' "${x}" \
+ || die "Failed to sed ${x}"
+ rm "${x}".bak
+ done
+
+ # This one is here because it also
+ # patches "${WORKDIR}/include"
+ cd "${WORKDIR}"
+ epatch "${FILESDIR}/${PN}-includes.patch"
+
+ # Don't install the hesiod man page or header
+ rm "${WORKDIR}"/include/hesiod.h || die
+ sed -i.bak -e 's:hesiod.h::' "${WORKDIR}"/include/Makefile || die
+ sed -i.bak -e 's:hesiod.c::' -e 's:hesiod.3::' \
+ "${WORKDIR}"/lib/libc/net/Makefile.inc || die
+
+ # Fix the Makefiles of these few libraries that will overwrite our LDADD.
+ cd "${S}"
+ for dir in libradius libtacplus libcam libdevstat libfetch libgeom libmemstat libopie \
+ libsmb libprocstat libulog; do sed -i.bak -e 's:LDADD=:LDADD+=:g' "${dir}/Makefile" || \
+ die "Problem fixing \"${dir}/Makefile"
+ done
+ # Call LD with LDFLAGS, rename them to RAW_LDFLAGS
+ sed -e 's/LDFLAGS/RAW_LDFLAGS/g' \
+ -i "${S}/csu/i386/Makefile" || die
+
+ if install --version 2> /dev/null | grep -q GNU; then
+ sed -i.bak -e 's:${INSTALL} -C:${INSTALL}:' "${WORKDIR}/include/Makefile"
+ fi
+
+ # libsysdecode requires the latest headers.
+ need_bootstrap && \
+ sed -i "s:\${DESTDIR}\${INCLUDEDIR}:${WORKDIR}/include_proper_${ABI}:g" "${S}/libsysdecode/Makefile"
+
+ # Taken from freebsd-libexec.
+ cd "${WORKDIR}/libexec"
+ dummy_mk smrsh mail.local tcpd telnetd rshd rlogind ftpd
+ # The old version of yacc doesn't support YFLAGS="-i".
+ if has_version "<sys-freebsd/freebsd-ubin-11.0"; then
+ sed -i -e '/^YFLAGS/d' "${WORKDIR}/libexec/dma/dmagent/Makefile"
+ fi
+
+ # Try to fix sed calls for GNU sed. Do it only with GNU userland and force
+ # BSD's sed on BSD.
+ cd "${S}"
+ if [[ ${CBUILD:-${CHOST}} != *bsd* ]]; then
+ find . -name Makefile -exec sed -ibak 's/sed -i /sed -i/' {} \;
+ sed -i -e 's/-i ""/-i""/' "${S}/csu/Makefile.inc" || die
+ fi
+
+ if use build; then
+ cd "${WORKDIR}"
+ # This patch has to be applied on ${WORKDIR}/sys, so we do it here since it
+ # shouldn't be a symlink to /usr/src/sys (which should be already patched)
+ epatch "${FILESDIR}"/freebsd-sources-9.0-sysctluint.patch
+ epatch "${FILESDIR}/${PN}-11.1-elf-nhdr.patch"
+ return 0
+ fi
+
+ if ! is_crosscompile ; then
+ if [[ ! -e "${WORKDIR}/sys" ]]; then
+ ln -s "${SYSROOT}/usr/src/sys" "${WORKDIR}/sys" || die "Couldn't make sys symlink!"
+ fi
+ else
+ sed -i.bak -e "s:/usr/include:/usr/${CTARGET}/usr/include:g" \
+ "${S}/libc/rpc/Makefile.inc" \
+ "${S}/libc/yp/Makefile.inc"
+ fi
+}
+
+bootstrap_lib() {
+ for i ; do
+ cd "${WORKDIR}/${i}" || die "missing ${i}"
+ freebsd_src_compile
+ append-ldflags "-L${MAKEOBJDIRPREFIX}/${WORKDIR}/${i}"
+ done
+}
+
+get_csudir() {
+ if [ -d "${WORKDIR}/lib/csu/$1-elf" ]; then
+ echo "lib/csu/$1-elf"
+ else
+ echo "lib/csu/$1"
+ fi
+}
+
+bootstrap_csu() {
+ local csudir="$(get_csudir $(tc-arch-kernel ${CTARGET}))"
+ export RAW_LDFLAGS=$(raw-ldflags)
+ bootstrap_lib "${csudir}"
+
+ CFLAGS="${CFLAGS} -B ${MAKEOBJDIRPREFIX}/${WORKDIR}/${csudir}"
+ append-ldflags "-B ${MAKEOBJDIRPREFIX}/${WORKDIR}/${csudir}"
+
+ bootstrap_lib "gnu/lib/csu"
+
+ cd "${MAKEOBJDIRPREFIX}/${WORKDIR}/gnu/lib/csu"
+ for i in *.So ; do
+ ln -s $i ${i%.So}S.o
+ done
+ CFLAGS="${CFLAGS} -B ${MAKEOBJDIRPREFIX}/${WORKDIR}/gnu/lib/csu"
+ append-ldflags "-B ${MAKEOBJDIRPREFIX}/${WORKDIR}/gnu/lib/csu"
+}
+
+# Compile libssp_nonshared.a and add it's path to LDFLAGS.
+bootstrap_libssp_nonshared() {
+ bootstrap_lib "gnu/lib/libssp/libssp_nonshared"
+}
+
+# We should call this function to compile itself correctly.
+# A better solution is very welcome.
+bootstrap_libc() {
+ mkdir "${WORKDIR}/bootstrap_libc_${ABI}" || die
+ append-ldflags "-L${WORKDIR}/bootstrap_libc_${ABI}"
+
+ bootstrap_lib "lib/libc" "lib/libc_nonshared"
+ echo "GROUP ( ${MAKEOBJDIRPREFIX}/${WORKDIR}/lib/libc/libc.so.7 ${MAKEOBJDIRPREFIX}/${WORKDIR}/lib/libc_nonshared/libc_nonshared.a ${MAKEOBJDIRPREFIX}/${WORKDIR}/gnu/lib/libssp/libssp_nonshared/libssp_nonshared.a )" > "${WORKDIR}/bootstrap_libc_${ABI}/libc.so" || die
+}
+
+bootstrap_libgcc() {
+ bootstrap_lib "lib/libcompiler_rt"
+ cd "${MAKEOBJDIRPREFIX}/${WORKDIR}/lib/libcompiler_rt" || die
+ ln -s libcompiler_rt.a libgcc.a || die
+
+ bootstrap_libc
+ bootstrap_lib "gnu/lib/libgcc"
+}
+
+bootstrap_libthr() {
+ bootstrap_lib "lib/libthr"
+ cd "${MAKEOBJDIRPREFIX}/${WORKDIR}/lib/libthr" || die
+ ln -s libthr.so libpthread.so
+}
+
+# What to build for a cross-compiler.
+# We also need the csu but this has to be handled separately.
+CROSS_SUBDIRS="lib/libc lib/msun gnu/lib/libssp/libssp_nonshared lib/libthr lib/libutil lib/librt lib/libc_nonshared lib/libcompiler_rt"
+
+# What to build for non-default ABIs.
+NON_NATIVE_SUBDIRS="${CROSS_SUBDIRS} gnu/lib/csu gnu/lib/libgcc lib/libmd lib/libcrypt lib/libsbuf lib/libcam lib/libelf lib/libiconv_modules"
+
+# Subdirs for a native build:
+NATIVE_SUBDIRS="lib gnu/lib/libssp/libssp_nonshared gnu/lib/libregex gnu/lib/csu gnu/lib/libgcc lib/libiconv_modules"
+
+# Is my $ABI native ?
+is_native_abi() {
+ is_crosscompile && return 1
+ multilib_is_native_abi
+}
+
+# Do we need to bootstrap the csu and libssp_nonshared?
+need_bootstrap() {
+ is_crosscompile || use build || { ! is_native_abi && ! has_version '>=sys-freebsd/freebsd-lib-9.1-r8[multilib]' && ! has_version ">=sys-freebsd/freebsd-lib-9.1-r11[${MULTILIB_USEDEP}]" ; } || has_version "<${CATEGORY}/${P}"
+}
+
+# Get the subdirs we are building.
+get_subdirs() {
+ local ret=""
+ if is_native_abi ; then
+ # If we are building for the native ABI, build everything
+ ret="${NATIVE_SUBDIRS}"
+ elif is_crosscompile ; then
+ # With a cross-compiler we only build the very core parts.
+ ret="${CROSS_SUBDIRS}"
+ if [ "${EBUILD_PHASE}" = "install" ]; then
+ # Add the csu dir first when installing. We treat it separately for
+ # compiling.
+ ret="$(get_csudir $(tc-arch-kernel ${CTARGET})) ${ret}"
+ fi
+ else
+ # For the non-native ABIs we only build the csu parts and very core
+ # libraries for now.
+ ret="${NON_NATIVE_SUBDIRS} $(get_csudir $(tc-arch-kernel ${CHOST}))"
+ fi
+ echo "${ret}"
+}
+
+# Bootstrap the core libraries and setup the flags so that the other parts can
+# build against it.
+do_bootstrap() {
+ einfo "Bootstrapping on ${CHOST} for ${CTARGET}"
+ if ! is_crosscompile ; then
+ # Pre-install headers, but not when building a cross-compiler since we
+ # assume they have been installed in the previous pass.
+ einfo "Pre-installing includes in include_proper_${ABI}"
+ mkdir "${WORKDIR}/include_proper_${ABI}" || die
+ CTARGET="${CHOST}" install_includes "/include_proper_${ABI}"
+ CFLAGS="${CFLAGS} -isystem ${WORKDIR}/include_proper_${ABI}"
+ [[ $(tc-getCXX) = *clang++* ]] && CXXFLAGS="${CXXFLAGS} -isystem /usr/include/c++/v1"
+ CXXFLAGS="${CXXFLAGS} -isystem ${WORKDIR}/include_proper_${ABI}"
+ mymakeopts="${mymakeopts} RPCDIR=${WORKDIR}/include_proper_${ABI}/rpcsvc"
+ fi
+ bootstrap_csu
+ bootstrap_libssp_nonshared
+ if is_crosscompile ; then
+ bootstrap_lib "lib/libcompiler_rt"
+ bootstrap_libc
+ else
+ is_native_abi || bootstrap_libgcc
+ is_native_abi && has_version "<=sys-freebsd/freebsd-lib-10.0" && bootstrap_libgcc
+ fi
+ is_native_abi || bootstrap_libthr
+}
+
+# Taken from freebsd-libexec.
+libexec_setup_multilib_vars() {
+ export mymakeopts="${mymakeopts} WITHOUT_RCMDS= WITHOUT_PF= "
+ need_bootstrap && CFLAGS="${CFLAGS} -isystem ${WORKDIR}/include_proper_${ABI}"
+ append-ldflags "-L${MAKEOBJDIRPREFIX}/${WORKDIR}/lib/libc"
+ if ! multilib_is_native_abi ; then
+ cd "${WORKDIR}/libexec/rtld-elf" || die
+ export mymakeopts="${mymakeopts} PROG=ld-elf32.so.1 "
+ else
+ cd "${WORKDIR}/libexec" || die
+ fi
+ "$@"
+}
+
+# Compile it. Assume we have the toolchain setup correctly.
+do_compile() {
+ # Bootstrap if needed, otherwise assume the system headers are in
+ # /usr/include.
+ if need_bootstrap ; then
+ do_bootstrap
+ else
+ CFLAGS="${CFLAGS} -isystem /usr/include"
+ [[ $(tc-getCXX) = *clang++* ]] && CXXFLAGS="${CXXFLAGS} -isystem /usr/include/c++/v1"
+ fi
+
+ export RAW_LDFLAGS=$(raw-ldflags)
+
+ # Everything is now setup, build it!
+ for i in $(get_subdirs) ; do
+ einfo "Building in ${i}... with CC=${CC} and CFLAGS=${CFLAGS}"
+ cd "${WORKDIR}/${i}/" || die "missing ${i}."
+ freebsd_src_compile || die "make ${i} failed"
+ done
+}
+
+src_compile() {
+ # Does not work with GNU sed
+ # Force BSD's sed on BSD.
+ if [[ ${CBUILD:-${CHOST}} == *bsd* ]]; then
+ export ESED=/usr/bin/sed
+ unalias sed
+ fi
+
+ use usb && export NON_NATIVE_SUBDIRS="${NON_NATIVE_SUBDIRS} lib/libusb lib/libusbhid"
+
+ cd "${WORKDIR}/include"
+ $(freebsd_get_bmake) CC="$(tc-getCC)" SRCTOP="${WORKDIR}" || die "make include failed"
+
+ use headers-only && return 0
+
+ # Bug #270098
+ append-flags $(test-flags -fno-strict-aliasing)
+
+ # Bug #324445
+ append-flags $(test-flags -fno-strict-overflow)
+
+ # strip flags and do not do it later, we only add safe, and in fact
+ # needed flags after all
+ strip-flags
+ export NOFLAGSTRIP=yes
+ if is_crosscompile ; then
+ export YACC='yacc -by'
+ CHOST=${CTARGET} tc-export CC LD CXX RANLIB
+ mymakeopts="${mymakeopts} NLS="
+ CFLAGS="${CFLAGS} -isystem /usr/${CTARGET}/usr/include"
+ CXXFLAGS="${CXXFLAGS} -isystem /usr/${CTARGET}/usr/include"
+ append-ldflags "-L${WORKDIR}/${CHOST}/${WORKDIR}/lib/libc"
+ fi
+
+ if is_crosscompile ; then
+ do_compile
+ else
+ local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper do_compile
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper libexec_setup_multilib_vars freebsd_src_compile
+ fi
+}
+
+gen_libc_ldscript() {
+ # Parameters:
+ # $1 = target libdir
+ # $2 = source libc dir
+ # $3 = source libssp_nonshared dir
+
+ # Clear the symlink.
+ rm -f "${DESTDIR}/$2/libc.so" || die
+
+ # Move the library if needed
+ if [ "$1" != "$2" ] ; then
+ mv "${DESTDIR}/$2/libc.so.7" "${DESTDIR}/$1/" || die
+ fi
+
+ # Generate libc.so ldscript for inclusion of libssp_nonshared.a when linking
+ # this is done to avoid having to touch gcc spec file as it is currently
+ # done on FreeBSD upstream, mostly because their binutils aren't able to
+ # cope with linker scripts yet.
+ # Taken from toolchain-funcs.eclass:
+ local output_format
+ output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p')
+ [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"
+
+ # The iconv symbol is provided by libc_nonshared.a.
+ # http://svnweb.freebsd.org/base?view=revision&amp;revision=258283
+ cat > "${DESTDIR}/$2/libc.so" <<-END_LDSCRIPT
+/* GNU ld script
+ SSP (-fstack-protector) requires __stack_chk_fail_local to be local.
+ GCC invokes this symbol in a non-PIC way, which results in TEXTRELs if
+ this symbol was provided by a shared libc. So we link in
+ libssp_nonshared.a from here.
+ */
+${output_format}
+GROUP ( /$1/libc.so.7 /$3/libc_nonshared.a /$3/libssp_nonshared.a )
+END_LDSCRIPT
+}
+
+header_list=""
+
+move_header() {
+ local dirname=$(dirname ${1})
+ local filename=$(basename ${1})
+
+ if [ ! -d "${dirname}/${ABI}" ] ; then
+ mkdir "${dirname}/${ABI}" || die
+ fi
+
+ mv "${1}" "${dirname}/${ABI}/" || die
+
+ export header_list="${header_list} ${1}"
+}
+
+make_header_template() {
+ cat <<-END_HEADER
+/*
+ * Wrapped header for multilib support.
+ * See the real headers included below.
+ */
+
+#if defined(__x86_64__)
+ @ABI_amd64_fbsd@
+#elif defined(__i386__)
+ @ABI_x86_fbsd@
+#else
+ @ABI_${DEFAULT_ABI}@
+#endif
+END_HEADER
+}
+
+wrap_header() {
+ local dirname=$(dirname ${1})
+ local filename=$(basename ${1})
+
+ if [ -n "${dirname#.}" ] ; then
+ dirname="${dirname}/${2}"
+ else
+ dirname="${2}"
+ fi
+
+ if [ -f "${dirname}/${filename}" ] ; then
+ sed -e "s:@ABI_${2}@:#include <${dirname}/${filename}>:" ${1}
+ else
+ cat ${1}
+ fi
+}
+
+wrap_header_end() {
+ sed -e "s:@ABI_.*@:#error \"Sorry, no support for your ABI.\":" ${1}
+}
+
+do_install() {
+ if is_crosscompile ; then
+ INCLUDEDIR="/usr/${CTARGET}/usr/include"
+ else
+ INCLUDEDIR="/usr/include"
+ fi
+
+ dodir ${INCLUDEDIR}
+ CTARGET="${CHOST}" \
+ install_includes ${INCLUDEDIR}
+
+ is_crosscompile && use headers-only && return 0
+
+ # Install a libusb.pc for better compat with Linux's libusb
+ if use usb ; then
+ dodir /usr/$(get_libdir)/pkgconfig
+ sed -i.bkp "s:^libdir=.*:libdir=/usr/$(get_libdir):g" "${S}"/libusb/libusb-*.pc
+ fi
+
+ for i in $(get_subdirs) ; do
+ if [[ ${i} != *libiconv_modules* ]] ; then
+ einfo "Installing in ${i}..."
+ cd "${WORKDIR}/${i}/" || die "missing ${i}."
+ freebsd_src_install || die "Install ${i} failed"
+ fi
+ done
+
+ if ! is_crosscompile; then
+ local mymakeopts_save="${mymakeopts}"
+ mymakeopts="${mymakeopts} SHLIBDIR=/usr/$(get_libdir)/i18n LIBDIR=/usr/$(get_libdir)/i18n"
+
+ einfo "Installing in lib/libiconv_modules..."
+ cd "${WORKDIR}/lib/libiconv_modules/" || die "missing libiconv_modules."
+ freebsd_src_install || die "Install lib/libiconv_modules failed"
+
+ mymakeopts="${mymakeopts_save}"
+ fi
+
+ if ! is_crosscompile ; then
+ if ! multilib_is_native_abi ; then
+ DESTDIR="${D}" gen_libc_ldscript "usr/$(get_libdir)" "usr/$(get_libdir)" "usr/$(get_libdir)"
+ else
+ dodir "$(get_libdir)"
+ DESTDIR="${D}" gen_libc_ldscript "$(get_libdir)" "usr/$(get_libdir)" "usr/$(get_libdir)"
+ fi
+ else
+ CHOST=${CTARGET} DESTDIR="${D}/usr/${CTARGET}/" gen_libc_ldscript "usr/lib" "usr/lib" "usr/lib"
+ # We're done for the cross libc here.
+ return 0
+ fi
+
+ # Generate ldscripts for core libraries that will go in /
+ multilib_is_native_abi && \
+ gen_usr_ldscript -a alias cam geom ipsec jail kiconv \
+ kvm m md procstat sbuf thr ufs util elf
+
+ if [[ ${#MULTIBUILD_VARIANTS[@]} -gt 1 ]] ; then
+ cd "${D}/usr/include"
+ for i in machine/*.h fenv.h ; do
+ move_header ${i}
+ done
+ if multilib_is_native_abi ; then
+ # Supposedly the last one!
+ local uniq_headers="$(echo ${header_list} | tr ' ' '\n' | sort | uniq | tr '\n' ' ')"
+ for j in ${uniq_headers} ; do
+ make_header_template > ${j}
+ for i in $(get_all_abis) ; do
+ wrap_header ${j} ${i} > ${j}.new
+ cp ${j}.new ${j}
+ rm -f ${j}.new
+ done
+ wrap_header_end ${j} > ${j}.new
+ cp ${j}.new ${j}
+ rm -f ${j}.new
+ done
+ fi
+ fi
+}
+
+src_install() {
+ if is_crosscompile ; then
+ einfo "Installing for ${CTARGET} in ${CHOST}.."
+ # From this point we need to force: get stripped with the correct tools,
+ # get tc-arch-kernel to return the right value, etc.
+ export CHOST=${CTARGET}
+
+ mymakeopts="${mymakeopts} WITHOUT_MAN= \
+ INCLUDEDIR=/usr/${CTARGET}/usr/include \
+ SHLIBDIR=/usr/${CTARGET}/usr/lib \
+ LIBDIR=/usr/${CTARGET}/usr/lib"
+
+ dosym "usr/include" "/usr/${CTARGET}/sys-include"
+ do_install
+
+ return 0
+ else
+ export STRIP_MASK="*/usr/lib*/*crt*.o"
+ local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper do_install
+
+ # Taken from freebsd-libexec.
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper libexec_setup_multilib_vars freebsd_src_install
+ insinto /etc
+ doins "${WORKDIR}/etc/gettytab"
+ newinitd "${FILESDIR}/bootpd.initd" bootpd
+ newconfd "${FILESDIR}/bootpd.confd" bootpd
+
+ if use xinetd; then
+ for rpcd in rstatd rusersd walld rquotad sprayd; do
+ insinto /etc/xinetd.d
+ newins "${FILESDIR}/${rpcd}.xinetd" ${rpcd}
+ done
+ fi
+ fi
+
+ cd "${WORKDIR}/etc/"
+ insinto /etc
+ doins nls.alias mac.conf netconfig
+
+ # Install ttys file
+ local MACHINE="$(tc-arch-kernel)"
+ doins "etc.${MACHINE}"/*
+}
+
+install_includes()
+{
+ local INCLUDEDIR="$1"
+
+ # The idea is to be called from either install or unpack.
+ # During unpack it's required to install them as portage's user.
+ if [[ "${EBUILD_PHASE}" == "install" ]]; then
+ local DESTDIR="${D}"
+ BINOWN="root"
+ BINGRP="wheel"
+ else
+ local DESTDIR="${WORKDIR}"
+ [[ -z "${USER}" ]] && USER="portage"
+ BINOWN="${USER}"
+ [[ -z "${GROUPS}" ]] && GROUPS="portage"
+ BINGRP="${GROUPS}"
+ fi
+
+ # Must exist before we use it.
+ [[ -d "${DESTDIR}${INCLUDEDIR}" ]] || die "dodir or mkdir ${INCLUDEDIR} before using install_includes."
+ cd "${WORKDIR}/include"
+
+ local MACHINE="$(tc-arch-kernel)"
+
+ einfo "Installing includes into ${INCLUDEDIR} as ${BINOWN}:${BINGRP}..."
+ $(freebsd_get_bmake) installincludes \
+ MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE} \
+ DESTDIR="${DESTDIR}" \
+ INCLUDEDIR="${INCLUDEDIR}" BINOWN="${BINOWN}" \
+ BINGRP="${BINGRP}" \
+ WITHOUT_GSSAPI= \
+ $(usex zfs "WITH_CDDL=" "WITHOUT_CDDL=") \
+ SRCTOP="${WORKDIR}"|| die "install_includes() failed"
+ einfo "includes installed ok."
+ EXTRA_INCLUDES="lib/librtld_db lib/libutil lib/msun gnu/lib/libregex lib/libcasper lib/libmp"
+ for i in $EXTRA_INCLUDES; do
+ einfo "Installing $i includes into ${INCLUDEDIR} as ${BINOWN}:${BINGRP}..."
+ cd "${WORKDIR}/$i" || die
+ $(freebsd_get_bmake) installincludes DESTDIR="${DESTDIR}" \
+ MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE} \
+ INCLUDEDIR="${INCLUDEDIR}" BINOWN="${BINOWN}" \
+ BINGRP="${BINGRP}" \
+ SRCTOP="${WORKDIR}" || die "problem installing $i includes."
+ einfo "$i includes installed ok."
+ done
+}
diff --git a/sys-freebsd/freebsd-lib/freebsd-lib-9.1-r11.ebuild b/sys-freebsd/freebsd-lib/freebsd-lib-9.1-r11.ebuild
new file mode 100644
index 000000000000..354d1d40f722
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/freebsd-lib-9.1-r11.ebuild
@@ -0,0 +1,616 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd flag-o-matic multilib toolchain-funcs eutils multibuild multilib-build usr-ldscript
+
+DESCRIPTION="FreeBSD's base system libraries"
+SLOT="0"
+KEYWORDS="~amd64-fbsd ~x86-fbsd"
+
+# Crypto is needed to have an internal OpenSSL header
+# sys is needed for libalias, probably we can just extract that instead of
+# extracting the whole tarball
+SRC_URI="mirror://gentoo/${LIB}.tar.bz2
+ mirror://gentoo/${CONTRIB}.tar.bz2
+ mirror://gentoo/${CRYPTO}.tar.bz2
+ mirror://gentoo/${LIBEXEC}.tar.bz2
+ mirror://gentoo/${ETC}.tar.bz2
+ mirror://gentoo/${INCLUDE}.tar.bz2
+ mirror://gentoo/${USBIN}.tar.bz2
+ mirror://gentoo/${GNU}.tar.bz2
+ build? (
+ mirror://gentoo/${SYS}.tar.bz2 )
+ zfs? (
+ mirror://gentoo/${CDDL}.tar.bz2 )"
+
+if [ "${CATEGORY#*cross-}" = "${CATEGORY}" ]; then
+ RDEPEND="ssl? ( dev-libs/openssl )
+ kerberos? ( app-crypt/heimdal )
+ usb? ( !dev-libs/libusb )
+ zfs? ( =sys-freebsd/freebsd-cddl-${RV}* )
+ >=dev-libs/expat-2.0.1
+ !sys-libs/libutempter
+ !sys-freebsd/freebsd-headers"
+ DEPEND="${RDEPEND}
+ >=sys-devel/flex-2.5.31-r2
+ =sys-freebsd/freebsd-sources-${RV}*"
+else
+ SRC_URI="${SRC_URI}
+ mirror://gentoo/${SYS}.tar.bz2"
+fi
+
+DEPEND="${DEPEND}
+ userland_GNU? ( sys-apps/mtree )
+ =sys-freebsd/freebsd-mk-defs-${RV}*"
+
+S="${WORKDIR}/lib"
+
+export CTARGET=${CTARGET:-${CHOST}}
+if [ "${CTARGET}" = "${CHOST}" -a "${CATEGORY#*cross-}" != "${CATEGORY}" ]; then
+ export CTARGET=${CATEGORY/cross-}
+fi
+
+IUSE="atm bluetooth ssl ipv6 kerberos usb netware
+ build headers-only zfs
+ userland_GNU userland_BSD"
+
+QA_DT_NEEDED="lib/libc.so.7 usr/lib32/libc.so.7"
+
+pkg_setup() {
+ [ -c /dev/zero ] || \
+ die "You forgot to mount /dev; the compiled libc would break."
+
+ if ! use ssl && use kerberos; then
+ eerror "If you want kerberos support you need to enable ssl support, too."
+ fi
+
+ use atm || mymakeopts="${mymakeopts} WITHOUT_ATM= "
+ use bluetooth || mymakeopts="${mymakeopts} WITHOUT_BLUETOOTH= "
+ mymakeopts="${mymakeopts} WITHOUT_HESIOD= "
+ use ipv6 || mymakeopts="${mymakeopts} WITHOUT_INET6_SUPPORT= "
+ use kerberos || mymakeopts="${mymakeopts} WITHOUT_KERBEROS_SUPPORT= WITHOUT_GSSAPI= "
+ use netware || mymakeopts="${mymakeopts} WITHOUT_IPX= WITHOUT_IPX_SUPPORT= WITHOUT_NCP= "
+ use ssl || mymakeopts="${mymakeopts} WITHOUT_OPENSSL= "
+ use usb || mymakeopts="${mymakeopts} WITHOUT_USB= "
+ use zfs || mymakeopts="${mymakeopts} WITHOUT_CDDL= "
+
+ mymakeopts="${mymakeopts} WITHOUT_BIND= WITHOUT_BIND_LIBS= WITHOUT_SENDMAIL= WITHOUT_CLANG= "
+
+ if [ "${CTARGET}" != "${CHOST}" ]; then
+ mymakeopts="${mymakeopts} MACHINE=$(tc-arch-kernel ${CTARGET})"
+ mymakeopts="${mymakeopts} MACHINE_ARCH=$(tc-arch-kernel ${CTARGET})"
+ fi
+}
+
+PATCHES=(
+ "${FILESDIR}/${PN}-6.0-pmc.patch"
+ "${FILESDIR}/${PN}-6.0-flex-2.5.31.patch"
+ "${FILESDIR}/${PN}-6.1-csu.patch"
+ "${FILESDIR}/${PN}-9.0-liblink.patch"
+ "${FILESDIR}/${PN}-bsdxml2expat.patch"
+ "${FILESDIR}/${PN}-9.0-netware.patch"
+ "${FILESDIR}/${PN}-9.0-cve-2010-2632.patch"
+ "${FILESDIR}/${PN}-9.0-bluetooth.patch"
+ "${FILESDIR}/${PN}-9.1-.eh_frame_hdr-fix.patch"
+ "${FILESDIR}/${PN}-add-nossp-cflags.patch"
+ )
+
+# Here we disable and remove source which we don't need or want
+# In order:
+# - ncurses stuff
+# - libexpat creates a bsdxml library which is the same as expat
+# - archiving libraries (have their own ebuild)
+# - sendmail libraries (they are installed by sendmail)
+# - SNMP library and dependency (have their own ebuilds)
+# - libstand: static library, 32bits on amd64 used for boot0, we build it from
+# boot0 instead.
+#
+# The rest are libraries we already have somewhere else because
+# they are contribution.
+# Note: libtelnet is an internal lib used by telnet and telnetd programs
+# as it's not used in freebsd-lib package itself, it's pointless building
+# it here.
+REMOVE_SUBDIRS="ncurses \
+ libexpat \
+ libz libbz2 libarchive liblzma \
+ libsm libsmdb libsmutil \
+ libbegemot libbsnmp \
+ libpam libpcap bind libwrap libmagic \
+ libcom_err libtelnet
+ libelf libedit
+ libstand
+ libgssapi"
+
+# Are we building a cross-compiler?
+is_crosscompile() {
+ [ "${CATEGORY#*cross-}" != "${CATEGORY}" ]
+}
+
+src_prepare() {
+ sed -i.bak -e 's:-o/dev/stdout:-t:' "${S}/libc/net/Makefile.inc"
+
+ # Upstream Display Managers default to using VT7
+ # We should make FreeBSD allow this by default
+ local x=
+ for x in "${WORKDIR}"/etc/etc.*/ttys ; do
+ sed -i.bak \
+ -e '/ttyv5[[:space:]]/ a\
+# Display Managers default to VT7.\
+# If you use the xdm init script, keep ttyv6 commented out\
+# unless you force a different VT for the DM being used.' \
+ -e '/^ttyv[678][[:space:]]/ s/^/# /' "${x}" \
+ || die "Failed to sed ${x}"
+ rm "${x}".bak
+ done
+
+ # This one is here because it also
+ # patches "${WORKDIR}/include"
+ cd "${WORKDIR}"
+ epatch "${FILESDIR}/${PN}-includes.patch"
+ epatch "${FILESDIR}/${PN}-8.0-gcc45.patch"
+ epatch "${FILESDIR}/${PN}-9.0-opieincludes.patch"
+ epatch "${FILESDIR}/${PN}-9.1-aligned_alloc.patch"
+ epatch "${FILESDIR}/${PN}-9.1-rmgssapi.patch"
+
+ # Don't install the hesiod man page or header
+ rm "${WORKDIR}"/include/hesiod.h || die
+ sed -i.bak -e 's:hesiod.h::' "${WORKDIR}"/include/Makefile || die
+ sed -i.bak -e 's:hesiod.c::' -e 's:hesiod.3::' \
+ "${WORKDIR}"/lib/libc/net/Makefile.inc || die
+
+ # Fix the Makefiles of these few libraries that will overwrite our LDADD.
+ cd "${S}"
+ for dir in libradius libtacplus libcam libdevstat libfetch libgeom libmemstat libopie \
+ libsmb libprocstat libulog; do sed -i.bak -e 's:LDADD=:LDADD+=:g' "${dir}/Makefile" || \
+ die "Problem fixing \"${dir}/Makefile"
+ done
+ # Call LD with LDFLAGS, rename them to RAW_LDFLAGS
+ sed -e 's/LDFLAGS/RAW_LDFLAGS/g' \
+ -i "${S}/csu/i386-elf/Makefile" \
+ -i "${S}/csu/ia64/Makefile" || die
+ if use build; then
+ cd "${WORKDIR}"
+ # This patch has to be applied on ${WORKDIR}/sys, so we do it here since it
+ # shouldn't be a symlink to /usr/src/sys (which should be already patched)
+ epatch "${FILESDIR}"/${PN}-7.1-types.h-fix.patch
+ epatch "${FILESDIR}"/freebsd-sources-9.0-sysctluint.patch
+ return 0
+ fi
+
+ if ! is_crosscompile ; then
+ ln -s "/usr/src/sys-${RV}" "${WORKDIR}/sys" || die "Couldn't make sys symlink!"
+ else
+ sed -i.bak -e "s:/usr/include:/usr/${CTARGET}/usr/include:g" \
+ "${S}/libc/rpc/Makefile.inc" \
+ "${S}/libc/yp/Makefile.inc"
+ fi
+
+ if install --version 2> /dev/null | grep -q GNU; then
+ sed -i.bak -e 's:${INSTALL} -C:${INSTALL}:' "${WORKDIR}/include/Makefile"
+ fi
+
+ # Try to fix sed calls for GNU sed. Do it only with GNU userland and force
+ # BSD's sed on BSD.
+ cd "${S}"
+ if use userland_GNU; then
+ find . -name Makefile -exec sed -ibak 's/sed -i /sed -i/' {} \;
+ fi
+}
+
+get_csudir() {
+ if [ -d "${WORKDIR}/lib/csu/$1-elf" ]; then
+ echo "lib/csu/$1-elf"
+ else
+ echo "lib/csu/$1"
+ fi
+}
+
+bootstrap_csu() {
+ local csudir="$(get_csudir $(tc-arch-kernel ${CTARGET}))"
+ export RAW_LDFLAGS=$(raw-ldflags)
+ cd "${WORKDIR}/${csudir}" || die "Missing ${csudir}."
+ freebsd_src_compile
+
+ CFLAGS="${CFLAGS} -B ${MAKEOBJDIRPREFIX}/${WORKDIR}/${csudir}"
+ append-ldflags "-B ${MAKEOBJDIRPREFIX}/${WORKDIR}/${csudir}"
+
+ cd "${WORKDIR}/gnu/lib/csu" || die
+ freebsd_src_compile
+ cd "${MAKEOBJDIRPREFIX}/${WORKDIR}/gnu/lib/csu"
+ for i in *.So ; do
+ ln -s $i ${i%.So}S.o
+ done
+ CFLAGS="${CFLAGS} -B ${MAKEOBJDIRPREFIX}/${WORKDIR}/gnu/lib/csu"
+ append-ldflags "-B ${MAKEOBJDIRPREFIX}/${WORKDIR}/gnu/lib/csu"
+}
+
+# Compile libssp_nonshared.a and add it's path to LDFLAGS.
+bootstrap_libssp_nonshared() {
+ cd "${WORKDIR}/gnu/lib/libssp/libssp_nonshared/" || die "missing libssp."
+ freebsd_src_compile
+ append-ldflags "-L${MAKEOBJDIRPREFIX}/${WORKDIR}/gnu/lib/libssp/libssp_nonshared/"
+ export LDADD="-lssp_nonshared"
+}
+
+bootstrap_libc() {
+ cd "${WORKDIR}/lib/libc" || die
+ freebsd_src_compile
+ append-ldflags "-L${MAKEOBJDIRPREFIX}/${WORKDIR}/lib/libc"
+}
+
+bootstrap_libgcc() {
+ cd "${WORKDIR}/lib/libcompiler_rt" || die
+ freebsd_src_compile
+ cd "${MAKEOBJDIRPREFIX}/${WORKDIR}/lib/libcompiler_rt" || die
+ ln -s libcompiler_rt.a libgcc.a || die
+ append-ldflags "-L${MAKEOBJDIRPREFIX}/${WORKDIR}/lib/libcompiler_rt"
+
+ bootstrap_libc
+
+ cd "${WORKDIR}/gnu/lib/libgcc" || die
+ freebsd_src_compile
+ append-ldflags "-L${MAKEOBJDIRPREFIX}/${WORKDIR}/gnu/lib/libgcc"
+}
+
+bootstrap_libthr() {
+ cd "${WORKDIR}/lib/libthr" || die
+ freebsd_src_compile
+ append-ldflags "-L${MAKEOBJDIRPREFIX}/${WORKDIR}/lib/libthr"
+ cd "${MAKEOBJDIRPREFIX}/${WORKDIR}/lib/libthr" || die
+ ln -s libthr.so libpthread.so
+}
+
+# What to build for a cross-compiler.
+# We also need the csu but this has to be handled separately.
+CROSS_SUBDIRS="lib/libc lib/msun gnu/lib/libssp/libssp_nonshared lib/libthr lib/libutil lib/librt"
+
+# What to build for non-default ABIs.
+NON_NATIVE_SUBDIRS="${CROSS_SUBDIRS} gnu/lib/csu lib/libcompiler_rt gnu/lib/libgcc lib/libmd lib/libcrypt"
+
+# Subdirs for a native build:
+NATIVE_SUBDIRS="lib gnu/lib/libssp/libssp_nonshared gnu/lib/libregex gnu/lib/csu gnu/lib/libgcc"
+
+# Is my $ABI native ?
+is_native_abi() {
+ is_crosscompile && return 1
+ multilib_is_native_abi
+}
+
+# Do we need to bootstrap the csu and libssp_nonshared?
+need_bootstrap() {
+ is_crosscompile || use build || { ! is_native_abi && ! has_version '>=sys-freebsd/freebsd-lib-9.1-r8[multilib]' && ! has_version ">=sys-freebsd/freebsd-lib-9.1-r11[${MULTILIB_USEDEP}]" ; } || has_version "<${CATEGORY}/${P}"
+}
+
+# Get the subdirs we are building.
+get_subdirs() {
+ local ret=""
+ if is_native_abi ; then
+ # If we are building for the native ABI, build everything
+ ret="${NATIVE_SUBDIRS}"
+ elif is_crosscompile ; then
+ # With a cross-compiler we only build the very core parts.
+ ret="${CROSS_SUBDIRS}"
+ if [ "${EBUILD_PHASE}" = "install" ]; then
+ # Add the csu dir first when installing. We treat it separately for
+ # compiling.
+ ret="$(get_csudir $(tc-arch-kernel ${CTARGET})) ${ret}"
+ fi
+ else
+ # For the non-native ABIs we only build the csu parts and very core
+ # libraries for now.
+ ret="${NON_NATIVE_SUBDIRS} $(get_csudir $(tc-arch-kernel ${CHOST}))"
+ fi
+ echo "${ret}"
+}
+
+# Bootstrap the core libraries and setup the flags so that the other parts can
+# build against it.
+do_bootstrap() {
+ einfo "Bootstrapping on ${CHOST} for ${CTARGET}"
+ if ! is_crosscompile ; then
+ # Pre-install headers, but not when building a cross-compiler since we
+ # assume they have been installed in the previous pass.
+ einfo "Pre-installing includes in include_proper_${ABI}"
+ mkdir "${WORKDIR}/include_proper_${ABI}" || die
+ CTARGET="${CHOST}" install_includes "/include_proper_${ABI}"
+ CFLAGS="${CFLAGS} -isystem ${WORKDIR}/include_proper_${ABI}"
+ fi
+ bootstrap_csu
+ bootstrap_libssp_nonshared
+ is_crosscompile && bootstrap_libc
+ is_crosscompile || is_native_abi || bootstrap_libgcc
+ is_native_abi || bootstrap_libthr
+}
+
+# Compile it. Assume we have the toolchain setup correctly.
+do_compile() {
+ # Bootstrap if needed, otherwise assume the system headers are in
+ # /usr/include.
+ if need_bootstrap ; then
+ do_bootstrap
+ else
+ CFLAGS="${CFLAGS} -isystem /usr/include"
+ fi
+
+ export RAW_LDFLAGS=$(raw-ldflags)
+
+ # Everything is now setup, build it!
+ for i in $(get_subdirs) ; do
+ einfo "Building in ${i}... with CC=${CC} and CFLAGS=${CFLAGS}"
+ cd "${WORKDIR}/${i}/" || die "missing ${i}."
+ freebsd_src_compile || die "make ${i} failed"
+ done
+}
+
+src_compile() {
+ # Does not work with GNU sed
+ # Force BSD's sed on BSD.
+ if use userland_BSD ; then
+ export ESED=/usr/bin/sed
+ unalias sed
+ fi
+
+ use usb && export NON_NATIVE_SUBDIRS="${NON_NATIVE_SUBDIRS} lib/libusb lib/libusbhid"
+
+ cd "${WORKDIR}/include"
+ $(freebsd_get_bmake) CC="$(tc-getCC)" || die "make include failed"
+
+ use headers-only && return 0
+
+ # Bug #270098
+ append-flags $(test-flags -fno-strict-aliasing)
+
+ # Bug #324445
+ append-flags $(test-flags -fno-strict-overflow)
+
+ # strip flags and do not do it later, we only add safe, and in fact
+ # needed flags after all
+ strip-flags
+ export NOFLAGSTRIP=yes
+ if is_crosscompile ; then
+ export YACC='yacc -by'
+ CHOST=${CTARGET} tc-export CC LD CXX RANLIB
+ mymakeopts="${mymakeopts} NLS="
+ CFLAGS="${CFLAGS} -isystem /usr/${CTARGET}/usr/include"
+ append-ldflags "-L${WORKDIR}/${CHOST}/${WORKDIR}/lib/libc"
+ fi
+
+ if is_crosscompile ; then
+ do_compile
+ else
+ local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper do_compile
+ fi
+}
+
+gen_libc_ldscript() {
+ # Parameters:
+ # $1 = target libdir
+ # $2 = source libc dir
+ # $3 = source libssp_nonshared dir
+
+ # Clear the symlink.
+ rm -f "${D}/$2/libc.so" || die
+
+ # Move the library if needed
+ if [ "$1" != "$2" ] ; then
+ mv "${D}/$2/libc.so.7" "${D}/$1/" || die
+ fi
+
+ # Generate libc.so ldscript for inclusion of libssp_nonshared.a when linking
+ # this is done to avoid having to touch gcc spec file as it is currently
+ # done on FreeBSD upstream, mostly because their binutils aren't able to
+ # cope with linker scripts yet.
+ # Taken from toolchain-funcs.eclass:
+ local output_format
+ output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p')
+ [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"
+
+ cat > "${D}/$2/libc.so" <<-END_LDSCRIPT
+/* GNU ld script
+ SSP (-fstack-protector) requires __stack_chk_fail_local to be local.
+ GCC invokes this symbol in a non-PIC way, which results in TEXTRELs if
+ this symbol was provided by a shared libc. So we link in
+ libssp_nonshared.a from here.
+ */
+${output_format}
+GROUP ( /$1/libc.so.7 /$3/libssp_nonshared.a )
+END_LDSCRIPT
+}
+
+header_list=""
+
+move_header() {
+ local dirname=$(dirname ${1})
+ local filename=$(basename ${1})
+
+ if [ ! -d "${dirname}/${ABI}" ] ; then
+ mkdir "${dirname}/${ABI}" || die
+ fi
+
+ mv "${1}" "${dirname}/${ABI}/" || die
+
+ export header_list="${header_list} ${1}"
+}
+
+make_header_template() {
+ cat <<-END_HEADER
+/*
+ * Wrapped header for multilib support.
+ * See the real headers included below.
+ */
+
+#if defined(__x86_64__)
+ @ABI_amd64_fbsd@
+#elif defined(__i386__)
+ @ABI_x86_fbsd@
+#else
+ @ABI_${DEFAULT_ABI}@
+#endif
+END_HEADER
+}
+
+wrap_header() {
+ local dirname=$(dirname ${1})
+ local filename=$(basename ${1})
+
+ if [ -n "${dirname#.}" ] ; then
+ dirname="${dirname}/${2}"
+ else
+ dirname="${2}"
+ fi
+
+ if [ -f "${dirname}/${filename}" ] ; then
+ sed -e "s:@ABI_${2}@:#include <${dirname}/${filename}>:" ${1}
+ else
+ cat ${1}
+ fi
+}
+
+wrap_header_end() {
+ sed -e "s:@ABI_.*@:#error \"Sorry, no support for your ABI.\":" ${1}
+}
+
+do_install() {
+ if is_crosscompile ; then
+ INCLUDEDIR="/usr/${CTARGET}/usr/include"
+ else
+ INCLUDEDIR="/usr/include"
+ fi
+
+ dodir ${INCLUDEDIR}
+ CTARGET="${CHOST}" \
+ install_includes ${INCLUDEDIR}
+
+ is_crosscompile && use headers-only && return 0
+
+ for i in $(get_subdirs) ; do
+ einfo "Installing in ${i}..."
+ cd "${WORKDIR}/${i}/" || die "missing ${i}."
+ freebsd_src_install || die "Install ${i} failed"
+ done
+
+ if ! is_crosscompile ; then
+ if ! multilib_is_native_abi ; then
+ gen_libc_ldscript "usr/$(get_libdir)" "usr/$(get_libdir)" "usr/$(get_libdir)"
+ else
+ dodir "$(get_libdir)"
+ gen_libc_ldscript "$(get_libdir)" "usr/$(get_libdir)" "usr/$(get_libdir)"
+ fi
+ else
+ CHOST=${CTARGET} gen_libc_ldscript "usr/${CTARGET}/usr/lib" "usr/${CTARGET}/usr/lib" "usr/${CTARGET}/usr/lib"
+ fi
+
+ # Install a libusb.pc for better compat with Linux's libusb
+ if use usb ; then
+ dodir /usr/$(get_libdir)/pkgconfig
+ sed -e "s:@LIBDIR@:/usr/$(get_libdir):" "${FILESDIR}/libusb.pc.in" > "${D}/usr/$(get_libdir)/pkgconfig/libusb.pc" || die
+ sed -e "s:@LIBDIR@:/usr/$(get_libdir):" "${FILESDIR}/libusb-1.0.pc.in" > "${D}/usr/$(get_libdir)/pkgconfig/libusb-1.0.pc" || die
+ fi
+
+ # Generate ldscripts for core libraries that will go in /
+ multilib_is_native_abi && \
+ gen_usr_ldscript -a alias cam geom ipsec jail kiconv \
+ kvm m md procstat sbuf thr ufs util
+
+ if [[ ${#MULTIBUILD_VARIANTS[@]} -gt 1 ]] ; then
+ cd "${D}/usr/include"
+ for i in machine/*.h fenv.h ; do
+ move_header ${i}
+ done
+ if multilib_is_native_abi ; then
+ # Supposedly the last one!
+ local uniq_headers="$(echo ${header_list} | tr ' ' '\n' | sort | uniq | tr '\n' ' ')"
+ for j in ${uniq_headers} ; do
+ make_header_template > ${j}
+ for i in $(get_all_abis) ; do
+ wrap_header ${j} ${i} > ${j}.new
+ cp ${j}.new ${j}
+ rm -f ${j}.new
+ done
+ wrap_header_end ${j} > ${j}.new
+ cp ${j}.new ${j}
+ rm -f ${j}.new
+ done
+ fi
+ fi
+}
+
+src_install() {
+ if is_crosscompile ; then
+ einfo "Installing for ${CTARGET} in ${CHOST}.."
+ # From this point we need to force: get stripped with the correct tools,
+ # get tc-arch-kernel to return the right value, etc.
+ export CHOST=${CTARGET}
+
+ mymakeopts="${mymakeopts} NO_MAN= \
+ INCLUDEDIR=/usr/${CTARGET}/usr/include \
+ SHLIBDIR=/usr/${CTARGET}/usr/lib \
+ LIBDIR=/usr/${CTARGET}/usr/lib"
+
+ dosym "usr/include" "/usr/${CTARGET}/sys-include"
+ do_install
+
+ return 0
+ else
+ export STRIP_MASK="*/usr/lib*/*crt*.o"
+ local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper do_install
+ fi
+
+ cd "${WORKDIR}/etc/"
+ insinto /etc
+ doins nls.alias mac.conf netconfig
+
+ # Install ttys file
+ local MACHINE="$(tc-arch-kernel)"
+ doins "etc.${MACHINE}"/*
+
+ # unset to run QA check properly
+ unset ESED
+}
+
+install_includes()
+{
+ local INCLUDEDIR="$1"
+
+ # The idea is to be called from either install or unpack.
+ # During unpack it's required to install them as portage's user.
+ if [[ "${EBUILD_PHASE}" == "install" ]]; then
+ local DESTDIR="${D}"
+ BINOWN="root"
+ BINGRP="wheel"
+ else
+ local DESTDIR="${WORKDIR}"
+ [[ -z "${USER}" ]] && USER="portage"
+ BINOWN="${USER}"
+ [[ -z "${GROUPS}" ]] && GROUPS="portage"
+ BINGRP="${GROUPS}"
+ fi
+
+ # Must exist before we use it.
+ [[ -d "${DESTDIR}${INCLUDEDIR}" ]] || die "dodir or mkdir ${INCLUDEDIR} before using install_includes."
+ cd "${WORKDIR}/include"
+
+ local MACHINE="$(tc-arch-kernel)"
+
+ einfo "Installing includes into ${INCLUDEDIR} as ${BINOWN}:${BINGRP}..."
+ $(freebsd_get_bmake) installincludes \
+ MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE} \
+ DESTDIR="${DESTDIR}" \
+ INCLUDEDIR="${INCLUDEDIR}" BINOWN="${BINOWN}" \
+ BINGRP="${BINGRP}" || die "install_includes() failed"
+ einfo "includes installed ok."
+ EXTRA_INCLUDES="lib/librtld_db lib/libutil lib/msun gnu/lib/libregex"
+ for i in $EXTRA_INCLUDES; do
+ einfo "Installing $i includes into ${INCLUDEDIR} as ${BINOWN}:${BINGRP}..."
+ cd "${WORKDIR}/$i" || die
+ $(freebsd_get_bmake) installincludes DESTDIR="${DESTDIR}" \
+ MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE} \
+ INCLUDEDIR="${INCLUDEDIR}" BINOWN="${BINOWN}" \
+ BINGRP="${BINGRP}" || die "problem installing $i includes."
+ einfo "$i includes installed ok."
+ done
+}
diff --git a/sys-freebsd/freebsd-lib/metadata.xml b/sys-freebsd/freebsd-lib/metadata.xml
new file mode 100644
index 000000000000..4fa69d853494
--- /dev/null
+++ b/sys-freebsd/freebsd-lib/metadata.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <maintainer type="project">
+ <email>bsd@gentoo.org</email>
+ <name>BSD Project</name>
+ </maintainer>
+ <use>
+ <flag name="netware">
+ Build libraries and tools to work with NetWare protocols (IPX
+ and NCP).
+ </flag>
+ <flag name="zfs">Enable ZFS support.</flag>
+ </use>
+</pkgmetadata>
diff --git a/sys-freebsd/freebsd-libexec/Manifest b/sys-freebsd/freebsd-libexec/Manifest
new file mode 100644
index 000000000000..2b45079a62a3
--- /dev/null
+++ b/sys-freebsd/freebsd-libexec/Manifest
@@ -0,0 +1,16 @@
+AUX bootpd.confd 183 BLAKE2B 76fb1b41204f2b3d07cc974ec996ff9127945dc638796b176cd8809ca46fb69fa307f3fa313d48d79a7deb532d393ab58839ed7ae53927280f0178c20c4df3c4 SHA512 3f097c1acb5547add8d12fcee0b4b55b03896cb3ba473214d1634804f3683e0dea4b3c9559b61b2366b7f264d7a3d878695e16f29acff076b8060ca1fd79757f
+AUX bootpd.initd 554 BLAKE2B 86c2128a8f17a1d8eb57ef935a6e5a2b04f5c8c6654ecf40b10559912f30effb189f55e7f34ef37b496d8f9f8eb8726ab6af2ca179cb215809d76d1293ffb338 SHA512 69bc8dc708d955e41d3e0cfb997f96b589e8a3d33b11b2728541082fc5ab0844d753ca036a6c70ddd23a2a0085c39a89340b0f7d332b1384c94671cf3fe09b66
+AUX rquotad.xinetd 162 BLAKE2B 87633efa7d9732c498de807976fdc65e3ec15eaef596f7f3f52e3a065fd0b6a9d592c3823a3c84cb9d363df5870f81f00d4a140a6df6e54cbfe239157af05c6b SHA512 2cf16514f18abe2aeaa273fabc2dc94b09f31d02001ece5c82d9336c02d921e03dff6f82a613a4bffe57b5e415add2b82ef883a306907dd20ffe1bbe332b011f
+AUX rstatd.xinetd 218 BLAKE2B a998b50e4f3a49582529d0d1751a4111b0705f03e53e677395043db38b743a5d017799d4dbfa26eeb107d5d657d82af88198d6477452976b59458ce5f7912417 SHA512 febca8ab8248b1c103dd7be0806e3d678c5b5cf165a7b3bd0305bc905da228bf92392d65d44a765b7692f772befeedcbc3df205d32bb62ad5aa307f71a1c1011
+AUX rusersd.xinetd 220 BLAKE2B 60590eb0a4115ab0cdc3248beb4940f7cc6526967963e1e1791dee53a08b2ada06d2f740246bcf4e5c2a9665f612e7b613e5f437576df468ec6fd29712cb0d0f SHA512 fdf4ef4e0b0dd11c64fb38d32c9fca2d378a69e4cff87523127089d7dc0db12b26f6399c7a61fc43d62ca8083b116440f6fffff9e3329f0548bf54f0f26699cd
+AUX sprayd.xinetd 216 BLAKE2B 8e154d0eb67616b6245a002d95b260c32243c8f230861b31a51f67b84d6b56627f2328b58db5cc6d6df85c8831d0c1996ea707ff0058a059b7b5b77a81b6e59d SHA512 a49824ab0421560699901f54d9faf3f38fb6f8d8f63f05e33eb11da053278838e80eaabf5963b1c2a7292ba2d2118e1efd90954b2f3b2dc01b945fbadc6ce101
+AUX walld.xinetd 215 BLAKE2B dbf0093f41762c8e493e34bd52e52f61961fcd2dfeeae981c275c983f3ce4f85283c6e81ca379f827088b1274dff9a1f9dd9dffd714a33021b34c12ca07ccfe1 SHA512 ab78d32e48d660649d3415a4432a5f3e98f8a6a8854791d1d828b0dc678f58e9f24532c264c5f5b039ccd706e0bb70c369ba9fb55fc9af9d3ed9b28e10b9e830
+DIST freebsd-bin-9.1.tar.bz2 385664 BLAKE2B f890e37393186ae2cddf8868d47ca8a7a5767240f02aa0d353561fd746da3c0ca57461871906481b75c8c52c9f6d45f7ea5b3c9b30f27fe81a3a64fba3085e8b SHA512 fa0571a705befe1cb9c07285d3df55c9b5f4f295760511d668d80fec8cd4d59b70c676f07164f2aa44911decef0fb54fa6d78405ac2ceec822b6b8920abc5ca8
+DIST freebsd-contrib-9.1.tar.bz2 54751432 BLAKE2B 8a30e78021e6388d679637d2dbe0ed3f4896d3902064baaafa79de9c328171cbcb895b0ffd3d0d0cd3ca25c93a73584ed4900b45bd672a73b15b75721de59de5 SHA512 71be13049258c6e6b5e4f63cc16da5d349a89d68f04d87446e4ad33ae8bf2a93ea67d9c256b7bec60b61e65db0487268070cfb77a484c3ac0f8ba368b48c2438
+DIST freebsd-etc-9.1.tar.bz2 207776 BLAKE2B 61fbfa11dfcd24c007c20940a4b7cc802dfb9a991e41433840c57f113eaaa9e2b833a15f48d60c706e55d941b0a999baabd0c33197cffd522b67c57eaa9460f1 SHA512 4fbe56fde519cf2f44e39a8869efa26c34f703cf540f4a83389da8d170873d7c6fb18e4010e643b8d793cfc5c55d15eeb198057a5b2a8da9d9e8f791801bf314
+DIST freebsd-lib-9.1.tar.bz2 3206685 BLAKE2B 67f93b7951fc03e877ee525d53b81ba49c8c1a70041c30aac97665d5dab7b3f2817fdb3bbb1475be66c33a7f996309e9020f1a3d1154fab8e2f6789f5ae0bb18 SHA512 40d0c36b6b889c404fa0e0afa38ba4e84a55bc88ffa2f98a70afbd7a32c4f32c158617ba770567d082a986d62c09b3ec8db3dc5ab853ee1c9bbe0b90bb82396e
+DIST freebsd-libexec-9.1.tar.bz2 304592 BLAKE2B 994543ac910e4703d36682f6c0550596e340605754b9386770660f0ed0e70f8d437185f2010e6be795a8cc508aa7d69c90cc0a0df968c5dd8de4c5c4bb38e8c2 SHA512 7baa4160dda2610250dd52f445e24478e0f1ea10bce21fcd0e5d1b856f399b896adc334114de0c7f61a5637e4349bb1688fdbe5c72798d8568ae791114710b92
+DIST freebsd-ubin-9.1.tar.bz2 1910472 BLAKE2B 4bab770072543d9eb25ce7ce450084e0eb9ca603deb58886a26495a92a05373f4f8f5821c65dc76365bf325a7291e6b630b00af5ba895784093d450163637504 SHA512 74ae0aceec8597aa66c3f1ab313f0685a3c63d7273c36ae7baf8794275ad9bca241c60c3f6281cccf6d531d250d7611099977d3b1a27279cef3586401b6af05e
+DIST freebsd-usbin-9.1.tar.bz2 2670916 BLAKE2B 353c7e641c0cccf25b99cb454368bd3001cd6b85a15956b1ee2de1ab240c420602e04bf6d0389aca0bdd4f7d1206a6848516e58a17eda4881d849f078b71a139 SHA512 21c234312f70eb35cd2926519efc1f61592892f5d0940786dbeb959c3c5ec7819a51ae95c6e8a1a06aa01f669350fe0fd3dd7c4ec8a84dd6b90f24cb192356ca
+EBUILD freebsd-libexec-9.1-r2.ebuild 2284 BLAKE2B 239c52de3c17872b465dacaffbf4962ab25905deca80b32aec70ebee1239efd24e45ba5841a14cf1450f092bd9161c9f0477983fb084165b3c8aa217ac59d945 SHA512 ac17fd62e1d0bd470f4420c12783bb187dfe1a9ca48af5b87494d5a0de6aa4dc2537640a4e1bf386adf3433bbfcf95081bf005d4ff097a0a2fd54bd81cc582b3
+MISC metadata.xml 238 BLAKE2B 5d18b211ca67cdae4e0f4d6e1598b20b39a471aa07326791c53bb4e1013607b85bac28a64c1939e53b01228d0c9b7814314b95c0f76928de265d95ef7ee6cd45 SHA512 173efaa53a514acf1e2f0c6681c82a48ec16d505844f551d2cc823ee8685b27837c7461f7956c12182059ee7e83023e2f0bcd5d1afab74beeaf998487193656d
diff --git a/sys-freebsd/freebsd-libexec/files/bootpd.confd b/sys-freebsd/freebsd-libexec/files/bootpd.confd
new file mode 100644
index 000000000000..6d238e4d4853
--- /dev/null
+++ b/sys-freebsd/freebsd-libexec/files/bootpd.confd
@@ -0,0 +1,7 @@
+# Configuration file for /etc/init.d/bootpd
+
+# Name of the configuration file for bootpd
+# bootptab_file="/etc/bootptab"
+
+# Options to pass to bootpd. See bootpd(8).
+# bootpd_opts=""
diff --git a/sys-freebsd/freebsd-libexec/files/bootpd.initd b/sys-freebsd/freebsd-libexec/files/bootpd.initd
new file mode 100644
index 000000000000..82288ebf19c3
--- /dev/null
+++ b/sys-freebsd/freebsd-libexec/files/bootpd.initd
@@ -0,0 +1,27 @@
+#!/sbin/openrc-run
+# Copyright 2008 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+depend() {
+ need net
+}
+
+start() {
+ local bootptab=${bootptab_file:-/etc/bootptab}
+
+ if ! [ -f "${bootptab}" ]; then
+ eerror "Unable to find the bootptab file: ${bootptab}"
+ eend 1
+ return 1
+ fi
+
+ ebegin "Starting BOOTP server"
+ start-stop-daemon --start --exec /usr/libexec/bootpd -- ${bootpd_opts} ${bootptab}
+ eend $?
+}
+
+stop() {
+ ebegin "Stopping BOOTP server"
+ start-stop-daemon --stop --exec /usr/libexec/bootpd
+ eend $?
+}
diff --git a/sys-freebsd/freebsd-libexec/files/rquotad.xinetd b/sys-freebsd/freebsd-libexec/files/rquotad.xinetd
new file mode 100644
index 000000000000..876cd16c53c2
--- /dev/null
+++ b/sys-freebsd/freebsd-libexec/files/rquotad.xinetd
@@ -0,0 +1,11 @@
+service rquotad
+{
+ type = rpc
+ socket_type = dgram
+ protocol = udp
+ wait = yes
+ user = root
+ server = /usr/libexec/rpc.rquotad
+ rpc_version = 1
+ disabled = yes
+}
diff --git a/sys-freebsd/freebsd-libexec/files/rstatd.xinetd b/sys-freebsd/freebsd-libexec/files/rstatd.xinetd
new file mode 100644
index 000000000000..ba1b819851eb
--- /dev/null
+++ b/sys-freebsd/freebsd-libexec/files/rstatd.xinetd
@@ -0,0 +1,11 @@
+service rstatd
+{
+ type = rpc
+ socket_type = dgram
+ protocol = udp
+ wait = yes
+ user = root
+ server = /usr/libexec/rpc.rstatd
+ rpc_version = 1-3
+ disabled = yes
+}
diff --git a/sys-freebsd/freebsd-libexec/files/rusersd.xinetd b/sys-freebsd/freebsd-libexec/files/rusersd.xinetd
new file mode 100644
index 000000000000..5cbe091881e8
--- /dev/null
+++ b/sys-freebsd/freebsd-libexec/files/rusersd.xinetd
@@ -0,0 +1,11 @@
+service rusersd
+{
+ type = rpc
+ socket_type = dgram
+ protocol = udp
+ wait = yes
+ user = root
+ server = /usr/libexec/rpc.rusersd
+ rpc_version = 1-2
+ disabled = yes
+}
diff --git a/sys-freebsd/freebsd-libexec/files/sprayd.xinetd b/sys-freebsd/freebsd-libexec/files/sprayd.xinetd
new file mode 100644
index 000000000000..7be55771ac22
--- /dev/null
+++ b/sys-freebsd/freebsd-libexec/files/sprayd.xinetd
@@ -0,0 +1,11 @@
+service sprayd
+{
+ type = rpc
+ socket_type = dgram
+ protocol = udp
+ wait = yes
+ user = root
+ server = /usr/libexec/rpc.sprayd
+ rpc_version = 1
+ disabled = yes
+}
diff --git a/sys-freebsd/freebsd-libexec/files/walld.xinetd b/sys-freebsd/freebsd-libexec/files/walld.xinetd
new file mode 100644
index 000000000000..800b84fa21e6
--- /dev/null
+++ b/sys-freebsd/freebsd-libexec/files/walld.xinetd
@@ -0,0 +1,11 @@
+service walld
+{
+ type = rpc
+ socket_type = dgram
+ protocol = udp
+ wait = yes
+ user = root
+ server = /usr/libexec/rpc.rwalld
+ rpc_version = 1
+ disabled = yes
+}
diff --git a/sys-freebsd/freebsd-libexec/freebsd-libexec-9.1-r2.ebuild b/sys-freebsd/freebsd-libexec/freebsd-libexec-9.1-r2.ebuild
new file mode 100644
index 000000000000..ff73fbf563b9
--- /dev/null
+++ b/sys-freebsd/freebsd-libexec/freebsd-libexec-9.1-r2.ebuild
@@ -0,0 +1,80 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd pam multilib multibuild multilib-build
+
+DESCRIPTION="FreeBSD libexec things"
+SLOT="0"
+KEYWORDS="~amd64-fbsd ~x86-fbsd"
+
+SRC_URI="mirror://gentoo/${LIBEXEC}.tar.bz2
+ mirror://gentoo/${UBIN}.tar.bz2
+ mirror://gentoo/${BIN}.tar.bz2
+ mirror://gentoo/${CONTRIB}.tar.bz2
+ mirror://gentoo/${LIB}.tar.bz2
+ mirror://gentoo/${ETC}.tar.bz2
+ mirror://gentoo/${USBIN}.tar.bz2"
+
+RDEPEND="=sys-freebsd/freebsd-lib-${RV}*
+ >=sys-freebsd/freebsd-lib-9.1-r11[${MULTILIB_USEDEP}]
+ pam? ( virtual/pam )"
+DEPEND="${RDEPEND}
+ =sys-freebsd/freebsd-mk-defs-${RV}*
+ =sys-freebsd/freebsd-sources-${RV}*"
+RDEPEND="${RDEPEND}
+ xinetd? ( sys-apps/xinetd )"
+
+S="${WORKDIR}/libexec"
+
+# Remove sendmail, tcp_wrapper and other useless stuff
+REMOVE_SUBDIRS="smrsh mail.local tcpd telnetd rshd rlogind lukemftpd ftpd"
+
+IUSE="pam ssl kerberos ipv6 nis xinetd"
+
+pkg_setup() {
+ use ipv6 || mymakeopts="${mymakeopts} WITHOUT_INET6= WITHOUT_INET6_SUPPORT= "
+ use kerberos || mymakeopts="${mymakeopts} WITHOUT_KERBEROS_SUPPORT= "
+ use nis || mymakeopts="${mymakeopts} WITHOUT_NIS= "
+ use pam || mymakeopts="${mymakeopts} WITHOUT_PAM_SUPPORT= "
+ use ssl || mymakeopts="${mymakeopts} WITHOUT_OPENSSL= "
+
+ mymakeopts="${mymakeopts} WITHOUT_SENDMAIL= WITHOUT_PF= WITHOUT_RCMDS= "
+}
+
+src_prepare() {
+ ln -s /usr/include "${WORKDIR}/include"
+}
+
+setup_multilib_vars() {
+ if ! multilib_is_native_abi ; then
+ cd "${WORKDIR}/libexec/rtld-elf" || die
+ export mymakeopts="${mymakeopts} PROG=ld-elf32.so.1"
+ else
+ cd "${S}"
+ fi
+ "$@"
+}
+
+src_compile() {
+ local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper setup_multilib_vars freebsd_src_compile
+}
+
+src_install() {
+ local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper setup_multilib_vars freebsd_src_install
+
+ insinto /etc
+ doins "${WORKDIR}/etc/gettytab"
+ newinitd "${FILESDIR}/bootpd.initd" bootpd
+ newconfd "${FILESDIR}/bootpd.confd" bootpd
+
+ if use xinetd; then
+ for rpcd in rstatd rusersd walld rquotad sprayd; do
+ insinto /etc/xinetd.d
+ newins "${FILESDIR}/${rpcd}.xinetd" ${rpcd}
+ done
+ fi
+}
diff --git a/sys-freebsd/freebsd-libexec/metadata.xml b/sys-freebsd/freebsd-libexec/metadata.xml
new file mode 100644
index 000000000000..a00f3aeb1f81
--- /dev/null
+++ b/sys-freebsd/freebsd-libexec/metadata.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+<maintainer type="project">
+ <email>bsd@gentoo.org</email>
+ <name>BSD Project</name>
+</maintainer>
+</pkgmetadata>
diff --git a/sys-freebsd/freebsd-mk-defs/Manifest b/sys-freebsd/freebsd-mk-defs/Manifest
new file mode 100644
index 000000000000..7b3bf271db14
--- /dev/null
+++ b/sys-freebsd/freebsd-mk-defs/Manifest
@@ -0,0 +1,8 @@
+AUX freebsd-mk-defs-11.0-drop-unsupport-cflags.patch 461 BLAKE2B 9e27da87743872a3d4361a353c2864c00dacdbf33d7df2197507262769512e0f34e40aa3ff4247601e0393a0e2c4545a866448025ed6013a5e9ca283ff91a56d SHA512 82275fe36338a31f1da5ed7d60d72e3f7f5eb3c8e029700afbcb9bc6219dc3051f35a49d33694d553fb8bce0dcf2fbdfbead5bc6e074fa7d9aebda19da603168
+AUX freebsd-mk-defs-11.0-gnu.patch 1946 BLAKE2B 5d9cdff486102e88aa7e7a12ed2d6af43f8d278c1eb9fe1aed95df0aea36a291d85d6e143d74ce7ff65fb777258f31ec4138ac8dc2b00710254538ff95f743fa SHA512 bda6a5396c653b964426a3de80ed9c37205d30f3a863f7df231e0cc708ce3bca65ef46f2ca8bf63ea9a37309e2d3ac74ccbf0000e147688be686c998d940ded0
+AUX freebsd-mk-defs-11.0-libproc-libcxx.patch 369 BLAKE2B fdaefd66f08bad103db14ca3b32e5898ff09587094c6460743b3034e1549777c40abf99a2537c84535df1bee5b22f8fe96d65d6afd9c951d2121ed73cf94f473 SHA512 87de2c90588bccdc2e74ee206f2ca4135fbf5a4674d8400479d5eb08575a30a5b421bb81008ae1cf577e7acbebdc951fd1bd204b7b99f2818343c3f74ed59545
+AUX freebsd-mk-defs-11.0-rename-libs.patch 478 BLAKE2B 83171c7cffbfc5a64ca0b73b3c0da30b76056df877fa8b6501992e36ec3131ae67d52e3dbfb650a081f8b7bbfa2a3d74fa5ad1c4fb7bd6f0d1b267caa203b9dc SHA512 e07091f6b91d4d02cc6db5f76e0fbddc682f594dc5b9176cf282758253eddfb03093f4ef0b0bb5c514724d6065a6a4784e518526b32a86c7b344f43cb1e56ec2
+AUX freebsd-mk-defs-11.1-gentoo.patch 12921 BLAKE2B 1a0e8c098e6ccd6294bd02c3b8cf50faa69b3ae47f00b2fb20b3078439b2f5170d2f9e488fddbeaaf2c06a32355dd4ed563ecfc0854cc32736edf367be932355 SHA512 5253780ce30522f90d7c6ba7292333e3e8edf7a295042f954dd70d3b0806a0cea16f8f6eb0fc9bd9e60d6d191569b4e4248d96b114c5133832c5a1c5e3a50339
+DIST freebsd-src-11.1.tar.xz 147661560 BLAKE2B a9e6ba9d0e12c8b56ac58575d5f02931edbb6a3545d9dccae78810d2d0470a29b29dd7f724b03b8afafbca23717a71346e4cfbd3530e0f40118a23609c3f414e SHA512 b97707ec7a601ca6bcb682c45f6d94a38484301ac24630d7285eff6f88b027ce6900c93fc62f8ce36e0cf32c91f73a9d1c999db397b7f8782fd74a8551a03aca
+EBUILD freebsd-mk-defs-11.1.ebuild 1136 BLAKE2B ffd94b408344303a33c949098cb8bf7084255cfe8adaf4f3bfb5d31a0907c37fb05596f955dd21ac0012c84a836c16267608b5083b343f187f16f1b622e4f4bb SHA512 645fff46a41d3c00ffb966139d58f2e46a6bedabbd163692300fa46bd7cf956d75dd5a7a41b733f7a6eb7743a2049de038a2c9484671a1a0d861dd2bab34b544
+MISC metadata.xml 238 BLAKE2B 5d18b211ca67cdae4e0f4d6e1598b20b39a471aa07326791c53bb4e1013607b85bac28a64c1939e53b01228d0c9b7814314b95c0f76928de265d95ef7ee6cd45 SHA512 173efaa53a514acf1e2f0c6681c82a48ec16d505844f551d2cc823ee8685b27837c7461f7956c12182059ee7e83023e2f0bcd5d1afab74beeaf998487193656d
diff --git a/sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.0-drop-unsupport-cflags.patch b/sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.0-drop-unsupport-cflags.patch
new file mode 100644
index 000000000000..d12bbbe552fd
--- /dev/null
+++ b/sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.0-drop-unsupport-cflags.patch
@@ -0,0 +1,13 @@
+diff --git a/share/mk/bsd.sys.mk b/share/mk/bsd.sys.mk
+index 37c4d01..e840a25 100644
+--- a/share/mk/bsd.sys.mk
++++ b/share/mk/bsd.sys.mk
+@@ -112,7 +112,7 @@ CWARNFLAGS+= -Wno-error=unused-function -Wno-error=enum-compare -Wno-error=logic
+ .if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 30600
+ FORMAT_EXTENSIONS= -D__printf__=__freebsd_kprintf__
+ .else
+-FORMAT_EXTENSIONS= -fformat-extensions
++FORMAT_EXTENSIONS=
+ .endif
+
+ .if defined(IGNORE_PRAGMA)
diff --git a/sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.0-gnu.patch b/sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.0-gnu.patch
new file mode 100644
index 000000000000..97e882d51aac
--- /dev/null
+++ b/sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.0-gnu.patch
@@ -0,0 +1,63 @@
+diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk
+index 92df111..88c75d9 100644
+--- a/share/mk/bsd.lib.mk
++++ b/share/mk/bsd.lib.mk
+@@ -184,7 +184,7 @@ _LIBS= lib${LIB_PRIVATE}${LIB}.a
+ lib${LIB_PRIVATE}${LIB}.a: ${OBJS} ${STATICOBJS}
+ @${ECHO} building static ${LIB} library
+ @rm -f ${.TARGET}
+- ${AR} ${ARFLAGS} ${.TARGET} `NM='${NM}' NMFLAGS='${NMFLAGS}' lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
++ ${AR} ${ARFLAGS} ${.TARGET} ${OBJS} ${STATICOBJS} ${ARADD}
+ ${RANLIB} ${RANLIBFLAGS} ${.TARGET}
+ .endif
+
+@@ -199,7 +199,7 @@ CLEANFILES+= ${POBJS}
+ lib${LIB_PRIVATE}${LIB}_p.a: ${POBJS}
+ @${ECHO} building profiled ${LIB} library
+ @rm -f ${.TARGET}
+- ${AR} ${ARFLAGS} ${.TARGET} `NM='${NM}' NMFLAGS='${NMFLAGS}' lorder ${POBJS} | tsort -q` ${ARADD}
++ ${AR} ${ARFLAGS} ${.TARGET} {POBJS} ${ARADD}
+ ${RANLIB} ${RANLIBFLAGS} ${.TARGET}
+ .endif
+
+@@ -247,7 +247,7 @@ ${SHLIB_NAME_FULL}: ${SOBJS}
+ .endif
+ ${_LD:N${CCACHE_BIN}} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \
+ -o ${.TARGET} -Wl,-soname,${SONAME} \
+- `NM='${NM}' NMFLAGS='${NMFLAGS}' lorder ${SOBJS} | tsort -q` ${LDADD}
++ `echo ${SOBJS} | xargs -n 1 echo | sort -u` ${LDADD}
+ .if ${MK_CTF} != "no"
+ ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS}
+ .endif
+@@ -312,13 +312,6 @@ _EXTRADEPEND:
+
+ .if !target(install)
+
+-.if defined(PRECIOUSLIB)
+-.if !defined(NO_FSCHG)
+-SHLINSTALLFLAGS+= -fschg
+-.endif
+-SHLINSTALLFLAGS+= -S
+-.endif
+-
+ _INSTALLFLAGS:= ${INSTALLFLAGS}
+ .for ie in ${INSTALLFLAGS_EDIT}
+ _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
+diff --git a/share/mk/bsd.prog.mk b/share/mk/bsd.prog.mk
+index 3b1ecf8..26ac9c5 100644
+--- a/share/mk/bsd.prog.mk
++++ b/share/mk/bsd.prog.mk
+@@ -196,13 +196,6 @@ _EXTRADEPEND:
+
+ .if !target(install)
+
+-.if defined(PRECIOUSPROG)
+-.if !defined(NO_FSCHG)
+-INSTALLFLAGS+= -fschg
+-.endif
+-INSTALLFLAGS+= -S
+-.endif
+-
+ _INSTALLFLAGS:= ${INSTALLFLAGS}
+ .for ie in ${INSTALLFLAGS_EDIT}
+ _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
diff --git a/sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.0-libproc-libcxx.patch b/sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.0-libproc-libcxx.patch
new file mode 100644
index 000000000000..5da025d03f37
--- /dev/null
+++ b/sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.0-libproc-libcxx.patch
@@ -0,0 +1,13 @@
+diff --git a/share/mk/src.libnames.mk b/share/mk/src.libnames.mk
+index 14489a8..c993f7c 100644
+--- a/share/mk/src.libnames.mk
++++ b/share/mk/src.libnames.mk
+@@ -245,7 +245,7 @@ _DP_radius= crypto
+ .endif
+ _DP_procstat= kvm util elf
+ .if ${MK_CXX} == "yes"
+-.if ${MK_LIBCPLUSPLUS} != "no"
++.if ${COMPILER_TYPE} == "clang"
+ _DP_proc= cxxrt
+ .else
+ _DP_proc= supcplusplus
diff --git a/sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.0-rename-libs.patch b/sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.0-rename-libs.patch
new file mode 100644
index 000000000000..fd72f1fe846e
--- /dev/null
+++ b/sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.0-rename-libs.patch
@@ -0,0 +1,16 @@
+diff --git a/share/mk/src.libnames.mk b/share/mk/src.libnames.mk
+index 249ac52..14489a8 100644
+--- a/share/mk/src.libnames.mk
++++ b/share/mk/src.libnames.mk
+@@ -343,6 +343,11 @@ LIBATF_CXX= ${DESTDIR}${LIBDIR}/libprivateatf-c++.a
+ LDADD_atf_c= -lprivateatf-c
+ LDADD_atf_cxx= -lprivateatf-c++
+
++LDADD_bsdxml= -lexpat
++LDADD_l= -lfl
++LDADD_termcap= -lncurses
++LDADD_termcapw= -lncursesw
++
+ .for _l in ${_PRIVATELIBS}
+ LIB${_l:tu}?= ${DESTDIR}${LIBDIR}/libprivate${_l}.a
+ .endfor
diff --git a/sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.1-gentoo.patch b/sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.1-gentoo.patch
new file mode 100644
index 000000000000..051fd899b748
--- /dev/null
+++ b/sys-freebsd/freebsd-mk-defs/files/freebsd-mk-defs-11.1-gentoo.patch
@@ -0,0 +1,343 @@
+diff --git a/share/mk/bsd.doc.mk b/share/mk/bsd.doc.mk
+index 9baa335..8cb61e2 100644
+--- a/share/mk/bsd.doc.mk
++++ b/share/mk/bsd.doc.mk
+@@ -144,10 +144,12 @@ CLEANFILES+= ${DOC}.ascii ${DOC}.ascii${DCOMPRESS_EXT} \
+ realinstall:
+ .if ${PRINTERDEVICE:Mhtml}
+ cd ${SRCDIR}; \
++ ${INSTALL} -d ${DESTDIR}${BINDIR}/${VOLUME}; \
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},docs} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
+ ${DOC}*.html ${DESTDIR}${BINDIR}/${VOLUME}/
+ .endif
+ .for _dev in ${PRINTERDEVICE:Nhtml}
++ ${INSTALL} -d ${DESTDIR}${BINDIR}/${VOLUME}; \
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},docs} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
+ ${DFILE.${_dev}} ${DESTDIR}${BINDIR}/${VOLUME}/
+ .endfor
+diff --git a/share/mk/bsd.files.mk b/share/mk/bsd.files.mk
+index 111a7f1..cde2568 100644
+--- a/share/mk/bsd.files.mk
++++ b/share/mk/bsd.files.mk
+@@ -61,6 +61,7 @@ stage_as.${file:T}: ${file}
+
+ installfiles-${group}: _${group}INS_${file:T}
+ _${group}INS_${file:T}: ${file}
++ ${INSTALL} -d ${DESTDIR}${${group}DIR_${.ALLSRC:T}}
+ ${INSTALL} ${${group}TAG_ARGS} -o ${${group}OWN_${.ALLSRC:T}} \
+ -g ${${group}GRP_${.ALLSRC:T}} -m ${${group}MODE_${.ALLSRC:T}} \
+ ${.ALLSRC} \
+@@ -75,10 +76,12 @@ stage_files.${group}: ${_${group}FILES}
+ installfiles-${group}: _${group}INS
+ _${group}INS: ${_${group}FILES}
+ .if defined(${group}NAME)
++ ${INSTALL} -d ${DESTDIR}${${group}DIR}/${${group}NAME}
+ ${INSTALL} ${${group}TAG_ARGS} -o ${${group}OWN} -g ${${group}GRP} \
+ -m ${${group}MODE} ${.ALLSRC} \
+ ${DESTDIR}${${group}DIR}/${${group}NAME}
+ .else
++ ${INSTALL} -d ${DESTDIR}${${group}DIR}
+ ${INSTALL} ${${group}TAG_ARGS} -o ${${group}OWN} -g ${${group}GRP} \
+ -m ${${group}MODE} ${.ALLSRC} ${DESTDIR}${${group}DIR}/
+ .endif
+diff --git a/share/mk/bsd.incs.mk b/share/mk/bsd.incs.mk
+index 04c1407..06ddde3 100644
+--- a/share/mk/bsd.incs.mk
++++ b/share/mk/bsd.incs.mk
+@@ -60,6 +60,9 @@ stage_includes: stage_as.${header:T}
+
+ installincludes: _${group}INS_${header:T}
+ _${group}INS_${header:T}: ${header}
++ ${INSTALL} -d -o ${${group}OWN_${.ALLSRC:T}} \
++ -g ${${group}GRP_${.ALLSRC:T}} \
++ ${DESTDIR}${${group}DIR_${.ALLSRC:T}}
+ ${INSTALL} -C -o ${${group}OWN_${.ALLSRC:T}} \
+ -g ${${group}GRP_${.ALLSRC:T}} -m ${${group}MODE_${.ALLSRC:T}} \
+ ${.ALLSRC} \
+@@ -75,9 +78,13 @@ stage_includes: stage_files.${group}
+ installincludes: _${group}INS
+ _${group}INS: ${_${group}INCS}
+ .if defined(${group}NAME)
++ ${INSTALL} -d -o ${${group}OWN} -g ${${group}GRP} \
++ ${DESTDIR}${${group}DIR}
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},development} -C -o ${${group}OWN} -g ${${group}GRP} -m ${${group}MODE} \
+ ${.ALLSRC} ${DESTDIR}${${group}DIR}/${${group}NAME}
+ .else
++ ${INSTALL} -d -o ${${group}OWN} -g ${${group}GRP} \
++ ${DESTDIR}${${group}DIR}
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},development} -C -o ${${group}OWN} -g ${${group}GRP} -m ${${group}MODE} \
+ ${.ALLSRC} ${DESTDIR}${${group}DIR}/
+ .endif
+diff --git a/share/mk/bsd.info.mk b/share/mk/bsd.info.mk
+index 46498fa..7b673f8 100644
+--- a/share/mk/bsd.info.mk
++++ b/share/mk/bsd.info.mk
+@@ -83,6 +83,7 @@ INFO2HTML?= info2html
+ TEX?= tex
+ DVIPS?= dvips
+ DVIPS2ASCII?= dvips2ascii
++INSTALL?= install
+
+ .SUFFIXES: ${ICOMPRESS_EXT} .info .texi .texinfo .dvi .ps .latin1 .html
+
+@@ -141,15 +142,17 @@ ${x:S/$/${ICOMPRESS_EXT}/}: ${x}
+ INSTALLINFODIRS+= ${x:S/$/-install/}
+ ${x:S/$/-install/}:
+ .if !empty(.MAKEFLAGS:M-j)
++ ${INSTALL} -d ${DESTDIR}${INFODIR}
+ lockf -k ${DESTDIR}${INFODIR}/${INFODIRFILE} \
+ ${INSTALLINFO} ${INSTALLINFOFLAGS} \
+- --defsection=${INFOSECTION} \
+- --defentry=${INFOENTRY_${x}} \
++ --section=${INFOSECTION} \
++ --entry=${INFOENTRY_${x}} \
+ ${x}.info ${DESTDIR}${INFODIR}/${INFODIRFILE}
+ .else
++ ${INSTALL} -d ${DESTDIR}${INFODIR}
+ ${INSTALLINFO} ${INSTALLINFOFLAGS} \
+- --defsection=${INFOSECTION} \
+- --defentry=${INFOENTRY_${x}} \
++ --section=${INFOSECTION} \
++ --entry=${INFOENTRY_${x}} \
+ ${x}.info ${DESTDIR}${INFODIR}/${INFODIRFILE}
+ .endif
+ .endfor
+diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk
+index c59027c..f996c35 100644
+--- a/share/mk/bsd.lib.mk
++++ b/share/mk/bsd.lib.mk
+@@ -52,8 +52,6 @@ CFLAGS+= ${DEBUG_FLAGS}
+ .if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
+ CTFFLAGS+= -g
+ .endif
+-.else
+-STRIP?= -s
+ .endif
+
+ .if ${SHLIBDIR:M*lib32*}
+@@ -336,14 +334,17 @@ realinstall: _libinstall
+ .ORDER: beforeinstall _libinstall
+ _libinstall:
+ .if defined(LIB) && !empty(LIB) && ${MK_INSTALLLIB} != "no"
++ ${INSTALL} -d ${DESTDIR}${_LIBDIR}
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},development} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${_INSTALLFLAGS} lib${LIB_PRIVATE}${LIB}.a ${DESTDIR}${_LIBDIR}/
+ .endif
+ .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
++ ${INSTALL} -d ${DESTDIR}${_LIBDIR}
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},profile} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${_INSTALLFLAGS} lib${LIB_PRIVATE}${LIB}_p.a ${DESTDIR}${_LIBDIR}/
+ .endif
+ .if defined(SHLIB_NAME)
++ ${INSTALL} -d ${DESTDIR}${_SHLIBDIR}
+ ${INSTALL} ${TAG_ARGS} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
+ ${SHLIB_NAME} ${DESTDIR}${_SHLIBDIR}/
+@@ -388,10 +389,12 @@ _libinstall:
+ .endif # SHLIB_LINK
+ .endif # SHIB_NAME
+ .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
++ ${INSTALL} -d ${DESTDIR}${_LIBDIR}
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},development} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${_LIBDIR}/
+ .endif
+ .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
++ ${INSTALL} -d ${DESTDIR}${LINTLIBDIR}
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},development} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR}/
+ .endif
+diff --git a/share/mk/bsd.libnames.mk b/share/mk/bsd.libnames.mk
+index 98746fa..5c541ab 100644
+--- a/share/mk/bsd.libnames.mk
++++ b/share/mk/bsd.libnames.mk
+@@ -64,7 +64,7 @@ LIBELF?= ${DESTDIR}${LIBDIR_BASE}/libelf.a
+ LIBEXECINFO?= ${DESTDIR}${LIBDIR_BASE}/libexecinfo.a
+ LIBFETCH?= ${DESTDIR}${LIBDIR_BASE}/libfetch.a
+ LIBFIGPAR?= ${DESTDIR}${LIBDIR_BASE}/libfigpar.a
+-LIBFL?= "don't use LIBFL, use LIBL"
++LIBFL?= ${DESTDIR}${LIBDIR_BASE}/libfl.a
+ LIBFORM?= ${DESTDIR}${LIBDIR_BASE}/libform.a
+ LIBG2C?= ${DESTDIR}${LIBDIR_BASE}/libg2c.a
+ LIBGEOM?= ${DESTDIR}${LIBDIR_BASE}/libgeom.a
+@@ -93,7 +93,7 @@ LIBKEYCAP?= ${DESTDIR}${LIBDIR_BASE}/libkeycap.a
+ LIBKICONV?= ${DESTDIR}${LIBDIR_BASE}/libkiconv.a
+ LIBKRB5?= ${DESTDIR}${LIBDIR_BASE}/libkrb5.a
+ LIBKVM?= ${DESTDIR}${LIBDIR_BASE}/libkvm.a
+-LIBL?= ${DESTDIR}${LIBDIR_BASE}/libl.a
++LIBL?= ${DESTDIR}${LIBDIR_BASE}/libfl.a
+ LIBLN?= "don't use LIBLN, use LIBL"
+ LIBLZMA?= ${DESTDIR}${LIBDIR_BASE}/liblzma.a
+ LIBM?= ${DESTDIR}${LIBDIR_BASE}/libm.a
+diff --git a/share/mk/bsd.links.mk b/share/mk/bsd.links.mk
+index 75acbe1..b662439 100644
+--- a/share/mk/bsd.links.mk
++++ b/share/mk/bsd.links.mk
+@@ -16,9 +16,11 @@ afterinstall: _installlinks
+ _installlinks:
+ .for s t in ${LINKS}
+ @${ECHO} "${t} -> ${s}" ;\
++ test -d ${DESTDIR}/`dirname ${t}` || mkdir ${DESTDIR}/`dirname ${t}`;\
+ ${INSTALL_LINK} ${TAG_ARGS} ${DESTDIR}${s} ${DESTDIR}${t}
+ .endfor
+ .for s t in ${SYMLINKS}
+ @${ECHO} "${t} -> ${s}" ;\
++ test -d ${DESTDIR}/`dirname ${t}` || mkdir ${DESTDIR}/`dirname ${t}`;\
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ${s} ${DESTDIR}/${t}
+ .endfor
+diff --git a/share/mk/bsd.man.mk b/share/mk/bsd.man.mk
+index 7306453..5fcd4f7 100644
+--- a/share/mk/bsd.man.mk
++++ b/share/mk/bsd.man.mk
+@@ -188,9 +188,11 @@ maninstall: ${MAN}
+ .if ${MK_MANCOMPRESS} == "no"
+ .if defined(MANFILTER)
+ .for __page in ${MAN}
++ ${INSTALL} -d ${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}/${__page}
+ ${MINSTALL} ${__page:T:S/$/${FILTEXTENSION}/g} \
+ ${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}/${__page}
+ .if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
++ ${INSTALL} -d ${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page}
+ ${MINSTALL} ${__page:T:S/$/${CATEXT}${FILTEXTENSION}/g} \
+ ${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page}
+ .endif
+@@ -204,11 +206,14 @@ maninstall: ${MAN}
+ esac; \
+ page=$$1; shift; sect=$$1; shift; \
+ d=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}; \
++ ${ECHO} ${INSTALL} -d $${d}; \
++ ${INSTALL} -d $${d}; \
+ ${ECHO} ${MINSTALL} $${page} $${d}; \
+ ${MINSTALL} $${page} $${d}; \
+ done
+ .if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
+ .for __page in ${MAN}
++ ${INSTALL} -d ${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T}
+ ${MINSTALL} ${__page:T:S/$/${CATEXT}/} \
+ ${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T}
+ .endfor
+@@ -216,9 +221,11 @@ maninstall: ${MAN}
+ .endif # defined(MANFILTER)
+ .else # ${MK_MANCOMPRESS} == "yes"
+ .for __page in ${MAN}
++ ${INSTALL} -d ${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}
+ ${MINSTALL} ${__page:T:S/$/${MCOMPRESS_EXT}/g} \
+ ${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}/
+ .if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
++ ${INSTALL} -d ${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T:S/$/${MCOMPRESS_EXT}
+ ${MINSTALL} ${__page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g} \
+ ${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T:S/$/${MCOMPRESS_EXT}/}
+ .endif
+diff --git a/share/mk/bsd.nls.mk b/share/mk/bsd.nls.mk
+index 6f769d3..1679973 100644
+--- a/share/mk/bsd.nls.mk
++++ b/share/mk/bsd.nls.mk
+@@ -71,7 +71,8 @@ STAGE_SYMLINKS_DIR.NLS= ${STAGE_OBJTOP}
+ SYMLINKS+= ${NLSSYMLINKS}
+ .endif
+ .for file in ${NLS}
+-NLSNAME_${file:T}= ${file:T:R}/${NLSNAME}.cat
++NLSDIR_${file:T}= ${SHAREDIR}/nls/${file:T:R}/
++NLSNAME_${file:T}= ${NLSNAME}.cat
+ .if defined(NLSLINKS_${file:R}) && !empty(NLSLINKS_${file:R})
+ .if !empty(NLSLINKS_${file:R}:M${file:R})
+ .error NLSLINKS_${file:R} contains itself: ${file:R}
+diff --git a/share/mk/bsd.own.mk b/share/mk/bsd.own.mk
+index 3450a01..8ad3e69 100644
+--- a/share/mk/bsd.own.mk
++++ b/share/mk/bsd.own.mk
+@@ -217,9 +217,6 @@ INSTALL_SYMLINK?= ${INSTALL} ${SYMLINK}
+ INSTALL_RSYMLINK?= ${INSTALL} ${RSYMLINK}
+
+ # Common variables
+-.if !defined(DEBUG_FLAGS)
+-STRIP?= -s
+-.endif
+
+ COMPRESS_CMD?= gzip -cn
+ COMPRESS_EXT?= .gz
+diff --git a/share/mk/bsd.prog.mk b/share/mk/bsd.prog.mk
+index e4727ac..775fd8a 100644
+--- a/share/mk/bsd.prog.mk
++++ b/share/mk/bsd.prog.mk
+@@ -44,10 +44,6 @@ CTFFLAGS+= -g
+ .endif
+ .endif
+
+-.if !defined(DEBUG_FLAGS)
+-STRIP?= -s
+-.endif
+-
+ .if defined(NO_ROOT)
+ .if !defined(TAGS) || ! ${TAGS:Mpackage=*}
+ TAGS+= package=${PACKAGE:Uruntime}
+@@ -217,6 +213,7 @@ realinstall: _proginstall
+ .ORDER: beforeinstall _proginstall
+ _proginstall:
+ .if defined(PROG)
++ ${INSTALL} -d ${DESTDIR}${BINDIR}
+ ${INSTALL} ${TAG_ARGS} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
+ ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
+ .if ${MK_DEBUG_FILES} != "no"
+@@ -255,6 +252,7 @@ SCRIPTSMODE_${script:T}?= ${SCRIPTSMODE}
+ STAGE_AS_${script:T}= ${SCRIPTSDIR_${script:T}}/${SCRIPTSNAME_${script:T}}
+ _scriptsinstall: _SCRIPTSINS_${script:T}
+ _SCRIPTSINS_${script:T}: ${script}
++ ${INSTALL} -d ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}
+ ${INSTALL} ${TAG_ARGS} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
+ -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
+ ${.ALLSRC} \
+diff --git a/share/mk/bsd.sys.mk b/share/mk/bsd.sys.mk
+index cb79bf1..3cad05f 100644
+--- a/share/mk/bsd.sys.mk
++++ b/share/mk/bsd.sys.mk
+@@ -29,9 +29,6 @@ CFLAGS+= -std=${CSTD}
+ .if defined(WARNS)
+ .if ${WARNS} >= 1
+ CWARNFLAGS+= -Wsystem-headers
+-.if !defined(NO_WERROR) && !defined(NO_WERROR.${COMPILER_TYPE})
+-CWARNFLAGS+= -Werror
+-.endif # !NO_WERROR && !NO_WERROR.${COMPILER_TYPE}
+ .endif # WARNS >= 1
+ .if ${WARNS} >= 2
+ CWARNFLAGS+= -Wall -Wno-format-y2k
+@@ -103,9 +100,6 @@ CWARNFLAGS+= -Wformat=2 -Wno-format-extra-args
+ .if ${WARNS} <= 3
+ CWARNFLAGS.clang+= -Wno-format-nonliteral
+ .endif # WARNS <= 3
+-.if !defined(NO_WERROR) && !defined(NO_WERROR.${COMPILER_TYPE})
+-CWARNFLAGS+= -Werror
+-.endif # !NO_WERROR && !NO_WERROR.${COMPILER_TYPE}
+ .endif # WFORMAT > 0
+ .endif # WFORMAT
+ .if defined(NO_WFORMAT) || defined(NO_WFORMAT.${COMPILER_TYPE})
+@@ -154,6 +148,13 @@ CFLAGS.clang+= -fno-dwarf2-cfi-asm
+ # but not yet.
+ CXXFLAGS.clang+= -Wno-c++11-extensions
+
++.if ${MK_SSP} == "no"
++# gcc-4.9, -fstack-protector-strong is enabled by default.
++# Add -fno-stack-protector to disable it. Gentoo Bug #511698.
++SSP_CFLAGS?= -fno-stack-protector
++CFLAGS+= ${SSP_CFLAGS}
++.endif
++
+ .if ${MK_SSP} != "no" && \
+ ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
+ .if (${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 30500) || \
+diff --git a/share/mk/sys.mk b/share/mk/sys.mk
+index 91d5a9a..7786edb 100644
+--- a/share/mk/sys.mk
++++ b/share/mk/sys.mk
+@@ -422,12 +422,6 @@ YFLAGS ?= -d
+ rm -f ${.PREFIX}.tmp.c
+ ${CTFCONVERT_CMD}
+
+-# Pull in global settings.
+-__MAKE_CONF?=/etc/make.conf
+-.if exists(${__MAKE_CONF})
+-.include "${__MAKE_CONF}"
+-.endif
+-
+ # late include for customization
+ .sinclude <local.sys.mk>
+
diff --git a/sys-freebsd/freebsd-mk-defs/freebsd-mk-defs-11.1.ebuild b/sys-freebsd/freebsd-mk-defs/freebsd-mk-defs-11.1.ebuild
new file mode 100644
index 000000000000..46502242b6f5
--- /dev/null
+++ b/sys-freebsd/freebsd-mk-defs/freebsd-mk-defs-11.1.ebuild
@@ -0,0 +1,54 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd
+
+DESCRIPTION="Makefile definitions used for building and installing libraries and system files"
+SLOT="0"
+
+IUSE="userland_GNU"
+
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64 ~x86 ~amd64-fbsd ~x86-fbsd"
+fi
+
+EXTRACTONLY="share/"
+
+RDEPEND=""
+DEPEND=""
+
+RESTRICT="strip"
+
+S="${WORKDIR}/share/mk"
+
+src_prepare() {
+ local installdir
+
+ epatch "${FILESDIR}/${PN}-11.1-gentoo.patch"
+ epatch "${FILESDIR}/${PN}-11.0-rename-libs.patch"
+ epatch "${FILESDIR}/${PN}-11.0-libproc-libcxx.patch"
+ epatch "${FILESDIR}/${PN}-11.0-drop-unsupport-cflags.patch"
+ use userland_GNU && epatch "${FILESDIR}/${PN}-11.0-gnu.patch"
+
+ if [[ ${CHOST} != *-freebsd* ]]; then
+ installdir="/usr/share/mk/freebsd"
+ else
+ installdir="/usr/share/mk"
+ fi
+
+ sed -i -e "s:FILESDIR=.*:FILESDIR= ${installdir}:" "${S}"/Makefile || die
+}
+
+src_compile() { :; }
+
+src_install() {
+ freebsd_src_install
+ if [[ ${CHOST} != *-freebsd* ]]; then
+ insinto /usr/share/mk/freebsd/system
+ else
+ insinto /usr/share/mk/system
+ fi
+ doins *.mk *.awk
+}
diff --git a/sys-freebsd/freebsd-mk-defs/metadata.xml b/sys-freebsd/freebsd-mk-defs/metadata.xml
new file mode 100644
index 000000000000..a00f3aeb1f81
--- /dev/null
+++ b/sys-freebsd/freebsd-mk-defs/metadata.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+<maintainer type="project">
+ <email>bsd@gentoo.org</email>
+ <name>BSD Project</name>
+</maintainer>
+</pkgmetadata>
diff --git a/sys-freebsd/freebsd-pam-modules/Manifest b/sys-freebsd/freebsd-pam-modules/Manifest
new file mode 100644
index 000000000000..cc767eadb168
--- /dev/null
+++ b/sys-freebsd/freebsd-pam-modules/Manifest
@@ -0,0 +1,4 @@
+AUX README.pamd 2840 BLAKE2B 06d8f86b6db63a0b401627a8e2cff0dcb7daa2b567b2d7f97f196db263956b95516495b3acc806cfaca448509638235a874845c088b898033e858e835c46fcba SHA512 7188bbb741bacbd2c826976f7f3b3150036f0855514ead679f56f0a4ab70fd6657fd38a33215cd883264ca2e801b7b2f3d7b73c40e04adc685e5fa6385c49357
+DIST freebsd-src-11.1.tar.xz 147661560 BLAKE2B a9e6ba9d0e12c8b56ac58575d5f02931edbb6a3545d9dccae78810d2d0470a29b29dd7f724b03b8afafbca23717a71346e4cfbd3530e0f40118a23609c3f414e SHA512 b97707ec7a601ca6bcb682c45f6d94a38484301ac24630d7285eff6f88b027ce6900c93fc62f8ce36e0cf32c91f73a9d1c999db397b7f8782fd74a8551a03aca
+EBUILD freebsd-pam-modules-11.1.ebuild 1023 BLAKE2B 0f3e81814eff77c96b6ffb6d6469fb3bb63ca97b5d31125ca14cbca595809bd4015213bde430be10b41d7995f91f3ff35f1218be7bc43ff87b5669444abb4d6c SHA512 f2fdb23d324125a06535dab07d753878ebbeb561e3e6a0f9d5ea0cc94664199675a7c1b2410d21adad627440920813cff68fd4c09f043fcf6b09a4798f0b3710
+MISC metadata.xml 238 BLAKE2B 5d18b211ca67cdae4e0f4d6e1598b20b39a471aa07326791c53bb4e1013607b85bac28a64c1939e53b01228d0c9b7814314b95c0f76928de265d95ef7ee6cd45 SHA512 173efaa53a514acf1e2f0c6681c82a48ec16d505844f551d2cc823ee8685b27837c7461f7956c12182059ee7e83023e2f0bcd5d1afab74beeaf998487193656d
diff --git a/sys-freebsd/freebsd-pam-modules/files/README.pamd b/sys-freebsd/freebsd-pam-modules/files/README.pamd
new file mode 100644
index 000000000000..51d703973be9
--- /dev/null
+++ b/sys-freebsd/freebsd-pam-modules/files/README.pamd
@@ -0,0 +1,61 @@
+/etc/pam.d
+
+This directory contains configuration files for the Pluggable
+Authentication Modules (PAM) library.
+
+Each file details the module chain for a single service, and must be
+named after that service. If no configuration file is found for a
+particular service, the /etc/pam.d/other is used instead. If that
+file does not exist, /etc/pam.conf is searched for entries matching
+the specified service or, failing that, the "other" service.
+
+See the pam(8) manual page for an explanation of the workings of the
+PAM library and descriptions of the various files and modules. Below
+is a summary of the format for the pam.conf and /etc/pam.d/* files.
+
+Configuration lines take the following form:
+
+module-type control-flag module-path arguments
+
+Comments are introduced with a hash mark ('#'). Blank lines and lines
+consisting entirely of comments are ignored.
+
+The meanings of the different fields are as follows:
+
+ module-type:
+ auth: prompt for a password to authenticate that the user is
+ who they say they are, and set any credentials.
+ account: non-authentication based authorization, based on time,
+ resources, etc.
+ session: housekeeping before and/or after login.
+ password: update authentication tokens.
+
+ control-flag: How libpam handles success or failure of the module.
+ required: success is required; on failure all remaining
+ modules are run, but the request will be denied.
+ requisite: success is required, and on failure no remaining
+ modules are run.
+ sufficient: success is sufficient, and if no previous required
+ module failed, no remaining modules are run.
+ binding: success is sufficient; on failure all remaining
+ modules are run, but the request will be denied.
+ optional: ignored unless the other modules return PAM_IGNORE.
+
+ arguments: Module-specific options, plus some generic ones:
+ debug: syslog debug info.
+ no_warn: return no warning messages to the application.
+ Remove this to feed back to the user the
+ reason(s) they are being rejected.
+ use_first_pass: try authentication using password from the
+ preceding auth module.
+ try_first_pass: first try authentication using password from
+ the preceding auth module, and if that fails
+ prompt for a new password.
+ use_mapped_pass: convert cleartext password to a crypto key.
+ expose_account: allow printing more info about the user when
+ prompting.
+
+Note that having a "sufficient" module as the last entry for a
+particular service and module type may result in surprising behaviour.
+To get the intended semantics, add a "required" entry listing the
+pam_deny module at the end of the chain.
diff --git a/sys-freebsd/freebsd-pam-modules/freebsd-pam-modules-11.1.ebuild b/sys-freebsd/freebsd-pam-modules/freebsd-pam-modules-11.1.ebuild
new file mode 100644
index 000000000000..058bd4a6a812
--- /dev/null
+++ b/sys-freebsd/freebsd-pam-modules/freebsd-pam-modules-11.1.ebuild
@@ -0,0 +1,45 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd multilib pam
+
+DESCRIPTION="FreeBSD's PAM authentication modules"
+SLOT="0"
+
+IUSE="kerberos nis"
+
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64-fbsd ~x86-fbsd"
+fi
+
+EXTRACTONLY="lib/"
+
+RDEPEND=">=sys-auth/openpam-20050201-r1
+ kerberos? ( dev-libs/openssl:0=
+ virtual/krb5 )"
+DEPEND="${RDEPEND}
+ =sys-freebsd/freebsd-mk-defs-${RV}*
+ =sys-freebsd/freebsd-sources-${RV}*"
+
+S=${WORKDIR}/lib/libpam/modules
+
+pkg_setup() {
+ # Avoid installing pam_ssh as that has its own ebuild.
+ mymakeopts="${mymakeopts} WITHOUT_OPENSSH= "
+ use kerberos || mymakeopts="${mymakeopts} WITHOUT_KERBEROS= "
+ use nis || mymakeopts="${mymakeopts} WITHOUT_NIS= "
+}
+
+src_prepare() {
+ for module in pam_deny pam_passwdqc pam_permit pam_krb5; do
+ sed -i -e "s:${module}::" "${S}"/modules.inc || die
+ done
+}
+
+src_install() {
+ freebsd_src_install "LIBDIR=/$(get_libdir)/security"
+
+ dodoc "${FILESDIR}/README.pamd"
+}
diff --git a/sys-freebsd/freebsd-pam-modules/metadata.xml b/sys-freebsd/freebsd-pam-modules/metadata.xml
new file mode 100644
index 000000000000..a00f3aeb1f81
--- /dev/null
+++ b/sys-freebsd/freebsd-pam-modules/metadata.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+<maintainer type="project">
+ <email>bsd@gentoo.org</email>
+ <name>BSD Project</name>
+</maintainer>
+</pkgmetadata>
diff --git a/sys-freebsd/freebsd-pf/Manifest b/sys-freebsd/freebsd-pf/Manifest
new file mode 100644
index 000000000000..b3be110be706
--- /dev/null
+++ b/sys-freebsd/freebsd-pf/Manifest
@@ -0,0 +1,9 @@
+AUX freebsd-pf-11.1-libevent.patch 305 BLAKE2B cce2abce33431885196c5bc44c7e38582b2c7db273ddd3b7d4c8b58dbd9902cbc6e2a5031f5cddd28db9361eafd75c98fc0ca8d14e822305ead12aa035990c5f SHA512 a75ff98e8d87ec5182bb1a7226b34d6223500c0a5659727392d97d69d1a66af6d439d4c23a6817740c25306654468e82e52ddfa591d4509001e407e099c83b44
+AUX freebsd-pf-11.1-pflogd.patch 363 BLAKE2B fac873813332149adc13e5b1a77cd8532c12bae7ee1c93644af31e517e7697cdd8e7c59412e7dbb616c97baabb6308049bd7c995b5e803627f6cc3049056380e SHA512 bceaf0f234948acf30aab4391d73c7545bd860dc5b2bba8eb8da1a9791de905654450592674c75419a8dc0646215ba5bcdd885d61cac336d34c017a7c57039fd
+AUX freebsd-pf-9.0-bpf.patch 309 BLAKE2B 38d4382e437301da49388333b18541699299f033df83e88decd9ba41a62a2b349facd00af806f2c414cfc5e2d356ff6025dadce40abe5767257391b741d1e62f SHA512 e3364e372b5c2d2c4a1960ee1f6d5fa411810ba3597356ec17b275afd8bb6813cce62d781fc683663037b008d81804d28a2617f308c942a741657cf8dcf0e039
+AUX freebsd-pf-9.0-pcap_pollution.patch 450 BLAKE2B daf9a836b6c8243e8b452c0e68bc740b4d5266460dc12615f2cc8361dbb000fe7c844f42bfb7b6c496f6856f8f1557261b2847ba92c9f57ef9e8885c93ffcf5c SHA512 262d23f74449f75d628dcda09a7c7e0d501b61899c0a2a1ca71179989803f5c5f70fd4f8908f06ce998aca994d54b43efe03578892ff121c0a27e7fa36e4f1dd
+AUX pf.confd 274 BLAKE2B ed3466c836e7c4958d371d7858cf15e532140c1d3afe7e3b2155275f24ec245628d2936d8ac26eba13bbb88b9d86ad13e5f662f0f37ae813a98e92428e160fae SHA512 bf476bf7dc796307f2bf916e73780a6c70a2defd75f4dcbce664a99fdbb5aa69ce7004483073036a0c52fadcf9e7e7c8bcc902e9eacb7ac1963714740bdfc5e5
+AUX pf.initd 803 BLAKE2B 8f3d10adae448a429b2e08954b5a3d3025d9cdde90073fed0b50f900de47c8e4611fd406409047fe8ad1f25c69465fe7954e8b3c937ad507b45fdd8096a9a4de SHA512 b447683fb3abd11a6c5158b452ac9a72858c0a57bb424a1ec3a4cc8dce09336228d6e43ce0c58a63d63ee3917211227a6c5f1d4ac4bde42ce7fc5aa6d188f28d
+DIST freebsd-src-11.1.tar.xz 147661560 BLAKE2B a9e6ba9d0e12c8b56ac58575d5f02931edbb6a3545d9dccae78810d2d0470a29b29dd7f724b03b8afafbca23717a71346e4cfbd3530e0f40118a23609c3f414e SHA512 b97707ec7a601ca6bcb682c45f6d94a38484301ac24630d7285eff6f88b027ce6900c93fc62f8ce36e0cf32c91f73a9d1c999db397b7f8782fd74a8551a03aca
+EBUILD freebsd-pf-11.1.ebuild 1491 BLAKE2B 01e49509dc7f3528e0f14a01eebb2a8b5f0c9fa927844b98f8a9f4c89bbc1b103f01b972efa4a370b9765dd1cb6620d51de0c012a1b58b108434d7e247562f57 SHA512 2ace1ad0f89365b9b707a2b9b29f04dff926ad3a3340abd156862aa0c50396ce078d4f997d1298b498df1c52745b5216f2c112424254ae12abbb554783c276a8
+MISC metadata.xml 238 BLAKE2B 5d18b211ca67cdae4e0f4d6e1598b20b39a471aa07326791c53bb4e1013607b85bac28a64c1939e53b01228d0c9b7814314b95c0f76928de265d95ef7ee6cd45 SHA512 173efaa53a514acf1e2f0c6681c82a48ec16d505844f551d2cc823ee8685b27837c7461f7956c12182059ee7e83023e2f0bcd5d1afab74beeaf998487193656d
diff --git a/sys-freebsd/freebsd-pf/files/freebsd-pf-11.1-libevent.patch b/sys-freebsd/freebsd-pf/files/freebsd-pf-11.1-libevent.patch
new file mode 100644
index 000000000000..057088f3298c
--- /dev/null
+++ b/sys-freebsd/freebsd-pf/files/freebsd-pf-11.1-libevent.patch
@@ -0,0 +1,13 @@
+diff --git a/usr.sbin/ftp-proxy/Makefile b/usr.sbin/ftp-proxy/Makefile
+index 3708edc..efdfcc6 100644
+--- a/usr.sbin/ftp-proxy/Makefile
++++ b/usr.sbin/ftp-proxy/Makefile
+@@ -7,8 +7,6 @@ MAN= ftp-proxy.8
+
+ SRCS= ftp-proxy.c filter.c
+
+-CFLAGS+=-I${SRCTOP}/contrib/pf/libevent
+-
+ LIBADD= event
+
+ WARNS?= 3
diff --git a/sys-freebsd/freebsd-pf/files/freebsd-pf-11.1-pflogd.patch b/sys-freebsd/freebsd-pf/files/freebsd-pf-11.1-pflogd.patch
new file mode 100644
index 000000000000..a10e21dd19c0
--- /dev/null
+++ b/sys-freebsd/freebsd-pf/files/freebsd-pf-11.1-pflogd.patch
@@ -0,0 +1,14 @@
+diff --git a/sbin/pflogd/Makefile b/sbin/pflogd/Makefile
+index f9d47da..bb00d39 100644
+--- a/sbin/pflogd/Makefile
++++ b/sbin/pflogd/Makefile
+@@ -7,9 +7,6 @@ PROG= pflogd
+ SRCS= pflogd.c pidfile.c privsep.c privsep_fdpass.c
+ MAN= pflogd.8
+
+-CFLAGS+=-include ${SRCTOP}/lib/libpcap/config.h
+-CFLAGS+=-I${.CURDIR}/../../contrib/libpcap
+-
+ LIBADD= pcap
+
+ WARNS?= 2
diff --git a/sys-freebsd/freebsd-pf/files/freebsd-pf-9.0-bpf.patch b/sys-freebsd/freebsd-pf/files/freebsd-pf-9.0-bpf.patch
new file mode 100644
index 000000000000..fb3c7012eccf
--- /dev/null
+++ b/sys-freebsd/freebsd-pf/files/freebsd-pf-9.0-bpf.patch
@@ -0,0 +1,10 @@
+--- contrib/pf/pflogd/pflogd.c.old 2011-11-02 21:12:57.000000000 +0000
++++ contrib/pf/pflogd/pflogd.c 2011-11-02 21:13:11.000000000 +0000
+@@ -39,6 +39,7 @@
+ #include <sys/stat.h>
+ #include <sys/socket.h>
+ #include <net/if.h>
++#include <net/bpf.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
diff --git a/sys-freebsd/freebsd-pf/files/freebsd-pf-9.0-pcap_pollution.patch b/sys-freebsd/freebsd-pf/files/freebsd-pf-9.0-pcap_pollution.patch
new file mode 100644
index 000000000000..184ab6f31bc4
--- /dev/null
+++ b/sys-freebsd/freebsd-pf/files/freebsd-pf-9.0-pcap_pollution.patch
@@ -0,0 +1,17 @@
+--- contrib/pf/pflogd/privsep.c.old 2011-11-02 21:04:01.000000000 +0000
++++ contrib/pf/pflogd/privsep.c 2011-11-02 21:04:27.000000000 +0000
+@@ -32,11 +32,13 @@
+ #include <errno.h>
+ #include <fcntl.h>
+ #include <limits.h>
++#include <stdio.h>
++#define HAVE_SNPRINTF
++#define HAVE_STRLCPY
+ #include <pcap.h>
+ #include <pcap-int.h>
+ #include <pwd.h>
+ #include <signal.h>
+-#include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <syslog.h>
diff --git a/sys-freebsd/freebsd-pf/files/pf.confd b/sys-freebsd/freebsd-pf/files/pf.confd
new file mode 100644
index 000000000000..87c21b281e2b
--- /dev/null
+++ b/sys-freebsd/freebsd-pf/files/pf.confd
@@ -0,0 +1,9 @@
+# Copyright 2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+# Defines where the rules file is found, by default /etc/pf.conf
+# pf_conf=/etc/pf.conf
+
+# Extra options to pass to pfctl when loading the rules
+# See pfctl(8)
+# pf_args=
diff --git a/sys-freebsd/freebsd-pf/files/pf.initd b/sys-freebsd/freebsd-pf/files/pf.initd
new file mode 100644
index 000000000000..c1b3e9eb5747
--- /dev/null
+++ b/sys-freebsd/freebsd-pf/files/pf.initd
@@ -0,0 +1,49 @@
+#!/sbin/openrc-run
+# Copyright 2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+depend() {
+ need net
+}
+
+checkconfig() {
+ if ! [ -c /dev/pf ]; then
+ ewarn "Pseudo-device /dev/pf not found."
+
+ ebegin "Loading pf module"
+ if ! kldload pf; then
+ eerror "Unable to load pf module."
+ eend 1
+ return 1
+ fi
+ eend $?
+
+ if ! [ -c /dev/pf ]; then
+ eerror "Pseudo-device /dev/pf still not found."
+ return 1
+ fi
+ fi
+
+ return 0
+}
+
+start() {
+ checkconfig || return 1
+
+ einfo "Starting firewall"
+
+ if [ -r "${PF_RULES_FILE}" ]; then
+ einfo "Loading firewall rules"
+ /sbin/pfctl -qe -f ${PF_RULES_FILE:-/etc/pf.conf} ${PF_OPTS}
+ else
+ /sbin/pfctl -qe ${PF_OPTS}
+ fi
+
+ eend $?
+}
+
+stop() {
+ einfo "Stopping firewall"
+ /sbin/pfctl -qd || retval=1
+ eend $?
+}
diff --git a/sys-freebsd/freebsd-pf/freebsd-pf-11.1.ebuild b/sys-freebsd/freebsd-pf/freebsd-pf-11.1.ebuild
new file mode 100644
index 000000000000..a210e789bf43
--- /dev/null
+++ b/sys-freebsd/freebsd-pf/freebsd-pf-11.1.ebuild
@@ -0,0 +1,70 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd user
+
+DESCRIPTION="FreeBSD's base system libraries"
+SLOT="0"
+
+IUSE=""
+
+# Crypto is needed to have an internal OpenSSL header
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64-fbsd ~x86-fbsd"
+fi
+
+EXTRACTONLY="
+ usr.sbin/
+ sbin/
+ contrib/pf/
+ etc/
+"
+
+RDEPEND="net-libs/libpcap"
+DEPEND="${RDEPEND}
+ dev-libs/libevent
+ =sys-freebsd/freebsd-mk-defs-${RV}*
+ =sys-freebsd/freebsd-sources-${RV}*"
+
+S="${WORKDIR}"
+
+SUBDIRS="usr.sbin/authpf sbin/pfctl sbin/pflogd usr.sbin/ftp-proxy"
+
+pkg_setup() {
+ enewgroup authpf 63
+}
+
+src_prepare() {
+ # pcap-int.h redefines snprintf as pcap_snprintf
+ epatch "${FILESDIR}/${PN}-9.0-pcap_pollution.patch"
+ # Use system's libevent
+ epatch "${FILESDIR}/${PN}-11.1-libevent.patch"
+ epatch "${FILESDIR}/${PN}-11.1-pflogd.patch"
+ epatch "${FILESDIR}/${PN}-9.0-bpf.patch"
+ # Link in kernel sources
+ [[ ! -e "${WORKDIR}/sys" ]] && ln -s "/usr/src/sys" "${WORKDIR}/sys"
+}
+
+src_compile() {
+ for dir in ${SUBDIRS}; do
+ einfo "Starting make in ${dir}"
+ cd "${S}/${dir}" || die
+ freebsd_src_compile || die "Make ${dir} failed"
+ done
+}
+
+src_install() {
+ for dir in ${SUBDIRS}; do
+ einfo "Starting install in ${dir}"
+ cd "${S}/${dir}" || die
+ freebsd_src_install || die "Install ${dir} failed"
+ done
+
+ cd "${WORKDIR}"/etc
+ insinto /etc
+ doins pf.os
+ # pf.initd provided by openrc, but no pf.confd
+ newconfd "${FILESDIR}/pf.confd" pf
+}
diff --git a/sys-freebsd/freebsd-pf/metadata.xml b/sys-freebsd/freebsd-pf/metadata.xml
new file mode 100644
index 000000000000..a00f3aeb1f81
--- /dev/null
+++ b/sys-freebsd/freebsd-pf/metadata.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+<maintainer type="project">
+ <email>bsd@gentoo.org</email>
+ <name>BSD Project</name>
+</maintainer>
+</pkgmetadata>
diff --git a/sys-freebsd/freebsd-rescue/Manifest b/sys-freebsd/freebsd-rescue/Manifest
new file mode 100644
index 000000000000..3424af135237
--- /dev/null
+++ b/sys-freebsd/freebsd-rescue/Manifest
@@ -0,0 +1,6 @@
+AUX freebsd-rescue-10.0-zlib.patch 861 BLAKE2B 6eb6f4dad43fbb66c6947b0c5aead42079eb9f3f58081f9871a6ec4c89c102cae3a3e27360092d39958b55b65fc8b79f657617bdd2e6b62f89e496121227b524 SHA512 b055878934144bb2403bcf7d93b6239d161654d822ff5839676430eec282b1a7d210e9d4d4b744995b6e6d400ac15a98af9268f0ef62e455c6e776fa79d7b037
+AUX freebsd-rescue-11.0-rename-libs.patch 874 BLAKE2B 104c74d323a40c228df812c31f9fa6799ee26f0069f54c087b9c6b6ec1e1bac440a98cdabb4b090ab9e5267121d1c8a22abbd4d7a53a785dc11c452dd75754d7 SHA512 8ac692342e0ce3cd39286c08523bc89d56f15964242c08ec2065e70fbf3cec24c00608d50ab5b94ab4a7781a4175acc40c2bcc0e4a2cfaf3afcd89fa06dd77c9
+AUX freebsd-ubin-10.2-bsdxml.patch 367 BLAKE2B 0a2dfc1b2646aa2c42bfa8b9a6cbd3d22d8b83b8bd252bb7faa3753390a376e8898d5155b16bba52378df304848f99a0cf3fcd141b013670f5dff8355ac0a062 SHA512 234fe495fcefaa9c36d97460da05365ff081661411451ae3d8dca83b3f8b1746450e111ac43baccd15a6c86c03c7cdd37d54d70fed551d694800dc6bca7c5e8d
+DIST freebsd-src-11.1.tar.xz 147661560 BLAKE2B a9e6ba9d0e12c8b56ac58575d5f02931edbb6a3545d9dccae78810d2d0470a29b29dd7f724b03b8afafbca23717a71346e4cfbd3530e0f40118a23609c3f414e SHA512 b97707ec7a601ca6bcb682c45f6d94a38484301ac24630d7285eff6f88b027ce6900c93fc62f8ce36e0cf32c91f73a9d1c999db397b7f8782fd74a8551a03aca
+EBUILD freebsd-rescue-11.1.ebuild 1863 BLAKE2B 192ee47076a02df932500c4441ce38fc6f8a03c05d177d6964b8ec8df9dcc13117d408ed5a890533ea14f04eb4d3345f8a64669565b791ba0398508279740aee SHA512 38821a85f4e5f2efb6746b096b64c02b6534ce98ad743c44e45f65d8a6cafc3fba6cc452d3d465df1021fa2bf02063d3a5fa5be89ce7c667a9912626a7317591
+MISC metadata.xml 402 BLAKE2B f24c7363fc3c6749311732e4b1722f301ad6a680e6d25450657645b3295611202f65ceb7386a6827cfd4448584584584c67b3f3d03089b8948709282b5cae0fa SHA512 247e4e4c80cd64a81f698fc7fbeab529a02f8b2c6b0040628936ab7d83a09c7242df0b10d7cb4e4e8d7d78806c303cd82903adc4a38b649e911337a832c35834
diff --git a/sys-freebsd/freebsd-rescue/files/freebsd-rescue-10.0-zlib.patch b/sys-freebsd/freebsd-rescue/files/freebsd-rescue-10.0-zlib.patch
new file mode 100644
index 000000000000..42165c4249ed
--- /dev/null
+++ b/sys-freebsd/freebsd-rescue/files/freebsd-rescue-10.0-zlib.patch
@@ -0,0 +1,22 @@
+diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c
+index 13c0d43..1f258f3 100644
+--- a/sbin/savecore/savecore.c
++++ b/sbin/savecore/savecore.c
+@@ -92,7 +92,7 @@ static int checkfor, compress, clear, force, keep, verbose; /* flags */
+ static int nfound, nsaved, nerr; /* statistics */
+ static int maxdumps;
+
+-extern FILE *zopen(const char *, const char *);
++extern FILE *gzopen(const char *, const char *);
+
+ static sig_atomic_t got_siginfo;
+ static void infohandler(int);
+@@ -626,7 +626,7 @@ DoFile(const char *savedir, const char *device)
+ if (compress) {
+ snprintf(corename, sizeof(corename), "%s.%d.gz",
+ istextdump ? "textdump.tar" : "vmcore", bounds);
+- fp = zopen(corename, "w");
++ fp = gzopen(corename, "w");
+ } else {
+ snprintf(corename, sizeof(corename), "%s.%d",
+ istextdump ? "textdump.tar" : "vmcore", bounds);
diff --git a/sys-freebsd/freebsd-rescue/files/freebsd-rescue-11.0-rename-libs.patch b/sys-freebsd/freebsd-rescue/files/freebsd-rescue-11.0-rename-libs.patch
new file mode 100644
index 000000000000..31035747a43d
--- /dev/null
+++ b/sys-freebsd/freebsd-rescue/files/freebsd-rescue-11.0-rename-libs.patch
@@ -0,0 +1,22 @@
+diff --git a/rescue/rescue/Makefile b/rescue/rescue/Makefile
+index e747c02..a061436 100644
+--- a/rescue/rescue/Makefile
++++ b/rescue/rescue/Makefile
+@@ -54,7 +54,7 @@ CRUNCH_PROGS_bin= cat chflags chio chmod cp date dd df echo \
+ ed expr getfacl hostname kenv kill ln ls mkdir mv \
+ pkill ps pwd realpath rm rmdir setfacl sh sleep stty \
+ sync test
+-CRUNCH_LIBS+= -lcrypt -ledit -ljail -lkvm -lelf -ll -ltermcapw -lutil -lxo
++CRUNCH_LIBS+= -lcrypt -ledit -ljail -lkvm -lelf -lfl -lncursesw -lutil -lxo
+ CRUNCH_BUILDTOOLS+= bin/sh
+
+ # Additional options for specific programs
+@@ -128,7 +128,7 @@ CRUNCH_LIBS+= -lavl -lzpool -lzfs_core -lzfs -lnvpair -lpthread -luutil -lumem
+ # liblzma needs pthread
+ CRUNCH_LIBS+= -lpthread
+ .endif
+-CRUNCH_LIBS+= -lgeom -lbsdxml -lkiconv
++CRUNCH_LIBS+= -lgeom -lexpat -lkiconv
+ .if ${MK_OPENSSL} == "no"
+ CRUNCH_LIBS+= -lmd
+ .endif
diff --git a/sys-freebsd/freebsd-rescue/files/freebsd-ubin-10.2-bsdxml.patch b/sys-freebsd/freebsd-rescue/files/freebsd-ubin-10.2-bsdxml.patch
new file mode 100644
index 000000000000..606471713fba
--- /dev/null
+++ b/sys-freebsd/freebsd-rescue/files/freebsd-ubin-10.2-bsdxml.patch
@@ -0,0 +1,13 @@
+diff --git a/usr.bin/mt/mt.c b/usr.bin/mt/mt.c
+index af6562b..3121c81 100644
+--- a/usr.bin/mt/mt.c
++++ b/usr.bin/mt/mt.c
+@@ -92,7 +92,7 @@ __FBSDID("$FreeBSD: stable/10/usr.bin/mt/mt.c 280438 2015-03-24 14:36:10Z ken $"
+ #include <unistd.h>
+ #include <stdint.h>
+ #include <errno.h>
+-#include <bsdxml.h>
++#include <expat.h>
+ #include <mtlib.h>
+
+ #include <cam/cam.h>
diff --git a/sys-freebsd/freebsd-rescue/freebsd-rescue-11.1.ebuild b/sys-freebsd/freebsd-rescue/freebsd-rescue-11.1.ebuild
new file mode 100644
index 000000000000..9cecae29df98
--- /dev/null
+++ b/sys-freebsd/freebsd-rescue/freebsd-rescue-11.1.ebuild
@@ -0,0 +1,83 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd toolchain-funcs
+
+DESCRIPTION="FreeBSD's rescue binaries"
+SLOT="0"
+LICENSE="BSD zfs? ( CDDL )"
+
+IUSE="atm netware nis zfs"
+
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64-fbsd ~x86-fbsd"
+fi
+
+EXTRACTONLY="
+ usr.bin/
+ contrib/
+ lib/
+ bin/
+ sbin/
+ usr.sbin/
+ gnu/
+ sys/
+ libexec/
+ rescue/
+"
+
+RDEPEND=""
+DEPEND="sys-devel/flex
+ app-arch/xz-utils[static-libs]
+ sys-libs/ncurses[static-libs]
+ dev-libs/expat[static-libs]
+ app-arch/bzip2[static-libs]
+ dev-libs/libedit[static-libs]
+ dev-libs/libxml2:2[static-libs]
+ dev-libs/openssl:0=[static-libs]
+ sys-libs/zlib[static-libs]
+ sys-libs/readline[static-libs]
+ =sys-freebsd/freebsd-lib-${RV}*[atm?,netware?]
+ =sys-freebsd/freebsd-sources-${RV}*
+ =sys-freebsd/freebsd-mk-defs-${RV}*
+ zfs? ( =sys-freebsd/freebsd-cddl-${RV}* )"
+
+S="${WORKDIR}/rescue"
+
+pkg_setup() {
+ # Add the required source files.
+ use zfs && EXTRACTONLY+="cddl/ "
+
+ use atm || mymakeopts="${mymakeopts} WITHOUT_ATM= "
+ use netware || mymakeopts="${mymakeopts} WITHOUT_IPX= "
+ use nis || mymakeopts="${mymakeopts} WITHOUT_NIS= "
+ use zfs || mymakeopts="${mymakeopts} WITHOUT_CDDL= "
+ mymakeopts="${mymakeopts} NO_PIC= "
+}
+
+src_prepare() {
+ # As they are patches from ${WORKDIR} apply them by hand
+ cd "${WORKDIR}" || die
+ epatch "${FILESDIR}/${PN}-10.0-zlib.patch"
+ epatch "${FILESDIR}/${PN}-11.0-rename-libs.patch"
+ epatch "${FILESDIR}/freebsd-ubin-10.2-bsdxml.patch"
+}
+
+src_compile() {
+ export ESED=/usr/bin/sed
+ unalias sed
+
+ tc-export CC
+ # crunchgen requires BSD's make to compile successfully.
+ export MAKE=/usr/bin/make
+
+ cd "${WORKDIR}/lib/libarchive" || die
+ echo "#include <expat.h>" > bsdxml.h
+ freebsd_src_compile
+ export CC="${CC} -L${WORKDIR}/lib/libarchive"
+
+ cd "${S}" || die
+ freebsd_src_compile
+}
diff --git a/sys-freebsd/freebsd-rescue/metadata.xml b/sys-freebsd/freebsd-rescue/metadata.xml
new file mode 100644
index 000000000000..8703f7b26e6d
--- /dev/null
+++ b/sys-freebsd/freebsd-rescue/metadata.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+<maintainer type="project">
+ <email>bsd@gentoo.org</email>
+ <name>BSD Project</name>
+ </maintainer>
+ <use>
+ <flag name="zfs">Enable ZFS support.</flag>
+ <flag name="netware"> Build tools to work with NetWare protocols (IPX and NCP).</flag>
+ </use>
+</pkgmetadata>
diff --git a/sys-freebsd/freebsd-sbin/Manifest b/sys-freebsd/freebsd-sbin/Manifest
new file mode 100644
index 000000000000..b267407a2056
--- /dev/null
+++ b/sys-freebsd/freebsd-sbin/Manifest
@@ -0,0 +1,8 @@
+AUX adjkerntz-crontab 184 BLAKE2B 80ccbdc7b07d36d56fd1025c926e594eea4b6526495182914dc82067d1f40d8191c2eecdd0c24a7bef1e1772e854473eff65384978ff3010ff93ff05bc36b1d6 SHA512 28ecfd94257eca2d91323e4bac1920969e589a13f877f1d67c4be0dd5d0bf4585eba8f749ae04f2e0761d5860b76e0c04993350bbdeb52736584ea9df97c6093
+AUX freebsd-sbin-10.0-zlib.patch 861 BLAKE2B 02d00e0430250604428de678eb2a9f266f327659349eef59f5c74ccbe7e50ee96862bd614b573f03860199a6a74b7ffd80bae7f650277815f50d489e644981a2 SHA512 8a6e14d15e44e9de22863c65cd359cc408207a4329ecdfe053317fd120d01025f5d42b958447ed0bb2e584cc050391306438934ac8cae0edc4a6a785da8138b7
+AUX freebsd-sbin-6.1-pr102701.patch 548 BLAKE2B 408f8783547f949042c20ba40071b630c50aa3d45e270b886f8d5a32e44be33361776d3f30f7b220a618265e21547d595f7af016d89d40e3eb1ef9c7002d45ac SHA512 2b882565670ffe559410b17e2fa6a94624eee89d25a791ef3e27d657dedcf95b2be282217a2350203af7727b839d5d6ff50368f72c4bef3d7e60fef8a6325cbe
+AUX freebsd-sbin-6.2-ldconfig.patch 389 BLAKE2B ec10d6af427bb32c0348d452dfc056d7265c50dfe7d816a202fbce174f5c136221e98763e937fc1c485e1035e32fd2e961a5198199338fd7b8b3ef926b2d5353 SHA512 ed8f6073991ba0c8823aea1570e720273d7dc68ec6daf38d7e1d41f2285d307d7905cf674a1148d4783c69f2dafd7fc8a51e729aa4727eb46d857218ab2d71ed
+AUX freebsd-sbin-setXid.patch 541 BLAKE2B 0e1e7ede0385d8f6ecbf905e4366712b7707aaf918780a93712afcbefa2741585e14be7536d2f6a823808f97756bebc6e0374882a04cc2743b9649ae777875db SHA512 e6f1aefab22eca6941a5b62f6f9d9c82e0efc2b308ec636ecab40d9a678e87f2f6ccfefac99f5367ad8a16d18ddadf9a877a2f93697248b3f38a09edac75ec6e
+DIST freebsd-src-11.1.tar.xz 147661560 BLAKE2B a9e6ba9d0e12c8b56ac58575d5f02931edbb6a3545d9dccae78810d2d0470a29b29dd7f724b03b8afafbca23717a71346e4cfbd3530e0f40118a23609c3f414e SHA512 b97707ec7a601ca6bcb682c45f6d94a38484301ac24630d7285eff6f88b027ce6900c93fc62f8ce36e0cf32c91f73a9d1c999db397b7f8782fd74a8551a03aca
+EBUILD freebsd-sbin-11.1.ebuild 2646 BLAKE2B 79418a3a6ef338c4a3b5cf8032d42606d42102e0bfd11bad8ebab3af03c84e785ddcfb7517e89945f4f34b690903bff5596b6b97d341f14d4dd9cfb77899504f SHA512 5ddec2a2ff87e62670d88fa71f4ed7166ff20de188d81adad3c6dd7b8988505a7f5a766d23fc7b93e50ddb5e44ea8cd75964bfb4202b70ff0b22dccca5d3fc73
+MISC metadata.xml 611 BLAKE2B 74992d5b0b76a115a51cb01273ca718f057f832fee09d1ee4959cb0cd058eceed28d1e71e77e41a386f1c056cbb7c08ca7a4dec1853b5b21209710b9eb96ef1f SHA512 f5564d34b62dfd20fda9ce5e17de3fc45b9d281de062e8858aa090049218ee5a05670967111032bce63363ae64a98ba39753964c013e12aaf5e15e90719a720e
diff --git a/sys-freebsd/freebsd-sbin/files/adjkerntz-crontab b/sys-freebsd/freebsd-sbin/files/adjkerntz-crontab
new file mode 100644
index 000000000000..5fc46f5bf48e
--- /dev/null
+++ b/sys-freebsd/freebsd-sbin/files/adjkerntz-crontab
@@ -0,0 +1,4 @@
+# Adjust the time zone if the CMOS clock keeps local time, as opposed to
+# UTC time. See adjkerntz(8) for details.
+1,31 0-5 * * * root /sbin/adjkerntz -a
+
diff --git a/sys-freebsd/freebsd-sbin/files/freebsd-sbin-10.0-zlib.patch b/sys-freebsd/freebsd-sbin/files/freebsd-sbin-10.0-zlib.patch
new file mode 100644
index 000000000000..c0a2bf923c23
--- /dev/null
+++ b/sys-freebsd/freebsd-sbin/files/freebsd-sbin-10.0-zlib.patch
@@ -0,0 +1,22 @@
+diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c
+index bdbf7e3..a4c67ec 100644
+--- a/sbin/savecore/savecore.c
++++ b/sbin/savecore/savecore.c
+@@ -92,7 +92,7 @@ static int checkfor, compress, clear, force, keep, verbose; /* flags */
+ static int nfound, nsaved, nerr; /* statistics */
+ static int maxdumps;
+
+-extern FILE *zopen(const char *, const char *);
++extern FILE *gzopen(const char *, const char *);
+
+ static sig_atomic_t got_siginfo;
+ static void infohandler(int);
+@@ -626,7 +626,7 @@ DoFile(const char *savedir, const char *device)
+ if (compress) {
+ snprintf(corename, sizeof(corename), "%s.%d.gz",
+ istextdump ? "textdump.tar" : "vmcore", bounds);
+- fp = zopen(corename, "w");
++ fp = gzopen(corename, "w");
+ } else {
+ snprintf(corename, sizeof(corename), "%s.%d",
+ istextdump ? "textdump.tar" : "vmcore", bounds);
diff --git a/sys-freebsd/freebsd-sbin/files/freebsd-sbin-6.1-pr102701.patch b/sys-freebsd/freebsd-sbin/files/freebsd-sbin-6.1-pr102701.patch
new file mode 100644
index 000000000000..7b9578c40c87
--- /dev/null
+++ b/sys-freebsd/freebsd-sbin/files/freebsd-sbin-6.1-pr102701.patch
@@ -0,0 +1,17 @@
+Solves the issue reported in Problem Report bin/102701.
+
+Can't delete an inet6 alias address from an interface.
+
+Index: fbsd-6.1/sbin/ifconfig/af_inet6.c
+===================================================================
+--- fbsd-6.1.orig/sbin/ifconfig/af_inet6.c
++++ fbsd-6.1/sbin/ifconfig/af_inet6.c
+@@ -515,7 +515,7 @@ static struct afswtch af_inet6 = {
+ .af_settunnel = in6_set_tunnel,
+ .af_difaddr = SIOCDIFADDR_IN6,
+ .af_aifaddr = SIOCAIFADDR_IN6,
+- .af_ridreq = &in6_addreq,
++ .af_ridreq = &in6_ridreq,
+ .af_addreq = &in6_addreq,
+ };
+
diff --git a/sys-freebsd/freebsd-sbin/files/freebsd-sbin-6.2-ldconfig.patch b/sys-freebsd/freebsd-sbin/files/freebsd-sbin-6.2-ldconfig.patch
new file mode 100644
index 000000000000..81ad02461681
--- /dev/null
+++ b/sys-freebsd/freebsd-sbin/files/freebsd-sbin-6.2-ldconfig.patch
@@ -0,0 +1,13 @@
+diff -ur sbin.orig/ldconfig/elfhints.c sbin/ldconfig/elfhints.c
+--- sbin.orig/ldconfig/elfhints.c 2001-05-03 00:56:18 +0100
++++ sbin/ldconfig/elfhints.c 2007-08-06 10:16:24 +0100
+@@ -245,6 +245,9 @@
+ else
+ add_dir(hintsfile, argv[i], 0);
+ }
++ /* Always add our system dirs */
++ add_dir (hintsfile, "/lib", 1);
++ add_dir (hintsfile, "/usr/lib", 1);
+ write_elf_hints(hintsfile);
+ }
+
diff --git a/sys-freebsd/freebsd-sbin/files/freebsd-sbin-setXid.patch b/sys-freebsd/freebsd-sbin/files/freebsd-sbin-setXid.patch
new file mode 100644
index 000000000000..c8cbebc68c2b
--- /dev/null
+++ b/sys-freebsd/freebsd-sbin/files/freebsd-sbin-setXid.patch
@@ -0,0 +1,20 @@
+diff -ur sbin.orig/ping/Makefile sbin.setXid/ping/Makefile
+--- sbin.orig/ping/Makefile Thu Apr 7 20:27:57 2005
++++ sbin.setXid/ping/Makefile Thu Apr 7 20:42:02 2005
+@@ -18,4 +18,6 @@
+ LDADD+= -lipsec
+ .endif
+
++LDFLAGS+= -Wl,-z,now
++
+ .include <bsd.prog.mk>
+diff -ur sbin.orig/shutdown/Makefile sbin.setXid/shutdown/Makefile
+--- sbin.orig/shutdown/Makefile Thu Apr 7 20:27:57 2005
++++ sbin.setXid/shutdown/Makefile Thu Apr 7 20:42:17 2005
+@@ -7,4 +7,6 @@
+ BINGRP= operator
+ BINMODE=4550
+
++LDFLAGS+= -Wl,-z,now
++
+ .include <bsd.prog.mk>
diff --git a/sys-freebsd/freebsd-sbin/freebsd-sbin-11.1.ebuild b/sys-freebsd/freebsd-sbin/freebsd-sbin-11.1.ebuild
new file mode 100644
index 000000000000..50a513208cb8
--- /dev/null
+++ b/sys-freebsd/freebsd-sbin/freebsd-sbin-11.1.ebuild
@@ -0,0 +1,102 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd multilib
+
+DESCRIPTION="FreeBSD sbin utils"
+SLOT="0"
+LICENSE="BSD zfs? ( CDDL )"
+
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64-fbsd ~x86-fbsd"
+fi
+
+EXTRACTONLY="
+ sbin/
+ contrib/
+ lib/
+ libexec/
+ usr.sbin/
+ etc/
+"
+
+RDEPEND="=sys-freebsd/freebsd-lib-${RV}*[ipv6?,atm?,netware?]
+ zfs? ( =sys-freebsd/freebsd-cddl-${RV}* )
+ >=dev-libs/expat-2.0.1
+ ssl? ( dev-libs/openssl:0= )
+ >=dev-libs/libedit-20120311.3.0-r1
+ sys-libs/readline:0=
+ || (
+ sys-process/cronie
+ sys-process/vixie-cron
+ )
+ atm? ( net-analyzer/bsnmp )"
+DEPEND="${RDEPEND}
+ !build? ( =sys-freebsd/freebsd-sources-${RV}* )
+ =sys-freebsd/freebsd-mk-defs-${RV}*"
+
+S="${WORKDIR}/sbin"
+
+IUSE="atm ipfilter +pf ipv6 build ssl +cxx netware zfs"
+
+pkg_setup() {
+ # Add the required source files.
+ use build && EXTRACTONLY+="sys/ "
+ use zfs && EXTRACTONLY+="cddl/ "
+
+ use atm || mymakeopts="${mymakeopts} WITHOUT_ATM= "
+ use cxx || mymakeopts="${mymakeopts} WITHOUT_CXX="
+ use ipfilter || mymakeopts="${mymakeopts} WITHOUT_IPFILTER= "
+ use ipv6 || mymakeopts="${mymakeopts} WITHOUT_INET6= WITHOUT_INET6_SUPPORT="
+ use netware || mymakeopts="${mymakeopts} WITHOUT_IPX= WITHOUT_IPX_SUPPORT= WITHOUT_NCP= "
+ use pf || mymakeopts="${mymakeopts} WITHOUT_PF= "
+ use ssl || mymakeopts="${mymakeopts} WITHOUT_OPENSSL= "
+ use zfs || mymakeopts="${mymakeopts} WITHOUT_CDDL= "
+}
+
+REMOVE_SUBDIRS="dhclient pfctl pflogd rcorder resolvconf"
+
+PATCHES=( "${FILESDIR}/${PN}-setXid.patch"
+ "${FILESDIR}/${PN}-10.0-zlib.patch"
+ "${FILESDIR}/${PN}-6.2-ldconfig.patch"
+ "${FILESDIR}/${PN}-6.1-pr102701.patch" )
+
+src_prepare() {
+ if [[ ! -e "${WORKDIR}/sys" ]]; then
+ use build || ln -s "/usr/src/sys" "${WORKDIR}/sys"
+ fi
+}
+
+src_install() {
+ mymakeopts="${mymakeopts} GEOM_CLASS_DIR=/$(get_libdir)/geom "
+ freebsd_src_install
+ keepdir /var/log
+ # Needed by ldconfig:
+ keepdir /var/run
+
+ # Maybe ship our own sysctl.conf so things like radvd work out of the box.
+ # New wireless config method requires regdomain.xml in /etc
+ cd "${WORKDIR}/etc/" || die
+ insinto /etc
+ doins minfree sysctl.conf regdomain.xml || die
+
+ # Install a crontab for adjkerntz
+ insinto /etc/cron.d
+ newins "${FILESDIR}/adjkerntz-crontab" adjkerntz
+
+ # Install the periodic stuff (needs probably to be ported in a more
+ # gentooish way)
+ cd "${WORKDIR}/etc/periodic" || die
+
+ doperiodic security \
+ security/*.ipfwlimit \
+ security/*.ipfwdenied || die
+
+ use ipfilter && { doperiodic security \
+ security/*.ipfdenied || die ; }
+
+ use pf && { doperiodic security \
+ security/*.pfdenied || die ; }
+}
diff --git a/sys-freebsd/freebsd-sbin/metadata.xml b/sys-freebsd/freebsd-sbin/metadata.xml
new file mode 100644
index 000000000000..d5e743263983
--- /dev/null
+++ b/sys-freebsd/freebsd-sbin/metadata.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <maintainer type="project">
+ <email>bsd@gentoo.org</email>
+ <name>BSD Project</name>
+ </maintainer>
+ <use>
+ <flag name="ipfilter">
+ Build tools to administer the ipfilter firewall.
+ </flag>
+ <flag name="pf">
+ Build tools to administer the PF firewall.
+ </flag>
+ <flag name="netware">
+ Build libraries and tools to work with NetWare protocols (IPX
+ and NCP).
+ </flag>
+ <flag name="zfs">Enable ZFS support.</flag>
+ </use>
+</pkgmetadata>
diff --git a/sys-freebsd/freebsd-share/Manifest b/sys-freebsd/freebsd-share/Manifest
new file mode 100644
index 000000000000..3e48e89a38f2
--- /dev/null
+++ b/sys-freebsd/freebsd-share/Manifest
@@ -0,0 +1,9 @@
+AUX freebsd-share-10.0-gentoo-eapi3.patch 475 BLAKE2B 2003dbeb08815d0b71450301bbb91cf387525ae67b876260eec625d087f0df84b2ba08bc080b99606cc960b938a4203b52cc670668a6da6656202d0f61acf970 SHA512 b7fe870aafe1cf9029c1d1d9de16413b5be8354b1c2ba0d0eab6f0fe3076ab03da08ff764c923c087e246b90355a48d55acef9b9b5a29238ddf8c92bdb3ca0f8
+AUX freebsd-share-10.2-gnu-miscfiles.patch 913 BLAKE2B 2c264e3f7422f8f8f0994d2e888221e1f5223865596e5cfd4ab41cf6c4f6bb640cde891f7a32fe09d91115cb9bb934e5fc4bade310407205ec454cb3b0904c9b SHA512 fa792f15e325117e4448b344ab3dbf64d3880719698d88d8dda60c8cc4afea8c11cb845f44fa3b78ddc98fc6b021ef9edac639f649e8d166d79bf2c0e4f654f5
+AUX freebsd-share-10.3-gentoo-skel.patch 600 BLAKE2B b04b8653aef9add52fe180b587635809cdbfc644d0df59eef1f471449228689a19adc1f19613ba7265c30f200e52ecd6e5f95fbd7312c488d1565e629baaeb67 SHA512 338eb369c50b11835f00474be5363bf6af43d8391a28a6e78e1517afc686b168fd0bfc32d45a78e79515c3d89a35b097548117cb2838b751d3d41330939c7dc2
+AUX freebsd-share-SA-1808-tcp-11.patch 896 BLAKE2B 6f459795078217835f6accbe4ed27bd82f639a103f89e45bd78429d0de9ef8ee2f63be3afac63780f5cf663e2f3e1327bf15e655b612e2a0f6416f272ddd75c9 SHA512 f2bb1085b680eaad997d79940a33d8dfd56e0e4ec6d2df628f58f208d2a37cb7f60ed94b4738afcd25112ea55268c06a1bc6534128802fd522771537fa7f4164
+AUX freebsd-share-SA-1810-ip.patch 4563 BLAKE2B efbe805bccbff5e49c3e1f0d5fd6a95ebd077cdc026a296f314815a3918eaffb694a1f9fb4beffcd609ca5d57da37762e28c9c2ee450d681d22f0f280c8b164f SHA512 55404a2ed446b0aa3bcd4bc6f82f5c253644d448645da82233865e0fadb3875501810fd0eeda1caab2489445dc759e52b2cccfcad99f65678640692fb5abf404
+DIST freebsd-src-11.1.tar.xz 147661560 BLAKE2B a9e6ba9d0e12c8b56ac58575d5f02931edbb6a3545d9dccae78810d2d0470a29b29dd7f724b03b8afafbca23717a71346e4cfbd3530e0f40118a23609c3f414e SHA512 b97707ec7a601ca6bcb682c45f6d94a38484301ac24630d7285eff6f88b027ce6900c93fc62f8ce36e0cf32c91f73a9d1c999db397b7f8782fd74a8551a03aca
+EBUILD freebsd-share-11.1.ebuild 3324 BLAKE2B a4a35392bc6e32b2e7c8922e887260717b30df97d4c18b9d6b068338ed536e5cc4dafdbca59391345d1c2af93798b28417d660aa2cb86778b53d5097a904f3ce SHA512 6e91be861b588dc5e91ac6b6e71fd242c5b7d86f9aabc8077bc2084326b65d71c1da6a6c4bb1b61e71e991c501eb7ebd13bd2bb46352bdcd8b37815bd5ae1ea9
+EBUILD freebsd-share-11.1_p1.ebuild 3405 BLAKE2B b0d7ec19e8b9c2adf20a377d9f1a096d3e02e51bff41d1e969ee57b51c38f81049b1ee83906770cab466e2c7e17119354c92fc5e54b9714f9ca1ebc896cb79e5 SHA512 004f0e831b08895cb162117d4d4eab291a58581e655177997ae823f4825af8bb31067c1fcf0c58d0c50757027c7feee5ab051d7a9702d983469a57e6bd81fde5
+MISC metadata.xml 303 BLAKE2B 32a957edfc2dcb1fd1076d208b253fbe2408a65f44585ebd3863a9f6d95f4e25d8e3fc5ada378074e0d7e1ebd47793c4e8241656087da905100f68375c70df9e SHA512 4483a50bd02a3644bd12148d0a54ff78686d974337b5c22a267bdae228eefec85bf1a8b74a1c04a7759645e451e59c75734318d07376692d26c97261eaf2fbf3
diff --git a/sys-freebsd/freebsd-share/files/freebsd-share-10.0-gentoo-eapi3.patch b/sys-freebsd/freebsd-share/files/freebsd-share-10.0-gentoo-eapi3.patch
new file mode 100644
index 000000000000..1d0a53ef10cb
--- /dev/null
+++ b/sys-freebsd/freebsd-share/files/freebsd-share-10.0-gentoo-eapi3.patch
@@ -0,0 +1,17 @@
+diff --git a/share/i18n/esdb/Makefile.part b/share/i18n/esdb/Makefile.part
+index 9ca8577..329e9fb 100644
+--- a/share/i18n/esdb/Makefile.part
++++ b/share/i18n/esdb/Makefile.part
+@@ -13,10 +13,10 @@ PART!= sed '/^\#/d;/^ *$$/d' ${PARTFILE}
+ .endif
+ .if !defined(NO_EPREFIX)
+ CODESETS?= ${PART:C/^/${CODE}${SEP}/}
+-EPREFIX?= ${CODE}${SEP}
++EPREFIX= ${CODE}${SEP}
+ .else
+ CODESETS?= ${PART}
+-EPREFIX?=
++EPREFIX=
+ .endif
+ ESUBDIR?= ${CODE}
+ ESDB?= ${CODESETS:C/$/.esdb/:S/:/@/}
diff --git a/sys-freebsd/freebsd-share/files/freebsd-share-10.2-gnu-miscfiles.patch b/sys-freebsd/freebsd-share/files/freebsd-share-10.2-gnu-miscfiles.patch
new file mode 100644
index 000000000000..1dc848873a67
--- /dev/null
+++ b/sys-freebsd/freebsd-share/files/freebsd-share-10.2-gnu-miscfiles.patch
@@ -0,0 +1,30 @@
+diff --git a/share/dict/Makefile b/share/dict/Makefile
+index 3e2a0df..5395077 100644
+--- a/share/dict/Makefile
++++ b/share/dict/Makefile
+@@ -4,8 +4,7 @@
+ NO_OBJ=
+
+ # XXX MISSING: connectives words
+-FILES= README propernames web2 web2a freebsd
++FILES= README freebsd
+ FILESDIR= ${BINDIR}/dict
+-SYMLINKS= web2 ${FILESDIR}/words
+
+ .include <bsd.prog.mk>
+diff --git a/share/misc/Makefile b/share/misc/Makefile
+index ffd42d8..7eb90bb 100644
+--- a/share/misc/Makefile
++++ b/share/misc/Makefile
+@@ -5,9 +5,9 @@
+
+ .PATH: ${.CURDIR}/../../sys/dev/usb
+
+-FILES= ascii birthtoken bsd-family-tree committers-doc.dot committers-ports.dot \
++FILES= bsd-family-tree committers-doc.dot committers-ports.dot \
+ committers-src.dot eqnchar flowers init.ee \
+- iso3166 iso639 latin1 man.template mdoc.template operator pci_vendors \
++ iso3166 iso639 man.template mdoc.template pci_vendors \
+ scsi_modes \
+ organization.dot
+
diff --git a/sys-freebsd/freebsd-share/files/freebsd-share-10.3-gentoo-skel.patch b/sys-freebsd/freebsd-share/files/freebsd-share-10.3-gentoo-skel.patch
new file mode 100644
index 000000000000..79e29e989e2a
--- /dev/null
+++ b/sys-freebsd/freebsd-share/files/freebsd-share-10.3-gentoo-skel.patch
@@ -0,0 +1,20 @@
+diff --git a/share/skel/Makefile b/share/skel/Makefile
+index 024985c..6f6e563 100644
+--- a/share/skel/Makefile
++++ b/share/skel/Makefile
+@@ -2,11 +2,11 @@
+ # $FreeBSD: stable/10/share/skel/Makefile 291794 2015-12-04 18:21:05Z bdrewery $
+
+ FILESGROUPS= FILES1 FILES2
+-FILES1= dot.cshrc dot.login dot.login_conf dot.mailrc dot.profile \
++FILES1= dot.login_conf dot.mailrc \
+ dot.shrc
+-FILES2= dot.mail_aliases dot.rhosts
+-FILES1DIR= ${SHAREDIR}/skel
+-FILES2DIR= ${SHAREDIR}/skel
++FILES2= dot.mail_aliases
++FILES1DIR= /etc/skel
++FILES2DIR= /etc/skel
+ FILES1MODE= 0644
+ FILES2MODE= 0600
+ NO_OBJ=
diff --git a/sys-freebsd/freebsd-share/files/freebsd-share-SA-1808-tcp-11.patch b/sys-freebsd/freebsd-share/files/freebsd-share-SA-1808-tcp-11.patch
new file mode 100644
index 000000000000..b7d2a750c789
--- /dev/null
+++ b/sys-freebsd/freebsd-share/files/freebsd-share-SA-1808-tcp-11.patch
@@ -0,0 +1,23 @@
+--- share/man/man4/tcp.4.orig
++++ share/man/man4/tcp.4
+@@ -445,6 +445,20 @@
+ Reseeding should not be necessary, and will break
+ .Dv TIME_WAIT
+ recycling for a few minutes.
++.It Va reass.cursegments
++The current total number of segments present in all reassembly queues.
++.It Va reass.maxsegments
++The maximum limit on the total number of segments across all reassembly
++queues.
++The limit can be adjusted as a tunable.
++.It Va reass.maxqueuelen
++The maximum number of segments allowed in each reassembly queue.
++By default, the system chooses a limit based on each TCP connection's
++receive buffer size and maximum segment size (MSS).
++The actual limit applied to a session's reassembly queue will be the lower of
++the system-calculated automatic limit and the user-specified
++.Va reass.maxqueuelen
++limit.
+ .It Va rexmit_min , rexmit_slop
+ Adjust the retransmit timer calculation for
+ .Tn TCP .
diff --git a/sys-freebsd/freebsd-share/files/freebsd-share-SA-1810-ip.patch b/sys-freebsd/freebsd-share/files/freebsd-share-SA-1810-ip.patch
new file mode 100644
index 000000000000..1fee32f348b6
--- /dev/null
+++ b/sys-freebsd/freebsd-share/files/freebsd-share-SA-1810-ip.patch
@@ -0,0 +1,113 @@
+--- share/man/man4/inet.4.orig
++++ share/man/man4/inet.4
+@@ -28,7 +28,7 @@
+ .\" From: @(#)inet.4 8.1 (Berkeley) 6/5/93
+ .\" $FreeBSD$
+ .\"
+-.Dd Feb 4, 2016
++.Dd August 14, 2018
+ .Dt INET 4
+ .Os
+ .Sh NAME
+@@ -229,15 +229,38 @@
+ cycle greatly.
+ Default is 0 (sequential IP IDs).
+ IPv6 flow IDs and fragment IDs are always random.
++.It Va ip.maxfrags
++Integer: maximum number of fragments the host will accept and simultaneously
++hold across all reassembly queues in all VNETs.
++If set to 0, reassembly is disabled.
++If set to -1, this limit is not applied.
++This limit is recalculated when the number of mbuf clusters is changed.
++This is a global limit.
+ .It Va ip.maxfragpackets
+-Integer: maximum number of fragmented packets the host will accept and hold
+-in the reassembling queue simultaneously.
+-0 means that the host will not accept any fragmented packets.
+-\-1 means that the host will accept as many fragmented packets as it receives.
++Integer: maximum number of fragmented packets the host will accept and
++simultaneously hold in the reassembly queue for a particular VNET.
++0 means that the host will not accept any fragmented packets for that VNET.
++\-1 means that the host will not apply this limit for that VNET.
++This limit is recalculated when the number of mbuf clusters is changed.
++This is a per-VNET limit.
++.It Va ip.maxfragbucketsize
++Integer: maximum number of reassembly queues per bucket.
++Fragmented packets are hashed to buckets.
++Each bucket has a list of reassembly queues.
++The system must compare the incoming packets to the existing reassembly queues
++in the bucket to find a matching reassembly queue.
++To preserve system resources, the system limits the number of reassembly
++queues allowed in each bucket.
++This limit is recalculated when the number of mbuf clusters is changed or
++when the value of
++.Va ip.maxfragpackets
++changes.
++This is a per-VNET limit.
+ .It Va ip.maxfragsperpacket
+ Integer: maximum number of fragments the host will accept and hold
+-in the reassembling queue for a packet.
+-0 means that the host will not accept any fragmented packets.
++in the reassembly queue for a packet.
++0 means that the host will not accept any fragmented packets for the VNET.
++This is a per-VNET limit.
+ .El
+ .Sh SEE ALSO
+ .Xr ioctl 2 ,
+--- share/man/man4/inet6.4.orig
++++ share/man/man4/inet6.4
+@@ -29,7 +29,7 @@
+ .\"
+ .\" $FreeBSD$
+ .\"
+-.Dd September 2, 2009
++.Dd August 14, 2018
+ .Dt INET6 4
+ .Os
+ .Sh NAME
+@@ -219,12 +219,41 @@
+ This value applies to all the transport protocols on top of
+ .Tn IPv6 .
+ There are APIs to override the value.
++.It Dv IPV6CTL_MAXFRAGS
++.Pq ip6.maxfrags
++Integer: maximum number of fragments the host will accept and simultaneously
++hold across all reassembly queues in all VNETs.
++If set to 0, fragment reassembly is disabled.
++If set to -1, this limit is not applied.
++This limit is recalculated when the number of mbuf clusters is changed.
++This is a global limit.
+ .It Dv IPV6CTL_MAXFRAGPACKETS
+ .Pq ip6.maxfragpackets
+-Integer: default maximum number of fragmented packets the node will accept.
+-0 means that the node will not accept any fragmented packets.
+--1 means that the node will accept as many fragmented packets as it receives.
+-The flag is provided basically for avoiding possible DoS attacks.
++Integer: maximum number of fragmented packets the node will accept and
++simultaneously hold in the reassembly queue for a particular VNET.
++0 means that the node will not accept any fragmented packets for that VNET.
++-1 means that the node will not apply this limit for that VNET.
++This limit is recalculated when the number of mbuf clusters is changed.
++This is a per-VNET limit.
++.It Dv IPV6CTL_MAXFRAGBUCKETSIZE
++.Pq ip6.maxfragbucketsize
++Integer: maximum number of reassembly queues per bucket.
++Fragmented packets are hashed to buckets.
++Each bucket has a list of reassembly queues.
++The system must compare the incoming packets to the existing reassembly queues
++in the bucket to find a matching reassembly queue.
++To preserve system resources, the system limits the number of reassembly
++queues allowed in each bucket.
++This limit is recalculated when the number of mbuf clusters is changed or
++when the value of
++.Va ip6.maxfragpackets
++changes.
++This is a per-VNET limit.
++.It Dv IPV6CTL_MAXFRAGSPERPACKET
++.Pq ip6.maxfragsperpacket
++Integer: maximum number of fragments the host will accept and hold in the
++ressembly queue for a packet.
++This is a per-VNET limit.
+ .It Dv IPV6CTL_ACCEPT_RTADV
+ .Pq ip6.accept_rtadv
+ Boolean: the default value of a per-interface flag to
diff --git a/sys-freebsd/freebsd-share/freebsd-share-11.1.ebuild b/sys-freebsd/freebsd-share/freebsd-share-11.1.ebuild
new file mode 100644
index 000000000000..27899c51835f
--- /dev/null
+++ b/sys-freebsd/freebsd-share/freebsd-share-11.1.ebuild
@@ -0,0 +1,118 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd
+
+DESCRIPTION="FreeBSD shared tools/files"
+SLOT="0"
+LICENSE="BSD zfs? ( CDDL )"
+
+IUSE="doc usb zfs"
+
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64-fbsd ~x86-fbsd"
+fi
+
+EXTRACTONLY="
+ share/
+ contrib/
+ gnu/
+ usr.bin/
+ usr.sbin/
+ sbin/
+ bin/
+ lib/
+ etc/
+ tools/tools/locale/
+"
+
+DEPEND="=sys-freebsd/freebsd-mk-defs-${RV}*
+ =sys-freebsd/freebsd-sources-${RV}*"
+RDEPEND="sys-apps/miscfiles"
+
+RESTRICT="strip"
+
+S="${WORKDIR}/share"
+
+pkg_setup() {
+ # Add the required source files.
+ use zfs && EXTRACTONLY+="cddl/ "
+
+ use doc || mymakeopts="${mymakeopts} WITHOUT_SHAREDOCS= "
+ use usb || mymakeopts="${mymakeopts} WITHOUT_USB= "
+ use zfs || mymakeopts="${mymakeopts} WITHOUT_CDDL= "
+
+ has_version "<sys-freebsd/freebsd-ubin-10.1" && mymakeopts="${mymakeopts} WITHOUT_VT= "
+ has_version "<sys-freebsd/freebsd-ubin-11.0" && mymakeopts="${mymakeopts} WITHOUT_LOCALES= "
+ has_version "<sys-freebsd/freebsd-lib-9.1-r11" && mymakeopts="${mymakeopts} WITHOUT_ICONV= "
+
+ mymakeopts="${mymakeopts} WITHOUT_SENDMAIL= WITHOUT_CLANG= "
+}
+
+REMOVE_SUBDIRS="mk termcap zoneinfo tabset"
+
+PATCHES=( "${FILESDIR}/${PN}-10.3-gentoo-skel.patch"
+ "${FILESDIR}/${PN}-10.0-gentoo-eapi3.patch"
+ "${FILESDIR}/${PN}-10.2-gnu-miscfiles.patch" )
+
+src_prepare() {
+ # Remove make.conf manpage as it describes bsdmk's make.conf.
+ sed -i -e 's:make.conf.5::' "${S}/man/man5/Makefile"
+ # Remove rc.conf manpage as it describes bsd's rc.conf.
+ sed -i -e 's:\brc.conf.5::' "${S}/man/man5/Makefile"
+ sed -i -e 's:\brc.conf.local.5::' "${S}/man/man5/Makefile"
+ # Remove mailer.conf manpage
+ sed -i -e 's:mailer.conf.5::' "${S}/man/man5/Makefile"
+ # Remove pbm and moduli(ssh) manpages
+ sed -i -e 's:pbm.5::' -e 's:moduli.5::' "${S}/man/man5/Makefile"
+ # Remove builtins manpage
+ sed -i -e '/builtins\.1/d' "${S}/man/man1/Makefile"
+ # Remove rc manpages
+ sed -i -e '/rc.8/d' "${S}/man/man8/Makefile"
+ # Remove hv_kvp_daemon.8 manpage. It's provided by freebsd-usbin.
+ sed -i -e '/hv_kvp_daemon.8/d' "${S}/man/man8/Makefile"
+
+ # Don't install the arch-specific directories in subdirectories
+ sed -i -e '/MANSUBDIR/d' "${S}"/man/man4/man4.{i386,sparc64}/Makefile
+
+ # Remove them so that they can't be included by error
+ rm -rf "${S}"/mk/*.mk
+
+ # Make proper symlinks by defining the full target.
+ local sdir
+ for sdir in colldef monetdef msgdef numericdef timedef
+ do
+ sed -e 's:\${enc2}$:\${enc2}/\${FILESNAME}:g' -i \
+ "${S}/${sdir}/Makefile" || \
+ die "Error fixing ${sdir}/Makefile"
+ done
+ if [[ ! -e "${WORKDIR}/sys" ]]; then
+ ln -s "/usr/src/sys" "${WORKDIR}/sys" || die "failed to set sys symlink"
+ fi
+}
+
+src_compile() {
+ export ESED="/usr/bin/sed"
+
+ # libiconv support.
+ if ! has_version "<sys-freebsd/freebsd-lib-9.1-r11" ; then
+ # i18n/csmapper/APPLE requires mkcsmapper_static
+ # i18n/esdb/APPLE requires mkesdb_static
+ for pkg in mkcsmapper_static mkesdb_static
+ do
+ cd "${WORKDIR}"/usr.bin/${pkg} || die
+ freebsd_src_compile
+ done
+ fi
+
+ # This is a groff problem and not a -shared problem.
+ cd "${S}" || die
+ export GROFF_TMAC_PATH="/usr/share/tmac/:/usr/share/groff/1.22.2/tmac/"
+ freebsd_src_compile -j1 || die "emake failed"
+}
+
+src_install() {
+ freebsd_src_install -j1 DOCDIR=/usr/share/doc/${PF}
+}
diff --git a/sys-freebsd/freebsd-share/freebsd-share-11.1_p1.ebuild b/sys-freebsd/freebsd-share/freebsd-share-11.1_p1.ebuild
new file mode 100644
index 000000000000..a8b673e53ec3
--- /dev/null
+++ b/sys-freebsd/freebsd-share/freebsd-share-11.1_p1.ebuild
@@ -0,0 +1,122 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd
+
+DESCRIPTION="FreeBSD shared tools/files"
+SLOT="0"
+LICENSE="BSD zfs? ( CDDL )"
+
+IUSE="doc usb zfs"
+
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64-fbsd ~x86-fbsd"
+fi
+
+EXTRACTONLY="
+ share/
+ contrib/
+ gnu/
+ usr.bin/
+ usr.sbin/
+ sbin/
+ bin/
+ lib/
+ etc/
+ tools/tools/locale/
+"
+
+DEPEND="=sys-freebsd/freebsd-mk-defs-${RV}*
+ =sys-freebsd/freebsd-sources-${RV}*"
+RDEPEND="sys-apps/miscfiles"
+
+RESTRICT="strip"
+
+S="${WORKDIR}/share"
+
+pkg_setup() {
+ # Add the required source files.
+ use zfs && EXTRACTONLY+="cddl/ "
+
+ use doc || mymakeopts="${mymakeopts} WITHOUT_SHAREDOCS= "
+ use usb || mymakeopts="${mymakeopts} WITHOUT_USB= "
+ use zfs || mymakeopts="${mymakeopts} WITHOUT_CDDL= "
+
+ has_version "<sys-freebsd/freebsd-ubin-10.1" && mymakeopts="${mymakeopts} WITHOUT_VT= "
+ has_version "<sys-freebsd/freebsd-ubin-11.0" && mymakeopts="${mymakeopts} WITHOUT_LOCALES= "
+ has_version "<sys-freebsd/freebsd-lib-9.1-r11" && mymakeopts="${mymakeopts} WITHOUT_ICONV= "
+
+ mymakeopts="${mymakeopts} WITHOUT_SENDMAIL= WITHOUT_CLANG= "
+}
+
+REMOVE_SUBDIRS="mk termcap zoneinfo tabset"
+
+PATCHES=(
+ "${FILESDIR}/${PN}-10.3-gentoo-skel.patch"
+ "${FILESDIR}/${PN}-10.0-gentoo-eapi3.patch"
+ "${FILESDIR}/${PN}-10.2-gnu-miscfiles.patch"
+ "${FILESDIR}/${PN}-SA-1808-tcp-11.patch"
+ "${FILESDIR}/${PN}-SA-1810-ip.patch"
+)
+
+src_prepare() {
+ # Remove make.conf manpage as it describes bsdmk's make.conf.
+ sed -i -e 's:make.conf.5::' "${S}/man/man5/Makefile"
+ # Remove rc.conf manpage as it describes bsd's rc.conf.
+ sed -i -e 's:\brc.conf.5::' "${S}/man/man5/Makefile"
+ sed -i -e 's:\brc.conf.local.5::' "${S}/man/man5/Makefile"
+ # Remove mailer.conf manpage
+ sed -i -e 's:mailer.conf.5::' "${S}/man/man5/Makefile"
+ # Remove pbm and moduli(ssh) manpages
+ sed -i -e 's:pbm.5::' -e 's:moduli.5::' "${S}/man/man5/Makefile"
+ # Remove builtins manpage
+ sed -i -e '/builtins\.1/d' "${S}/man/man1/Makefile"
+ # Remove rc manpages
+ sed -i -e '/rc.8/d' "${S}/man/man8/Makefile"
+ # Remove hv_kvp_daemon.8 manpage. It's provided by freebsd-usbin.
+ sed -i -e '/hv_kvp_daemon.8/d' "${S}/man/man8/Makefile"
+
+ # Don't install the arch-specific directories in subdirectories
+ sed -i -e '/MANSUBDIR/d' "${S}"/man/man4/man4.{i386,sparc64}/Makefile
+
+ # Remove them so that they can't be included by error
+ rm -rf "${S}"/mk/*.mk
+
+ # Make proper symlinks by defining the full target.
+ local sdir
+ for sdir in colldef monetdef msgdef numericdef timedef
+ do
+ sed -e 's:\${enc2}$:\${enc2}/\${FILESNAME}:g' -i \
+ "${S}/${sdir}/Makefile" || \
+ die "Error fixing ${sdir}/Makefile"
+ done
+ if [[ ! -e "${WORKDIR}/sys" ]]; then
+ ln -s "/usr/src/sys" "${WORKDIR}/sys" || die "failed to set sys symlink"
+ fi
+}
+
+src_compile() {
+ export ESED="/usr/bin/sed"
+
+ # libiconv support.
+ if ! has_version "<sys-freebsd/freebsd-lib-9.1-r11" ; then
+ # i18n/csmapper/APPLE requires mkcsmapper_static
+ # i18n/esdb/APPLE requires mkesdb_static
+ for pkg in mkcsmapper_static mkesdb_static
+ do
+ cd "${WORKDIR}"/usr.bin/${pkg} || die
+ freebsd_src_compile
+ done
+ fi
+
+ # This is a groff problem and not a -shared problem.
+ cd "${S}" || die
+ export GROFF_TMAC_PATH="/usr/share/tmac/:/usr/share/groff/1.22.2/tmac/"
+ freebsd_src_compile -j1 || die "emake failed"
+}
+
+src_install() {
+ freebsd_src_install -j1 DOCDIR=/usr/share/doc/${PF}
+}
diff --git a/sys-freebsd/freebsd-share/metadata.xml b/sys-freebsd/freebsd-share/metadata.xml
new file mode 100644
index 000000000000..a470eb89458a
--- /dev/null
+++ b/sys-freebsd/freebsd-share/metadata.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <maintainer type="project">
+ <email>bsd@gentoo.org</email>
+ <name>BSD Project</name>
+ </maintainer>
+ <use>
+ <flag name="zfs">Enable ZFS support.</flag>
+ </use>
+</pkgmetadata>
diff --git a/sys-freebsd/freebsd-sources/Manifest b/sys-freebsd/freebsd-sources/Manifest
new file mode 100644
index 000000000000..31cdb3a0f260
--- /dev/null
+++ b/sys-freebsd/freebsd-sources/Manifest
@@ -0,0 +1,27 @@
+AUX config-GENTOO 73 BLAKE2B fbe623f265438162db2f20edd9281752eee65fb3b55412b1427321668bf405f1d04523ba23959c0bf17742ca0128eebe71575827430434418a5724c89d4f8c02 SHA512 436e1e1cb4077488cd1e054a96598c1c6dc2fda5c060d2d6c1bf2986b534016c86ea2afee0dcf883b4bde6946625596ea474a273013b18fdfa5538ebcfe6ea54
+AUX freebsd-sources-10.1-gcc48.patch 452 BLAKE2B d1d9efc7be5bed287bbc2c9b05dc2db5a22671932ec01e436c2cd8fcd4ac6f5ce1584bc0faf64597787291bd9c4c26526bf0f8050de5d748a3a9af8d85c600f9 SHA512 55e5249ec8337d880d96fd9429a0ffe5663c6182996b6b2ab8d19fe9d5168a0042b81222b2bb89de6d90f98d042b593fb40a7f4178ac739f681f84c2d62b5c96
+AUX freebsd-sources-11.0-gentoo-gcc.patch 430 BLAKE2B fadee46d0d675fe69d256d93c287f0cc11cfce7e9c7a5ba0e3bb7e51155ab1b8766df3508fc5672db10b8849fecb0cb1f32e4d2fa64e68ecd50f08b1d58bd9c2 SHA512 9869ba13091cc0975a7fe1a1b18a279835d19f1f57204dd3463798d3695a250ba6c96f2c1f6a2352dfce0022d7365257b0f938032b55e7090f68e58c4455bffe
+AUX freebsd-sources-11.0-gentoo.patch 852 BLAKE2B 81306d42748674cf550d5399a1ab02f183f2db82e1247a5d79acae77fee459a8f1a5265bc54a0d94f3310f1758e9bc97855b22c1c58d4f54cb573fcc9a8de6b7 SHA512 11f65627bb5436052b227d884c384e888bb8f44696c36b80a8715c912e41c953b57c1420b37030155c2751c72289470c4f681d14ed149e4f6aa82d8b63766ade
+AUX freebsd-sources-6.0-flex-2.5.31.patch 826 BLAKE2B 7644dccfb8ad6242c903fb0d5d81601c9ab395628a1cfdc299a31575db4ea6656ac1d3e6c15c751e96a7ce384909e95a90928b3cd1caa9de7d926a3ad9682092 SHA512 7183b1923019df12849e7d3984c4227d65275077cf95c3b0719b99dc852234eb3813db0e69e9c34bdfca45a59f7340209211d0b7a2a5074c2d1ad8ea0a3a3f64
+AUX freebsd-sources-7.1-includes.patch 318 BLAKE2B e95da1360824b9a5037bf55deda2d92a72a08e0e42f8ecd4080863bed69f10137b2c2637bafbe1088fe6bf2bfed7f83a748cab42a14b41b7243efd524ae15589 SHA512 f73db3fd72bdd2972ae25c3f661e7677bd5877aa623981303a4b0c5e9522fd458e294799a0ebad17ac3c639d588394b10ad5fcab4d88743a6dfcc8a8d60eecd7
+AUX freebsd-sources-8.0-subnet-route-pr40133.patch 548 BLAKE2B 2c783822d71de3633c5b914a38d1a80b9afd4a5e4335ac9a01da605306c8d0f5605970f808d9b7c93e9853a7b741eaec8f0b1701602160761404558eaf93f680 SHA512 9ae65e2775302b664dd4e5f5cbc58fe1ca7db61b6182db10971660207c72ec74e542181f1c2aefcacd2fd4b54e10d371efc619c3c03a977c35d3cf67b99b7de5
+AUX freebsd-sources-9.0-disable-optimization.patch 927 BLAKE2B 42fff42c4d1bc57aed5c4b4dc30328f8ac3317f36cb3b4df60690e5ce9e3ef19d2a1b6a8e35082aad6c43283b47af8df6c94912710d55fc925e2eae08d275459 SHA512 0b74874d42eab95994309b922f37ebbf3706d01db6c447c9f062b03e64b77c7f793bc297150b539acdf39530a8afd91f4bf824a87c674dd625a59056656c614b
+AUX freebsd-sources-9.0-sysctluint.patch 403 BLAKE2B 3860821b308a75dcad8fa5910cb6c287ca2013269d21b588d0abbb1a79197366eac7eb733c87136f77ba2556913f36784842ac5f089d5c9bdb59bdb836748049 SHA512 f3a87cb187858bc6fd1bafda3c3bd7bbda52b07239a50a7c1aa201df2c52a58d4809e196b8799b1949c8ca1a556519d454ad1789358540e3a96cd480fc0a504c
+DIST freebsd-sources-11.1_p3-patchset.tar.xz 36348 BLAKE2B b88f8a0f0bfde97a0416967c76ffb1d8fcb3f9050d69caa83941ab38e289622a9a5d25887e895d364f333980f7ab21af454d6fbe48157119279b4a0b600856ff SHA512 c981eee806ad93ebc720434789da1ae38f21a131ec8f92c3e55dab4e5fbc61e225c615132bb971e2b9bf4bc6922b2c7bdd9117644e8ba6547c20857deea0bbc1
+DIST freebsd-sources-EN-1707-vnet.patch 356 BLAKE2B 6e586e8cc767c0f177b6f1175512c4d5bd4fdf9abb94b644348dbe8b681d4838bdba8c83496ae351fb075329fed4e270bdd8768ce63e8c99fc69ba36d3040d8c SHA512 2fdb58388acb98811588beeabaf8a533926f96ac3f594f53dd80dcdb38ede4fe0dd66f0dd7bb32b40a27f756e2b03fed91c4416cbdcd4c16dd8143f5438885d7
+DIST freebsd-sources-EN-1708-pf.patch 706 BLAKE2B 7b812c1d696f2a1ab6e648228fe4fce8b8e32f57ed8dc713b24db5dacca70e693ee24001f0db168d79c528e2c20c6011ac423629a807949757e9f468969c3127 SHA512 e9dc61ff10aafb9b92721c599577ce995458b8a1a93b31fc6cc39b910db2b8f965ff0354a45bf82d2d57abba7aa0bf6d2f002044d242e19121d5ee4cd7a1dc15
+DIST freebsd-sources-EN-1804-mem.11.patch 2932 BLAKE2B 41eb2445cbc9a339f21b64ae0aa64b477c6691540236b8b3c378475fa3f451b35f3e9793eae240f15364b39b0a9fda0971c92f4dadb0933c103a933db154a718 SHA512 feb22d2cc614c0fc80eea5410894a9f0c091ec77e01810fe1476a8702624331e3a45d44e1de15945586dfa0a334a12442f46e61ad148fa555e4900d486f79185
+DIST freebsd-sources-EN-1805-mem.11.1.patch 4106 BLAKE2B 598b12547f66e1cb3b915878bb37f73c6a028655f78cb50f8fb113af4c0a31f6ba82f884de4b79151b6512bc67aa8a2cc404c5bce6ffcf07dada37426eb5082c SHA512 ec80584da7ba7f6d0b6039b9a4acb151b18fcf5671a805c52911a97fc53cc5bcc5cfe427d37f91fcb130f437a134eed7d746b652131591fc28986d18d5b3a48c
+DIST freebsd-sources-EN-1807-pmap.patch 1639 BLAKE2B 437379a0471f1c36dcebfcce471d1e65426773c96a18ad4f4272c3617cecedce45b6a09a518a45947b36d1e1d47aa485839f24fa24d4b8dea14fd9f7fb5b480f SHA512 f3a482fc573ccee1ed779a3fc4bbd5c54a0a93395ca83e4e5b36293ce3b298545b4f9e1bb91c557d00d89890a2ef3c425e966077de4fccdb670059519bb75b44
+DIST freebsd-sources-SA-1708-ptrace.patch 696 BLAKE2B d040de29c3aca8fbc5d837c574e5ee81196ba41f1a90720579e854ba4e9786e23545547892d4e6d90c850161a53aaef7de014cbb918c45a261aea56b02cd2d7b SHA512 973bfe4e594fe34340ae723b3451a1b84a9877b51e1e14e8cd0a9944bec5bc4efec6ff39ba61998c1da1f2c2df0fe17272b3dad2e2cc3880cfa0ff6017d2730e
+DIST freebsd-sources-SA-1710-kldstat.patch 2155 BLAKE2B e2c47d72a4a497283d7def916cdf0991b5ec791f545736474db18301866362b3c96f0a4ac5e7c1c2a91535961ac048e5e1c1e7ad10d10ced3dba954453a04ef5 SHA512 a5cc0acfcac8401fb4066fd5bfbaa1c5718a38f05877b8fb1c5a9cce1df9af4a82bd1c263c80c2b58ad058349753dcec9c4aa13bdb178f3b80493785badc65a4
+DIST freebsd-sources-SA-1801-ipsec-11.patch 1153 BLAKE2B bc7b0fb85a5d03873cf8dc61c2478b450167f8d0d5f9094c14cf9a3647a9d1ecdee8245ba45e70270aa95e21f112a0c10978a57b41ecbafa0a5392c101bef4b0 SHA512 034777a8f5bacd73ae989747bdb1669747d7af0e1655cb033e95068a2318063301b05a2ddbb3debbfd32f938c77bef1614535b6a667a511bf3f0287fb6e1667c
+DIST freebsd-sources-SA-1804-vt.patch 640 BLAKE2B 2cf3dcecfac7b33136c47c5fad23840c98c19ae7690fdd6520eacb4779d3101a615a1416c5337a0fe740cc56d7ea19ed4de9481ccced73a5322610950637fecb SHA512 461ca668363f1b334b626b7256830d1abe249d8c76417e524a366a2643676c8681127cd8c326dfe7cd1b1ee3ad67fb4819f08fd2a2db9b5b7a108171e8777a5b
+DIST freebsd-sources-SA-1805-ipsec.patch 3182 BLAKE2B 43c7e5b80a4b552c167efcca392fc1ec5d6aed3c425d081a63b9e221aed92f891674fc6f9b17805e449c806422d4b8624e773e4b463d50b51ec629197a014004 SHA512 116d9a6d67452863e5dc12124ad3bad4a29c472755235e65f97f474e048ba7f9a4711d0f73d1301072aa31281d3f444fded4b6e429e4f28367c713708402d33a
+DIST freebsd-sources-SA-1806-debugreg.11.1.patch 10505 BLAKE2B 1071869efe163bcba8b118cde3eb85a5a3cf31f589f270735b63d9f670a12d17fcf4bca297d266c5d8a89e73ee20abaf0ef0193a1d9d5cbce934e34946cee827 SHA512 06386a69b386f05ecb115d8dd511ca2afa6b8fe18290eab92357b111e62277b7180ea116620ce854a12ae6f42f997a0d57db8c7fdeb42584f8711c23ab50db44
+DIST freebsd-sources-SA-1807-lazyfpu-11.patch 10024 BLAKE2B 0dfa6e0a86d6227230a686963f80dbc4c512486471c02577d769110899e74e8064f3cdab45afb29a8283bf9423bd521c085d70174560361529b21fddea1787a6 SHA512 932cead50235a77b8bb0a41b600e7bb1722dd5b5d95601d30041a953b0c1a6a421d794138f1b6adfcb71e5e1904f09288e8ec3a8ce7f9c879ad8d9c77ffdb162
+DIST freebsd-sources-SA-1809-l1tf-11.1.patch 5357 BLAKE2B f7b93d61a63827908afc66fd5f28b15c4e951a7f50038eba92f7d3b824c771fb22fc6ea4e55316c0565ac73e2f27af0f39a189a7ee3f8914ed4d87819208959d SHA512 9920f43f5cf26bc72b7cb704276073a1f44a57dec340cdd369d119465d3f4a6585fa760d164c246c101f629af30d74c249b2892e5b25f17534a1d7caff98263c
+DIST freebsd-src-11.1.tar.xz 147661560 BLAKE2B a9e6ba9d0e12c8b56ac58575d5f02931edbb6a3545d9dccae78810d2d0470a29b29dd7f724b03b8afafbca23717a71346e4cfbd3530e0f40118a23609c3f414e SHA512 b97707ec7a601ca6bcb682c45f6d94a38484301ac24630d7285eff6f88b027ce6900c93fc62f8ce36e0cf32c91f73a9d1c999db397b7f8782fd74a8551a03aca
+EBUILD freebsd-sources-11.1_p2.ebuild 4594 BLAKE2B b4861bdab72dcfbaaadccacd98efabada77878264140e35428acbe427e17a9d56edda10c5275bb7abcc9107badfe010fa642bcc1bf760e02241b4da6c9644887 SHA512 a700daa8edbfc20f6aa9e82288529f613bc2134ed5dab624d0aba56b4189b78a680ec3a13110d7e4aa15471c4133651ce4472096ae242c772a73faa953df10ab
+EBUILD freebsd-sources-11.1_p3.ebuild 5306 BLAKE2B 30bd04cd1b97c778c07cfa8059be9737d1fe05bac0b6f7af7b5182524ffb026f3f1217d755db53cb7d0efe15c6bc487bd145833df4239f86e324d4025065b8c0 SHA512 695422cbf5270ab90aa8c93a8ce4b467746a2132720018c286284b525f02f2b88b89ea8310c508f002b89d5047e93cc351e38cf5da9edc7dc36d3e6115466ae7
+MISC metadata.xml 444 BLAKE2B 26160b0d71ed4eb333357e7d3d5fd131038abfeb50db42107cabab63fe2123cc9d495d53a33bc8fea3622dee7994076c57163ab9904c452c1d3bbdad569481b9 SHA512 9e2abef67d9a4092a62f92a0b32e5d8547a046d26551ef15c577dedf3b56231ba055702a7476104993a8ed15717b5610d1cdbd6c167b0571a84392f41f177cdc
diff --git a/sys-freebsd/freebsd-sources/files/config-GENTOO b/sys-freebsd/freebsd-sources/files/config-GENTOO
new file mode 100644
index 000000000000..7c7eb26cccc2
--- /dev/null
+++ b/sys-freebsd/freebsd-sources/files/config-GENTOO
@@ -0,0 +1,4 @@
+# Kernel configuration for Gentoo/FreeBSD.
+include GENERIC
+ident GENTOO
+
diff --git a/sys-freebsd/freebsd-sources/files/freebsd-sources-10.1-gcc48.patch b/sys-freebsd/freebsd-sources/files/freebsd-sources-10.1-gcc48.patch
new file mode 100644
index 000000000000..5cb4cf809b12
--- /dev/null
+++ b/sys-freebsd/freebsd-sources/files/freebsd-sources-10.1-gcc48.patch
@@ -0,0 +1,18 @@
+https://svnweb.freebsd.org/base?view=revision&revision=281606
+
+diff --git a/sys/crypto/aesni/aesencdec.h b/sys/crypto/aesni/aesencdec.h
+index d4ed8b3..79847ee 100644
+--- a/sys/crypto/aesni/aesencdec.h
++++ b/sys/crypto/aesni/aesencdec.h
+@@ -27,6 +27,11 @@
+ *
+ */
+
++#if defined(__GNUC__) && defined(_KERNEL)
++/* Suppress inclusion of gcc's mm_malloc.h header */
++#define _MM_MALLOC_H_INCLUDED 1
++#endif
++
+ #include <wmmintrin.h>
+
+ static inline void
diff --git a/sys-freebsd/freebsd-sources/files/freebsd-sources-11.0-gentoo-gcc.patch b/sys-freebsd/freebsd-sources/files/freebsd-sources-11.0-gentoo-gcc.patch
new file mode 100644
index 000000000000..1d3c8d68a2ee
--- /dev/null
+++ b/sys-freebsd/freebsd-sources/files/freebsd-sources-11.0-gentoo-gcc.patch
@@ -0,0 +1,13 @@
+diff --git a/sys/conf/newvers.sh b/sys/conf/newvers.sh
+index e4b2ad4..411bedf 100644
+--- a/sys/conf/newvers.sh
++++ b/sys/conf/newvers.sh
+@@ -110,7 +110,7 @@ else
+ t=`date`
+ fi
+ i=`${MAKE:-make} -V KERN_IDENT`
+-compiler_v=$($(${MAKE:-make} -V CC) -v 2>&1 | grep -w 'version')
++compiler_v=$($(${MAKE:-make} -V CC) -v 2>&1 | grep 'version' | tail -n 1)
+
+ for dir in /usr/bin /usr/local/bin; do
+ if [ ! -z "${svnversion}" ] ; then
diff --git a/sys-freebsd/freebsd-sources/files/freebsd-sources-11.0-gentoo.patch b/sys-freebsd/freebsd-sources/files/freebsd-sources-11.0-gentoo.patch
new file mode 100644
index 000000000000..6acd6aab3608
--- /dev/null
+++ b/sys-freebsd/freebsd-sources/files/freebsd-sources-11.0-gentoo.patch
@@ -0,0 +1,22 @@
+diff --git a/sys/conf/kern.mk b/sys/conf/kern.mk
+index e27ea93..615dbac 100644
+--- a/sys/conf/kern.mk
++++ b/sys/conf/kern.mk
+@@ -5,7 +5,7 @@
+ #
+ CWARNFLAGS?= -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes \
+ -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual \
+- -Wundef -Wno-pointer-sign ${FORMAT_EXTENSIONS} \
++ -Wundef -Wno-pointer-sign \
+ -Wmissing-include-dirs -fdiagnostics-show-option \
+ -Wno-unknown-pragmas \
+ ${CWARNEXTRA}
+@@ -86,7 +86,7 @@ FORMAT_EXTENSIONS= -fformat-extensions
+ # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
+ #
+ .if ${MACHINE_CPUARCH} == "i386"
+-CFLAGS.gcc+= -mno-align-long-strings -mpreferred-stack-boundary=2
++CFLAGS.gcc+= -mpreferred-stack-boundary=2
+ CFLAGS.clang+= -mno-aes -mno-avx
+ CFLAGS+= -mno-mmx -mno-sse -msoft-float
+ INLINE_LIMIT?= 8000
diff --git a/sys-freebsd/freebsd-sources/files/freebsd-sources-6.0-flex-2.5.31.patch b/sys-freebsd/freebsd-sources/files/freebsd-sources-6.0-flex-2.5.31.patch
new file mode 100644
index 000000000000..88710cf69dd8
--- /dev/null
+++ b/sys-freebsd/freebsd-sources/files/freebsd-sources-6.0-flex-2.5.31.patch
@@ -0,0 +1,22 @@
+Index: fbsd-6/sys/dev/aic7xxx/aicasm/aicasm_scan.l
+===================================================================
+--- fbsd-6.orig/sys/dev/aic7xxx/aicasm/aicasm_scan.l
++++ fbsd-6/sys/dev/aic7xxx/aicasm/aicasm_scan.l
+@@ -528,7 +528,7 @@ expand_macro(struct symbol *macro_symbol
+
+ /* Put back everything up until the replacement. */
+ while (body_pos > next_match)
+- unput(*--body_pos);
++ yyunput(*--body_pos, body_head);
+
+ /* Perform the replacement. */
+ if (match_marg != NULL) {
+@@ -537,7 +537,7 @@ expand_macro(struct symbol *macro_symbol
+ next_match = match_marg->replacement_text;
+ strp = next_match + strlen(next_match);
+ while (strp > next_match)
+- unput(*--strp);
++ yyunput(*--strp, next_match);
+
+ /* Skip past the unexpanded macro arg. */
+ body_pos -= match.rm_eo - match.rm_so;
diff --git a/sys-freebsd/freebsd-sources/files/freebsd-sources-7.1-includes.patch b/sys-freebsd/freebsd-sources/files/freebsd-sources-7.1-includes.patch
new file mode 100644
index 000000000000..3db46fa1d7e3
--- /dev/null
+++ b/sys-freebsd/freebsd-sources/files/freebsd-sources-7.1-includes.patch
@@ -0,0 +1,13 @@
+Make headers usable alone, include the headers they need.
+There are probably much more missing.
+
+--- sys/net/if.h.old 2009-05-15 10:51:50 +0000
++++ sys/net/if.h 2009-05-15 10:52:05 +0000
+@@ -34,6 +34,7 @@
+ #define _NET_IF_H_
+
+ #include <sys/cdefs.h>
++#include <sys/socket.h>
+
+ #ifdef _KERNEL
+ #include <sys/queue.h>
diff --git a/sys-freebsd/freebsd-sources/files/freebsd-sources-8.0-subnet-route-pr40133.patch b/sys-freebsd/freebsd-sources/files/freebsd-sources-8.0-subnet-route-pr40133.patch
new file mode 100644
index 000000000000..a7335f6d427f
--- /dev/null
+++ b/sys-freebsd/freebsd-sources/files/freebsd-sources-8.0-subnet-route-pr40133.patch
@@ -0,0 +1,21 @@
+Fixes changing the default subnet route after removing an ip address.
+
+See: http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=40133
+and http://mail-index.netbsd.org/tech-net/2008/12/03/msg000896.html
+
+Thanks to Roy Marples.
+--- sys/netinet/in.c.orig
++++ sys/netinet/in.c
+@@ -858,6 +858,12 @@
+ error = rtinit(&target->ia_ifa, (int)RTM_ADD, flags);
+ if (!error)
+ target->ia_flags |= IFA_ROUTE;
++ else if (error == EEXIST) {
++ /*
++ * the fact that the route already exists is not an error.
++ */
++ error = 0;
++ }
+ return (error);
+ }
+
diff --git a/sys-freebsd/freebsd-sources/files/freebsd-sources-9.0-disable-optimization.patch b/sys-freebsd/freebsd-sources/files/freebsd-sources-9.0-disable-optimization.patch
new file mode 100644
index 000000000000..4824ff6e1a09
--- /dev/null
+++ b/sys-freebsd/freebsd-sources/files/freebsd-sources-9.0-disable-optimization.patch
@@ -0,0 +1,32 @@
+Taken from debian GNU/kFreeBSD.
+
+Regretably, with GCC 4.4 or later this is the only flag combination
+I could find that doesn't cause kernel panics CPU triple-faults or
+other kind of severe breakage. This is Gentoo Bug #410945.
+
+Clang can use -O2, so we do not force -O1 on it
+
+--- a/sys/conf/kern.pre.mk
++++ b/sys/conf/kern.pre.mk
+@@ -41,6 +41,9 @@
+ .if !empty(COPTFLAGS:M-O[23s]) && empty(COPTFLAGS:M-fno-strict-aliasing)
+ COPTFLAGS+= -fno-strict-aliasing
+ .endif
++.if ${CC:T:Mclang} != "clang" && !empty(COPTFLAGS:M-O[23s])
++COPTFLAGS+= -O1
++.endif
+ .if !defined(NO_CPU_COPTFLAGS)
+ COPTFLAGS+= ${_CPUCFLAGS}
+ .endif
+--- a/sys/conf/kmod.mk
++++ b/sys/conf/kmod.mk
+@@ -91,6 +91,9 @@
+ .if !empty(CFLAGS:M-O[23s]) && empty(CFLAGS:M-fno-strict-aliasing)
+ CFLAGS+= -fno-strict-aliasing
+ .endif
++.if ${CC:T:Mclang} != "clang" && !empty(CFLAGS:M-O[23s])
++CFLAGS+= -O1
++.endif
+ WERROR?= -Werror
+ CFLAGS+= ${WERROR}
+ CFLAGS+= -D_KERNEL
diff --git a/sys-freebsd/freebsd-sources/files/freebsd-sources-9.0-sysctluint.patch b/sys-freebsd/freebsd-sources/files/freebsd-sources-9.0-sysctluint.patch
new file mode 100644
index 000000000000..751a77c843bb
--- /dev/null
+++ b/sys-freebsd/freebsd-sources/files/freebsd-sources-9.0-sysctluint.patch
@@ -0,0 +1,13 @@
+u_int is defined in sys/types.h
+makes header usable alone.
+
+--- sys/sys/sysctl.h.old 2012-05-25 11:08:53.000000000 -0400
++++ sys/sys/sysctl.h 2012-05-25 11:09:16.000000000 -0400
+@@ -788,6 +788,7 @@
+ struct sysctl_req *);
+ #else /* !_KERNEL */
+ #include <sys/cdefs.h>
++#include <sys/types.h> /* for u_int */
+
+ __BEGIN_DECLS
+ int sysctl(const int *, u_int, void *, size_t *, const void *, size_t);
diff --git a/sys-freebsd/freebsd-sources/freebsd-sources-11.1_p2.ebuild b/sys-freebsd/freebsd-sources/freebsd-sources-11.1_p2.ebuild
new file mode 100644
index 000000000000..32b3d46dc935
--- /dev/null
+++ b/sys-freebsd/freebsd-sources/freebsd-sources-11.1_p2.ebuild
@@ -0,0 +1,159 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd flag-o-matic toolchain-funcs
+
+DESCRIPTION="FreeBSD kernel sources"
+SLOT="0"
+LICENSE="BSD dtrace? ( CDDL ) zfs? ( CDDL )"
+
+IUSE="+build-kernel debug dtrace zfs"
+
+# Security Advisory and Errata patches.
+UPSTREAM_PATCHES=( "SA-17:08/ptrace.patch"
+ "SA-17:10/kldstat.patch"
+ "EN-17:07/vnet.patch"
+ "EN-17:08/pf.patch" )
+
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64-fbsd ~x86-fbsd"
+ SRC_URI="${SRC_URI}
+ $(freebsd_upstream_patches)"
+fi
+
+EXTRACTONLY="sys/"
+
+RDEPEND="dtrace? ( >=sys-freebsd/freebsd-cddl-9.2_rc1 )
+ =sys-freebsd/freebsd-mk-defs-${RV}*
+ !sys-freebsd/virtio-kmod
+ !sys-fs/fuse4bsd
+ !<sys-freebsd/freebsd-sources-9.2_beta1"
+DEPEND="build-kernel? (
+ dtrace? ( >=sys-freebsd/freebsd-cddl-9.2_rc1 )
+ >=sys-freebsd/freebsd-usbin-9.1
+ =sys-freebsd/freebsd-mk-defs-${RV}*
+ )"
+
+RESTRICT="strip binchecks"
+
+S="${WORKDIR}/sys"
+
+KERN_BUILD=GENTOO
+
+PATCHES=( "${FILESDIR}/${PN}-9.0-disable-optimization.patch"
+ "${FILESDIR}/${PN}-6.0-flex-2.5.31.patch"
+ "${FILESDIR}/${PN}-8.0-subnet-route-pr40133.patch"
+ "${FILESDIR}/${PN}-7.1-includes.patch"
+ "${FILESDIR}/${PN}-9.0-sysctluint.patch"
+ "${FILESDIR}/${PN}-11.0-gentoo.patch"
+ "${FILESDIR}/${PN}-11.0-gentoo-gcc.patch"
+ "${FILESDIR}/${PN}-10.1-gcc48.patch" )
+
+pkg_setup() {
+ # Add the required source files.
+ use dtrace && EXTRACTONLY+="cddl/ "
+
+ # WITHOUT_SSP= is required to boot kernel that compiled with newer gcc, bug #477914
+ [[ $(tc-getCC) == *gcc* ]] && mymakeopts="${mymakeopts} WITHOUT_SSP= WITHOUT_FORMAT_EXTENSIONS="
+ use dtrace || mymakeopts="${mymakeopts} WITHOUT_CDDL="
+ use zfs || mymakeopts="${mymakeopts} WITHOUT_ZFS="
+}
+
+src_prepare() {
+ local conf="${S}/$(tc-arch-kernel)/conf/${KERN_BUILD}"
+
+ # This replaces the gentoover patch, it doesn't need reapply every time.
+ sed -i -e 's:^REVISION=.*:REVISION="'${PVR}'":' \
+ -e 's:^BRANCH=.*:BRANCH="Gentoo":' \
+ -e 's:^VERSION=.*:VERSION="${TYPE} ${BRANCH} ${REVISION}":' \
+ "${S}/conf/newvers.sh"
+
+ # __FreeBSD_cc_version comes from FreeBSD's gcc.
+ # on 11.0-RELEASE it's 1100001.
+ # FYI, we can get it from gnu/usr.bin/cc/cc_tools/freebsd-native.h.
+ sed -e "s:-D_KERNEL:-D_KERNEL -D__FreeBSD_cc_version=1100001:g" \
+ -i "${S}/conf/kern.pre.mk" \
+ -i "${S}/conf/kmod.mk" || die "Couldn't set __FreeBSD_cc_version"
+
+ # Remove -Werror
+ sed -e "s:-Werror:-Wno-error:g" \
+ -i "${S}/conf/kern.pre.mk" \
+ -i "${S}/conf/kmod.mk" || die
+
+ # Set the kernel configuration using USE flags.
+ cp -f "${FILESDIR}/config-GENTOO" "${conf}" || die
+ use debug || echo 'nomakeoptions DEBUG' >> "${conf}"
+ use dtrace || echo 'nomakeoptions WITH_CTF' >> "${conf}"
+
+ # hyperv fails to compile on x86-fbsd.
+ if use x86-fbsd && [[ $(tc-getCC) == *gcc* ]] ; then
+ echo 'nodevice hyperv' >> "${conf}"
+ dummy_mk modules/hyperv
+ fi
+
+ # Only used with USE=build-kernel, let the kernel build with its own flags, its safer.
+ unset LDFLAGS CFLAGS CXXFLAGS ASFLAGS KERNEL
+}
+
+src_configure() {
+ if use build-kernel ; then
+ tc-export CC
+ cd "${S}/$(tc-arch-kernel)/conf" || die
+ config ${KERN_BUILD} || die
+ fi
+}
+
+src_compile() {
+ if use build-kernel ; then
+ cd "${S}/$(tc-arch-kernel)/compile/${KERN_BUILD}" || die
+ freebsd_src_compile depend
+ freebsd_src_compile
+ else
+ einfo "Nothing to compile.."
+ fi
+}
+
+src_install() {
+ if use build-kernel ; then
+ cd "${S}/$(tc-arch-kernel)/compile/${KERN_BUILD}" || die
+ freebsd_src_install
+ rm -rf "${S}/$(tc-arch-kernel)/compile/${KERN_BUILD}"
+ cd "${S}"
+ fi
+
+ insinto "/usr/src/sys"
+ doins -r "${S}/".
+ if use dtrace ; then
+ insinto "/usr/src/cddl"
+ doins -r "${WORKDIR}/cddl/".
+ fi
+}
+
+pkg_preinst() {
+ if [[ -L "${ROOT}/usr/src/sys" ]]; then
+ einfo "/usr/src/sys is a symlink, removing it..."
+ rm -f "${ROOT}/usr/src/sys"
+ fi
+
+# if use sparc-fbsd ; then
+# ewarn "WARNING: kldload currently causes kernel panics"
+# ewarn "on sparc64. This is probably a gcc-4.1 issue, but"
+# ewarn "we need gcc-4.1 to compile the kernel correctly :/"
+# ewarn "Please compile all modules you need into the kernel"
+# fi
+
+ ewarn "If you want to manually compile (not recommended), please don't forget the following steps."
+# if ! use sparc-fbsd ; then
+# ewarn "export CC=clang"
+# ewarn "export CXX=clang++"
+# fi
+ if ! use zfs ; then
+ ewarn "export WITHOUT_CDDL="
+ ewarn "Note, Please set USE=zfs if you want to enable modules under the CDDL."
+ fi
+ if ! use dtrace && ! has_version '>=sys-freebsd/freebsd-cddl-9.2_beta1' ; then
+ ewarn "The GENERIC config requires sys-freebsd/freebsd-cddl. Please emerge it."
+ fi
+}
diff --git a/sys-freebsd/freebsd-sources/freebsd-sources-11.1_p3.ebuild b/sys-freebsd/freebsd-sources/freebsd-sources-11.1_p3.ebuild
new file mode 100644
index 000000000000..2fb9e00362f0
--- /dev/null
+++ b/sys-freebsd/freebsd-sources/freebsd-sources-11.1_p3.ebuild
@@ -0,0 +1,188 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd flag-o-matic toolchain-funcs
+
+DESCRIPTION="FreeBSD kernel sources"
+SRC_URI+="
+ https://dev.gentoo.org/~mgorny/dist/${P}-patchset.tar.xz"
+
+SLOT="0"
+LICENSE="BSD dtrace? ( CDDL ) zfs? ( CDDL )"
+
+IUSE="+build-kernel debug dtrace zfs"
+
+# Security Advisory and Errata patches.
+# (commented out patches go via FILESDIR/PATCHES)
+UPSTREAM_PATCHES=(
+ "SA-17:08/ptrace.patch"
+ "SA-17:10/kldstat.patch"
+ "EN-17:07/vnet.patch"
+ "EN-17:08/pf.patch"
+ "SA-18:01/ipsec-11.patch"
+# "SA-18:03/speculative_execution-amd64-11.patch"
+ "SA-18:04/vt.patch"
+ "SA-18:05/ipsec.patch"
+ "EN-18:04/mem.11.patch"
+ "EN-18:05/mem.11.1.patch"
+ "SA-18:06/debugreg.11.1.patch"
+ "SA-18:07/lazyfpu-11.patch"
+ "EN-18:07/pmap.patch"
+# "SA-18:08/tcp-11.patch"
+ "SA-18:09/l1tf-11.1.patch"
+# "SA-18:10/ip.patch"
+)
+
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64-fbsd ~x86-fbsd"
+ SRC_URI="${SRC_URI}
+ $(freebsd_upstream_patches)"
+fi
+
+EXTRACTONLY="sys/"
+
+RDEPEND="dtrace? ( >=sys-freebsd/freebsd-cddl-9.2_rc1 )
+ =sys-freebsd/freebsd-mk-defs-${RV}*
+ !sys-freebsd/virtio-kmod
+ !sys-fs/fuse4bsd
+ !<sys-freebsd/freebsd-sources-9.2_beta1"
+DEPEND="build-kernel? (
+ dtrace? ( >=sys-freebsd/freebsd-cddl-9.2_rc1 )
+ >=sys-freebsd/freebsd-usbin-9.1
+ =sys-freebsd/freebsd-mk-defs-${RV}*
+ )"
+
+RESTRICT="strip binchecks"
+
+S="${WORKDIR}/sys"
+
+KERN_BUILD=GENTOO
+
+PATCHES=(
+ "${FILESDIR}/${PN}-9.0-disable-optimization.patch"
+ "${FILESDIR}/${PN}-6.0-flex-2.5.31.patch"
+ "${FILESDIR}/${PN}-8.0-subnet-route-pr40133.patch"
+ "${FILESDIR}/${PN}-7.1-includes.patch"
+ "${FILESDIR}/${PN}-9.0-sysctluint.patch"
+ "${FILESDIR}/${PN}-11.0-gentoo.patch"
+ "${FILESDIR}/${PN}-11.0-gentoo-gcc.patch"
+ "${FILESDIR}/${PN}-10.1-gcc48.patch"
+
+ "${WORKDIR}/${P}-patchset/${PN}-SA-1803-speculative_execution-amd64-11.patch"
+ "${WORKDIR}/${P}-patchset/${PN}-SA-1808-tcp-11.patch"
+ "${WORKDIR}/${P}-patchset/${PN}-SA-1810-ip.patch"
+)
+
+pkg_setup() {
+ # Add the required source files.
+ use dtrace && EXTRACTONLY+="cddl/ "
+
+ # WITHOUT_SSP= is required to boot kernel that compiled with newer gcc, bug #477914
+ [[ $(tc-getCC) == *gcc* ]] && mymakeopts="${mymakeopts} WITHOUT_SSP= WITHOUT_FORMAT_EXTENSIONS="
+ use dtrace || mymakeopts="${mymakeopts} WITHOUT_CDDL="
+ use zfs || mymakeopts="${mymakeopts} WITHOUT_ZFS="
+}
+
+src_unpack() {
+ unpack "${P}-patchset.tar.xz"
+ freebsd_src_unpack
+}
+
+src_prepare() {
+ local conf="${S}/$(tc-arch-kernel)/conf/${KERN_BUILD}"
+
+ # This replaces the gentoover patch, it doesn't need reapply every time.
+ sed -i -e 's:^REVISION=.*:REVISION="'${PVR}'":' \
+ -e 's:^BRANCH=.*:BRANCH="Gentoo":' \
+ -e 's:^VERSION=.*:VERSION="${TYPE} ${BRANCH} ${REVISION}":' \
+ "${S}/conf/newvers.sh"
+
+ # __FreeBSD_cc_version comes from FreeBSD's gcc.
+ # on 11.0-RELEASE it's 1100001.
+ # FYI, we can get it from gnu/usr.bin/cc/cc_tools/freebsd-native.h.
+ sed -e "s:-D_KERNEL:-D_KERNEL -D__FreeBSD_cc_version=1100001:g" \
+ -i "${S}/conf/kern.pre.mk" \
+ -i "${S}/conf/kmod.mk" || die "Couldn't set __FreeBSD_cc_version"
+
+ # Remove -Werror
+ sed -e "s:-Werror:-Wno-error:g" \
+ -i "${S}/conf/kern.pre.mk" \
+ -i "${S}/conf/kmod.mk" || die
+
+ # Set the kernel configuration using USE flags.
+ cp -f "${FILESDIR}/config-GENTOO" "${conf}" || die
+ use debug || echo 'nomakeoptions DEBUG' >> "${conf}"
+ use dtrace || echo 'nomakeoptions WITH_CTF' >> "${conf}"
+
+ # hyperv fails to compile on x86-fbsd.
+ if use x86-fbsd && [[ $(tc-getCC) == *gcc* ]] ; then
+ echo 'nodevice hyperv' >> "${conf}"
+ dummy_mk modules/hyperv
+ fi
+
+ # Only used with USE=build-kernel, let the kernel build with its own flags, its safer.
+ unset LDFLAGS CFLAGS CXXFLAGS ASFLAGS KERNEL
+}
+
+src_configure() {
+ if use build-kernel ; then
+ tc-export CC
+ cd "${S}/$(tc-arch-kernel)/conf" || die
+ config ${KERN_BUILD} || die
+ fi
+}
+
+src_compile() {
+ if use build-kernel ; then
+ cd "${S}/$(tc-arch-kernel)/compile/${KERN_BUILD}" || die
+ freebsd_src_compile depend
+ freebsd_src_compile
+ else
+ einfo "Nothing to compile.."
+ fi
+}
+
+src_install() {
+ if use build-kernel ; then
+ cd "${S}/$(tc-arch-kernel)/compile/${KERN_BUILD}" || die
+ freebsd_src_install
+ rm -rf "${S}/$(tc-arch-kernel)/compile/${KERN_BUILD}"
+ cd "${S}"
+ fi
+
+ insinto "/usr/src/sys"
+ doins -r "${S}/".
+ if use dtrace ; then
+ insinto "/usr/src/cddl"
+ doins -r "${WORKDIR}/cddl/".
+ fi
+}
+
+pkg_preinst() {
+ if [[ -L "${ROOT}/usr/src/sys" ]]; then
+ einfo "/usr/src/sys is a symlink, removing it..."
+ rm -f "${ROOT}/usr/src/sys"
+ fi
+
+# if use sparc-fbsd ; then
+# ewarn "WARNING: kldload currently causes kernel panics"
+# ewarn "on sparc64. This is probably a gcc-4.1 issue, but"
+# ewarn "we need gcc-4.1 to compile the kernel correctly :/"
+# ewarn "Please compile all modules you need into the kernel"
+# fi
+
+ ewarn "If you want to manually compile (not recommended), please don't forget the following steps."
+# if ! use sparc-fbsd ; then
+# ewarn "export CC=clang"
+# ewarn "export CXX=clang++"
+# fi
+ if ! use zfs ; then
+ ewarn "export WITHOUT_CDDL="
+ ewarn "Note, Please set USE=zfs if you want to enable modules under the CDDL."
+ fi
+ if ! use dtrace && ! has_version '>=sys-freebsd/freebsd-cddl-9.2_beta1' ; then
+ ewarn "The GENERIC config requires sys-freebsd/freebsd-cddl. Please emerge it."
+ fi
+}
diff --git a/sys-freebsd/freebsd-sources/metadata.xml b/sys-freebsd/freebsd-sources/metadata.xml
new file mode 100644
index 000000000000..3860e8098ad6
--- /dev/null
+++ b/sys-freebsd/freebsd-sources/metadata.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+<maintainer type="project">
+ <email>bsd@gentoo.org</email>
+ <name>BSD Project</name>
+ </maintainer>
+ <use>
+ <flag name="build-kernel">Build and install a kernel (recommended).</flag>
+ <flag name="dtrace">Enable DTrace support.</flag>
+ <flag name="zfs">Enable ZFS support.</flag>
+ </use>
+</pkgmetadata>
diff --git a/sys-freebsd/freebsd-ubin/Manifest b/sys-freebsd/freebsd-ubin/Manifest
new file mode 100644
index 000000000000..93f176b85e51
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/Manifest
@@ -0,0 +1,33 @@
+AUX freebsd-ubin-10.2-bsdxml.patch 367 BLAKE2B 0a2dfc1b2646aa2c42bfa8b9a6cbd3d22d8b83b8bd252bb7faa3753390a376e8898d5155b16bba52378df304848f99a0cf3fcd141b013670f5dff8355ac0a062 SHA512 234fe495fcefaa9c36d97460da05365ff081661411451ae3d8dca83b3f8b1746450e111ac43baccd15a6c86c03c7cdd37d54d70fed551d694800dc6bca7c5e8d
+AUX freebsd-ubin-10.2-talk-workaround.patch 349 BLAKE2B c5697082af994d7f019254c19bf8ab5ab3e193d248da95de45eefd4a26b21905fbec65e507a47790b2a603d982738532383435c336ee56d27db9bd1bcbf8da4a SHA512 5eb04f1769fd4e04a26b9ff69865a6188269d971b83b7e93a5c41def44c9152e5262a192c866e3949cb3aae3b8e0a13663b8e1a438e796b0b923d9171a3e6b27
+AUX freebsd-ubin-11.0-setXid.patch 3527 BLAKE2B feccd24c34869e35dad18391687be0bec1c86b5573c40ba9c97a3faef0578031226aee817552d19d4416892896ed9e69867287744637def99c2915ff31f96f36 SHA512 204ce8a36eae6435d9549de7c45e361715fd50f721ea44aba630fdfad482bf434e8ac34c1bab588b7af2e2c941931e2aeb4690d65904d617b65ecfa7c76c4211
+AUX freebsd-ubin-11.1-fixmakefiles.patch 453 BLAKE2B 626500cab079cb0a28a375cb3415fc1ecdd3f8ae5c92f564a63420d1e1d6a7f91184d45f81b6a6ac73a2b217b6345db3789ad59c8aa15571f9d259b603f52a03 SHA512 ec3cd800596998c2bc3499a0cde45a173daf87db2af709bef1ae47e70f88a16a7af7649492e4ab96abba4d9b10b58f82e7d8cb3c2882a738ae7963677fd60f0f
+AUX freebsd-ubin-11.1-man-paths.patch 1113 BLAKE2B b0f33f24552ef98d55988cfe39284122889d7cb612f01bb1ee64396ad50dbf994ea1ec03fd17565dd8b1dff6f2e0943ea866f5a86907a93b1f098e3da87a779c SHA512 82e7ef832741589343b40f108dd2f2f75c3d15ae86c65da89744437adfd397adb9a41e71b802f8e4372c29885aacc7bd47c25ff87a37d8684aac11a22dceed4e
+AUX freebsd-ubin-6.0-bsdcmp.patch 413 BLAKE2B 3c9b81f373d1438ca97edf0b0c0339faadf04a3b73f63a9fda51618803b191bbf697a038809ead6d276c3664c309acc68186f5fc571de26334605a693442536a SHA512 1516d984e7e17e8a3474ce519c9e5d6fefaee244ad27f1ed21af73335a6a25275e842007e71a60d6b18aa049f84c87b349f3350664cea03885cd55a846a73d50
+AUX freebsd-ubin-8.0-xinstall.patch 1014 BLAKE2B 9d51cab56860e63bc79057ec910b1f5d39dc1c100e43a0f15ce4c3696da4da3366dbb13bea280fdaae2dff91e2a5d0aad2f5b7448a46d76fdfce317393db7f46 SHA512 a39843600497876287c13a10ca783041123631ef7a82501df323c6a118eb20d871fa6683b812eeebea220c4cfa1eba81450dc7de7ea08888229f326375ff285d
+AUX freebsd-ubin-9.0-fixmakefiles.patch 445 BLAKE2B 6d284099f5c52d94fe682e190cb584f3a78e475005ddc349fbf1fb690a17f87e9753fc93a27715e3815450fadb51d7ae9158308cea1aeec9e58310709474a620 SHA512 588b0e7f58504ae338b714fb324b1525ed340b56e2e99a1ebaac2606799c9ff15b8c1a05e2ddaa5dfbdc7328684917de8753d99b0c8929c056d6eb6446aa9955
+AUX freebsd-ubin-9.1-ar-libarchive3.patch 593 BLAKE2B 7ff532f2bfa1b6f70894757fd249543e479f6bc31aa2328aa9c9edcd4ea7c67666ee6cea06af616f3de9e6e86dd50b8b76d6f860aa95705abe686227423b2ffc SHA512 ece840657b425a666af495332a00a57a4c9c353187ee98747651da4ba69227bd0a58dbbdc7af860d49e0d662c9eaca046ec2f087a86c5bf282530bb9cdcf7aaa
+AUX freebsd-ubin-9.1-bsdar.patch 656 BLAKE2B 3e224819d75dbba4b11fc3cb9a493ae2467f7396ee17d9e4511414f60c53578bff8442eda82497b33b37184e1814bbd54a48197577526c335e7447f1ed09817b SHA512 88fc86fdb0ee6f757cee9b6bd55226517e6b79946f0518904bedd8176230124b40b868dee30049daa7053ea0ebe7d242dc58778e3addae2612ffd53996303bac
+AUX freebsd-ubin-9.1-grep.patch 549 BLAKE2B ccb4f86914090e93c3ab0ab7211f8075f3479d8f19afb233a09c795175aa9d24d99e6b49e2a38075bf8554af0cbb019ab5420e06a911fcc06f1d58b4d8e1bdef SHA512 2ddec1a02064ee91a177edb78a964d37b5be14c6e92a78ba9ce0a902c40f673eb7a6449042e341dfb3f31be6bef1a19fdf735af0d32526c0891fe6d9cc060101
+AUX freebsd-ubin-9.1-kdump-ioctl.patch 1001 BLAKE2B b465e3aa8658c9184ad1ab26f345edd104fe22c463baa551f61ee9c62fc9a1318ed26a659c1c7a50e7fa9c62133a92f70a1c8f46a4d0cab80911b85de50aa87e SHA512 aadf3a6d97c5822aa9ff0d1ad8a7bfb2d17fc3193851f864bcb847ef05fe5b7e2b852cb95aaf159194a12b26900697f089113ccb15854c8e3bdb43518de9adf8
+AUX freebsd-ubin-9.1-minigzip.patch 336 BLAKE2B 16b927509c96c94a60d2ea40a3b45d5a50471e447b5da918fb15fff3aae5c46fd67b675be992bdce29f5557948c6dd8314bd5191a0fbdcd49a84c38a0fbbc4ee SHA512 e25cb6b74b17ee3d999321701fcc5a90ab94abac8ea33a155847f99e7836f16203485618be3426e34a1a5895b7582f5f466f997986486637e52dbc0e6c225dd5
+AUX freebsd-ubin-lint-stdarg.patch 792 BLAKE2B 55945714219529a535af19bbc98621f89474bcf8b5649daa56b8b061f1cfd16252db881c16d72dd7e8456b0a9ed7d193e6869bead7f89298b24fe42c013fe2b0 SHA512 0f06547b0b90c65466c5c032efe6563dfd32ca56175fbad0885228310f6dc5f973d3adffe93bdb35d42b8af045ecdc23d1198fd8bad0c96c46512dbedbab3059
+AUX freebsd-ubin-setXid.patch 3723 BLAKE2B 0594701e99babe25e796b7d6a1f4ae93919135a7147cf7cad7b9a43ba7da9a6bc1bc72cf1af5b6f77532804dfb9ba29daad1119b13604ab16ce35b5a0b662f31 SHA512 9edaac765405e28b123fa40b708b1ab05af3e151726e6f2b75ab1c0fd17b6c2a428a58726da999f7a63e9550bdd3e0d274ce63517717137872a7e9c77a591501
+AUX locate-updatedb-cron 122 BLAKE2B 47f9847f8d1ca474a882cdbb24ecdda4d15f8bf24a5562df14a69de11b54f7e1d760ea39841a6d08f6effc2bc8b20fc6b1f3acfc329a04a5168beb79b44949b6 SHA512 c3127d2ebb837d7fd6edc640604ce31c1639c036703b1e923e84b79f9840e13e28327eb7a5d655546ade8efb9188b041434552bcd0b4b76308c0e66132ad7985
+AUX login.1.pamd 145 BLAKE2B 74b7fc80ccfbe63fcdedc533bff27e9f857c0c71a8429cd7f7c748ac86924e38bdeaef19ab36fa9583eeb247b49a554618622311b28bee6c71f32ac838fb0df1 SHA512 2308d818de388be2973b59fad5a21ffe5a9c9d302b47ccf1a148182ccaf082421c5a277acf0c85649874fd607a8da20222e7a05c15606ee36f6e74d0968a1397
+AUX passwd.1.pamd 145 BLAKE2B b2d0f308d79db41bf38523ff309686da8a2feac0a9173100941b54d6a04f959ccb149f9a91fb747f73cd6b39eee74e075b37061a6e01a2a5360a49a33f38b882 SHA512 89f8a8a7058c2105c71a98099ba79f7169b660633cacc7be5352622481fd0a6c82f6b5403f34bfb059f8cf524671e86d7f0031dd7c89fc98fe5d5f33986a557a
+AUX su.1.pamd 312 BLAKE2B 2142e9f4cc37bd9b2f23b11f5c221ddd1bc73b18859e90931202900ffbbc4d896fb716b3d219d583facca4602e6836a10c4f53bac09b75dedc590c56323f3da5 SHA512 f7ceb3659313197138d057a67b325fab7a304426ad7b6e8e3fbda2cae47f42a3348eaa1e5153b20626cef63da5096c60cb7f2e1904c3031d9fd13df765fc70b4
+DIST freebsd-bin-9.1.tar.bz2 385664 BLAKE2B f890e37393186ae2cddf8868d47ca8a7a5767240f02aa0d353561fd746da3c0ca57461871906481b75c8c52c9f6d45f7ea5b3c9b30f27fe81a3a64fba3085e8b SHA512 fa0571a705befe1cb9c07285d3df55c9b5f4f295760511d668d80fec8cd4d59b70c676f07164f2aa44911decef0fb54fa6d78405ac2ceec822b6b8920abc5ca8
+DIST freebsd-cddl-9.1.tar.bz2 899348 BLAKE2B 419e475b4c3debacd0d0fbbad4d1b13685c1c5ac741cc8cfb53dadce9d30cf9ddd7132ef8ab897787be538028d34bb9603eb76caf7650f4f50bb3295f19bf035 SHA512 ae0a969e710785bbcf36a2ec22cc5b1dcdb25398be951e047a1237d0c977e38fc9e05504db51f8bf9ed83bc1f68b04fc88ce18fc48a93f785b8a3f8ef481bacd
+DIST freebsd-contrib-9.1.tar.bz2 54751432 BLAKE2B 8a30e78021e6388d679637d2dbe0ed3f4896d3902064baaafa79de9c328171cbcb895b0ffd3d0d0cd3ca25c93a73584ed4900b45bd672a73b15b75721de59de5 SHA512 71be13049258c6e6b5e4f63cc16da5d349a89d68f04d87446e4ad33ae8bf2a93ea67d9c256b7bec60b61e65db0487268070cfb77a484c3ac0f8ba368b48c2438
+DIST freebsd-etc-9.1.tar.bz2 207776 BLAKE2B 61fbfa11dfcd24c007c20940a4b7cc802dfb9a991e41433840c57f113eaaa9e2b833a15f48d60c706e55d941b0a999baabd0c33197cffd522b67c57eaa9460f1 SHA512 4fbe56fde519cf2f44e39a8869efa26c34f703cf540f4a83389da8d170873d7c6fb18e4010e643b8d793cfc5c55d15eeb198057a5b2a8da9d9e8f791801bf314
+DIST freebsd-include-9.1.tar.bz2 146881 BLAKE2B 3db8570a8c841ec1c9ceff479bd0ef9b146b2a343d6596892c9d8a9f9193404f6c62712cb96d7416c6e5cc4c46e7fb942421c47e1bc2c707dde534e2050be442 SHA512 779c8315ce2b10b343bb62e331525d510b0d68ce5d665a1672bd6f4d1eff6445bc6b7a0f178b319828aa203c4e4c04c561ce793052703f4f936ce9711280a0c9
+DIST freebsd-lib-9.1.tar.bz2 3206685 BLAKE2B 67f93b7951fc03e877ee525d53b81ba49c8c1a70041c30aac97665d5dab7b3f2817fdb3bbb1475be66c33a7f996309e9020f1a3d1154fab8e2f6789f5ae0bb18 SHA512 40d0c36b6b889c404fa0e0afa38ba4e84a55bc88ffa2f98a70afbd7a32c4f32c158617ba770567d082a986d62c09b3ec8db3dc5ab853ee1c9bbe0b90bb82396e
+DIST freebsd-src-11.1.tar.xz 147661560 BLAKE2B a9e6ba9d0e12c8b56ac58575d5f02931edbb6a3545d9dccae78810d2d0470a29b29dd7f724b03b8afafbca23717a71346e4cfbd3530e0f40118a23609c3f414e SHA512 b97707ec7a601ca6bcb682c45f6d94a38484301ac24630d7285eff6f88b027ce6900c93fc62f8ce36e0cf32c91f73a9d1c999db397b7f8782fd74a8551a03aca
+DIST freebsd-sys-9.1.tar.bz2 32588103 BLAKE2B 7f94a4735c6a17b39a86fa0fda0682924b18e4b466dc6319a5df889522aaeaffaa87e1b76582c48ae034df8c20169c8cea93bbd3d6e7abd0526716686f88dfe8 SHA512 7dc9d9e00dde8f592bb171f4386d02b655b73cb4f153fe5ec063d010a148ef0639eae0dcdb3eeb09ecd1e3653c69e49a2d261329fa6d0381d2ddabe258ddde6d
+DIST freebsd-ubin-9.1.tar.bz2 1910472 BLAKE2B 4bab770072543d9eb25ce7ce450084e0eb9ca603deb58886a26495a92a05373f4f8f5821c65dc76365bf325a7291e6b630b00af5ba895784093d450163637504 SHA512 74ae0aceec8597aa66c3f1ab313f0685a3c63d7273c36ae7baf8794275ad9bca241c60c3f6281cccf6d531d250d7611099977d3b1a27279cef3586401b6af05e
+EBUILD freebsd-ubin-11.1-r1.ebuild 6259 BLAKE2B 0ea000ae8ce17f50f24a50b49d3d31eae30aa5f501aac300a37951dcdebf822dee30c4ba733ed722b4fc41e7b24d1c839373694a6fc68db9921d02141017cda3 SHA512 7fa660a330c80865c32efe64d8cdfac2ecb1cc1b4ad82f4edb34e25b8775340a9e53f397e75f376e49193ddc2efaec1c83d229c7933f0e5ce6c091c3da69c986
+EBUILD freebsd-ubin-11.1.ebuild 6191 BLAKE2B f39322b75a7d4a208e00c4a254fa785ed97f47c02fe74982cb724d83d8d9990dad52d3147b79ac228ffa01fe97e39e4863a8335ed7c8986e955dc7f422ffc2e5 SHA512 a900e3f060f44f9b15f0894725cfb0c247e3cfd7785184a2847714d1089a2dd61c3c7882d9dd0922e88e1d83bb0572ff874106bc0466dae883538cfd23009ea1
+EBUILD freebsd-ubin-9.1-r2.ebuild 5435 BLAKE2B 593ac216d25f29ea13839a4713115d7b502d9c706b5c44d258c6fd95d96a1782dd5065ec4a439ce01208cefa056f75d7ca629160d9c43b88d4dab6d172d04e6f SHA512 10cbe0ef273e83d0828ba54178fc03f736f0eba0e77d194ccd497bc1fc9123cb88705dca4bc3918fcc1a6fb8adca71edc215a4056c7a2f59e0a60c8e091fc395
+EBUILD freebsd-ubin-9.1-r3.ebuild 5442 BLAKE2B a19be7516757aafad2141d462023cd0dcc078393be1f8b54219c1ba8d214c737f2a956d1a30931be9f07fc95633e90d18f3f56cb4b1c1bd955767a521c602abd SHA512 53e627e4f98a2b7636992cd7d33366128b4d1f39bfea2ab1af49ccfc896db8ba98d9dc391d67d09a0ba609b6ee05fcde285cce6cf5cf4b0739c65adacf5930a5
+MISC metadata.xml 738 BLAKE2B 610b94f0d41c0b374855c3e340e18061db019949712332be10179ece5ad4ed84512c519279695d1c294bb1b8482d7980135c1b53b254e7078a4ba7c9575da471 SHA512 1761e6535f251fb4e9e8495ab0682677c633109b410984d142a3e3de144bd79e2a472044c064dc3c2f8aea7eded011e2848770257d100b4837701d2c71f3b824
diff --git a/sys-freebsd/freebsd-ubin/files/freebsd-ubin-10.2-bsdxml.patch b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-10.2-bsdxml.patch
new file mode 100644
index 000000000000..606471713fba
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-10.2-bsdxml.patch
@@ -0,0 +1,13 @@
+diff --git a/usr.bin/mt/mt.c b/usr.bin/mt/mt.c
+index af6562b..3121c81 100644
+--- a/usr.bin/mt/mt.c
++++ b/usr.bin/mt/mt.c
+@@ -92,7 +92,7 @@ __FBSDID("$FreeBSD: stable/10/usr.bin/mt/mt.c 280438 2015-03-24 14:36:10Z ken $"
+ #include <unistd.h>
+ #include <stdint.h>
+ #include <errno.h>
+-#include <bsdxml.h>
++#include <expat.h>
+ #include <mtlib.h>
+
+ #include <cam/cam.h>
diff --git a/sys-freebsd/freebsd-ubin/files/freebsd-ubin-10.2-talk-workaround.patch b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-10.2-talk-workaround.patch
new file mode 100644
index 000000000000..3a65b3714b72
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-10.2-talk-workaround.patch
@@ -0,0 +1,12 @@
+diff --git a/usr.bin/talk/io.c b/usr.bin/talk/io.c
+index 4daad7a..1fb9105 100644
+--- a/usr.bin/talk/io.c
++++ b/usr.bin/talk/io.c
+@@ -50,6 +50,7 @@ static const char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93";
+ #include <stdlib.h>
+ #include <string.h>
+ #include <unistd.h>
++#include <wctype.h>
+ #define _XOPEN_SOURCE_EXTENDED
+ #include <curses.h>
+
diff --git a/sys-freebsd/freebsd-ubin/files/freebsd-ubin-11.0-setXid.patch b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-11.0-setXid.patch
new file mode 100644
index 000000000000..946cc5b125f9
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-11.0-setXid.patch
@@ -0,0 +1,147 @@
+diff --git a/usr.bin/at/Makefile b/usr.bin/at/Makefile
+index d199a85..dc5cafd 100644
+--- a/usr.bin/at/Makefile
++++ b/usr.bin/at/Makefile
+@@ -17,6 +17,8 @@ BINOWN= root
+ BINMODE= 4555
+ CLEANFILES+= at.1
+
++LDFLAGS+=-Wl,-z,now
++
+ at.1: at.man
+ @${ECHO} Making ${.TARGET:T} from ${.ALLSRC:T}; \
+ sed -e \
+diff --git a/usr.bin/chpass/Makefile b/usr.bin/chpass/Makefile
+index 4427417..4f774a1 100644
+--- a/usr.bin/chpass/Makefile
++++ b/usr.bin/chpass/Makefile
+@@ -17,6 +17,8 @@ CFLAGS+= -DYP
+ #CFLAGS+=-DRESTRICT_FULLNAME_CHANGE
+ CFLAGS+=-I${.CURDIR}/../../usr.sbin/pwd_mkdb -I${.CURDIR}/../../lib/libc/gen -I.
+
++LDFLAGS+=-Wl,-z,now
++
+ LIBADD= crypt util
+ .if ${MK_NIS} != "no"
+ LIBADD+= ypclnt
+diff --git a/usr.bin/fstat/Makefile b/usr.bin/fstat/Makefile
+index cd03a51..9a0fe6e 100644
+--- a/usr.bin/fstat/Makefile
++++ b/usr.bin/fstat/Makefile
+@@ -9,3 +9,5 @@ LIBADD= procstat
+ MAN1= fuser.1 fstat.1
+
+ .include <bsd.prog.mk>
++LDFLAGS+=-Wl,-z,now
++
+diff --git a/usr.bin/lock/Makefile b/usr.bin/lock/Makefile
+index 07321f7..ed2c786 100644
+--- a/usr.bin/lock/Makefile
++++ b/usr.bin/lock/Makefile
+@@ -7,4 +7,6 @@ BINMODE=4555
+
+ LIBADD= crypt
+
++LDFLAGS+=-Wl,-z,now
++
+ .include <bsd.prog.mk>
+diff --git a/usr.bin/login/Makefile b/usr.bin/login/Makefile
+index 3499575..62a7356 100644
+--- a/usr.bin/login/Makefile
++++ b/usr.bin/login/Makefile
+@@ -16,6 +16,8 @@ CFLAGS+= -DUSE_BSM_AUDIT
+ LIBADD+= bsm
+ .endif
+
++LDFLAGS+=-Wl,-z,now
++
+ .if ${MK_SETUID_LOGIN} != "no"
+ BINOWN= root
+ BINMODE=4555
+diff --git a/usr.bin/netstat/Makefile b/usr.bin/netstat/Makefile
+index 52cc3c7..11ebb2f 100644
+--- a/usr.bin/netstat/Makefile
++++ b/usr.bin/netstat/Makefile
+@@ -57,6 +57,8 @@ BINGRP= kmem
+ BINMODE=2555
+ LIBADD= kvm memstat xo util
+
++LDFLAGS+=-Wl,-z,now
++
+ .if ${MK_NETGRAPH_SUPPORT} != "no"
+ SRCS+= netgraph.c
+ LIBADD+= netgraph
+diff --git a/usr.bin/opieinfo/Makefile b/usr.bin/opieinfo/Makefile
+index 3114a92..5c41213 100644
+--- a/usr.bin/opieinfo/Makefile
++++ b/usr.bin/opieinfo/Makefile
+@@ -12,6 +12,8 @@ WARNS?= 0
+
+ LIBADD= opie
+
++LDFLAGS+=-Wl,-z,now
++
+ BINOWN= root
+ BINMODE=4555
+ PRECIOUSPROG=
+diff --git a/usr.bin/opiepasswd/Makefile b/usr.bin/opiepasswd/Makefile
+index ae35b20..32ba59b 100644
+--- a/usr.bin/opiepasswd/Makefile
++++ b/usr.bin/opiepasswd/Makefile
+@@ -12,6 +12,8 @@ WARNS?= 0
+
+ LIBADD= opie
+
++LDFLAGS+=-Wl,-z,now
++
+ BINOWN= root
+ BINMODE=4555
+ PRECIOUSPROG=
+diff --git a/usr.bin/passwd/Makefile b/usr.bin/passwd/Makefile
+index 758be2d..ebde1a6 100644
+--- a/usr.bin/passwd/Makefile
++++ b/usr.bin/passwd/Makefile
+@@ -13,6 +13,8 @@ SYMLINKS = ${BINDIR}/passwd ${BINDIR}/yppasswd
+ MLINKS = passwd.1 yppasswd.1
+ .endif
+
++LDFLAGS+=-Wl,-z,now
++
+ beforeinstall:
+ .for i in passwd yppasswd
+ [ ! -e ${DESTDIR}${BINDIR}/$i ] || \
+diff --git a/usr.bin/su/Makefile b/usr.bin/su/Makefile
+index b3dd829..26eaa63 100644
+--- a/usr.bin/su/Makefile
++++ b/usr.bin/su/Makefile
+@@ -10,6 +10,8 @@ WARNS?= 5
+ LIBADD= util pam
+
+ .if ${MK_AUDIT} != "no"
++LDFLAGS+=-Wl,-z,now
++
+ CFLAGS+= -DUSE_BSM_AUDIT
+ LIBADD+= bsm
+ .endif
+diff --git a/usr.bin/wall/Makefile b/usr.bin/wall/Makefile
+index 0579add..571be8d 100644
+--- a/usr.bin/wall/Makefile
++++ b/usr.bin/wall/Makefile
+@@ -6,4 +6,6 @@ SRCS= ttymsg.c wall.c
+ BINGRP= tty
+ BINMODE=2555
+
++LDFLAGS+=-Wl,-z,now
++
+ .include <bsd.prog.mk>
+diff --git a/usr.bin/write/Makefile b/usr.bin/write/Makefile
+index ba06110..ba6ce04 100644
+--- a/usr.bin/write/Makefile
++++ b/usr.bin/write/Makefile
+@@ -5,4 +5,6 @@ PROG= write
+ BINMODE=2555
+ BINGRP= tty
+
++LDFLAGS+=-Wl,-z,now
++
+ .include <bsd.prog.mk>
diff --git a/sys-freebsd/freebsd-ubin/files/freebsd-ubin-11.1-fixmakefiles.patch b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-11.1-fixmakefiles.patch
new file mode 100644
index 000000000000..c8589fc24347
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-11.1-fixmakefiles.patch
@@ -0,0 +1,12 @@
+diff --git a/usr.bin/calendar/Makefile b/usr.bin/calendar/Makefile
+index c21fff9..06c0fe1 100644
+--- a/usr.bin/calendar/Makefile
++++ b/usr.bin/calendar/Makefile
+@@ -15,6 +15,7 @@ FR_LINKS= fr_FR.ISO8859-15
+ TEXTMODE?= 444
+
+ beforeinstall:
++ ${INSTALL} -d ${DESTDIR}${SHAREDIR}/calendar
+ ${INSTALL} ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m ${TEXTMODE} \
+ ${.CURDIR}/calendars/calendar.* ${DESTDIR}${SHAREDIR}/calendar
+ .for lang in ${INTER}
diff --git a/sys-freebsd/freebsd-ubin/files/freebsd-ubin-11.1-man-paths.patch b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-11.1-man-paths.patch
new file mode 100644
index 000000000000..c26a672f372b
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-11.1-man-paths.patch
@@ -0,0 +1,40 @@
+diff -dupr a/usr.bin/man/man.sh b/usr.bin/man/man.sh
+--- a/usr.bin/man/man.sh 2017-07-21 01:43:23.000000000 +0200
++++ b/usr.bin/man/man.sh 2019-01-22 19:32:52.136578832 +0100
+@@ -883,12 +883,12 @@ search_whatis() {
+ # Finds an appropriate decompressor based on extension
+ setup_cattool() {
+ case "$1" in
+- *.bz) cattool='/usr/bin/bzcat' ;;
+- *.bz2) cattool='/usr/bin/bzcat' ;;
+- *.gz) cattool='/usr/bin/zcat' ;;
+- *.lzma) cattool='/usr/bin/lzcat' ;;
+- *.xz) cattool='/usr/bin/xzcat' ;;
+- *) cattool='/usr/bin/zcat -f' ;;
++ *.bz) cattool='bzcat' ;;
++ *.bz2) cattool='bzcat' ;;
++ *.gz) cattool='zcat' ;;
++ *.lzma) cattool='lzcat' ;;
++ *.xz) cattool='xzcat' ;;
++ *) cattool='zcat -f' ;;
+ esac
+ }
+
+@@ -903,7 +903,7 @@ setup_pager() {
+ if [ -n "$PAGER" ]; then
+ MANPAGER="$PAGER"
+ else
+- MANPAGER="more -s"
++ MANPAGER="less -sR"
+ fi
+ fi
+ fi
+@@ -1008,7 +1008,7 @@ SYSCTL=/sbin/sysctl
+ debug=0
+ man_default_sections='1:8:2:3:n:4:5:6:7:9:l'
+ man_default_path='/usr/share/man:/usr/share/openssl/man:/usr/local/man'
+-cattool='/usr/bin/zcat -f'
++cattool='zcat -f'
+
+ config_global='/etc/man.conf'
+
diff --git a/sys-freebsd/freebsd-ubin/files/freebsd-ubin-6.0-bsdcmp.patch b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-6.0-bsdcmp.patch
new file mode 100644
index 000000000000..1a8552909653
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-6.0-bsdcmp.patch
@@ -0,0 +1,13 @@
+Index: fbsd-6.0/usr.bin/cmp/Makefile
+===================================================================
+--- fbsd-6.0.orig/usr.bin/cmp/Makefile
++++ fbsd-6.0/usr.bin/cmp/Makefile
+@@ -1,7 +1,7 @@
+ # @(#)Makefile 8.1 (Berkeley) 6/6/93
+ # $FreeBSD: src/usr.bin/cmp/Makefile,v 1.6.14.1 2005/09/17 11:33:41 brian Exp $
+
+-PROG= cmp
++PROG= bsdcmp
+ SRCS= cmp.c link.c misc.c regular.c special.c
+
+ .include <bsd.prog.mk>
diff --git a/sys-freebsd/freebsd-ubin/files/freebsd-ubin-8.0-xinstall.patch b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-8.0-xinstall.patch
new file mode 100644
index 000000000000..e8f978aabc9e
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-8.0-xinstall.patch
@@ -0,0 +1,26 @@
+Parallel make installs often cause 2 concurrent install -d to fail
+while they are creating the path to the target dirs.
+This patch changes the failure to a warning so that a make -j6 install doesn't
+fails as often as it does on Gentoo/FreeBSD, if it uses /usr/bin/install.
+
+--- usr.bin/xinstall/xinstall.c.orig
++++ usr.bin/xinstall/xinstall.c
+@@ -748,9 +748,17 @@
+ ch = *p;
+ *p = '\0';
+ if (stat(path, &sb)) {
+- if (errno != ENOENT || mkdir(path, 0755) < 0) {
++ if (errno != ENOENT) {
+ err(EX_OSERR, "mkdir %s", path);
+ /* NOTREACHED */
++ } else if (mkdir(path, 0755) < 0) {
++ /* Previous errno from stat() says that the directory didn't exist (ENOENT)
++ * But if errno is now EEXIST, then we just hit a parallel make bug.
++ */
++ if (errno == EEXIST)
++ warn("mkdir: %s now exists!", path); /* let me know when this happens */
++ else
++ err(EX_OSERR, "mkdir %s", path);
+ } else if (verbose)
+ (void)printf("install: mkdir %s\n",
+ path);
diff --git a/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.0-fixmakefiles.patch b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.0-fixmakefiles.patch
new file mode 100644
index 000000000000..d34eb9ef91af
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.0-fixmakefiles.patch
@@ -0,0 +1,11 @@
+diff -uNr usr.bin.old/calendar/Makefile usr.bin/calendar/Makefile
+--- usr.bin.old/calendar/Makefile 2011-11-02 18:22:09.000000000 +0000
++++ usr.bin/calendar/Makefile 2011-11-02 18:22:48.000000000 +0000
+@@ -15,6 +15,7 @@
+ WARNS?= 7
+
+ beforeinstall:
++ ${INSTALL} -d ${DESTDIR}${SHAREDIR}/calendar
+ ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${TEXTMODE} \
+ ${.CURDIR}/calendars/calendar.* ${DESTDIR}${SHAREDIR}/calendar
+ .for lang in ${INTER}
diff --git a/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-ar-libarchive3.patch b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-ar-libarchive3.patch
new file mode 100644
index 000000000000..d4d89e12e9e1
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-ar-libarchive3.patch
@@ -0,0 +1,19 @@
+diff -Nur usr.bin.orig/ar/ar.c usr.bin/ar/ar.c
+--- usr.bin.orig/ar/ar.c 2012-01-03 12:23:45.000000000 +0900
++++ usr.bin/ar/ar.c 2012-12-25 20:50:29.000000000 +0900
+@@ -386,13 +386,13 @@
+ static void
+ bsdar_version(void)
+ {
+- (void)printf("BSD ar %s - %s\n", BSDAR_VERSION, archive_version());
++ (void)printf("BSD ar %s - %s\n", BSDAR_VERSION, archive_version_string());
+ exit(EX_OK);
+ }
+
+ static void
+ ranlib_version(void)
+ {
+- (void)printf("ranlib %s - %s\n", BSDAR_VERSION, archive_version());
++ (void)printf("ranlib %s - %s\n", BSDAR_VERSION, archive_version_string());
+ exit(EX_OK);
+ }
diff --git a/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-bsdar.patch b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-bsdar.patch
new file mode 100644
index 000000000000..a65185fb7576
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-bsdar.patch
@@ -0,0 +1,25 @@
+diff -Nur work.orig/usr.bin/ar/Makefile work/usr.bin/ar/Makefile
+--- work.orig/usr.bin/ar/Makefile 2012-07-16 03:59:48.000000000 +0900
++++ work/usr.bin/ar/Makefile 2012-07-16 04:02:38.000000000 +0900
+@@ -2,7 +2,7 @@
+
+ .include <bsd.own.mk>
+
+-PROG= ar
++PROG= freebsd-ar
+ SRCS= ar.c acplex.l acpyacc.y read.c util.c write.c y.tab.h
+
+ DPADD= ${LIBARCHIVE} ${LIBELF}
+@@ -10,10 +10,7 @@
+
+ CFLAGS+=-I. -I${.CURDIR}
+
+-.if ${MK_SHARED_TOOLCHAIN} == "no"
+-NO_SHARED?= yes
+-.endif
+-LINKS= ${BINDIR}/ar ${BINDIR}/ranlib
+-MLINKS= ar.1 ranlib.1
++LINKS= ${BINDIR}/freebsd-ar ${BINDIR}/freebsd-ranlib
++MLINKS= freebsd-ar.1 freebsd-ranlib.1
+
+ .include <bsd.prog.mk>
diff --git a/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-grep.patch b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-grep.patch
new file mode 100644
index 000000000000..06cc5d28df80
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-grep.patch
@@ -0,0 +1,17 @@
+diff -Nur work.orig/usr.bin/grep/Makefile work/usr.bin/grep/Makefile
+--- work.orig/usr.bin/grep/Makefile 2012-07-16 04:59:01.000000000 +0900
++++ work/usr.bin/grep/Makefile 2012-07-16 05:00:15.000000000 +0900
+@@ -40,13 +40,6 @@
+ grep.1 lzfgrep.1
+ .endif
+
+-LINKS+= ${BINDIR}/${PROG} ${BINDIR}/xzgrep \
+- ${BINDIR}/${PROG} ${BINDIR}/xzegrep \
+- ${BINDIR}/${PROG} ${BINDIR}/xzfgrep \
+- ${BINDIR}/${PROG} ${BINDIR}/lzgrep \
+- ${BINDIR}/${PROG} ${BINDIR}/lzegrep \
+- ${BINDIR}/${PROG} ${BINDIR}/lzfgrep
+-
+ LDADD= -lz -llzma
+ DPADD= ${LIBZ} ${LIBLZMA}
+
diff --git a/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-kdump-ioctl.patch b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-kdump-ioctl.patch
new file mode 100644
index 000000000000..d98e599a280a
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-kdump-ioctl.patch
@@ -0,0 +1,24 @@
+diff -Nur work.orig/usr.bin/kdump/Makefile work/usr.bin/kdump/Makefile
+--- work.orig/usr.bin/kdump/Makefile 2012-07-12 13:24:01.000000000 +0900
++++ work/usr.bin/kdump/Makefile 2012-07-16 03:54:14.000000000 +0900
+@@ -21,7 +21,7 @@
+
+ ioctl.c: mkioctls
+ env CPP="${CPP}" \
+- sh ${.CURDIR}/mkioctls ${DESTDIR}/usr/include > ${.TARGET}
++ sh ${.CURDIR}/mkioctls ${.CURDIR}/../../include > ${.TARGET}
+
+ kdump_subr.c: mksubr
+ sh ${.CURDIR}/mksubr ${DESTDIR}/usr/include > ${.TARGET}
+diff -Nur work.orig/usr.bin/truss/Makefile work/usr.bin/truss/Makefile
+--- work.orig/usr.bin/truss/Makefile 2012-07-12 13:24:03.000000000 +0900
++++ work/usr.bin/truss/Makefile 2012-07-16 03:54:40.000000000 +0900
+@@ -24,7 +24,7 @@
+
+ ioctl.c: ${.CURDIR}/../kdump/mkioctls
+ env CPP="${CPP}" \
+- sh ${.CURDIR}/../kdump/mkioctls ${DESTDIR}/usr/include > ${.TARGET}
++ sh ${.CURDIR}/../kdump/mkioctls ${.CURDIR}/../../include > ${.TARGET}
+
+ .if ${MACHINE_CPUARCH} == "i386"
+ SRCS+= i386-linux.c linux_syscalls.h
diff --git a/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-minigzip.patch b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-minigzip.patch
new file mode 100644
index 000000000000..a9c062229ac1
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-9.1-minigzip.patch
@@ -0,0 +1,10 @@
+diff -Nur work.orig/usr.bin/minigzip/Makefile work/usr.bin/minigzip/Makefile
+--- work.orig/usr.bin/minigzip/Makefile 2012-07-16 04:39:31.000000000 +0900
++++ work/usr.bin/minigzip/Makefile 2012-07-16 04:45:30.000000000 +0900
+@@ -10,4 +10,6 @@
+ DPADD= ${LIBZ}
+ LDADD= -lz
+
++CFLAGS+= -I${.CURDIR}/../../lib/libz
++
+ .include <bsd.prog.mk>
diff --git a/sys-freebsd/freebsd-ubin/files/freebsd-ubin-lint-stdarg.patch b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-lint-stdarg.patch
new file mode 100644
index 000000000000..97747245552d
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-lint-stdarg.patch
@@ -0,0 +1,24 @@
+diff -ur usr.bin.orig/xlint/llib/llib-lposix usr.bin/xlint/llib/llib-lposix
+--- usr.bin.orig/xlint/llib/llib-lposix 2005-04-29 17:30:03 +0000
++++ usr.bin/xlint/llib/llib-lposix 2005-05-03 14:12:26 +0000
+@@ -42,7 +42,7 @@
+ #include <sys/utsname.h>
+ #include <sys/times.h>
+ #include <stdio.h>
+-#include <stdarg.h>
++#include <machine/stdarg.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+ #include <math.h>
+diff -ur usr.bin.orig/xlint/llib/llib-lstdc usr.bin/xlint/llib/llib-lstdc
+--- usr.bin.orig/xlint/llib/llib-lstdc 2005-04-29 17:30:03 +0000
++++ usr.bin/xlint/llib/llib-lstdc 2005-05-03 14:12:35 +0000
+@@ -44,7 +44,7 @@
+ #include <math.h>
+ #include <setjmp.h>
+ #include <signal.h>
+-#include <stdarg.h>
++#include <machine/stdarg.h>
+ #include <stddef.h>
+ #include <stdio.h>
+ #include <stdlib.h>
diff --git a/sys-freebsd/freebsd-ubin/files/freebsd-ubin-setXid.patch b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-setXid.patch
new file mode 100644
index 000000000000..631ee4f7b4f7
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/freebsd-ubin-setXid.patch
@@ -0,0 +1,129 @@
+diff -ur usr.bin.orig/at/Makefile usr.bin.setXid/at/Makefile
+--- usr.bin.orig/at/Makefile Thu Apr 7 20:52:57 2005
++++ usr.bin.setXid/at/Makefile Thu Apr 7 21:21:02 2005
+@@ -15,6 +15,8 @@
+ BINMODE= 4555
+ CLEANFILES+= at.1
+
++LDFLAGS+=-Wl,-z,now
++
+ at.1: at.man
+ @${ECHO} Making ${.TARGET:T} from ${.ALLSRC:T}; \
+ sed -e \
+diff -ur usr.bin.orig/chpass/Makefile usr.bin.setXid/chpass/Makefile
+--- usr.bin.orig/chpass/Makefile Thu Apr 7 20:52:57 2005
++++ usr.bin.setXid/chpass/Makefile Thu Apr 7 21:22:40 2005
+@@ -15,6 +15,8 @@
+ #CFLAGS+=-DRESTRICT_FULLNAME_CHANGE
+ CFLAGS+=-I${.CURDIR}/../../usr.sbin/pwd_mkdb -I${.CURDIR}/../../lib/libc/gen -I.
+
++LDFLAGS+=-Wl,-z,now
++
+ DPADD= ${LIBCRYPT} ${LIBUTIL}
+ LDADD= -lcrypt -lutil
+ .if !defined(NO_NIS)
+diff -ur usr.bin.orig/fstat/Makefile usr.bin.setXid/fstat/Makefile
+--- usr.bin.orig/fstat/Makefile Thu Apr 7 20:52:57 2005
++++ usr.bin.setXid/fstat/Makefile Thu Apr 7 21:24:35 2005
+@@ -9,4 +9,6 @@
+ BINMODE=2555
+ WARNS?= 6
+
++LDFLAGS+=-Wl,-z,now
++
+ .include <bsd.prog.mk>
+diff -ur usr.bin.orig/lock/Makefile usr.bin.setXid/lock/Makefile
+--- usr.bin.orig/lock/Makefile Thu Apr 7 20:52:57 2005
++++ usr.bin.setXid/lock/Makefile Thu Apr 7 21:24:45 2005
+@@ -7,4 +7,6 @@
+ DPADD= ${LIBCRYPT}
+ LDADD= -lcrypt
+
++LDFLAGS+=-Wl,-z,now
++
+ .include <bsd.prog.mk>
+diff -ur usr.bin.orig/login/Makefile usr.bin.setXid/login/Makefile
+--- usr.bin.orig/login/Makefile Thu Apr 7 20:52:57 2005
++++ usr.bin.setXid/login/Makefile Thu Apr 7 21:24:55 2005
+@@ -13,4 +13,6 @@
+ INSTALLFLAGS=-fschg
+ .endif
+
++LDFLAGS+=-Wl,-z,now
++
+ .include <bsd.prog.mk>
+diff -ur usr.bin.orig/netstat/Makefile usr.bin.setXid/netstat/Makefile
+--- usr.bin.orig/netstat/Makefile Thu Apr 7 20:52:58 2005
++++ usr.bin.setXid/netstat/Makefile Thu Apr 7 21:25:08 2005
+@@ -14,4 +14,6 @@
+ DPADD= ${LIBKVM} ${LIBIPX} ${LIBNETGRAPH} ${LIBUTIL}
+ LDADD= -lkvm -lipx -lnetgraph -lutil
+
++LDFLAGS+=-Wl,-z,now
++
+ .include <bsd.prog.mk>
+diff -ur usr.bin.orig/opieinfo/Makefile usr.bin.setXid/opieinfo/Makefile
+--- usr.bin.orig/opieinfo/Makefile Thu Apr 7 20:52:58 2005
++++ usr.bin.setXid/opieinfo/Makefile Thu Apr 7 21:25:20 2005
+@@ -11,6 +11,8 @@
+ DPADD= ${LIBOPIE} ${LIBMD}
+ LDADD= -lopie -lmd
+
++LDFLAGS+=-Wl,-z,now
++
+ BINOWN= root
+ BINMODE=4555
+ INSTALLFLAGS=-fschg
+diff -ur usr.bin.orig/opiepasswd/Makefile usr.bin.setXid/opiepasswd/Makefile
+--- usr.bin.orig/opiepasswd/Makefile Thu Apr 7 20:52:58 2005
++++ usr.bin.setXid/opiepasswd/Makefile Thu Apr 7 21:25:29 2005
+@@ -11,6 +11,8 @@
+ DPADD= ${LIBOPIE} ${LIBMD}
+ LDADD= -lopie -lmd
+
++LDFLAGS+=-Wl,-z,now
++
+ BINOWN= root
+ BINMODE=4555
+ INSTALLFLAGS=-fschg
+diff -ur usr.bin.orig/passwd/Makefile usr.bin.setXid/passwd/Makefile
+--- usr.bin.orig/passwd/Makefile Thu Apr 7 20:52:58 2005
++++ usr.bin.setXid/passwd/Makefile Thu Apr 7 21:25:37 2005
+@@ -10,6 +10,8 @@
+ MLINKS = passwd.1 yppasswd.1
+ WARNS ?= 4
+
++LDFLAGS+=-Wl,-z,now
++
+ beforeinstall:
+ .for i in passwd yppasswd
+ [ ! -e ${DESTDIR}${BINDIR}/$i ] || \
+--- usr.bin.orig/su/Makefile Thu Apr 7 20:52:58 2005
++++ usr.bin.setXid/su/Makefile Thu Apr 7 21:26:00 2005
+@@ -10,4 +10,6 @@
+ BINMODE=4555
+ INSTALLFLAGS=-fschg
+
++LDFLAGS+=-Wl,-z,now
++
+ .include <bsd.prog.mk>
+diff -ur usr.bin.orig/wall/Makefile usr.bin.setXid/wall/Makefile
+--- usr.bin.orig/wall/Makefile Thu Apr 7 20:52:59 2005
++++ usr.bin.setXid/wall/Makefile Thu Apr 7 21:26:07 2005
+@@ -5,4 +5,6 @@
+ BINGRP= tty
+ BINMODE=2555
+
++LDFLAGS+=-Wl,-z,now
++
+ .include <bsd.prog.mk>
+diff -ur usr.bin.orig/write/Makefile usr.bin.setXid/write/Makefile
+--- usr.bin.orig/write/Makefile Thu Apr 7 20:52:59 2005
++++ usr.bin.setXid/write/Makefile Thu Apr 7 21:26:13 2005
+@@ -4,4 +4,6 @@
+ BINMODE=2555
+ BINGRP= tty
+
++LDFLAGS+=-Wl,-z,now
++
+ .include <bsd.prog.mk>
diff --git a/sys-freebsd/freebsd-ubin/files/locate-updatedb-cron b/sys-freebsd/freebsd-ubin/files/locate-updatedb-cron
new file mode 100644
index 000000000000..323f455e9ba1
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/locate-updatedb-cron
@@ -0,0 +1,6 @@
+#! /bin/sh
+
+if [ -x /usr/libexec/locate.updatedb ]
+then
+ echo /usr/libexec/locate.updatedb | nice -n 5 su -fm nobody
+fi
diff --git a/sys-freebsd/freebsd-ubin/files/login.1.pamd b/sys-freebsd/freebsd-ubin/files/login.1.pamd
new file mode 100644
index 000000000000..2c09584f762c
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/login.1.pamd
@@ -0,0 +1,4 @@
+auth include system-local-login
+account include system-local-login
+session include system-local-login
+password include system-local-login
diff --git a/sys-freebsd/freebsd-ubin/files/passwd.1.pamd b/sys-freebsd/freebsd-ubin/files/passwd.1.pamd
new file mode 100644
index 000000000000..9c2938657679
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/passwd.1.pamd
@@ -0,0 +1,7 @@
+#
+# PAM configuration for the "passwd" service
+#
+
+# passwd(1) does not use the auth, account or session services.
+
+password include system-auth
diff --git a/sys-freebsd/freebsd-ubin/files/su.1.pamd b/sys-freebsd/freebsd-ubin/files/su.1.pamd
new file mode 100644
index 000000000000..33b35e285b0b
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/files/su.1.pamd
@@ -0,0 +1,15 @@
+#
+# PAM configuration for the "su" service
+#
+
+# auth
+auth sufficient pam_rootok.so no_warn
+auth sufficient pam_self.so no_warn
+auth requisite pam_group.so no_warn group=wheel root_only fail_safe
+auth include system-auth
+
+# account
+account include system-auth
+
+# session
+session required pam_permit.so
diff --git a/sys-freebsd/freebsd-ubin/freebsd-ubin-11.1-r1.ebuild b/sys-freebsd/freebsd-ubin/freebsd-ubin-11.1-r1.ebuild
new file mode 100644
index 000000000000..1ed9907fc971
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/freebsd-ubin-11.1-r1.ebuild
@@ -0,0 +1,214 @@
+# Copyright 1999-2019 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd flag-o-matic pam multilib multibuild multilib-build
+
+DESCRIPTION="FreeBSD's base system source for /usr/bin"
+SLOT="0"
+IUSE="ar atm audit bluetooth ipv6 kerberos netware nis ssl usb build zfs"
+LICENSE="BSD zfs? ( CDDL )"
+
+# Security Advisory and Errata patches.
+# UPSTREAM_PATCHES=()
+
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64-fbsd ~x86-fbsd"
+ SRC_URI="${SRC_URI}
+ $(freebsd_upstream_patches)"
+fi
+
+EXTRACTONLY="
+ usr.bin/
+ contrib/
+ lib/
+ etc/
+ bin/
+ include/
+"
+
+RDEPEND="=sys-freebsd/freebsd-lib-${RV}*[usb?,bluetooth?,${MULTILIB_USEDEP}]
+ ssl? ( dev-libs/openssl:0= )
+ kerberos? ( virtual/krb5 )
+ ar? ( >=app-arch/libarchive-3 )
+ virtual/pam
+ sys-libs/zlib
+ >=sys-libs/ncurses-5.9:0=
+ !sys-process/fuser-bsd
+ !dev-util/csup
+ !dev-libs/libiconv
+ !sys-apps/man
+ !sys-apps/man-db
+ !sys-freebsd/freebsd-contrib"
+
+DEPEND="${RDEPEND}
+ sys-devel/flex
+ !build? ( =sys-freebsd/freebsd-sources-${RV}* )
+ =sys-freebsd/freebsd-sbin-${RV}*
+ =sys-freebsd/freebsd-mk-defs-${RV}*"
+
+RDEPEND="${RDEPEND}
+ >=sys-auth/pambase-20080219.1
+ sys-process/cronbase"
+
+S="${WORKDIR}/usr.bin"
+
+PATCHES=( "${FILESDIR}/${PN}-6.0-bsdcmp.patch"
+ "${FILESDIR}/${PN}-11.1-fixmakefiles.patch"
+ "${FILESDIR}/${PN}-11.0-setXid.patch"
+ "${FILESDIR}/${PN}-lint-stdarg.patch"
+ "${FILESDIR}/${PN}-9.1-bsdar.patch"
+ "${FILESDIR}/${PN}-10.2-talk-workaround.patch"
+ "${FILESDIR}/${PN}-10.2-bsdxml.patch"
+ "${FILESDIR}/${PN}-11.1-man-paths.patch" )
+
+# Here we remove some sources we don't need because they are already
+# provided by portage's packages or similar. In order:
+# - Archiving tools, provided by their own ebuilds
+# - ncurses stuff
+# - less stuff
+# - bind utils
+# - rsh stuff
+# - binutils gprof
+# - dc stuff
+# and the rest are misc utils we already provide somewhere else.
+REMOVE_SUBDIRS="bzip2 bzip2recover tar cpio
+ gzip gprof minigzip
+ lzmainfo xz xzdec
+ unzip
+ tput tset tabs
+ less lessecho lesskey
+ hesinfo host
+ rsh rlogin rusers rwho ruptime
+ compile_et lex vi smbutil file vacation nc ftp telnet
+ c99 c89
+ bc dc
+ whois tftp
+ addr2line bsdcat cxxfilt cxxfilt elfcopy nm readelf sdiff size soelim strings"
+
+pkg_setup() {
+ # Add the required source files.
+ use zfs && EXTRACTONLY+="cddl/ "
+ use build && EXTRACTONLY+="sys/ "
+ use nis && EXTRACTONLY+="usr.sbin/ypserv/ "
+
+ use atm || mymakeopts="${mymakeopts} WITHOUT_ATM= "
+ use audit || mymakeopts="${mymakeopts} WITHOUT_AUDIT= "
+ use bluetooth || mymakeopts="${mymakeopts} WITHOUT_BLUETOOTH= "
+ use ipv6 || mymakeopts="${mymakeopts} WITHOUT_INET6= WITHOUT_INET6_SUPPORT= "
+ use kerberos || mymakeopts="${mymakeopts} WITHOUT_KERBEROS_SUPPORT= "
+ use netware || mymakeopts="${mymakeopts} WITHOUT_IPX= WITHOUT_IPX_SUPPORT= WITHOUT_NCP= "
+ use nis || mymakeopts="${mymakeopts} WITHOUT_NIS= "
+ use ssl || mymakeopts="${mymakeopts} WITHOUT_OPENSSL= "
+ use usb || mymakeopts="${mymakeopts} WITHOUT_USB= "
+ use zfs || mymakeopts="${mymakeopts} WITHOUT_CDDL= "
+ mymakeopts="${mymakeopts} WITHOUT_CLANG= WITHOUT_LZMA_SUPPORT= WITHOUT_SVN= WITHOUT_SVNLITE= WITHOUT_OPENSSH= WITHOUT_LDNS_UTILS= WITHOUT_MANDOCDB= "
+}
+
+pkg_preinst() {
+ # bison installs a /usr/bin/yacc symlink ...
+ # we need to remove it to avoid triggering
+ # collision-protect errors
+ if [[ -L ${ROOT}/usr/bin/yacc ]]; then
+ rm -f "${ROOT}"/usr/bin/yacc || die
+ fi
+}
+
+src_prepare() {
+ if [[ ! -e "${WORKDIR}/sys" ]]; then
+ use build || ln -s "/usr/src/sys" "${WORKDIR}/sys"
+ fi
+
+ # Rename manpage for renamed cmp
+ mv "${S}"/cmp/cmp.1 "${S}"/cmp/bsdcmp.1 || die
+ # Rename manpage for renamed ar
+ mv "${S}"/ar/ar.1 "${S}"/ar/freebsd-ar.1 || die
+ # Fix whereis(1) manpath search.
+ sed -i -e 's:"manpath -q":"manpath":' "${S}/whereis/pathnames.h" || die
+
+ # Build a dynamic make
+ sed -i -e '/^NO_SHARED/ s/^/#/' "${S}"/bmake/Makefile.inc || die
+
+ # Disable it here otherwise our patch wont apply
+ use ar || dummy_mk ar
+
+ # Preparing to build xlint
+ export LINT=xlint
+}
+
+setup_multilib_vars() {
+ if ! multilib_is_native_abi ; then
+ cd "${WORKDIR}/usr.bin/ldd" || die
+ export mymakeopts="${mymakeopts} PROG=ldd32 WITHOUT_MAN="
+ else
+ cd "${S}" || die
+ fi
+ "$@"
+}
+
+src_compile() {
+ local MULTIBUILD_VARIANTS="${DEFAULT_ABI}"
+ # Preparing to build addr2line, elfcopy, m4, getaddrinfo
+ for dir in libelftc libpe libopenbsd libnetbsd; do
+ cd "${WORKDIR}/lib/${dir}" || die
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper freebsd_src_compile -j1
+ done
+
+ MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper setup_multilib_vars freebsd_src_compile -j1
+}
+
+src_install() {
+ cd "${S}"/calendar/calendars || die
+ for dir in $(find . -type d ! -name "." ); do
+ dodir /usr/share/calendar/"$(basename ${dir})"
+ done
+
+ local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper setup_multilib_vars freebsd_src_install
+
+ # baselayout requires these in /bin
+ dodir /bin
+ for bin in sed printf ; do
+ mv "${D}/usr/bin/${bin}" "${D}/bin/" || die "mv ${bin} failed"
+ dosym /bin/${bin} /usr/bin/${bin} || die "dosym ${bin} failed"
+ done
+
+ for pamdfile in login passwd su; do
+ newpamd "${FILESDIR}/${pamdfile}.1.pamd" ${pamdfile} || die
+ done
+
+ cd "${WORKDIR}/etc" || die
+ insinto /etc
+ doins remote phones opieaccess fbtab
+
+ exeinto /etc/cron.daily
+ newexe "${FILESDIR}/locate-updatedb-cron" locate.updatedb || die
+
+ # tip requires /var/spool/lock/, bug #200700
+ keepdir /var/spool/lock
+
+ # create locate database #472468
+ local f=/var/db/locate.database
+ mkdir "${ED}${f%/*}" || die
+ touch "${ED}${f}" || die
+ fowners nobody:nobody ${f}
+}
+
+pkg_postinst() {
+ # We need to ensure that login.conf.db is up-to-date.
+ if [[ -e "${ROOT}"etc/login.conf ]] ; then
+ einfo "Updating ${ROOT}etc/login.conf.db"
+ "${ROOT}"usr/bin/cap_mkdb -f "${ROOT}"etc/login.conf "${ROOT}"etc/login.conf || die
+ elog "Remember to run cap_mkdb /etc/login.conf after making changes to it"
+ fi
+}
+
+pkg_postrm() {
+ # and if we uninstall yacc but keep bison,
+ # lets restore the /usr/bin/yacc symlink
+ if [[ ! -e ${ROOT}/usr/bin/yacc ]] && [[ -e ${ROOT}/usr/bin/yacc.bison ]] ; then
+ ln -s yacc.bison "${ROOT}"/usr/bin/yacc || die
+ fi
+}
diff --git a/sys-freebsd/freebsd-ubin/freebsd-ubin-11.1.ebuild b/sys-freebsd/freebsd-ubin/freebsd-ubin-11.1.ebuild
new file mode 100644
index 000000000000..4a52e0bedec6
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/freebsd-ubin-11.1.ebuild
@@ -0,0 +1,211 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd flag-o-matic pam multilib multibuild multilib-build
+
+DESCRIPTION="FreeBSD's base system source for /usr/bin"
+SLOT="0"
+IUSE="ar atm audit bluetooth ipv6 kerberos netware nis ssl usb build zfs"
+LICENSE="BSD zfs? ( CDDL )"
+
+# Security Advisory and Errata patches.
+# UPSTREAM_PATCHES=()
+
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64-fbsd ~x86-fbsd"
+ SRC_URI="${SRC_URI}
+ $(freebsd_upstream_patches)"
+fi
+
+EXTRACTONLY="
+ usr.bin/
+ contrib/
+ lib/
+ etc/
+ bin/
+ include/
+"
+
+RDEPEND="=sys-freebsd/freebsd-lib-${RV}*[usb?,bluetooth?,${MULTILIB_USEDEP}]
+ ssl? ( dev-libs/openssl:0= )
+ kerberos? ( virtual/krb5 )
+ ar? ( >=app-arch/libarchive-3 )
+ virtual/pam
+ sys-libs/zlib
+ >=sys-libs/ncurses-5.9:0=
+ !sys-process/fuser-bsd
+ !dev-util/csup
+ !dev-libs/libiconv
+ !sys-freebsd/freebsd-contrib"
+
+DEPEND="${RDEPEND}
+ sys-devel/flex
+ !build? ( =sys-freebsd/freebsd-sources-${RV}* )
+ =sys-freebsd/freebsd-sbin-${RV}*
+ =sys-freebsd/freebsd-mk-defs-${RV}*"
+
+RDEPEND="${RDEPEND}
+ >=sys-auth/pambase-20080219.1
+ sys-process/cronbase"
+
+S="${WORKDIR}/usr.bin"
+
+PATCHES=( "${FILESDIR}/${PN}-6.0-bsdcmp.patch"
+ "${FILESDIR}/${PN}-11.1-fixmakefiles.patch"
+ "${FILESDIR}/${PN}-11.0-setXid.patch"
+ "${FILESDIR}/${PN}-lint-stdarg.patch"
+ "${FILESDIR}/${PN}-9.1-bsdar.patch"
+ "${FILESDIR}/${PN}-10.2-talk-workaround.patch"
+ "${FILESDIR}/${PN}-10.2-bsdxml.patch" )
+
+# Here we remove some sources we don't need because they are already
+# provided by portage's packages or similar. In order:
+# - Archiving tools, provided by their own ebuilds
+# - ncurses stuff
+# - less stuff
+# - bind utils
+# - rsh stuff
+# - binutils gprof
+# - dc stuff
+# and the rest are misc utils we already provide somewhere else.
+REMOVE_SUBDIRS="bzip2 bzip2recover tar cpio
+ gzip gprof minigzip
+ lzmainfo xz xzdec
+ unzip
+ tput tset tabs
+ less lessecho lesskey
+ hesinfo host
+ rsh rlogin rusers rwho ruptime
+ compile_et lex vi smbutil file vacation nc ftp telnet
+ c99 c89
+ bc dc
+ whois tftp man
+ addr2line bsdcat cxxfilt cxxfilt elfcopy nm readelf sdiff size soelim strings"
+
+pkg_setup() {
+ # Add the required source files.
+ use zfs && EXTRACTONLY+="cddl/ "
+ use build && EXTRACTONLY+="sys/ "
+ use nis && EXTRACTONLY+="usr.sbin/ypserv/ "
+
+ use atm || mymakeopts="${mymakeopts} WITHOUT_ATM= "
+ use audit || mymakeopts="${mymakeopts} WITHOUT_AUDIT= "
+ use bluetooth || mymakeopts="${mymakeopts} WITHOUT_BLUETOOTH= "
+ use ipv6 || mymakeopts="${mymakeopts} WITHOUT_INET6= WITHOUT_INET6_SUPPORT= "
+ use kerberos || mymakeopts="${mymakeopts} WITHOUT_KERBEROS_SUPPORT= "
+ use netware || mymakeopts="${mymakeopts} WITHOUT_IPX= WITHOUT_IPX_SUPPORT= WITHOUT_NCP= "
+ use nis || mymakeopts="${mymakeopts} WITHOUT_NIS= "
+ use ssl || mymakeopts="${mymakeopts} WITHOUT_OPENSSL= "
+ use usb || mymakeopts="${mymakeopts} WITHOUT_USB= "
+ use zfs || mymakeopts="${mymakeopts} WITHOUT_CDDL= "
+ mymakeopts="${mymakeopts} WITHOUT_CLANG= WITHOUT_LZMA_SUPPORT= WITHOUT_SVN= WITHOUT_SVNLITE= WITHOUT_OPENSSH= WITHOUT_LDNS_UTILS= WITHOUT_MANDOCDB= "
+}
+
+pkg_preinst() {
+ # bison installs a /usr/bin/yacc symlink ...
+ # we need to remove it to avoid triggering
+ # collision-protect errors
+ if [[ -L ${ROOT}/usr/bin/yacc ]]; then
+ rm -f "${ROOT}"/usr/bin/yacc || die
+ fi
+}
+
+src_prepare() {
+ if [[ ! -e "${WORKDIR}/sys" ]]; then
+ use build || ln -s "/usr/src/sys" "${WORKDIR}/sys"
+ fi
+
+ # Rename manpage for renamed cmp
+ mv "${S}"/cmp/cmp.1 "${S}"/cmp/bsdcmp.1 || die
+ # Rename manpage for renamed ar
+ mv "${S}"/ar/ar.1 "${S}"/ar/freebsd-ar.1 || die
+ # Fix whereis(1) manpath search.
+ sed -i -e 's:"manpath -q":"manpath":' "${S}/whereis/pathnames.h" || die
+
+ # Build a dynamic make
+ sed -i -e '/^NO_SHARED/ s/^/#/' "${S}"/bmake/Makefile.inc || die
+
+ # Disable it here otherwise our patch wont apply
+ use ar || dummy_mk ar
+
+ # Preparing to build xlint
+ export LINT=xlint
+}
+
+setup_multilib_vars() {
+ if ! multilib_is_native_abi ; then
+ cd "${WORKDIR}/usr.bin/ldd" || die
+ export mymakeopts="${mymakeopts} PROG=ldd32 WITHOUT_MAN="
+ else
+ cd "${S}" || die
+ fi
+ "$@"
+}
+
+src_compile() {
+ local MULTIBUILD_VARIANTS="${DEFAULT_ABI}"
+ # Preparing to build addr2line, elfcopy, m4, getaddrinfo
+ for dir in libelftc libpe libopenbsd libnetbsd; do
+ cd "${WORKDIR}/lib/${dir}" || die
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper freebsd_src_compile -j1
+ done
+
+ MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper setup_multilib_vars freebsd_src_compile -j1
+}
+
+src_install() {
+ cd "${S}"/calendar/calendars || die
+ for dir in $(find . -type d ! -name "." ); do
+ dodir /usr/share/calendar/"$(basename ${dir})"
+ done
+
+ local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper setup_multilib_vars freebsd_src_install
+
+ # baselayout requires these in /bin
+ dodir /bin
+ for bin in sed printf ; do
+ mv "${D}/usr/bin/${bin}" "${D}/bin/" || die "mv ${bin} failed"
+ dosym /bin/${bin} /usr/bin/${bin} || die "dosym ${bin} failed"
+ done
+
+ for pamdfile in login passwd su; do
+ newpamd "${FILESDIR}/${pamdfile}.1.pamd" ${pamdfile} || die
+ done
+
+ cd "${WORKDIR}/etc" || die
+ insinto /etc
+ doins remote phones opieaccess fbtab
+
+ exeinto /etc/cron.daily
+ newexe "${FILESDIR}/locate-updatedb-cron" locate.updatedb || die
+
+ # tip requires /var/spool/lock/, bug #200700
+ keepdir /var/spool/lock
+
+ # create locate database #472468
+ local f=/var/db/locate.database
+ mkdir "${ED}${f%/*}" || die
+ touch "${ED}${f}" || die
+ fowners nobody:nobody ${f}
+}
+
+pkg_postinst() {
+ # We need to ensure that login.conf.db is up-to-date.
+ if [[ -e "${ROOT}"etc/login.conf ]] ; then
+ einfo "Updating ${ROOT}etc/login.conf.db"
+ "${ROOT}"usr/bin/cap_mkdb -f "${ROOT}"etc/login.conf "${ROOT}"etc/login.conf || die
+ elog "Remember to run cap_mkdb /etc/login.conf after making changes to it"
+ fi
+}
+
+pkg_postrm() {
+ # and if we uninstall yacc but keep bison,
+ # lets restore the /usr/bin/yacc symlink
+ if [[ ! -e ${ROOT}/usr/bin/yacc ]] && [[ -e ${ROOT}/usr/bin/yacc.bison ]] ; then
+ ln -s yacc.bison "${ROOT}"/usr/bin/yacc || die
+ fi
+}
diff --git a/sys-freebsd/freebsd-ubin/freebsd-ubin-9.1-r2.ebuild b/sys-freebsd/freebsd-ubin/freebsd-ubin-9.1-r2.ebuild
new file mode 100644
index 000000000000..51d1442d20f2
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/freebsd-ubin-9.1-r2.ebuild
@@ -0,0 +1,180 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd flag-o-matic pam multilib multibuild multilib-build
+
+DESCRIPTION="FreeBSD's base system source for /usr/bin"
+SLOT="0"
+KEYWORDS="~amd64-fbsd ~x86-fbsd"
+IUSE="ar atm audit bluetooth ipv6 kerberos netware nis ssl usb build zfs"
+LICENSE="BSD zfs? ( CDDL )"
+
+SRC_URI="mirror://gentoo/${UBIN}.tar.bz2
+ mirror://gentoo/${CONTRIB}.tar.bz2
+ mirror://gentoo/${LIB}.tar.bz2
+ mirror://gentoo/${ETC}.tar.bz2
+ mirror://gentoo/${BIN}.tar.bz2
+ mirror://gentoo/${INCLUDE}.tar.bz2
+ zfs? ( mirror://gentoo/${CDDL}.tar.bz2 )
+ build? ( mirror://gentoo/${SYS}.tar.bz2 )"
+
+RDEPEND="=sys-freebsd/freebsd-lib-${RV}*[usb?,bluetooth?,${MULTILIB_USEDEP}]
+ ssl? ( dev-libs/openssl )
+ kerberos? ( virtual/krb5 )
+ ar? ( >=app-arch/libarchive-3 )
+ virtual/pam
+ sys-libs/zlib
+ >=sys-libs/ncurses-5.9
+ !sys-process/fuser-bsd
+ !dev-util/csup"
+
+DEPEND="${RDEPEND}
+ sys-devel/flex
+ !build? ( =sys-freebsd/freebsd-sources-${RV}* )
+ =sys-freebsd/freebsd-mk-defs-${RV}*"
+
+RDEPEND="${RDEPEND}
+ >=sys-auth/pambase-20080219.1
+ sys-process/cronbase"
+
+S="${WORKDIR}/usr.bin"
+
+PATCHES=( "${FILESDIR}/${PN}-6.0-bsdcmp.patch"
+ "${FILESDIR}/${PN}-9.0-fixmakefiles.patch"
+ "${FILESDIR}/${PN}-setXid.patch"
+ "${FILESDIR}/${PN}-lint-stdarg.patch"
+ "${FILESDIR}/${PN}-9.1-kdump-ioctl.patch"
+ "${FILESDIR}/${PN}-8.0-xinstall.patch"
+ "${FILESDIR}/${PN}-9.1-bsdar.patch"
+ "${FILESDIR}/${PN}-9.1-minigzip.patch"
+ "${FILESDIR}/${PN}-9.1-grep.patch"
+ "${FILESDIR}/${PN}-9.1-ar-libarchive3.patch" )
+
+# Here we remove some sources we don't need because they are already
+# provided by portage's packages or similar. In order:
+# - Archiving tools, provided by their own ebuilds
+# - ncurses stuff
+# - less stuff
+# - bind utils
+# - rsh stuff
+# - binutils gprof
+# - dc stuff
+# and the rest are misc utils we already provide somewhere else.
+REMOVE_SUBDIRS="bzip2 bzip2recover tar cpio
+ gzip gprof
+ lzmainfo xz xzdec
+ unzip
+ tput tset tabs
+ less lessecho lesskey
+ dig hesinfo nslookup nsupdate host
+ rsh rlogin rusers rwho ruptime
+ compile_et lex vi smbutil file vacation nc ftp telnet
+ c99 c89
+ bc dc
+ whois tftp man"
+
+pkg_setup() {
+ use atm || mymakeopts="${mymakeopts} WITHOUT_ATM= "
+ use audit || mymakeopts="${mymakeopts} WITHOUT_AUDIT= "
+ use bluetooth || mymakeopts="${mymakeopts} WITHOUT_BLUETOOTH= "
+ use ipv6 || mymakeopts="${mymakeopts} WITHOUT_INET6= WITHOUT_INET6_SUPPORT= "
+ use kerberos || mymakeopts="${mymakeopts} WITHOUT_KERBEROS_SUPPORT= "
+ use netware || mymakeopts="${mymakeopts} WITHOUT_IPX= WITHOUT_IPX_SUPPORT= WITHOUT_NCP= "
+ use nis || mymakeopts="${mymakeopts} WITHOUT_NIS= "
+ use ssl || mymakeopts="${mymakeopts} WITHOUT_OPENSSL= "
+ use usb || mymakeopts="${mymakeopts} WITHOUT_USB= "
+ use zfs || mymakeopts="${mymakeopts} WITHOUT_CDDL= "
+ mymakeopts="${mymakeopts} WITHOUT_CLANG= "
+}
+
+pkg_preinst() {
+ # bison installs a /usr/bin/yacc symlink ...
+ # we need to remove it to avoid triggering
+ # collision-protect errors
+ if [[ -L ${ROOT}/usr/bin/yacc ]] ; then
+ rm -f "${ROOT}"/usr/bin/yacc
+ fi
+}
+
+src_prepare() {
+ use build || ln -s "/usr/src/sys-${RV}" "${WORKDIR}/sys"
+
+ # Rename manpage for renamed cmp
+ mv "${S}"/cmp/cmp.1 "${S}"/cmp/bsdcmp.1 || die
+ # Rename manpage for renamed ar
+ mv "${S}"/ar/ar.1 "${S}"/ar/freebsd-ar.1 || die
+ # Fix whereis(1) manpath search.
+ sed -i -e 's:"manpath -q":"manpath":' "${S}/whereis/pathnames.h"
+
+ # Build a dynamic make
+ sed -i -e '/^NO_SHARED/ s/^/#/' "${S}"/make/Makefile || die
+
+ # Disable it here otherwise our patch wont apply
+ use ar || dummy_mk ar
+}
+
+setup_multilib_vars() {
+ if ! multilib_is_native_abi ; then
+ cd "${WORKDIR}/usr.bin/ldd" || die
+ export mymakeopts="${mymakeopts} PROG=ldd32 WITHOUT_MAN="
+ else
+ cd "${S}"
+ fi
+ "$@"
+}
+
+src_compile() {
+ local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper setup_multilib_vars freebsd_src_compile
+}
+
+src_install() {
+ local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper setup_multilib_vars freebsd_src_install
+
+ # baselayout requires these in /bin
+ dodir /bin
+ for bin in sed printf fuser; do
+ mv "${D}/usr/bin/${bin}" "${D}/bin/" || die "mv ${bin} failed"
+ dosym /bin/${bin} /usr/bin/${bin} || die "dosym ${bin} failed"
+ done
+
+ for pamdfile in login passwd su; do
+ newpamd "${FILESDIR}/${pamdfile}.1.pamd" ${pamdfile} || die
+ done
+
+ cd "${WORKDIR}/etc"
+ insinto /etc
+ doins remote phones opieaccess fbtab || die
+
+ exeinto /etc/cron.daily
+ newexe "${FILESDIR}/locate-updatedb-cron" locate.updatedb || die
+
+ # tip requires /var/spool/lock/, bug #200700
+ keepdir /var/spool/lock
+
+ # create locate database #472468
+ local f=/var/db/locate.database
+ mkdir "${ED}${f%/*}" || die
+ touch "${ED}${f}" || die
+ fowners nobody:nobody ${f}
+}
+
+pkg_postinst() {
+ # We need to ensure that login.conf.db is up-to-date.
+ if [[ -e "${ROOT}"etc/login.conf ]] ; then
+ einfo "Updating ${ROOT}etc/login.conf.db"
+ "${ROOT}"usr/bin/cap_mkdb -f "${ROOT}"etc/login.conf "${ROOT}"etc/login.conf
+ elog "Remember to run cap_mkdb /etc/login.conf after making changes to it"
+ fi
+}
+
+pkg_postrm() {
+ # and if we uninstall yacc but keep bison,
+ # lets restore the /usr/bin/yacc symlink
+ if [[ ! -e ${ROOT}/usr/bin/yacc ]] && [[ -e ${ROOT}/usr/bin/yacc.bison ]] ; then
+ ln -s yacc.bison "${ROOT}"/usr/bin/yacc
+ fi
+}
diff --git a/sys-freebsd/freebsd-ubin/freebsd-ubin-9.1-r3.ebuild b/sys-freebsd/freebsd-ubin/freebsd-ubin-9.1-r3.ebuild
new file mode 100644
index 000000000000..5c516589984e
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/freebsd-ubin-9.1-r3.ebuild
@@ -0,0 +1,180 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd flag-o-matic pam multilib multibuild multilib-build
+
+DESCRIPTION="FreeBSD's base system source for /usr/bin"
+SLOT="0"
+KEYWORDS="~amd64-fbsd ~x86-fbsd"
+IUSE="ar atm audit bluetooth ipv6 kerberos netware nis ssl usb build zfs"
+LICENSE="BSD zfs? ( CDDL )"
+
+SRC_URI="mirror://gentoo/${UBIN}.tar.bz2
+ mirror://gentoo/${CONTRIB}.tar.bz2
+ mirror://gentoo/${LIB}.tar.bz2
+ mirror://gentoo/${ETC}.tar.bz2
+ mirror://gentoo/${BIN}.tar.bz2
+ mirror://gentoo/${INCLUDE}.tar.bz2
+ zfs? ( mirror://gentoo/${CDDL}.tar.bz2 )
+ build? ( mirror://gentoo/${SYS}.tar.bz2 )"
+
+RDEPEND="=sys-freebsd/freebsd-lib-${RV}*[usb?,bluetooth?,${MULTILIB_USEDEP}]
+ ssl? ( dev-libs/openssl )
+ kerberos? ( virtual/krb5 )
+ ar? ( >=app-arch/libarchive-3 )
+ virtual/pam
+ sys-libs/zlib
+ >=sys-libs/ncurses-5.9
+ !sys-process/fuser-bsd
+ !dev-util/csup"
+
+DEPEND="${RDEPEND}
+ sys-devel/flex
+ !build? ( =sys-freebsd/freebsd-sources-${RV}* )
+ =sys-freebsd/freebsd-mk-defs-${RV}*"
+
+RDEPEND="${RDEPEND}
+ >=sys-auth/pambase-20080219.1
+ sys-process/cronbase"
+
+S="${WORKDIR}/usr.bin"
+
+PATCHES=( "${FILESDIR}/${PN}-6.0-bsdcmp.patch"
+ "${FILESDIR}/${PN}-9.0-fixmakefiles.patch"
+ "${FILESDIR}/${PN}-setXid.patch"
+ "${FILESDIR}/${PN}-lint-stdarg.patch"
+ "${FILESDIR}/${PN}-9.1-kdump-ioctl.patch"
+ "${FILESDIR}/${PN}-8.0-xinstall.patch"
+ "${FILESDIR}/${PN}-9.1-bsdar.patch"
+ "${FILESDIR}/${PN}-9.1-minigzip.patch"
+ "${FILESDIR}/${PN}-9.1-grep.patch"
+ "${FILESDIR}/${PN}-9.1-ar-libarchive3.patch" )
+
+# Here we remove some sources we don't need because they are already
+# provided by portage's packages or similar. In order:
+# - Archiving tools, provided by their own ebuilds
+# - ncurses stuff
+# - less stuff
+# - bind utils
+# - rsh stuff
+# - binutils gprof
+# - dc stuff
+# and the rest are misc utils we already provide somewhere else.
+REMOVE_SUBDIRS="bzip2 bzip2recover tar cpio
+ gzip gprof
+ lzmainfo xz xzdec
+ unzip
+ tput tset tabs
+ less lessecho lesskey
+ dig hesinfo nslookup nsupdate host
+ rsh rlogin rusers rwho ruptime
+ compile_et lex vi smbutil file vacation nc ftp telnet
+ c99 c89
+ bc dc
+ whois tftp man catman"
+
+pkg_setup() {
+ use atm || mymakeopts="${mymakeopts} WITHOUT_ATM= "
+ use audit || mymakeopts="${mymakeopts} WITHOUT_AUDIT= "
+ use bluetooth || mymakeopts="${mymakeopts} WITHOUT_BLUETOOTH= "
+ use ipv6 || mymakeopts="${mymakeopts} WITHOUT_INET6= WITHOUT_INET6_SUPPORT= "
+ use kerberos || mymakeopts="${mymakeopts} WITHOUT_KERBEROS_SUPPORT= "
+ use netware || mymakeopts="${mymakeopts} WITHOUT_IPX= WITHOUT_IPX_SUPPORT= WITHOUT_NCP= "
+ use nis || mymakeopts="${mymakeopts} WITHOUT_NIS= "
+ use ssl || mymakeopts="${mymakeopts} WITHOUT_OPENSSL= "
+ use usb || mymakeopts="${mymakeopts} WITHOUT_USB= "
+ use zfs || mymakeopts="${mymakeopts} WITHOUT_CDDL= "
+ mymakeopts="${mymakeopts} WITHOUT_CLANG= "
+}
+
+pkg_preinst() {
+ # bison installs a /usr/bin/yacc symlink ...
+ # we need to remove it to avoid triggering
+ # collision-protect errors
+ if [[ -L ${ROOT}/usr/bin/yacc ]] ; then
+ rm -f "${ROOT}"/usr/bin/yacc
+ fi
+}
+
+src_prepare() {
+ use build || ln -s "/usr/src/sys-${RV}" "${WORKDIR}/sys"
+
+ # Rename manpage for renamed cmp
+ mv "${S}"/cmp/cmp.1 "${S}"/cmp/bsdcmp.1 || die
+ # Rename manpage for renamed ar
+ mv "${S}"/ar/ar.1 "${S}"/ar/freebsd-ar.1 || die
+ # Fix whereis(1) manpath search.
+ sed -i -e 's:"manpath -q":"manpath":' "${S}/whereis/pathnames.h"
+
+ # Build a dynamic make
+ sed -i -e '/^NO_SHARED/ s/^/#/' "${S}"/make/Makefile || die
+
+ # Disable it here otherwise our patch wont apply
+ use ar || dummy_mk ar
+}
+
+setup_multilib_vars() {
+ if ! multilib_is_native_abi ; then
+ cd "${WORKDIR}/usr.bin/ldd" || die
+ export mymakeopts="${mymakeopts} PROG=ldd32 WITHOUT_MAN="
+ else
+ cd "${S}"
+ fi
+ "$@"
+}
+
+src_compile() {
+ local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper setup_multilib_vars freebsd_src_compile
+}
+
+src_install() {
+ local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
+ multibuild_foreach_variant freebsd_multilib_multibuild_wrapper setup_multilib_vars freebsd_src_install
+
+ # baselayout requires these in /bin
+ dodir /bin
+ for bin in sed printf fuser; do
+ mv "${D}/usr/bin/${bin}" "${D}/bin/" || die "mv ${bin} failed"
+ dosym /bin/${bin} /usr/bin/${bin} || die "dosym ${bin} failed"
+ done
+
+ for pamdfile in login passwd su; do
+ newpamd "${FILESDIR}/${pamdfile}.1.pamd" ${pamdfile} || die
+ done
+
+ cd "${WORKDIR}/etc"
+ insinto /etc
+ doins remote phones opieaccess fbtab || die
+
+ exeinto /etc/cron.daily
+ newexe "${FILESDIR}/locate-updatedb-cron" locate.updatedb || die
+
+ # tip requires /var/spool/lock/, bug #200700
+ keepdir /var/spool/lock
+
+ # create locate database #472468
+ local f=/var/db/locate.database
+ mkdir "${ED}${f%/*}" || die
+ touch "${ED}${f}" || die
+ fowners nobody:nobody ${f}
+}
+
+pkg_postinst() {
+ # We need to ensure that login.conf.db is up-to-date.
+ if [[ -e "${ROOT}"etc/login.conf ]] ; then
+ einfo "Updating ${ROOT}etc/login.conf.db"
+ "${ROOT}"usr/bin/cap_mkdb -f "${ROOT}"etc/login.conf "${ROOT}"etc/login.conf
+ elog "Remember to run cap_mkdb /etc/login.conf after making changes to it"
+ fi
+}
+
+pkg_postrm() {
+ # and if we uninstall yacc but keep bison,
+ # lets restore the /usr/bin/yacc symlink
+ if [[ ! -e ${ROOT}/usr/bin/yacc ]] && [[ -e ${ROOT}/usr/bin/yacc.bison ]] ; then
+ ln -s yacc.bison "${ROOT}"/usr/bin/yacc
+ fi
+}
diff --git a/sys-freebsd/freebsd-ubin/metadata.xml b/sys-freebsd/freebsd-ubin/metadata.xml
new file mode 100644
index 000000000000..ef58187231a3
--- /dev/null
+++ b/sys-freebsd/freebsd-ubin/metadata.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <maintainer type="project">
+ <email>bsd@gentoo.org</email>
+ <name>BSD Project</name>
+ </maintainer>
+ <use>
+ <flag name="audit">Build auditing tools</flag>
+ <flag name="netware">Build libraries and tools to work with NetWare protocols (IPX and NCP)</flag>
+ <flag name="ar">
+ Build FreeBSD's ar and ranlib replacements based on libarchive. The
+ toolchain will still use binutils' version but you can play with it.
+ They have been renamed to freebsd-ar and freebsd-ranlib not to collide
+ with binutils.
+ </flag>
+ <flag name="zfs">Enable ZFS support (for fstat actually).</flag>
+ </use>
+</pkgmetadata>
diff --git a/sys-freebsd/freebsd-usbin/Manifest b/sys-freebsd/freebsd-usbin/Manifest
new file mode 100644
index 000000000000..258eb84ae7a6
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/Manifest
@@ -0,0 +1,18 @@
+AUX freebsd-usbin-10.3-bsdxml2expat.patch 406 BLAKE2B bddbdf3869a084f4a3eed616398bbcad3759570ce25ff4467747f2ac1795a50cc082e5e2858f61faa3d70acecbf91c0f793d6a559622e3c8f8a07485138bfa79 SHA512 91a2323b5007e2381fb58d608dd19dcc010afb398a4b2285b53cae4157268fb6aa232323280cec72cccdb2010610f73e048b06bae76418b7db8cd1f34b7ad8dd
+AUX freebsd-usbin-11.0-workaround.patch 374 BLAKE2B 7e4b18ccddd1da87fc2d6bb8d8c98be45cc1b2d1d8b383316746a793b6eb3aa9d722e11ea600d0c49111b00c5ddb237eaa019b2babeed86da7d0beef6ff0189d SHA512 c9e8b493d99581dd7beac48def291843e31649a2962f720ed06ef095a128b039e8308662cfbbfcbecfbd0265132bb7a4df9d895ffe69aac09c129389ba5be518
+AUX freebsd-usbin-11.1-bsdxml2expat.patch 841 BLAKE2B 89b5b0ed64dcf5c95eb727110651bb77079a4ccfc346fbd9ac1b26e3a4d53c452d657379ca876e6eb8b50dd90be59737b84405de873613dadf3bebeae7c788de SHA512 69f9055dc536132f1ec46389b53e25261632d726bc74857210ecb5511114f07d4b550e5e4a7a6e066a4a68c4a4bb4e44309d01f569b154fc773247dbd7f3fb23
+AUX freebsd-usbin-9.0-newsyslog.patch 507 BLAKE2B 7c95ebd60ca6cc1bac56b84359a389dada9e71de9f275cf99d72f329fb408bd16845fb46d60037c514deb4ea21cd894da57ae28193e56970e383c5a8e1c689b7 SHA512 5423fc577035c2a272d4cb4305c5ee5e1e910a68af44595524665f7b867bd0a48bab0349b2fa13eabc385b2ec29c8f578d018cd8196f3ad20a13a68d36a335ae
+AUX freebsd-usbin-SA-1803-speculative_execution-amd64-11.patch 3658 BLAKE2B 4c7c4aa7d65ae2f36ea08568ca6fb9412456dda432f459a99b5e68858dc5b2ea6e023cb257e6659a5ca31e572c537c9169c832cc5ca39cad7a38efc2c52283df SHA512 c46b73a1c104470d631f3b874e592e33d2bf100258d774fbaec406c3d3985fb3283bce2f51911a5d73e5f66b5a3bc5d38d4cbeab0439acd21cfbf376e496971a
+AUX freebsd-usbin-adduser.patch 428 BLAKE2B 3008953aa7ea14405b0e914f518fa05a5de744283110959900ab1ee9887b8b48d8d15131f26280773ff0173f1c60c077c66fedfad1b0310d0e6c5abb5a2b1370 SHA512 51720e3db9bf3728afc0dc370a469746cb1bf61623c44a20c58e27d647e5a5d0360145b1d174382176d803f2558afa2f2a29eca6c85c638529d0e11e2859c0c3
+AUX iscsid.initd 429 BLAKE2B 366c216bf7f4584d1aa115302547b7066105b5107a976504c68725a1f7ca80adb7bd19b4acdaa2ea41b45c42bfed2b028a17ab28201163222788432768f2e5a6 SHA512 49a90719aa0279e19899a2107113cad0784a2cf3b57a0c24ad08549fa4b44dcb1aceecd71027e363b8d2cbbe1b590480ef7806cb05d8b00c1830c2d77b8a8540
+AUX nfs.confd 303 BLAKE2B 69f72512c7e518f9078ea3873c5a2c9f0e1fef02ba3d769a18d1c8f347a8f8d5981cbe7ce34946431b373ae2b580505d74714f7bdbc0a7298745f02f96d35404 SHA512 4224c7f525e39b105b8d80caa7db0f3e0b07d6c521970b2aacfd707ef524262cbdb9ed8aa5151022d571a759151dd25a280fc765a38e67864b0c446ee9fd6b5a
+AUX nfs.initd 1424 BLAKE2B d3988adba20f8c8d4114342ca90752ea6dfce1993bce29991655639b995784bb25f8ebd7d0dee687d5e5e2970862f688dcc74239fac4b7de4beb8cddc6c1cdad SHA512 1d85de665dfea1845189f2ad2e7205ab6185ce228f7140ccaafa22c84f8b9f0b4b4c5a26bd53895f1f2c4639bbeb8d5b76106d2e64851eb62f229028dc61cb5c
+AUX nfsuserd.confd 153 BLAKE2B 931bde9b889bae7a58a9dd2b37583e1b9caa610a4eda9f4b70ed15d8a8752edc669b9b7f45d5613db57f05648c9f20f0efe2808f25b000627dd7c36778efce58 SHA512 47bf885dc80a61c9f8aab5890a360063fc2e846ce8abefb84e9d504f62c455cd759af753c7a5ab8cdd624842200f6b0ec7d177ddfdc1e7564460764eb4d4d073
+AUX nfsuserd.initd 447 BLAKE2B 0367d6849fc1392ae308023c5c5ddf4df0db0b38e86c486d8d482ce2a31af5332462bc1a46d0c79006323341a50e994f1f86f5e08773206f8c7a99f1060508ff SHA512 e18cbd9efa3bf9e7283a9633bebfadfa9160b6eb668f48723bb9f1b37c5476b75b71b505046025a185a74d409ce09fd305257cdcb6e953c795ed1397fbe76323
+AUX pw.conf 179 BLAKE2B d93e3d2df7bc636b21b2bfa30b5b76b671f98631c360f7977c9368b0f1fa96cfa922c6820836addd24804b50c3a9978ca901dd7068f5d721b8ac8c6b8ff151f7 SHA512 042b7c7805d891f453da58f607edb3174fddc8443d6995ebe833185ab313328c131bae87dbbc9db95bf69a9ee71548d350191b34a8b2bf41a56416aff03c3891
+AUX rpc.lockd.initd 530 BLAKE2B 03926d9b01e3d191030a18785ef53824836d1826895d064a303d83f5eff8e3a3630273d5547d1d0d95bd85db7f421b790671cf9e882af58621dd8756fde86fe6 SHA512 930c42b63a230f6f64ecdaec95f61e43b463abe109f926c298507fa3c6b090edba1f8dcc95046a0a5b8c0378d336fbf728f9db77b8b0822d0e2b36713fefc9e5
+AUX rpc.statd.initd 520 BLAKE2B 701d58e57520dd9237a7e2261071304a1f820816c0902e06122a4729872432e6c29dc62a686f53d674a75f2c3050b6adf04b2d3c665f2f3639362fecf0ca929c SHA512 62c3bef69ca0619e3492050379a4c8b490305ab0ee7620143c31be7af414b1f1cbd79feaee345bd5e6bfdfa6c93bcce3cc9ff61a2f63e235a3807920e260cb7a
+DIST freebsd-src-11.1.tar.xz 147661560 BLAKE2B a9e6ba9d0e12c8b56ac58575d5f02931edbb6a3545d9dccae78810d2d0470a29b29dd7f724b03b8afafbca23717a71346e4cfbd3530e0f40118a23609c3f414e SHA512 b97707ec7a601ca6bcb682c45f6d94a38484301ac24630d7285eff6f88b027ce6900c93fc62f8ce36e0cf32c91f73a9d1c999db397b7f8782fd74a8551a03aca
+EBUILD freebsd-usbin-11.1.ebuild 5442 BLAKE2B 68a9b16ec4eceded11cbfda41eaf8e5d5108e43ba16d351c8e7e82480ab747f9088592bf6dc9aeb35507cfe0d53936108dee467ed0ddac1b728141116925f42b SHA512 ec043c20093c49637c5ee352259015addcf23c610c893a21b3a9f512b097b3d659ed788316540435b3edfedbe3b949325f2a935a8d46acd61593cb27dd6756ac
+EBUILD freebsd-usbin-11.1_p1.ebuild 5548 BLAKE2B 6217891573dc7dd83498f33f90b8c0c8a64ea6ace55694f395a95c9a076047235d8418874f3fc93fb858370a70ed52c3cbeb65a7e053a72ecea5f6feb02d9d9c SHA512 ffa8839deadf38ee3607f372d4aecc418254417c026b712deeb68cb2c7527c2d91f845580d3d3e31f985c6bd975a3524aa54786a76c115beaee765a2fc6f9d3e
+MISC metadata.xml 599 BLAKE2B 70b00a85a1d670dc842bf5234aa6a82cc31564ec25c2f1789440b5beae5e4e0ab76b7b16122b92205d616e86225d892eb183f21c3e0c8aa63cb32f60a0647265 SHA512 afe1f9e8ccacac89bcd308b6476bba009035542f86d71f70f27df029ff20dda7ff7ff8c9510e6939d502a31750c6bf69de608440fb61b1d590d018446aa14f99
diff --git a/sys-freebsd/freebsd-usbin/files/freebsd-usbin-10.3-bsdxml2expat.patch b/sys-freebsd/freebsd-usbin/files/freebsd-usbin-10.3-bsdxml2expat.patch
new file mode 100644
index 000000000000..207b6ab6a50d
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/files/freebsd-usbin-10.3-bsdxml2expat.patch
@@ -0,0 +1,13 @@
+diff --git a/usr.sbin/camdd/camdd.c b/usr.sbin/camdd/camdd.c
+index 88c648e..edf9c8b 100644
+--- a/usr.sbin/camdd/camdd.c
++++ b/usr.sbin/camdd/camdd.c
+@@ -71,7 +71,7 @@ __FBSDID("$FreeBSD: stable/10/usr.sbin/camdd/camdd.c 293409 2016-01-08 02:56:21Z
+ #include <libutil.h>
+ #include <pthread.h>
+ #include <assert.h>
+-#include <bsdxml.h>
++#include <expat.h>
+
+ #include <cam/cam.h>
+ #include <cam/cam_debug.h>
diff --git a/sys-freebsd/freebsd-usbin/files/freebsd-usbin-11.0-workaround.patch b/sys-freebsd/freebsd-usbin/files/freebsd-usbin-11.0-workaround.patch
new file mode 100644
index 000000000000..04ba75a17ec5
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/files/freebsd-usbin-11.0-workaround.patch
@@ -0,0 +1,13 @@
+diff --git a/usr.sbin/nmtree/Makefile b/usr.sbin/nmtree/Makefile
+index 033002c..d198f10 100644
+--- a/usr.sbin/nmtree/Makefile
++++ b/usr.sbin/nmtree/Makefile
+@@ -5,7 +5,7 @@
+ .PATH: ${.CURDIR}/../../contrib/mtree
+
+ PROG= mtree
+-MAN= mtree.5 mtree.8
++MAN= mtree.8
+ SRCS= compare.c crc.c create.c excludes.c getid.c misc.c mtree.c \
+ only.c spec.c specspec.c verify.c
+
diff --git a/sys-freebsd/freebsd-usbin/files/freebsd-usbin-11.1-bsdxml2expat.patch b/sys-freebsd/freebsd-usbin/files/freebsd-usbin-11.1-bsdxml2expat.patch
new file mode 100644
index 000000000000..5317b256cb4c
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/files/freebsd-usbin-11.1-bsdxml2expat.patch
@@ -0,0 +1,26 @@
+diff --git a/usr.sbin/ctladm/ctladm.c b/usr.sbin/ctladm/ctladm.c
+index 9a9d3ff..bf6b1b2 100644
+--- a/usr.sbin/ctladm/ctladm.c
++++ b/usr.sbin/ctladm/ctladm.c
+@@ -51,7 +51,7 @@ __FBSDID("$FreeBSD: stable/11/usr.sbin/ctladm/ctladm.c 319152 2017-05-29 18:17:3
+ #include <sys/queue.h>
+ #include <sys/sbuf.h>
+ #include <sys/stat.h>
+-#include <bsdxml.h>
++#include <expat.h>
+ #include <ctype.h>
+ #include <err.h>
+ #include <errno.h>
+diff --git a/usr.sbin/ctld/kernel.c b/usr.sbin/ctld/kernel.c
+index 7054a04..ee05214 100644
+--- a/usr.sbin/ctld/kernel.c
++++ b/usr.sbin/ctld/kernel.c
+@@ -47,7 +47,7 @@ __FBSDID("$FreeBSD: stable/11/usr.sbin/ctld/kernel.c 319152 2017-05-29 18:17:34Z
+ #include <sys/sbuf.h>
+ #include <sys/stat.h>
+ #include <assert.h>
+-#include <bsdxml.h>
++#include <expat.h>
+ #include <ctype.h>
+ #include <errno.h>
+ #include <fcntl.h>
diff --git a/sys-freebsd/freebsd-usbin/files/freebsd-usbin-9.0-newsyslog.patch b/sys-freebsd/freebsd-usbin/files/freebsd-usbin-9.0-newsyslog.patch
new file mode 100644
index 000000000000..1d838655c88e
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/files/freebsd-usbin-9.0-newsyslog.patch
@@ -0,0 +1,12 @@
+diff -uNr usr.sbin/newsyslog.old/pathnames.h usr.sbin/newsyslog/pathnames.h
+--- usr.sbin/newsyslog.old/pathnames.h 2011-11-02 20:12:37.000000000 +0000
++++ usr.sbin/newsyslog/pathnames.h 2011-11-02 20:12:50.000000000 +0000
+@@ -24,6 +24,6 @@
+
+ #define _PATH_CONF "/etc/newsyslog.conf"
+ #define _PATH_SYSLOGPID _PATH_VARRUN "syslog.pid"
+-#define _PATH_BZIP2 "/usr/bin/bzip2"
+-#define _PATH_GZIP "/usr/bin/gzip"
++#define _PATH_BZIP2 "/bin/bzip2"
++#define _PATH_GZIP "/bin/gzip"
+ #define _PATH_XZ "/usr/bin/xz"
diff --git a/sys-freebsd/freebsd-usbin/files/freebsd-usbin-SA-1803-speculative_execution-amd64-11.patch b/sys-freebsd/freebsd-usbin/files/freebsd-usbin-SA-1803-speculative_execution-amd64-11.patch
new file mode 100644
index 000000000000..0cc67ad8f342
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/files/freebsd-usbin-SA-1803-speculative_execution-amd64-11.patch
@@ -0,0 +1,189 @@
+--- usr.sbin/cpucontrol/cpucontrol.8.orig
++++ usr.sbin/cpucontrol/cpucontrol.8
+@@ -24,7 +24,7 @@
+ .\"
+ .\" $FreeBSD$
+ .\"
+-.Dd June 30, 2009
++.Dd January 5, 2018
+ .Dt CPUCONTROL 8
+ .Os
+ .Sh NAME
+@@ -36,44 +36,48 @@
+ .Nm
+ .Op Fl vh
+ .Fl m Ar msr
+-.Bk
+ .Ar device
+ .Ek
++.Bk
+ .Nm
+ .Op Fl vh
+ .Fl m Ar msr Ns = Ns Ar value
+-.Bk
+ .Ar device
+ .Ek
++.Bk
+ .Nm
+ .Op Fl vh
+ .Fl m Ar msr Ns &= Ns Ar mask
+-.Bk
+ .Ar device
+ .Ek
++.Bk
+ .Nm
+ .Op Fl vh
+ .Fl m Ar msr Ns |= Ns Ar mask
+-.Bk
+ .Ar device
+ .Ek
++.Bk
+ .Nm
+ .Op Fl vh
+ .Fl i Ar level
+-.Bk
+ .Ar device
+ .Ek
++.Bk
+ .Nm
+ .Op Fl vh
+ .Fl i Ar level,level_type
+-.Bk
+ .Ar device
+ .Ek
++.Bk
+ .Nm
+ .Op Fl vh
+ .Op Fl d Ar datadir
+ .Fl u
++.Ar device
++.Ek
+ .Bk
++.Nm
++.Fl e
+ .Ar device
+ .Ek
+ .Sh DESCRIPTION
+@@ -129,6 +133,20 @@
+ .Nm
+ utility will walk through the configured data directories
+ and apply all firmware updates available for this CPU.
++.It Fl e
++Re-evaluate the kernel flags indicating the present CPU features.
++This command is typically executed after a firmware update was applied
++which changes information reported by the
++.Dv CPUID
++instruction.
++.Pp
++.Bf -symbolic
++Only execute the
++.Fl e
++command after the microcode update was applied to all CPUs in the system.
++The kernel does not operate correctly if the features of processors are
++not identical.
++.Ef
+ .It Fl v
+ Increase the verbosity level.
+ .It Fl h
+--- usr.sbin/cpucontrol/cpucontrol.c.orig
++++ usr.sbin/cpucontrol/cpucontrol.c
+@@ -60,6 +60,7 @@
+ #define FLAG_I 0x01
+ #define FLAG_M 0x02
+ #define FLAG_U 0x04
++#define FLAG_E 0x10
+
+ #define OP_INVAL 0x00
+ #define OP_READ 0x01
+@@ -114,7 +115,7 @@
+ if (name == NULL)
+ name = "cpuctl";
+ fprintf(stderr, "Usage: %s [-vh] [-d datadir] [-m msr[=value] | "
+- "-i level | -i level,level_type | -u] device\n", name);
++ "-i level | -i level,level_type | -e | -u] device\n", name);
+ exit(EX_USAGE);
+ }
+
+@@ -338,6 +339,25 @@
+ }
+
+ static int
++do_eval_cpu_features(const char *dev)
++{
++ int fd, error;
++
++ assert(dev != NULL);
++
++ fd = open(dev, O_RDWR);
++ if (fd < 0) {
++ WARN(0, "error opening %s for writing", dev);
++ return (1);
++ }
++ error = ioctl(fd, CPUCTL_EVAL_CPU_FEATURES, NULL);
++ if (error < 0)
++ WARN(0, "ioctl(%s, CPUCTL_EVAL_CPU_FEATURES)", dev);
++ close(fd);
++ return (error);
++}
++
++static int
+ do_update(const char *dev)
+ {
+ int fd;
+@@ -431,11 +451,14 @@
+ * Add all default data dirs to the list first.
+ */
+ datadir_add(DEFAULT_DATADIR);
+- while ((c = getopt(argc, argv, "d:hi:m:uv")) != -1) {
++ while ((c = getopt(argc, argv, "d:ehi:m:uv")) != -1) {
+ switch (c) {
+ case 'd':
+ datadir_add(optarg);
+ break;
++ case 'e':
++ flags |= FLAG_E;
++ break;
+ case 'i':
+ flags |= FLAG_I;
+ cmdarg = optarg;
+@@ -464,22 +487,25 @@
+ /* NOTREACHED */
+ }
+ dev = argv[0];
+- c = flags & (FLAG_I | FLAG_M | FLAG_U);
++ c = flags & (FLAG_E | FLAG_I | FLAG_M | FLAG_U);
+ switch (c) {
+- case FLAG_I:
+- if (strstr(cmdarg, ",") != NULL)
+- error = do_cpuid_count(cmdarg, dev);
+- else
+- error = do_cpuid(cmdarg, dev);
+- break;
+- case FLAG_M:
+- error = do_msr(cmdarg, dev);
+- break;
+- case FLAG_U:
+- error = do_update(dev);
+- break;
+- default:
+- usage(); /* Only one command can be selected. */
++ case FLAG_I:
++ if (strstr(cmdarg, ",") != NULL)
++ error = do_cpuid_count(cmdarg, dev);
++ else
++ error = do_cpuid(cmdarg, dev);
++ break;
++ case FLAG_M:
++ error = do_msr(cmdarg, dev);
++ break;
++ case FLAG_U:
++ error = do_update(dev);
++ break;
++ case FLAG_E:
++ error = do_eval_cpu_features(dev);
++ break;
++ default:
++ usage(); /* Only one command can be selected. */
+ }
+ SLIST_FREE(&datadirs, next, free);
+ return (error == 0 ? 0 : 1);
diff --git a/sys-freebsd/freebsd-usbin/files/freebsd-usbin-adduser.patch b/sys-freebsd/freebsd-usbin/files/freebsd-usbin-adduser.patch
new file mode 100644
index 000000000000..39177b4a987d
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/files/freebsd-usbin-adduser.patch
@@ -0,0 +1,20 @@
+--- usr.sbin/adduser/adduser.sh.old 2006-10-01 13:41:16 +0000
++++ usr.sbin/adduser/adduser.sh 2006-10-01 13:41:38 +0000
+@@ -809,7 +809,7 @@
+ NOHOME="/nonexistent"
+ NOLOGIN="nologin"
+ NOLOGIN_PATH="/usr/sbin/nologin"
+-GREPCMD="/usr/bin/grep"
++GREPCMD="/bin/grep"
+ DATECMD="/bin/date"
+
+ # Set default values
+@@ -823,7 +823,7 @@
+ uhome=
+ upass=
+ ushell=
+-udotdir=/usr/share/skel
++udotdir=/etc/skel
+ ugroups=
+ uexpire=
+ upwexpire=
diff --git a/sys-freebsd/freebsd-usbin/files/iscsid.initd b/sys-freebsd/freebsd-usbin/files/iscsid.initd
new file mode 100644
index 000000000000..f16d00e876ab
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/files/iscsid.initd
@@ -0,0 +1,20 @@
+#!/sbin/openrc-run
+# Copyright 1999-2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+depend() {
+ need net
+}
+
+start() {
+ ebegin "Starting iscsid"
+ start-stop-daemon --start --quiet --exec \
+ /usr/sbin/iscsid -- $iscsidopts
+ eend $? "Error starting iscsid"
+}
+
+stop() {
+ ebegin "Stopping iscsid"
+ start-stop-daemon --stop --quiet --exec /usr/sbin/iscsid
+ eend $? "Error stopping iscsid"
+}
diff --git a/sys-freebsd/freebsd-usbin/files/nfs.confd b/sys-freebsd/freebsd-usbin/files/nfs.confd
new file mode 100644
index 000000000000..844252fdc54d
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/files/nfs.confd
@@ -0,0 +1,10 @@
+# Config file for /etc/init.d/nfs
+# Options for nfsd (see man nfsd)
+# Example: 8 nfsd servers started:
+#nfsdopts="-n 8"
+
+# Options for mountd (see man mountd)
+# Example: allow non-root users to mount shares:
+#mountdopts="-n"
+# Specify t he exports file, this is the default:
+#exportsfile="/etc/exports"
diff --git a/sys-freebsd/freebsd-usbin/files/nfs.initd b/sys-freebsd/freebsd-usbin/files/nfs.initd
new file mode 100644
index 000000000000..17974ca0998a
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/files/nfs.initd
@@ -0,0 +1,54 @@
+#!/sbin/openrc-run
+# Copyright 1999-2013 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+#---------------------------------------------------------------------------
+# This script starts/stops nfsd and mountd
+# Daemons rpc.rquotad, rpc.rstatd, rpc.rusersd, rpc.rwalld and rpc.sprayd
+# should be started from inetd on FreeBSD.
+#---------------------------------------------------------------------------
+
+extra_started_commands="reload"
+
+# The binary locations
+nfsd=/usr/sbin/nfsd
+mountd=/usr/sbin/mountd
+
+depend() {
+ use ypbind net rpc.lockd
+ need rpcbind
+ after quota
+}
+
+start() {
+ ebegin "Starting NFS daemon"
+ start-stop-daemon --start --quiet --exec \
+ $nfsd -- ${nfsdopts}
+ eend $? "Error starting NFS daemon"
+
+ # Start mountd
+ ebegin "Starting NFS mountd"
+ start-stop-daemon --start --quiet --exec \
+ $mountd -- ${mountdopts} ${exportsfile}
+ eend $? "Error starting NFS mountd"
+}
+
+stop() {
+ ebegin "Stopping NFS mountd"
+ start-stop-daemon --stop --quiet --exec $mountd \
+ --pidfile /var/run/mountd.pid
+ eend $? "Error stopping NFS mountd"
+
+ ebegin "Stopping NFS daemon"
+ start-stop-daemon --stop --signal USR1 --quiet \
+ --name nfsd --user root
+ eend $? "Error stopping NFS daemon"
+}
+
+reload() {
+ # Hangup signal to mountd reloads /etc/exports.
+ ebegin "Reloading /etc/exports"
+ start-stop-daemon --signal 1 --quiet --exec $mountd \
+ --pidfile /var/run/mountd.pid
+ eend $?
+}
diff --git a/sys-freebsd/freebsd-usbin/files/nfsuserd.confd b/sys-freebsd/freebsd-usbin/files/nfsuserd.confd
new file mode 100644
index 000000000000..f8f3ea1e31de
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/files/nfsuserd.confd
@@ -0,0 +1,5 @@
+# Config file for /etc/init.d/nfsuserd
+# Options for nfsuserd (see man nfsuserd)
+# Example: set domain example.com:
+#nfsuserdopts="-domain example.com"
+
diff --git a/sys-freebsd/freebsd-usbin/files/nfsuserd.initd b/sys-freebsd/freebsd-usbin/files/nfsuserd.initd
new file mode 100644
index 000000000000..d69007412fc6
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/files/nfsuserd.initd
@@ -0,0 +1,20 @@
+#!/sbin/openrc-run
+# Copyright 1999-2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+depend() {
+ need net nfs
+}
+
+start() {
+ ebegin "Starting nfsuserd"
+ start-stop-daemon --start --quiet --exec \
+ /usr/sbin/nfsuserd -- $nfsuserdopts
+ eend $? "Error starting nfsuserd"
+}
+
+stop() {
+ ebegin "Stopping nfsuserd"
+ start-stop-daemon --stop --quiet --exec /usr/sbin/nfsuserd
+ eend $? "Error stopping nfsuserd"
+}
diff --git a/sys-freebsd/freebsd-usbin/files/pw.conf b/sys-freebsd/freebsd-usbin/files/pw.conf
new file mode 100644
index 000000000000..29a246f72b8f
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/files/pw.conf
@@ -0,0 +1,5 @@
+# Change this to Gentoo's Default, instead of FreeBSD's default of
+# /usr/share/skel, so that bash and other packages installs the files on the
+# right place.
+skeleton /etc/skel
+
diff --git a/sys-freebsd/freebsd-usbin/files/rpc.lockd.initd b/sys-freebsd/freebsd-usbin/files/rpc.lockd.initd
new file mode 100644
index 000000000000..dd2fdbe8a756
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/files/rpc.lockd.initd
@@ -0,0 +1,20 @@
+#!/sbin/openrc-run
+# Copyright 1999-2008 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+depend() {
+ need net rpcbind rpc.statd
+}
+
+start() {
+ ebegin "Starting NFS lockd"
+ start-stop-daemon --start --quiet --exec \
+ /usr/sbin/rpc.lockd -- $rpclockdopts
+ eend $? "Error starting NFS lockd"
+}
+
+stop() {
+ ebegin "Stopping NFS lockd"
+ start-stop-daemon --stop --quiet --exec /usr/sbin/rpc.lockd
+ eend $? "Error stopping NFS lockd"
+}
diff --git a/sys-freebsd/freebsd-usbin/files/rpc.statd.initd b/sys-freebsd/freebsd-usbin/files/rpc.statd.initd
new file mode 100644
index 000000000000..163af5a4b4a1
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/files/rpc.statd.initd
@@ -0,0 +1,20 @@
+#!/sbin/openrc-run
+# Copyright 1999-2008 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+depend() {
+ need net rpcbind
+}
+
+start() {
+ ebegin "Starting NFS statd"
+ start-stop-daemon --start --quiet --exec \
+ /usr/sbin/rpc.statd -- $rpcstatdopts
+ eend $? "Error starting NFS statd"
+}
+
+stop() {
+ ebegin "Stopping NFS statd"
+ start-stop-daemon --stop --quiet --exec /usr/sbin/rpc.statd
+ eend $? "Error stopping NFS statd"
+}
diff --git a/sys-freebsd/freebsd-usbin/freebsd-usbin-11.1.ebuild b/sys-freebsd/freebsd-usbin/freebsd-usbin-11.1.ebuild
new file mode 100644
index 000000000000..5e4b26e2c2fd
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/freebsd-usbin-11.1.ebuild
@@ -0,0 +1,189 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd flag-o-matic eutils
+
+DESCRIPTION="FreeBSD /usr/sbin tools"
+SLOT="0"
+LICENSE="BSD zfs? ( CDDL )"
+
+# Security Advisory and Errata patches.
+# UPSTREAM_PATCHES=()
+
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64-fbsd ~x86-fbsd"
+ SRC_URI="${SRC_URI}
+ $(freebsd_upstream_patches)"
+fi
+
+EXTRACTONLY="
+ usr.sbin/
+ contrib/
+ usr.bin/
+ lib/
+ sbin/
+ etc/
+ gnu/
+"
+
+RDEPEND="=sys-freebsd/freebsd-lib-${RV}*[usb?,bluetooth?,netware?]
+ build? ( sys-apps/baselayout )
+ ssl? ( dev-libs/openssl:0 )
+ >=app-arch/libarchive-3
+ sys-apps/tcp-wrappers
+ dev-util/dialog
+ >=dev-libs/libedit-20120311.3.0-r1
+ net-libs/libpcap
+ kerberos? ( app-crypt/heimdal )"
+DEPEND="${RDEPEND}
+ =sys-freebsd/freebsd-mk-defs-${RV}*
+ =sys-freebsd/freebsd-ubin-${RV}*
+ zfs? ( =sys-freebsd/freebsd-cddl-${RV}* )
+ !build? ( =sys-freebsd/freebsd-sources-${RV}* )
+ sys-apps/texinfo
+ sys-devel/flex"
+
+S="${WORKDIR}/usr.sbin"
+
+IUSE="acpi atm audit bluetooth floppy ipv6 kerberos minimal netware nis pam ssl usb build zfs"
+
+pkg_setup() {
+ # Add the required source files.
+ use nis && EXTRACTONLY+="libexec/ "
+ use build && EXTRACTONLY+="sys/ include/ "
+ use zfs && EXTRACTONLY+="cddl/ "
+
+ # Release crunch is something like minimal. It seems to remove everything
+ # which is not needed to work.
+ use minimal && mymakeopts="${mymakeopts} RELEASE_CRUNCH= "
+
+ use acpi || mymakeopts="${mymakeopts} WITHOUT_ACPI= "
+ use atm || mymakeopts="${mymakeopts} WITHOUT_ATM= "
+ use audit || mymakeopts="${mymakeopts} WITHOUT_AUDIT= "
+ use bluetooth || mymakeopts="${mymakeopts} WITHOUT_BLUETOOTH= "
+ use ipv6 || mymakeopts="${mymakeopts} WITHOUT_INET6= WITHOUT_INET6_SUPPORT= "
+ use netware || mymakeopts="${mymakeopts} WITHOUT_IPX= WITHOUT_IPX_SUPPORT= WITHOUT_NCP= "
+ use nis || mymakeopts="${mymakeopts} WITHOUT_NIS= "
+ use pam || mymakeopts="${mymakeopts} WITHOUT_PAM_SUPPORT= "
+ use ssl || mymakeopts="${mymakeopts} WITHOUT_OPENSSL= "
+ use usb || mymakeopts="${mymakeopts} WITHOUT_USB= "
+ use floppy || mymakeopts="${mymakeopts} WITHOUT_FLOPPY= "
+ use kerberos || mymakeopts="${mymakeopts} WITHOUT_GSSAPI= "
+ use zfs || mymakeopts="${mymakeopts} WITHOUT_CDDL= "
+
+ mymakeopts="${mymakeopts} WITHOUT_PF= WITHOUT_LPR= WITHOUT_SENDMAIL= WITHOUT_AUTHPF= WITHOUT_MAILWRAPPER= WITHOUT_UNBOUND= "
+
+ append-flags $(test-flags -fno-strict-aliasing)
+}
+
+PATCHES=(
+ "${FILESDIR}/${PN}-adduser.patch"
+ "${FILESDIR}/${PN}-9.0-newsyslog.patch"
+ "${FILESDIR}/${PN}-11.1-bsdxml2expat.patch"
+ "${FILESDIR}/${PN}-10.3-bsdxml2expat.patch"
+ "${FILESDIR}/${PN}-11.0-workaround.patch"
+ )
+
+REMOVE_SUBDIRS="
+ tcpdchk tcpdmatch
+ sendmail praliases editmap mailstats makemap
+ pc-sysinstall cron mailwrapper ntp bsnmpd
+ tcpdump ndp inetd
+ wpa/wpa_supplicant wpa/hostapd wpa/hostapd_cli wpa/wpa_cli wpa/wpa_passphrase
+ zic amd
+ pkg freebsd-update service sysrc bsdinstall"
+
+src_prepare() {
+ if ! use build; then
+ [[ ! -e "${WORKDIR}/sys" ]] && ln -s "/usr/src/sys" "${WORKDIR}/sys"
+ [[ ! -e "${WORKDIR}/include" ]] && ln -s "/usr/include" "${WORKDIR}/include"
+ else
+ dummy_mk mount_smbfs
+ fi
+}
+
+src_compile() {
+ # Preparing to build nmtree, ypldap
+ for dir in libnetbsd libopenbsd; do
+ cd "${WORKDIR}/lib/${dir}" || die
+ freebsd_src_compile -j1
+ done
+
+ cd "${S}" || die
+ freebsd_src_compile
+}
+
+src_install() {
+ # By creating these directories we avoid having to do a
+ # more complex hack
+ dodir /usr/share/doc
+ dodir /sbin
+ dodir /usr/libexec
+ dodir /usr/bin
+
+ # FILESDIR is used by some makefiles which will install files
+ # in the wrong place, just put it in the doc directory.
+ freebsd_src_install DOCDIR=/usr/share/doc/${PF}
+
+ # Most of these now come from openrc.
+ for util in iscsid nfs nfsuserd rpc.statd rpc.lockd; do
+ newinitd "${FILESDIR}/"${util}.initd ${util}
+ if [[ -e "${FILESDIR}"/${util}.confd ]]; then \
+ newconfd "${FILESDIR}"/${util}.confd ${util}
+ fi
+ done
+
+ for class in daily monthly weekly; do
+ cat - > "${T}/periodic.${class}" <<EOS
+#!/bin/sh
+/usr/sbin/periodic ${class}
+EOS
+ exeinto /etc/cron.${class}
+ newexe "${T}/periodic.${class}" periodic
+ done
+
+ # Install the pw.conf file to let pw use Gentoo's skel location
+ insinto /etc
+ doins "${FILESDIR}/pw.conf"
+
+ cd "${WORKDIR}/etc" || die
+ doins apmd.conf syslog.conf newsyslog.conf nscd.conf
+
+ if use bluetooth; then
+ insinto /etc/bluetooth
+ doins bluetooth/*
+ rm -f "${D}"/etc/bluetooth/Makefile
+ fi
+
+ cd "${S}"/ppp || die
+ insinto /etc/ppp
+ doins ppp.conf
+
+ # Install the periodic stuff (needs probably to be ported in a more
+ # gentooish way)
+ cd "${WORKDIR}/etc/periodic" || die
+
+ doperiodic daily daily/*.accounting
+ doperiodic monthly monthly/*.accounting
+}
+
+pkg_postinst() {
+ # We need to run pwd_mkdb if key files are not present
+ # If they are, then there is no need to run pwd_mkdb
+ if [[ ! -e "${ROOT}etc/passwd" || ! -e "${ROOT}etc/pwd.db" || ! -e "${ROOT}etc/spwd.db" ]] ; then
+ if [[ -e "${ROOT}etc/master.passwd" ]] ; then
+ einfo "Generating passwd files from ${ROOT}etc/master.passwd"
+ "${ROOT}"usr/sbin/pwd_mkdb -p -d "${ROOT}etc" "${ROOT}etc/master.passwd"
+ else
+ eerror "${ROOT}etc/master.passwd does not exist!"
+ eerror "You will no be able to log into your system!"
+ fi
+ fi
+
+ for logfile in messages security auth.log maillog lpd-errs xferlog cron \
+ debug.log slip.log ppp.log; do
+ [[ -f "${ROOT}/var/log/${logfile}" ]] || touch "${ROOT}/var/log/${logfile}"
+ done
+}
diff --git a/sys-freebsd/freebsd-usbin/freebsd-usbin-11.1_p1.ebuild b/sys-freebsd/freebsd-usbin/freebsd-usbin-11.1_p1.ebuild
new file mode 100644
index 000000000000..7eb0e4f04f7c
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/freebsd-usbin-11.1_p1.ebuild
@@ -0,0 +1,191 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit bsdmk freebsd flag-o-matic eutils
+
+DESCRIPTION="FreeBSD /usr/sbin tools"
+SLOT="0"
+LICENSE="BSD zfs? ( CDDL )"
+
+# Security Advisory and Errata patches.
+# UPSTREAM_PATCHES=()
+
+if [[ ${PV} != *9999* ]]; then
+ KEYWORDS="~amd64-fbsd ~x86-fbsd"
+ SRC_URI="${SRC_URI}
+ $(freebsd_upstream_patches)"
+fi
+
+EXTRACTONLY="
+ usr.sbin/
+ contrib/
+ usr.bin/
+ lib/
+ sbin/
+ etc/
+ gnu/
+"
+
+RDEPEND="=sys-freebsd/freebsd-lib-${RV}*[usb?,bluetooth?,netware?]
+ build? ( sys-apps/baselayout )
+ ssl? ( dev-libs/openssl:0 )
+ >=app-arch/libarchive-3
+ sys-apps/tcp-wrappers
+ dev-util/dialog
+ >=dev-libs/libedit-20120311.3.0-r1
+ net-libs/libpcap
+ kerberos? ( app-crypt/heimdal )"
+DEPEND="${RDEPEND}
+ =sys-freebsd/freebsd-mk-defs-${RV}*
+ =sys-freebsd/freebsd-ubin-${RV}*
+ zfs? ( =sys-freebsd/freebsd-cddl-${RV}* )
+ !build? ( =sys-freebsd/freebsd-sources-${RV}*
+ >=sys-freebsd/freebsd-sources-11.1_p3 )
+ sys-apps/texinfo
+ sys-devel/flex"
+
+S="${WORKDIR}/usr.sbin"
+
+IUSE="acpi atm audit bluetooth floppy ipv6 kerberos minimal netware nis pam ssl usb build zfs"
+
+pkg_setup() {
+ # Add the required source files.
+ use nis && EXTRACTONLY+="libexec/ "
+ use build && EXTRACTONLY+="sys/ include/ "
+ use zfs && EXTRACTONLY+="cddl/ "
+
+ # Release crunch is something like minimal. It seems to remove everything
+ # which is not needed to work.
+ use minimal && mymakeopts="${mymakeopts} RELEASE_CRUNCH= "
+
+ use acpi || mymakeopts="${mymakeopts} WITHOUT_ACPI= "
+ use atm || mymakeopts="${mymakeopts} WITHOUT_ATM= "
+ use audit || mymakeopts="${mymakeopts} WITHOUT_AUDIT= "
+ use bluetooth || mymakeopts="${mymakeopts} WITHOUT_BLUETOOTH= "
+ use ipv6 || mymakeopts="${mymakeopts} WITHOUT_INET6= WITHOUT_INET6_SUPPORT= "
+ use netware || mymakeopts="${mymakeopts} WITHOUT_IPX= WITHOUT_IPX_SUPPORT= WITHOUT_NCP= "
+ use nis || mymakeopts="${mymakeopts} WITHOUT_NIS= "
+ use pam || mymakeopts="${mymakeopts} WITHOUT_PAM_SUPPORT= "
+ use ssl || mymakeopts="${mymakeopts} WITHOUT_OPENSSL= "
+ use usb || mymakeopts="${mymakeopts} WITHOUT_USB= "
+ use floppy || mymakeopts="${mymakeopts} WITHOUT_FLOPPY= "
+ use kerberos || mymakeopts="${mymakeopts} WITHOUT_GSSAPI= "
+ use zfs || mymakeopts="${mymakeopts} WITHOUT_CDDL= "
+
+ mymakeopts="${mymakeopts} WITHOUT_PF= WITHOUT_LPR= WITHOUT_SENDMAIL= WITHOUT_AUTHPF= WITHOUT_MAILWRAPPER= WITHOUT_UNBOUND= "
+
+ append-flags $(test-flags -fno-strict-aliasing)
+}
+
+PATCHES=(
+ "${FILESDIR}/${PN}-adduser.patch"
+ "${FILESDIR}/${PN}-9.0-newsyslog.patch"
+ "${FILESDIR}/${PN}-11.1-bsdxml2expat.patch"
+ "${FILESDIR}/${PN}-10.3-bsdxml2expat.patch"
+ "${FILESDIR}/${PN}-11.0-workaround.patch"
+ "${FILESDIR}/${PN}-SA-1803-speculative_execution-amd64-11.patch"
+ )
+
+REMOVE_SUBDIRS="
+ tcpdchk tcpdmatch
+ sendmail praliases editmap mailstats makemap
+ pc-sysinstall cron mailwrapper ntp bsnmpd
+ tcpdump ndp inetd
+ wpa/wpa_supplicant wpa/hostapd wpa/hostapd_cli wpa/wpa_cli wpa/wpa_passphrase
+ zic amd
+ pkg freebsd-update service sysrc bsdinstall"
+
+src_prepare() {
+ if ! use build; then
+ [[ ! -e "${WORKDIR}/sys" ]] && ln -s "/usr/src/sys" "${WORKDIR}/sys"
+ [[ ! -e "${WORKDIR}/include" ]] && ln -s "/usr/include" "${WORKDIR}/include"
+ else
+ dummy_mk mount_smbfs
+ fi
+}
+
+src_compile() {
+ # Preparing to build nmtree, ypldap
+ for dir in libnetbsd libopenbsd; do
+ cd "${WORKDIR}/lib/${dir}" || die
+ freebsd_src_compile -j1
+ done
+
+ cd "${S}" || die
+ freebsd_src_compile
+}
+
+src_install() {
+ # By creating these directories we avoid having to do a
+ # more complex hack
+ dodir /usr/share/doc
+ dodir /sbin
+ dodir /usr/libexec
+ dodir /usr/bin
+
+ # FILESDIR is used by some makefiles which will install files
+ # in the wrong place, just put it in the doc directory.
+ freebsd_src_install DOCDIR=/usr/share/doc/${PF}
+
+ # Most of these now come from openrc.
+ for util in iscsid nfs nfsuserd rpc.statd rpc.lockd; do
+ newinitd "${FILESDIR}/"${util}.initd ${util}
+ if [[ -e "${FILESDIR}"/${util}.confd ]]; then \
+ newconfd "${FILESDIR}"/${util}.confd ${util}
+ fi
+ done
+
+ for class in daily monthly weekly; do
+ cat - > "${T}/periodic.${class}" <<EOS
+#!/bin/sh
+/usr/sbin/periodic ${class}
+EOS
+ exeinto /etc/cron.${class}
+ newexe "${T}/periodic.${class}" periodic
+ done
+
+ # Install the pw.conf file to let pw use Gentoo's skel location
+ insinto /etc
+ doins "${FILESDIR}/pw.conf"
+
+ cd "${WORKDIR}/etc" || die
+ doins apmd.conf syslog.conf newsyslog.conf nscd.conf
+
+ if use bluetooth; then
+ insinto /etc/bluetooth
+ doins bluetooth/*
+ rm -f "${D}"/etc/bluetooth/Makefile
+ fi
+
+ cd "${S}"/ppp || die
+ insinto /etc/ppp
+ doins ppp.conf
+
+ # Install the periodic stuff (needs probably to be ported in a more
+ # gentooish way)
+ cd "${WORKDIR}/etc/periodic" || die
+
+ doperiodic daily daily/*.accounting
+ doperiodic monthly monthly/*.accounting
+}
+
+pkg_postinst() {
+ # We need to run pwd_mkdb if key files are not present
+ # If they are, then there is no need to run pwd_mkdb
+ if [[ ! -e "${ROOT}etc/passwd" || ! -e "${ROOT}etc/pwd.db" || ! -e "${ROOT}etc/spwd.db" ]] ; then
+ if [[ -e "${ROOT}etc/master.passwd" ]] ; then
+ einfo "Generating passwd files from ${ROOT}etc/master.passwd"
+ "${ROOT}"usr/sbin/pwd_mkdb -p -d "${ROOT}etc" "${ROOT}etc/master.passwd"
+ else
+ eerror "${ROOT}etc/master.passwd does not exist!"
+ eerror "You will no be able to log into your system!"
+ fi
+ fi
+
+ for logfile in messages security auth.log maillog lpd-errs xferlog cron \
+ debug.log slip.log ppp.log; do
+ [[ -f "${ROOT}/var/log/${logfile}" ]] || touch "${ROOT}/var/log/${logfile}"
+ done
+}
diff --git a/sys-freebsd/freebsd-usbin/metadata.xml b/sys-freebsd/freebsd-usbin/metadata.xml
new file mode 100644
index 000000000000..45c930b831cb
--- /dev/null
+++ b/sys-freebsd/freebsd-usbin/metadata.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <maintainer type="project">
+ <email>bsd@gentoo.org</email>
+ <name>BSD Project</name>
+ </maintainer>
+ <use>
+ <flag name="floppy">Enable floppy disk utilities (fdcontrol, fdformat, fdread, fdwrite).</flag>
+ <flag name="audit">
+ Build auditing tools.
+ </flag>
+ <flag name="netware">
+ Build libraries and tools to work with NetWare protocols (IPX
+ and NCP).
+ </flag>
+ <flag name='zfs'>Enable ZFS support.</flag>
+ </use>
+</pkgmetadata>
diff --git a/sys-freebsd/metadata.xml b/sys-freebsd/metadata.xml
new file mode 100644
index 000000000000..f03a55473120
--- /dev/null
+++ b/sys-freebsd/metadata.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE catmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<catmetadata>
+ <longdescription lang="en">
+ Ebuilds for the Gentoo/FreeBSD base system software.
+ </longdescription>
+ <longdescription lang="it">
+ Ebuild per il software di sistema base di Gentoo/FreeBSD.
+ </longdescription>
+ <longdescription lang="es">
+ Ebuilds para el software base del sistema Gentoo/FreeBSD.
+ </longdescription>
+</catmetadata>
+
diff --git a/sys-freebsd/ubin-wrappers/Manifest b/sys-freebsd/ubin-wrappers/Manifest
new file mode 100644
index 000000000000..ef3aa211791a
--- /dev/null
+++ b/sys-freebsd/ubin-wrappers/Manifest
@@ -0,0 +1,2 @@
+EBUILD ubin-wrappers-0.ebuild 769 BLAKE2B b18bca98024fc32a287283f5ad80cf6d7070fe0c57368e356c5e43e3f2958d677151adc3c87e06d7f0ac580e5497ade2c5001a093384f416824a0592524017d6 SHA512 6b11cf09d20ce8a585c3191ff69b19ef918c87b7a1e35d2dc6f71b3662e879147059f05588e821f908d13f17e274148bec4711020137098888f7355c3eb17959
+MISC metadata.xml 167 BLAKE2B e4dadf27fd344484f2bccb5b904909c89aac568c32e5b3c44bdf139eacefd4b4fae74419f503d2b7da0dccc1b68ba05d777d11292c0f89270d1ac5c9c703e8ca SHA512 7c8decb24ee3a850e38186cf3c7f8933a28017426806870ad6ef9ceb2533be147a2681fc789b535a81cb528af8c29d90d3006e4f250aee23bd7dea4561294e33
diff --git a/sys-freebsd/ubin-wrappers/metadata.xml b/sys-freebsd/ubin-wrappers/metadata.xml
new file mode 100644
index 000000000000..7a38bb900964
--- /dev/null
+++ b/sys-freebsd/ubin-wrappers/metadata.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <!-- maintainer-needed -->
+</pkgmetadata>
diff --git a/sys-freebsd/ubin-wrappers/ubin-wrappers-0.ebuild b/sys-freebsd/ubin-wrappers/ubin-wrappers-0.ebuild
new file mode 100644
index 000000000000..e183e180cc94
--- /dev/null
+++ b/sys-freebsd/ubin-wrappers/ubin-wrappers-0.ebuild
@@ -0,0 +1,36 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+DESCRIPTION="/usr/bin wrapper scripts for FreeBSD script compatibility"
+HOMEPAGE="https://www.gentoo.org"
+SRC_URI=""
+
+LICENSE="public-domain"
+SLOT="0"
+KEYWORDS="~amd64-fbsd ~x86-fbsd"
+IUSE="userland_BSD userland_GNU"
+
+DEPEND=""
+RDEPEND="${DEPEND}"
+
+S="${WORKDIR}"
+
+dowrap() {
+ local x
+ for x do
+ [[ -e ${x} ]] || die "${x} does not exist"
+ newbin - "$(basename "${x}")" <<-EOF
+ #!/bin/sh
+ exec ${x} \${1:+"\$@"}
+ EOF
+ done
+}
+
+src_install() {
+ dowrap \
+ "${EPREFIX}"/bin/{bunzip2,bzcat,cpio,egrep,fgrep,grep,gunzip,gzip,zcat}
+ use userland_BSD && dowrap "${EPREFIX}"/bin/sort
+ use userland_GNU && dowrap "${EPREFIX}"/bin/{fuser,sed,uncompress}
+}