diff --git a/config/always-compiler-options.m4 b/config/always-compiler-options.m4 index 6383b12506ee..d2689ee56ae8 100644 --- a/config/always-compiler-options.m4 +++ b/config/always-compiler-options.m4 @@ -355,3 +355,23 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_KERNEL_CC_NO_IPA_SRA], [ CFLAGS="$saved_flags" AC_SUBST([KERNEL_NO_IPA_SRA]) ]) + +dnl # Check if cc supports -finline-hint-functions +dnl # +AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_INLINE_HINT_FUNCTIONS], [ + AC_MSG_CHECKING([whether $CC supports -finline-hint-functions]) + + saved_flags="$CFLAGS" + CFLAGS="$CFLAGS -Werror -finline-hint-functions" + + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [ + INLINE_HINT_FUNCTIONS=-finline-hint-functions + AC_MSG_RESULT([yes]) + ], [ + INLINE_HINT_FUNCTIONS= + AC_MSG_RESULT([no]) + ]) + + CFLAGS="$saved_flags" + AC_SUBST([INLINE_HINT_FUNCTIONS]) +]) diff --git a/config/always-system.m4 b/config/always-system.m4 index 3a3d4212f8b0..4bda7831e23d 100644 --- a/config/always-system.m4 +++ b/config/always-system.m4 @@ -16,6 +16,12 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_SYSTEM], [ ac_system="FreeBSD" ac_system_l="freebsd" ;; + *darwin*) + AC_DEFINE([SYSTEM_MACOS], [1], + [True if ZFS is to be compiled for a macOS system]) + ac_system="macOS" + ac_system_l="macos" + ;; *) ac_system="unknown" ac_system_l="unknown" @@ -27,4 +33,5 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_SYSTEM], [ AM_CONDITIONAL([BUILD_LINUX], [test "x$ac_system" = "xLinux"]) AM_CONDITIONAL([BUILD_FREEBSD], [test "x$ac_system" = "xFreeBSD"]) + AM_CONDITIONAL([BUILD_MACOS], [test "x$ac_system" = "xmacOS"]) ]) diff --git a/config/kernel-macos-headers.m4 b/config/kernel-macos-headers.m4 new file mode 100644 index 000000000000..0adbb9ba7133 --- /dev/null +++ b/config/kernel-macos-headers.m4 @@ -0,0 +1,103 @@ +dnl # +dnl # macOS - attempt to find kernel headers. This is expected to +dnl # only run on mac platforms (using xcrun command) to iterate +dnl # through versions of xcode, and xnu kernel source locations +dnl # +AC_DEFUN([ZFS_AC_KERNEL_SRC_MACOS_HEADERS], [ + AM_COND_IF([BUILD_MACOS], [ + AC_MSG_CHECKING([macOS kernel source directory]) + AS_IF([test -z "$kernelsrc"], [ + system_major_version=`sw_vers -productVersion | $AWK -F '.' '{ print $[]1 "." $[]2 }'` + AS_IF([test -d "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${system_major_version}.sdk/System/Library/Frameworks/Kernel.framework/Headers"], [ + kernelsrc="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${system_major_version}.sdk/System/Library/Frameworks/Kernel.framework"]) + ]) + AS_IF([test -z "$kernelsrc"], [ + AS_IF([test -d "/System/Library/Frameworks/Kernel.framework/Headers"], [ + kernelsrc="/System/Library/Frameworks/Kernel.framework"]) + ]) + AS_IF([test -z "$kernelsrc"], [ + tmpdir=`xcrun --show-sdk-path` + AS_IF([test -d "$tmpdir/System/Library/Frameworks/Kernel.framework/Headers"], [ + kernelsrc="$tmpdir/System/Library/Frameworks/Kernel.framework"]) + ]) + AS_IF([test -z "$kernelsrc"], [ + AS_IF([test -d "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/Kernel.framework"], [ + kernelsrc="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/Kernel.framework"]) + ]) + AS_IF([test -z "$kernelsrc"], [ + AS_IF([test -d "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Kernel.framework"], [ + kernelsrc="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Kernel.framework"]) + ]) + AS_IF([test -z "$kernelsrc"], [ + AS_IF([test -d "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Kernel.framework"], [ + kernelsrc="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Kernel.framework"]) + ]) + + AC_MSG_RESULT([$kernelsrc]) + + AC_MSG_CHECKING([macOS kernel build directory]) + AS_IF([test -z "$kernelbuild"], [ + kernelbuild=${kernelsrc} + ]) + ]) + AC_MSG_RESULT([$kernelbuild]) + + AC_ARG_WITH([kernel-modprefix], + AS_HELP_STRING([--with-kernel-modprefix=PATH], + [Path to kernel module prefix]), + [KERNEL_MODPREFIX="$withval"]) + AC_MSG_CHECKING([macOS kernel module prefix]) + AS_IF([test -z "$KERNEL_MODPREFIX"], [ + KERNEL_MODPREFIX="/Library/Extensions" + ]) + AC_MSG_RESULT([$KERNEL_MODPREFIX]) + AC_DEFINE_UNQUOTED([KERNEL_MODPREFIX], + ["$KERNEL_MODPREFIX"], + [Path where the kernel module is installed.] + ) + + AC_MSG_CHECKING([macOS kernel source version]) + utsrelease1=$kernelbuild/Headers/libkern/version.h + AS_IF([test -r $utsrelease1 && fgrep -q OSRELEASE $utsrelease1], [ + kernverfile=libkern/version.h ]) + + AS_IF([test "$kernverfile"], [ + kernsrcver=`(echo "#include <$kernverfile>"; + echo "kernsrcver=OSRELEASE") | + cpp -I$kernelbuild/Headers | + grep "^kernsrcver=" | cut -d \" -f 2` + + AS_IF([test -z "$kernsrcver"], [ + AC_MSG_RESULT([Not found]) + AC_MSG_ERROR([*** Cannot determine kernel version.]) + ]) + AC_MSG_RESULT([$kernsrcver]) + ]) + + AC_MSG_CHECKING([mach_kernel]) + AS_IF([test -z "$machkernel"], [ + AS_IF([test -e "/System/Library/Kernels/kernel"], [ + machkernel="/System/Library/Kernels/kernel" ] ) + AS_IF([test -e "/mach_kernel"], [ + machkernel="/mach_kernel" ] ) + AS_IF([test ! -f "$machkernel"], [ + AC_MSG_ERROR([ + *** mach_kernel file not found. For 10.9 and prior, this should be + *** '/mach_kernel' and for 10.10 and following, this should be + *** '/System/Library/Kernels/kernel']) + ]) + ]) + AC_MSG_RESULT($machkernel) + + +dnl More Generic names: + MACH_KERNEL=${machkernel} + KERNEL_HEADERS=${kernelsrc} + KERNEL_VERSION=${kernsrcver} + AC_SUBST(KERNEL_HEADERS) + AC_SUBST(KERNEL_MODPREFIX) + AC_SUBST(KERNEL_VERSION) + AC_SUBST(MACH_KERNEL) + ]) +]) + diff --git a/config/kernel.m4 b/config/kernel.m4 index d25b65994f6f..2a2ab75cefb8 100644 --- a/config/kernel.m4 +++ b/config/kernel.m4 @@ -28,6 +28,10 @@ AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [ AC_SUBST(KERNEL_MAKE) ]) + AM_COND_IF([BUILD_MACOS], [ + ZFS_AC_KERNEL_SRC_MACOS_HEADERS + ZFS_AC_CONFIG_ALWAYS_CC_FRAME_LARGER_THAN + ]) ]) dnl # @@ -380,6 +384,7 @@ dnl # and `/usr/src/linux-*` with the highest version number according dnl # to `sort -V` is assumed to be both source and build directory. dnl # AC_DEFUN([ZFS_AC_KERNEL], [ + AC_ARG_WITH([linux], AS_HELP_STRING([--with-linux=PATH], [Path to kernel source]), @@ -390,6 +395,15 @@ AC_DEFUN([ZFS_AC_KERNEL], [ [Path to kernel build objects]), [kernelbuild="$withval"]) + AC_ARG_WITH([macos], + AS_HELP_STRING([--with-macos=PATH], + [Path to macOS source]), + [kernelsrc="$withval/sys"]) + AC_ARG_WITH(macos-obj, + AS_HELP_STRING([--with-macos-obj=PATH], + [Path to macOS build objects]), + [kernelbuild="$withval/$kernelsrc"]) + AC_MSG_CHECKING([kernel source and build directories]) AS_IF([test -n "$kernelsrc" && test -z "$kernelbuild"], [ kernelbuild="$kernelsrc" @@ -453,7 +467,8 @@ AC_DEFUN([ZFS_AC_KERNEL], [ *** Please make sure the kernel devel package for your distribution *** is installed and then try again. If that fails, you can specify the *** location of the kernel source and build with the '--with-linux=PATH' and - *** '--with-linux-obj=PATH' options respectively.]) + *** '--with-linux-obj=PATH' options respectively. + *** If you are configuring for macOS, use '--with-macos=PATH'.]) ]) AC_MSG_CHECKING([kernel source version]) @@ -604,9 +619,9 @@ dnl # ZFS_LINUX_CONFTEST_H dnl # AC_DEFUN([ZFS_LINUX_CONFTEST_H], [ test -d build/$2 || mkdir -p build/$2 -cat - <<_ACEOF >build/$2/$2.h +cat - <<_ACEOF1 >build/$2/$2.h $1 -_ACEOF +_ACEOF1 ]) dnl # @@ -614,9 +629,9 @@ dnl # ZFS_LINUX_CONFTEST_C dnl # AC_DEFUN([ZFS_LINUX_CONFTEST_C], [ test -d build/$2 || mkdir -p build/$2 -cat confdefs.h - <<_ACEOF >build/$2/$2.c +cat confdefs.h - <<_ACEOF2 >build/$2/$2.c $1 -_ACEOF +_ACEOF2 ]) dnl # @@ -633,12 +648,12 @@ AC_DEFUN([ZFS_LINUX_CONFTEST_MAKEFILE], [ file=build/$1/Makefile dnl # Example command line to manually build source. - cat - <<_ACEOF >$file + cat - <<_ACEOF3 >$file # Example command line to manually build source # make modules -C $LINUX_OBJ $ARCH_UM M=$PWD/build/$1 ccflags-y := -Werror $FRAME_LARGER_THAN -_ACEOF +_ACEOF3 dnl # Additional custom CFLAGS as requested. m4_ifval($3, [echo "ccflags-y += $3" >>$file], []) diff --git a/config/macos.m4 b/config/macos.m4 new file mode 100644 index 000000000000..30e8ebf2ec46 --- /dev/null +++ b/config/macos.m4 @@ -0,0 +1,11 @@ + + +AC_DEFUN([ZFS_AC_MACOS_IMPURE_ENABLE], [ + AC_ARG_ENABLE(macos_impure, + AS_HELP_STRING([--enable-macos-impure], + [Use XNU Private.exports [[default: no]]]), + [CPPFLAGS="$CPPFLAGS -DMACOS_IMPURE"], + []) +]) + + diff --git a/config/user-libfetch.m4 b/config/user-libfetch.m4 index d961c6ca77a1..0b727e43dd66 100644 --- a/config/user-libfetch.m4 +++ b/config/user-libfetch.m4 @@ -45,8 +45,14 @@ AC_DEFUN([ZFS_AC_CONFIG_USER_LIBFETCH], [ LIBFETCH_IS_LIBCURL=1 if test "$(curl-config --built-shared)" = "yes"; then LIBFETCH_DYNAMIC=1 - LIBFETCH_SONAME="libcurl.so.4" - LIBFETCH_LIBS="-ldl" + dnl # why are we hardcoding libnames? + AM_COND_IF([BUILD_MACOS], [ + LIBFETCH_SONAME="libcurl.4.dylib" + LIBFETCH_LIBS="" + ], [ + LIBFETCH_SONAME="libcurl.so.4" + LIBFETCH_LIBS="-ldl" + ]) AC_MSG_RESULT([libcurl]) else LIBFETCH_LIBS="$(curl-config --libs)" diff --git a/config/user.m4 b/config/user.m4 index 87df8c7ccabd..5cb47026b61c 100644 --- a/config/user.m4 +++ b/config/user.m4 @@ -24,8 +24,11 @@ AC_DEFUN([ZFS_AC_CONFIG_USER], [ ZFS_AC_CONFIG_USER_LIBATOMIC ZFS_AC_CONFIG_USER_LIBFETCH ZFS_AC_CONFIG_USER_AIO_H - ZFS_AC_CONFIG_USER_CLOCK_GETTIME - ZFS_AC_CONFIG_USER_PAM + AM_COND_IF([BUILD_MACOS], [ + ZFS_AC_MACOS_IMPURE_ENABLE], [ + ZFS_AC_CONFIG_USER_CLOCK_GETTIME + ZFS_AC_CONFIG_USER_PAM + ]) ZFS_AC_CONFIG_USER_RUNSTATEDIR ZFS_AC_CONFIG_USER_MAKEDEV_IN_SYSMACROS ZFS_AC_CONFIG_USER_MAKEDEV_IN_MKDEV diff --git a/config/zfs-build.m4 b/config/zfs-build.m4 index 5f36569fe25b..155c7dbf6bd0 100644 --- a/config/zfs-build.m4 +++ b/config/zfs-build.m4 @@ -538,6 +538,8 @@ AC_DEFUN([ZFS_AC_DEFAULT_PACKAGE], [ VENDOR=freebsd ; elif test -f /etc/openEuler-release ; then VENDOR=openeuler ; + elif test -f /usr/bin/sw_vers ; then + VENDOR=apple ; else VENDOR= ; fi], @@ -563,6 +565,7 @@ AC_DEFUN([ZFS_AC_DEFAULT_PACKAGE], [ debian) DEFAULT_PACKAGE=deb ;; freebsd) DEFAULT_PACKAGE=pkg ;; openeuler) DEFAULT_PACKAGE=rpm ;; + apple) DEFAULT_PACKAGE=pkg ;; *) DEFAULT_PACKAGE=rpm ;; esac AC_MSG_RESULT([$DEFAULT_PACKAGE]) @@ -606,6 +609,7 @@ AC_DEFUN([ZFS_AC_DEFAULT_PACKAGE], [ ubuntu) initconfdir=/etc/default ;; debian) initconfdir=/etc/default ;; freebsd) initconfdir=$sysconfdir/rc.conf.d;; + apple) initconfdir=${prefix}/etc/launchd/launchd.d/ ;; *) initconfdir=/etc/default ;; esac AC_MSG_RESULT([$initconfdir]) @@ -639,7 +643,7 @@ dnl # Default ZFS package configuration dnl # AC_DEFUN([ZFS_AC_PACKAGE], [ ZFS_AC_DEFAULT_PACKAGE - AS_IF([test x$VENDOR != xfreebsd], [ + AS_IF([test x$VENDOR != xfreebsd -a x$VENDOR != xapple], [ ZFS_AC_RPM ZFS_AC_DPKG ZFS_AC_ALIEN