aboutsummaryrefslogtreecommitdiff
path: root/cddl/lib
diff options
context:
space:
mode:
authorMatt Macy <mmacy@FreeBSD.org>2020-08-25 02:21:27 +0000
committerMatt Macy <mmacy@FreeBSD.org>2020-08-25 02:21:27 +0000
commit9e5787d2284e187abb5b654d924394a65772e004 (patch)
tree2ebf833af6b1953d4a683e2da830fe87bf3435e1 /cddl/lib
parent22df1ffd812f0395cdb7c0b1edae1f67b991562a (diff)
downloadsrc-9e5787d2284e187abb5b654d924394a65772e004.tar.gz
src-9e5787d2284e187abb5b654d924394a65772e004.zip
Merge OpenZFS support in to HEAD.
The primary benefit is maintaining a completely shared code base with the community allowing FreeBSD to receive new features sooner and with less effort. I would advise against doing 'zpool upgrade' or creating indispensable pools using new features until this change has had a month+ to soak. Work on merging FreeBSD support in to what was at the time "ZFS on Linux" began in August 2018. I first publicly proposed transitioning FreeBSD to (new) OpenZFS on December 18th, 2018. FreeBSD support in OpenZFS was finally completed in December 2019. A CFT for downstreaming OpenZFS support in to FreeBSD was first issued on July 8th. All issues that were reported have been addressed or, for a couple of less critical matters there are pull requests in progress with OpenZFS. iXsystems has tested and dogfooded extensively internally. The TrueNAS 12 release is based on OpenZFS with some additional features that have not yet made it upstream. Improvements include: project quotas, encrypted datasets, allocation classes, vectorized raidz, vectorized checksums, various command line improvements, zstd compression. Thanks to those who have helped along the way: Ryan Moeller, Allan Jude, Zack Welch, and many others. Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D25872
Notes
Notes: svn path=/head/; revision=364746
Diffstat (limited to 'cddl/lib')
-rw-r--r--cddl/lib/Makefile17
-rw-r--r--cddl/lib/drti/Makefile9
-rw-r--r--cddl/lib/libavl/Makefile11
-rw-r--r--cddl/lib/libctf/Makefile10
-rw-r--r--cddl/lib/libdtrace/Makefile10
-rw-r--r--cddl/lib/libicp/Makefile101
-rw-r--r--cddl/lib/libicp_rescue/Makefile99
-rw-r--r--cddl/lib/libnvpair/Makefile44
-rw-r--r--cddl/lib/libspl/Makefile56
-rw-r--r--cddl/lib/libtpool/Makefile27
-rw-r--r--cddl/lib/libuutil/Makefile22
-rw-r--r--cddl/lib/libzfs/Makefile146
-rw-r--r--cddl/lib/libzfs_core/Makefile39
-rw-r--r--cddl/lib/libzpool/Makefile264
-rw-r--r--cddl/lib/libzpool/Makefile.depend1
-rw-r--r--cddl/lib/libzutil/Makefile42
16 files changed, 733 insertions, 165 deletions
diff --git a/cddl/lib/Makefile b/cddl/lib/Makefile
index b65983dd64a7..399e314e76b1 100644
--- a/cddl/lib/Makefile
+++ b/cddl/lib/Makefile
@@ -6,27 +6,40 @@ SUBDIR= drti \
libavl \
libctf \
libdtrace \
+ ${_libicp} \
+ ${_libicp_rescue} \
libnvpair \
+ libspl \
+ ${_libtpool} \
libumem \
libuutil \
${_libzfs_core} \
${_libzfs} \
${_libzpool} \
+ ${_libzutil}
SUBDIR.${MK_TESTS}+= tests
.if ${MK_ZFS} != "no"
_libzfs_core= libzfs_core
+_libicp= libicp
+_libicp_rescue= libicp_rescue
_libzfs= libzfs
+_libzutil= libzutil
.if ${MK_LIBTHR} != "no"
_libzpool= libzpool
+_libtpool= libtpool
.endif
.endif
+SUBDIR_DEPEND_libctf= libspl
SUBDIR_DEPEND_libdtrace= libctf
+SUBDIR_DEPEND_libtpool= libspl
+SUBDIR_DEPEND_libuutil= libavl libspl
SUBDIR_DEPEND_libzfs_core= libnvpair
-SUBDIR_DEPEND_libzfs= libavl libnvpair libumem libuutil libzfs_core
-SUBDIR_DEPEND_libzpool= libavl libnvpair libumem
+SUBDIR_DEPEND_libzfs= libavl libnvpair libumem libuutil libzfs_core libzutil
+SUBDIR_DEPEND_libzpool= libavl libnvpair libumem libicp
+SUBDIR_DEPEND_libzutil= libavl libtpool
SUBDIR_PARALLEL=
diff --git a/cddl/lib/drti/Makefile b/cddl/lib/drti/Makefile
index 19cbd748d234..eeb1c865e632 100644
--- a/cddl/lib/drti/Makefile
+++ b/cddl/lib/drti/Makefile
@@ -11,7 +11,14 @@ FILESDIR= ${LIBDIR}/dtrace
CLEANFILES= ${FILES}
# These FILES qualify as libraries for the purpose of LIBRARIES_ONLY.
.undef LIBRARIES_ONLY
-
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd/spl
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
CFLAGS+= -I${SRCTOP}/sys/cddl/compat/opensolaris \
-I${SRCTOP}/cddl/compat/opensolaris/include \
-I${OPENSOLARIS_USR_DISTDIR}/head \
diff --git a/cddl/lib/libavl/Makefile b/cddl/lib/libavl/Makefile
index 995e4d013e50..2f7b9ad30856 100644
--- a/cddl/lib/libavl/Makefile
+++ b/cddl/lib/libavl/Makefile
@@ -1,12 +1,15 @@
# $FreeBSD$
-.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/common/avl
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/avl
PACKAGE= runtime
LIB= avl
SRCS= avl.c
WARNS?= 3
-CFLAGS+= -I${SRCTOP}/sys/cddl/compat/opensolaris
-CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common
-
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
.include <bsd.lib.mk>
diff --git a/cddl/lib/libctf/Makefile b/cddl/lib/libctf/Makefile
index ed7ebc5351de..b45bda3385e6 100644
--- a/cddl/lib/libctf/Makefile
+++ b/cddl/lib/libctf/Makefile
@@ -21,6 +21,14 @@ MAN= ctf.5
WARNS?= 2
CFLAGS+= -DCTF_OLD_VERSIONS
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd/spl
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+
CFLAGS+= -I${SRCTOP}/sys/cddl/compat/opensolaris \
-I${SRCTOP}/cddl/compat/opensolaris/include \
-I${OPENSOLARIS_USR_DISTDIR}/head \
@@ -28,6 +36,6 @@ CFLAGS+= -I${SRCTOP}/sys/cddl/compat/opensolaris \
-I${OPENSOLARIS_USR_DISTDIR}/lib/libctf/common \
-I${OPENSOLARIS_SYS_DISTDIR}/uts/common
-LIBADD+= z
+LIBADD+= spl z
.include <bsd.lib.mk>
diff --git a/cddl/lib/libdtrace/Makefile b/cddl/lib/libdtrace/Makefile
index 11565b03b0ac..e0125cad2b38 100644
--- a/cddl/lib/libdtrace/Makefile
+++ b/cddl/lib/libdtrace/Makefile
@@ -66,6 +66,16 @@ FILESMODE= ${NOBINMODE}
WARNS?= 1
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd/spl
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+
+
CFLAGS+= -I${.OBJDIR} -I${.CURDIR} \
-I${SRCTOP}/sys/cddl/dev/dtrace/${MACHINE_ARCH} \
-I${SRCTOP}/sys/cddl/compat/opensolaris \
diff --git a/cddl/lib/libicp/Makefile b/cddl/lib/libicp/Makefile
new file mode 100644
index 000000000000..36858338ac6b
--- /dev/null
+++ b/cddl/lib/libicp/Makefile
@@ -0,0 +1,101 @@
+# $FreeBSD$
+
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/icp
+
+PACKAGE= runtime
+LIB= icp
+LIBADD=
+
+
+.if ${MACHINE_ARCH} == "amd64"
+ASM_SOURCES_C = asm-x86_64/aes/aeskey.c
+ASM_SOURCES_AS = \
+ asm-x86_64/aes/aes_amd64.S \
+ asm-x86_64/aes/aes_aesni.S \
+ asm-x86_64/modes/gcm_pclmulqdq.S \
+ asm-x86_64/modes/aesni-gcm-x86_64.S \
+ asm-x86_64/modes/ghash-x86_64.S \
+ asm-x86_64/sha1/sha1-x86_64.S \
+ asm-x86_64/sha2/sha256_impl.S \
+ asm-x86_64/sha2/sha512_impl.S
+
+CFLAGS+= -D__amd64 -D_SYS_STACK_H -UHAVE_AES
+.else
+ASM_SOURCES_C =
+ASM_SOURCES_AS =
+.endif
+
+
+KERNEL_C = \
+ spi/kcf_spi.c \
+ api/kcf_ctxops.c \
+ api/kcf_digest.c \
+ api/kcf_cipher.c \
+ api/kcf_miscapi.c \
+ api/kcf_mac.c \
+ algs/aes/aes_impl_aesni.c \
+ algs/aes/aes_impl_generic.c \
+ algs/aes/aes_impl_x86-64.c \
+ algs/aes/aes_impl.c \
+ algs/aes/aes_modes.c \
+ algs/edonr/edonr.c \
+ algs/modes/modes.c \
+ algs/modes/cbc.c \
+ algs/modes/gcm_generic.c \
+ algs/modes/gcm_pclmulqdq.c \
+ algs/modes/gcm.c \
+ algs/modes/ctr.c \
+ algs/modes/ccm.c \
+ algs/modes/ecb.c \
+ algs/sha1/sha1.c \
+ algs/sha2/sha2.c \
+ algs/skein/skein.c \
+ algs/skein/skein_block.c \
+ algs/skein/skein_iv.c \
+ illumos-crypto.c \
+ io/aes.c \
+ io/edonr_mod.c \
+ io/sha1_mod.c \
+ io/sha2_mod.c \
+ io/skein_mod.c \
+ os/modhash.c \
+ os/modconf.c \
+ core/kcf_sched.c \
+ core/kcf_prov_lib.c \
+ core/kcf_callprov.c \
+ core/kcf_mech_tabs.c \
+ core/kcf_prov_tabs.c \
+ $(ASM_SOURCES_C)
+
+
+
+
+
+
+SRCS= $(ASM_SOURCES_AS) $(KERNEL_C)
+
+WARNS?= 2
+SHLIB_MAJOR= 3
+CSTD= c99
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+
+
+CFLAGS.aes_amd64.S+= -DLOCORE
+CFLAGS.aes_aesni.S+= -DLOCORE
+CFLAGS.gcm_pclmulqdq.S+= -DLOCORE
+CFLAGS.aesni-gcm-x86_64.S+= -DLOCORE
+CFLAGS.ghash-x86_64.S+= -DLOCORE
+CFLAGS.sha1-x86_64.S+= -DLOCORE
+CFLAGS.sha256_impl.S+= -DLOCORE
+CFLAGS.sha512_impl.S+= -DLOCORE
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libicp_rescue/Makefile b/cddl/lib/libicp_rescue/Makefile
new file mode 100644
index 000000000000..1ebe1b0ff649
--- /dev/null
+++ b/cddl/lib/libicp_rescue/Makefile
@@ -0,0 +1,99 @@
+# $FreeBSD$
+
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/icp
+
+PACKAGE= runtime
+LIB= icp_rescue
+LIBADD=
+
+
+.if ${MACHINE_ARCH} == "amd64"
+ASM_SOURCES_C = asm-x86_64/aes/aeskey.c
+ASM_SOURCES_AS = \
+ asm-x86_64/aes/aes_amd64.S \
+ asm-x86_64/aes/aes_aesni.S \
+ asm-x86_64/modes/gcm_pclmulqdq.S \
+ asm-x86_64/modes/aesni-gcm-x86_64.S \
+ asm-x86_64/sha1/sha1-x86_64.S \
+ asm-x86_64/sha2/sha256_impl.S \
+ asm-x86_64/sha2/sha512_impl.S
+
+CFLAGS+= -D__amd64 -D_SYS_STACK_H
+.else
+ASM_SOURCES_C =
+ASM_SOURCES_AS =
+.endif
+
+
+KERNEL_C = \
+ spi/kcf_spi.c \
+ api/kcf_ctxops.c \
+ api/kcf_digest.c \
+ api/kcf_cipher.c \
+ api/kcf_miscapi.c \
+ api/kcf_mac.c \
+ algs/aes/aes_impl_aesni.c \
+ algs/aes/aes_impl_generic.c \
+ algs/aes/aes_impl_x86-64.c \
+ algs/aes/aes_impl.c \
+ algs/aes/aes_modes.c \
+ algs/edonr/edonr.c \
+ algs/modes/modes.c \
+ algs/modes/cbc.c \
+ algs/modes/gcm_generic.c \
+ algs/modes/gcm_pclmulqdq.c \
+ algs/modes/gcm.c \
+ algs/modes/ctr.c \
+ algs/modes/ccm.c \
+ algs/modes/ecb.c \
+ algs/sha1/sha1.c \
+ algs/sha2/sha2.c \
+ algs/skein/skein_block.c \
+ illumos-crypto.c \
+ io/aes.c \
+ io/edonr_mod.c \
+ io/sha1_mod.c \
+ io/sha2_mod.c \
+ io/skein_mod.c \
+ os/modhash.c \
+ os/modconf.c \
+ core/kcf_sched.c \
+ core/kcf_prov_lib.c \
+ core/kcf_callprov.c \
+ core/kcf_mech_tabs.c \
+ core/kcf_prov_tabs.c \
+ $(ASM_SOURCES_C)
+
+
+
+
+
+
+SRCS= $(ASM_SOURCES_AS) $(KERNEL_C)
+
+WARNS?= 2
+SHLIB_MAJOR= 3
+CSTD= c99
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID -UHAVE_AVX -DRESCUE
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+
+
+CFLAGS.aes_amd64.S+= -DLOCORE
+CFLAGS.aes_aesni.S+= -DLOCORE
+CFLAGS.gcm_pclmulqdq.S+= -DLOCORE
+CFLAGS.aesni-gcm-x86_64.S+= -DLOCORE
+CFLAGS.ghash-x86_64.S+= -DLOCORE
+CFLAGS.sha1-x86_64.S+= -DLOCORE
+CFLAGS.sha256_impl.S+= -DLOCORE
+CFLAGS.sha512_impl.S+= -DLOCORE
+CFLAGS.gcm.c+= -UCAN_USE_GCM_ASM
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libnvpair/Makefile b/cddl/lib/libnvpair/Makefile
index 90c3295d5048..670253eff7c1 100644
--- a/cddl/lib/libnvpair/Makefile
+++ b/cddl/lib/libnvpair/Makefile
@@ -1,36 +1,30 @@
# $FreeBSD$
-.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libnvpair
-.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/common/nvpair
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/nvpair
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libnvpair
LIB= nvpair
PACKAGE= runtime
-INCS= libnvpair.h
+# user
SRCS= libnvpair.c \
- nvpair_alloc_system.c \
- nvpair_json.c \
- opensolaris_fnvpair.c \
- opensolaris_nvpair.c \
- opensolaris_nvpair_alloc_fixed.c
+ libnvpair_json.c \
+ nvpair_alloc_system.c
+# kernel
+SRCS+= nvpair_alloc_fixed.c \
+ nvpair.c \
+ fnvpair.c
-WARNS?= 1
-CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libzpool/common
-CFLAGS+= -I${SRCTOP}/sys/cddl/compat/opensolaris
-CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common
-CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
+WARNS?= 2
+CFLAGS+= -DIN_BASE -DHAVE_RPC_TYPES
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
CFLAGS+= -I${SRCTOP}/sys
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/head
-CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/lib/libumem
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID -DHAVE_CONFIG_H -DHAVE_XDR_BYTESREC
+
-# This library uses macros to define fprintf behavior for several object types
-# The compiler will see the non-string literal arguments to the fprintf calls and
-# omit warnings for them. Quiesce these warnings in contrib code:
-#
-# cddl/contrib/opensolaris/lib/libnvpair/libnvpair.c:743:12: warning: format
-# string is not a string literal (potentially insecure) [-Wformat-security]
-# ARENDER(pctl, nvlist_array, nvl, name, val, nelem);
-#
-CFLAGS+= -Wno-format-security
+CFLAGS.nvpair.c+= -UHAVE_RPC_TYPES
.include <bsd.lib.mk>
diff --git a/cddl/lib/libspl/Makefile b/cddl/lib/libspl/Makefile
new file mode 100644
index 000000000000..64317c41b730
--- /dev/null
+++ b/cddl/lib/libspl/Makefile
@@ -0,0 +1,56 @@
+# $FreeBSD$
+
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libspl
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libspl/os/freebsd
+.PATH: ${SRCTOP}/sys/contrib/openzfs/include
+
+
+LIB= spl
+LIBADD=
+PACKAGE= runtime
+
+SRCS = \
+ assert.c \
+ list.c \
+ mkdirp.c \
+ page.c \
+ strlcat.c \
+ strlcpy.c \
+ timestamp.c \
+ zone.c \
+ include/sys/list.h \
+ include/sys/list_impl.h
+
+SRCS += \
+ getexecname.c \
+ gethostid.c \
+ getmntany.c \
+ mnttab.c
+
+
+.if ${MACHINE_ARCH} == "amd64"
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libspl/asm-x86_64
+SRCS += atomic.S
+.elif ${MACHINE_ARCH} == "i386"
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libspl/asm-i386
+SRCS += atomic.S
+.else
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libspl/asm-generic
+SRCS += atomic.c
+.endif
+
+
+WARNS?= 2
+CSTD= c99
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+CFLAGS.atomic.S+= -DLOCORE
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libtpool/Makefile b/cddl/lib/libtpool/Makefile
new file mode 100644
index 000000000000..637385bc842e
--- /dev/null
+++ b/cddl/lib/libtpool/Makefile
@@ -0,0 +1,27 @@
+# $FreeBSD$
+
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libtpool
+.PATH: ${SRCTOP}/sys/contrib/openzfs/include
+
+
+LIB= tpool
+LIBADD= spl
+PACKAGE= runtime
+
+INCS= thread_pool_impl.h
+SRCS= thread_pool.c
+
+WARNS?= 2
+CSTD= c99
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+
+.include <bsd.lib.mk>
diff --git a/cddl/lib/libuutil/Makefile b/cddl/lib/libuutil/Makefile
index 63997c70c236..76567b50c610 100644
--- a/cddl/lib/libuutil/Makefile
+++ b/cddl/lib/libuutil/Makefile
@@ -1,11 +1,10 @@
# $FreeBSD$
-.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libuutil/common
-.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/common/avl
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libuutil
PACKAGE= runtime
LIB= uutil
-SRCS= avl.c \
+SRCS=\
uu_alloc.c \
uu_avl.c \
uu_dprintf.c \
@@ -14,14 +13,17 @@ SRCS= avl.c \
uu_misc.c \
uu_open.c \
uu_pname.c \
- uu_strtoint.c
+ uu_string.c
-WARNS?= 1
-CFLAGS+= -DNATIVE_BUILD
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libuutil/common
-CFLAGS+= -I${SRCTOP}/sys/cddl/compat/opensolaris
-CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common
+WARNS?= 2
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/head
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+
+LIBADD= avl spl
.include <bsd.lib.mk>
diff --git a/cddl/lib/libzfs/Makefile b/cddl/lib/libzfs/Makefile
index b42365cf0d93..cd2d2b99deb0 100644
--- a/cddl/lib/libzfs/Makefile
+++ b/cddl/lib/libzfs/Makefile
@@ -1,62 +1,102 @@
# $FreeBSD$
-.PATH: ${SRCTOP}/cddl/compat/opensolaris/misc
-.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/common/zfs
-.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
-.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libzfs/common
-.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libcmdutils/common
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/icp
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/zcommon
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libzfs
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libzfs/os/freebsd
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libshare
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libshare/os/freebsd
+.PATH: ${SRCTOP}/sys/contrib/openzfs/include
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/zstd
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/zstd/lib
PACKAGE= runtime
LIB= zfs
-LIBADD= md pthread umem util uutil m avl bsdxml geom nvpair z zfs_core
-SRCS= deviceid.c \
- fsshare.c \
- mkdirp.c \
- mnttab.c \
- thread_pool.c \
- zmount.c \
- zone.c
-
-SRCS+= nicenum.c
-
-SRCS+= libzfs_changelist.c \
- libzfs_compat.c \
- libzfs_config.c \
- libzfs_dataset.c \
- libzfs_diff.c \
- libzfs_import.c \
- libzfs_iter.c \
- libzfs_mount.c \
- libzfs_pool.c \
- libzfs_sendrecv.c \
- libzfs_status.c \
- libzfs_util.c \
- zfeature_common.c \
- zfs_comutil.c \
- zfs_deleg.c \
- zfs_fletcher.c \
- zfs_namecheck.c \
- zfs_prop.c \
- zpool_prop.c \
- zprop_common.c \
-
-WARNS?= 0
-SHLIB_MAJOR= 3
+LIBADD= md pthread umem util uutil m avl bsdxml geom nvpair z zfs_core zutil
+
+INCS= libzfs.h
+USER_C = \
+ libzfs_changelist.c \
+ libzfs_config.c \
+ libzfs_crypto.c \
+ libzfs_dataset.c \
+ libzfs_diff.c \
+ libzfs_import.c \
+ libzfs_iter.c \
+ libzfs_mount.c \
+ libzfs_pool.c \
+ libzfs_sendrecv.c \
+ libzfs_status.c \
+ libzfs_util.c
+
+# FreeBSD
+USER_C += \
+ libzfs_compat.c \
+ libzfs_ioctl_compat.c \
+ libzfs_zmount.c
+
+# libshare
+USER_C += \
+ libshare.c \
+ nfs.c \
+ smb.c
+
+
+KERNEL_C = \
+ algs/sha2/sha2.c \
+ cityhash.c \
+ zfeature_common.c \
+ zfs_comutil.c \
+ zfs_deleg.c \
+ zfs_fletcher.c \
+ zfs_fletcher_superscalar.c \
+ zfs_fletcher_superscalar4.c \
+ zfs_namecheck.c \
+ zfs_prop.c \
+ zfs_uio.c \
+ zpool_prop.c \
+ zprop_common.c
+
+
+KERNEL_C+= zstd.c \
+ zfs_zstd.c
+
+
+ARCH_C =
+.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386"
+ARCH_C += zfs_fletcher_intel.c \
+ zfs_fletcher_sse.c
+CFLAGS += -DHAVE_SSE2
+.endif
+.if ${MACHINE_ARCH} == "amd64"
+ARCH_C += zfs_fletcher_avx512.c
+CFLAGS+= -DHAVE_AVX2 -DHAVE_AVX -D__x86_64 -DHAVE_AVX512F
+.endif
+.if ${MACHINE_ARCH} == "aarch64"
+ARCH_C += zfs_fletcher_aarch64_neon.c
+.endif
+
+SRCS= $(USER_C) $(KERNEL_C) $(ARCH_C)
+
+WARNS?= 2
+SHLIB_MAJOR= 4
CSTD= c99
-CFLAGS+= -DZFS_NO_ACL
-CFLAGS+= -I${SRCTOP}/sbin/mount
-CFLAGS+= -I${SRCTOP}/sys/cddl/compat/opensolaris
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libshare
+CFLAGS+= -I${SRCTOP}/sys/contrib/ck/include
+CFLAGS+= -I${SRCTOP}/sys
CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
-CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/lib/libumem
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libzpool/common
-CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/common/zfs
-CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/head
-CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libnvpair
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libuutil/common
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libzfs/common
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libzfs_core/common
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libcmdutils
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
+CFLAGS+= -I${SRCDIR}/sys/contrib/openzfs/module/zstd/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+CFLAGS.zfs_zstd.c= -Wno-cast-qual -Wno-pointer-arith
+CFLAGS.zstd.c= -fno-tree-vectorize
+
.include <bsd.lib.mk>
diff --git a/cddl/lib/libzfs_core/Makefile b/cddl/lib/libzfs_core/Makefile
index 412a5d2be938..52747bfcc2d8 100644
--- a/cddl/lib/libzfs_core/Makefile
+++ b/cddl/lib/libzfs_core/Makefile
@@ -1,37 +1,28 @@
# $FreeBSD$
-.PATH: ${SRCTOP}/cddl/compat/opensolaris/misc
-.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/common/zfs
-.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
-.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libzfs_core/common
-.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libzfs/common
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libzfs_core
+.PATH: ${SRCTOP}/sys/contrib/openzfs/include
+
LIB= zfs_core
LIBADD= nvpair
PACKAGE= runtime
INCS= libzfs_core.h
-SRCS= libzfs_core.c \
- libzfs_core_compat.c \
- zfs_ioctl_compat.c
-
-SRCS+= libzfs_compat.c
+SRCS= libzfs_core.c
-WARNS?= 0
+WARNS?= 2
CSTD= c99
-CFLAGS+= -DZFS_NO_ACL
-CFLAGS+= -I${SRCTOP}/sbin/mount
-CFLAGS+= -I${SRCTOP}/sys/cddl/compat/opensolaris
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzfs_core/common
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
-CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/lib/libumem
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libzpool/common
-CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/common/zfs
-CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/head
-CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libnvpair
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libuutil/common
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libzfs_core/common
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libzfs/common
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
.include <bsd.lib.mk>
diff --git a/cddl/lib/libzpool/Makefile b/cddl/lib/libzpool/Makefile
index 576b89b7725a..e1090c628c1f 100644
--- a/cddl/lib/libzpool/Makefile
+++ b/cddl/lib/libzpool/Makefile
@@ -1,20 +1,17 @@
# $FreeBSD$
-.include "${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common/Makefile.files"
# ZFS_COMMON_SRCS
-.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/zfs
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/zcommon
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/unicode
# LUA_SRCS
-.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua
-# ZFS_SHARED_SRCS
-.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/common/zfs
-# LZ4_COMMON_SRCS
-.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/common/lz4
-# KERNEL_SRCS
-.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libzpool/common
-# LIST_SRCS
-.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common/os
-# ATOMIC_SRCS
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/lua
+
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/os/linux/zfs
+
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libzpool
+
.if exists(${SRCTOP}/sys/cddl/contrib/opensolaris/common/atomic/${MACHINE_ARCH}/opensolaris_atomic.S)
.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/common/atomic/${MACHINE_ARCH}
ATOMIC_SRCS= opensolaris_atomic.S
@@ -23,40 +20,218 @@ ACFLAGS+= -Wa,--noexecstack
.PATH: ${SRCTOP}/sys/cddl/compat/opensolaris/kern
ATOMIC_SRCS= opensolaris_atomic.c
.endif
-# UNICODE_SRCS
-.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/common/unicode
-# LIBCMDUTILS_SRCS
-.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libcmdutils/common
+
+.if ${MACHINE_ARCH} == "powerpc"
+# Don't waste GOT entries on small data.
+PICFLAG= -fPIC
+.endif
LIB= zpool
-ZFS_COMMON_SRCS= ${ZFS_COMMON_OBJS:C/.o$/.c/} trim_map.c
-ZFS_SHARED_SRCS= ${ZFS_SHARED_OBJS:C/.o$/.c/}
-LZ4_COMMON_SRCS= lz4.c
-LUA_SRCS= ${LUA_OBJS:C/.o$/.c/}
-KERNEL_SRCS= kernel.c taskq.c util.c
-LIST_SRCS= list.c
-UNICODE_SRCS= u8_textprep.c
-LIBCMDUTILS_SRCS=nicenum.c
-
-SRCS= ${ZFS_COMMON_SRCS} ${ZFS_SHARED_SRCS} ${LUA_SRCS} \
- ${LZ4_COMMON_SRCS} ${KERNEL_SRCS} ${LIST_SRCS} ${ATOMIC_SRCS} \
- ${UNICODE_SRCS} ${LIBCMDUTILS_SRCS}
-
-WARNS?= 0
-CFLAGS+= -I${SRCTOP}/sys/cddl/compat/opensolaris
-CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
-CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/lib/libumem
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libzfs/common
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libzpool/common
-CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
-CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua
-CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/common/zfs
-CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/common/lz4
-CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/head
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libnvpair
-CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libcmdutils
+
+
+USER_C = \
+ kernel.c \
+ taskq.c \
+ util.c
+
+KERNEL_C = \
+ zfeature_common.c \
+ zfs_comutil.c \
+ zfs_deleg.c \
+ zfs_fletcher.c \
+ zfs_fletcher_superscalar.c \
+ zfs_fletcher_superscalar4.c \
+ zfs_namecheck.c \
+ zfs_prop.c \
+ zfs_uio.c \
+ zpool_prop.c \
+ zprop_common.c \
+ abd.c \
+ abd_os.c \
+ aggsum.c \
+ arc.c \
+ arc_os.c \
+ blkptr.c \
+ bplist.c \
+ bpobj.c \
+ bptree.c \
+ btree.c \
+ bqueue.c \
+ cityhash.c \
+ dbuf.c \
+ dbuf_stats.c \
+ ddt.c \
+ ddt_zap.c \
+ dmu.c \
+ dmu_diff.c \
+ dmu_object.c \
+ dmu_objset.c \
+ dmu_recv.c \
+ dmu_redact.c \
+ dmu_send.c \
+ dmu_traverse.c \
+ dmu_tx.c \
+ dmu_zfetch.c \
+ dnode.c \
+ dnode_sync.c \
+ dsl_bookmark.c \
+ dsl_dataset.c \
+ dsl_deadlist.c \
+ dsl_deleg.c \
+ dsl_dir.c \
+ dsl_crypt.c \
+ dsl_pool.c \
+ dsl_prop.c \
+ dsl_scan.c \
+ dsl_synctask.c \
+ dsl_destroy.c \
+ dsl_userhold.c \
+ edonr_zfs.c \
+ hkdf.c \
+ fm.c \
+ gzip.c \
+ lzjb.c \
+ lz4.c \
+ metaslab.c \
+ mmp.c \
+ multilist.c \
+ objlist.c \
+ pathname.c \
+ range_tree.c \
+ refcount.c \
+ rrwlock.c \
+ sa.c \
+ sha256.c \
+ skein_zfs.c \
+ spa.c \
+ spa_boot.c \
+ spa_checkpoint.c \
+ spa_config.c \
+ spa_errlog.c \
+ spa_history.c \
+ spa_log_spacemap.c \
+ spa_misc.c \
+ spa_stats.c \
+ space_map.c \
+ space_reftree.c \
+ txg.c \
+ trace.c \
+ uberblock.c \
+ unique.c \
+ vdev.c \
+ vdev_cache.c \
+ vdev_file.c \
+ vdev_indirect_births.c \
+ vdev_indirect.c \
+ vdev_indirect_mapping.c \
+ vdev_initialize.c \
+ vdev_label.c \
+ vdev_mirror.c \
+ vdev_missing.c \
+ vdev_queue.c \
+ vdev_raidz.c \
+ vdev_raidz_math_aarch64_neon.c \
+ vdev_raidz_math_aarch64_neonx2.c \
+ vdev_raidz_math_avx2.c \
+ vdev_raidz_math_avx512bw.c \
+ vdev_raidz_math_avx512f.c \
+ vdev_raidz_math.c \
+ vdev_raidz_math_scalar.c \
+ vdev_rebuild.c \
+ vdev_removal.c \
+ vdev_root.c \
+ vdev_trim.c \
+ zap.c \
+ zap_leaf.c \
+ zap_micro.c \
+ zcp.c \
+ zcp_get.c \
+ zcp_global.c \
+ zcp_iter.c \
+ zcp_set.c \
+ zcp_synctask.c \
+ zfeature.c \
+ zfs_byteswap.c \
+ zfs_debug.c \
+ zfs_fm.c \
+ zfs_fuid.c \
+ zfs_sa.c \
+ zfs_znode.c \
+ zfs_ratelimit.c \
+ zfs_rlock.c \
+ zil.c \
+ zio.c \
+ zio_checksum.c \
+ zio_compress.c \
+ zio_crypt.c \
+ zio_inject.c \
+ zle.c \
+ zrlock.c \
+ zthr.c
+
+ARCH_C =
+.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386"
+ARCH_C += vdev_raidz_math_sse2.c \
+ vdev_raidz_math_ssse3.c \
+ zfs_fletcher_intel.c \
+ zfs_fletcher_sse.c
+CFLAGS += -DHAVE_SSE2 -DHAVE_SSE3
+.endif
+.if ${MACHINE_ARCH} == "amd64"
+ARCH_C += zfs_fletcher_avx512.c
+CFLAGS+= -DHAVE_AVX2 -DHAVE_AVX -D__x86_64 -DHAVE_AVX512F \
+ -DHAVE_AVX512BW
+.endif
+.if ${MACHINE_ARCH} == "aarch64"
+ARCH_C += zfs_fletcher_aarch64_neon.c
+.endif
+
+LUA_C = \
+ lapi.c \
+ lauxlib.c \
+ lbaselib.c \
+ lcode.c \
+ lcompat.c \
+ lcorolib.c \
+ lctype.c \
+ ldebug.c \
+ ldo.c \
+ lfunc.c \
+ lgc.c \
+ llex.c \
+ lmem.c \
+ lobject.c \
+ lopcodes.c \
+ lparser.c \
+ lstate.c \
+ lstring.c \
+ lstrlib.c \
+ ltable.c \
+ ltablib.c \
+ ltm.c \
+ lvm.c \
+ lzio.c
+
+UNICODE_C = u8_textprep.c uconv.c
+
+SRCS= ${USER_C} ${KERNEL_C} ${LUA_C} ${UNICODE_C} ${ARCH_C}
+
+WARNS?= 2
+CFLAGS+= -DIN_BASE
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DHAVE_ISSETUGID
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+CFLAGS+= -I${SRCTOP}/sys/modules/zfs
+CFLAGS+= -DLIB_ZPOOL_BUILD -DZFS_DEBUG
+
+
# XXX: pthread doesn't have mutex_owned() equivalent, so we need to look
# into libthr private structures. That's sooo evil, but it's only for
# ZFS debugging tools needs.
@@ -64,10 +239,9 @@ CFLAGS+= -DWANTS_MUTEX_OWNED
CFLAGS+= -I${SRCTOP}/lib/libpthread/thread
CFLAGS+= -I${SRCTOP}/lib/libpthread/sys
CFLAGS+= -I${SRCTOP}/lib/libthr/arch/${MACHINE_CPUARCH}/include
-CFLAGS.lz4.c+= -D_FAKE_KERNEL
CFLAGS.gcc+= -fms-extensions
-LIBADD= md pthread z nvpair avl umem
+LIBADD= md pthread z spl icp nvpair avl umem
# atomic.S doesn't like profiling.
MK_PROFILE= no
diff --git a/cddl/lib/libzpool/Makefile.depend b/cddl/lib/libzpool/Makefile.depend
index 97914fc35322..06045f57b437 100644
--- a/cddl/lib/libzpool/Makefile.depend
+++ b/cddl/lib/libzpool/Makefile.depend
@@ -3,6 +3,7 @@
DIRDEPS = \
cddl/lib/libavl \
+ cddl/lib/libicp \
cddl/lib/libnvpair \
cddl/lib/libumem \
gnu/lib/csu \
diff --git a/cddl/lib/libzutil/Makefile b/cddl/lib/libzutil/Makefile
new file mode 100644
index 000000000000..7aea9da14e90
--- /dev/null
+++ b/cddl/lib/libzutil/Makefile
@@ -0,0 +1,42 @@
+# $FreeBSD$
+
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libzutil
+.PATH: ${SRCTOP}/sys/contrib/openzfs/lib/libzutil/os/freebsd
+.PATH: ${SRCTOP}/sys/contrib/openzfs/module/os/freebsd/zfs
+
+LIB= zutil
+LIBADD= avl tpool
+PACKAGE= runtime
+
+INCS = zutil_import.h
+
+SRCS = \
+ zutil_device_path.c \
+ zutil_import.c \
+ zutil_import.h \
+ zutil_nicenum.c \
+ zutil_pool.c
+
+SRCS += \
+ zutil_device_path_os.c \
+ zutil_import_os.c \
+ zutil_compat.c
+
+SRCS += zfs_ioctl_compat.c
+
+
+WARNS?= 2
+CSTD= c99
+
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/zfs
+CFLAGS+= -I${SRCTOP}/sys
+CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
+CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzutil
+CFLAGS+= -DHAVE_ISSETUGID -DIN_BASE
+CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h
+
+.include <bsd.lib.mk>