Macos: m4 changes

Signed-off-by: Andrew Innes <andrew.c12@gmail.com>
Co-authored-by: Jorgen Lundman <lundman@lundman.net>
This commit is contained in:
Andrew Innes 2023-11-14 13:13:44 +08:00
parent f0bf7a247d
commit 9a390d0ab6
8 changed files with 181 additions and 12 deletions

View File

@ -355,3 +355,23 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_KERNEL_CC_NO_IPA_SRA], [
CFLAGS="$saved_flags" CFLAGS="$saved_flags"
AC_SUBST([KERNEL_NO_IPA_SRA]) 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])
])

View File

@ -16,6 +16,12 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_SYSTEM], [
ac_system="FreeBSD" ac_system="FreeBSD"
ac_system_l="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="unknown"
ac_system_l="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_LINUX], [test "x$ac_system" = "xLinux"])
AM_CONDITIONAL([BUILD_FREEBSD], [test "x$ac_system" = "xFreeBSD"]) AM_CONDITIONAL([BUILD_FREEBSD], [test "x$ac_system" = "xFreeBSD"])
AM_CONDITIONAL([BUILD_MACOS], [test "x$ac_system" = "xmacOS"])
]) ])

View File

@ -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)
])
])

View File

@ -28,6 +28,10 @@ AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
AC_SUBST(KERNEL_MAKE) AC_SUBST(KERNEL_MAKE)
]) ])
AM_COND_IF([BUILD_MACOS], [
ZFS_AC_KERNEL_SRC_MACOS_HEADERS
ZFS_AC_CONFIG_ALWAYS_CC_FRAME_LARGER_THAN
])
]) ])
dnl # 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 # to `sort -V` is assumed to be both source and build directory.
dnl # dnl #
AC_DEFUN([ZFS_AC_KERNEL], [ AC_DEFUN([ZFS_AC_KERNEL], [
AC_ARG_WITH([linux], AC_ARG_WITH([linux],
AS_HELP_STRING([--with-linux=PATH], AS_HELP_STRING([--with-linux=PATH],
[Path to kernel source]), [Path to kernel source]),
@ -390,6 +395,15 @@ AC_DEFUN([ZFS_AC_KERNEL], [
[Path to kernel build objects]), [Path to kernel build objects]),
[kernelbuild="$withval"]) [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]) AC_MSG_CHECKING([kernel source and build directories])
AS_IF([test -n "$kernelsrc" && test -z "$kernelbuild"], [ AS_IF([test -n "$kernelsrc" && test -z "$kernelbuild"], [
kernelbuild="$kernelsrc" kernelbuild="$kernelsrc"
@ -453,7 +467,8 @@ AC_DEFUN([ZFS_AC_KERNEL], [
*** Please make sure the kernel devel package for your distribution *** Please make sure the kernel devel package for your distribution
*** is installed and then try again. If that fails, you can specify the *** 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 *** 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]) AC_MSG_CHECKING([kernel source version])
@ -604,9 +619,9 @@ dnl # ZFS_LINUX_CONFTEST_H
dnl # dnl #
AC_DEFUN([ZFS_LINUX_CONFTEST_H], [ AC_DEFUN([ZFS_LINUX_CONFTEST_H], [
test -d build/$2 || mkdir -p build/$2 test -d build/$2 || mkdir -p build/$2
cat - <<_ACEOF >build/$2/$2.h cat - <<_ACEOF1 >build/$2/$2.h
$1 $1
_ACEOF _ACEOF1
]) ])
dnl # dnl #
@ -614,9 +629,9 @@ dnl # ZFS_LINUX_CONFTEST_C
dnl # dnl #
AC_DEFUN([ZFS_LINUX_CONFTEST_C], [ AC_DEFUN([ZFS_LINUX_CONFTEST_C], [
test -d build/$2 || mkdir -p build/$2 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 $1
_ACEOF _ACEOF2
]) ])
dnl # dnl #
@ -633,12 +648,12 @@ AC_DEFUN([ZFS_LINUX_CONFTEST_MAKEFILE], [
file=build/$1/Makefile file=build/$1/Makefile
dnl # Example command line to manually build source. dnl # Example command line to manually build source.
cat - <<_ACEOF >$file cat - <<_ACEOF3 >$file
# Example command line to manually build source # Example command line to manually build source
# make modules -C $LINUX_OBJ $ARCH_UM M=$PWD/build/$1 # make modules -C $LINUX_OBJ $ARCH_UM M=$PWD/build/$1
ccflags-y := -Werror $FRAME_LARGER_THAN ccflags-y := -Werror $FRAME_LARGER_THAN
_ACEOF _ACEOF3
dnl # Additional custom CFLAGS as requested. dnl # Additional custom CFLAGS as requested.
m4_ifval($3, [echo "ccflags-y += $3" >>$file], []) m4_ifval($3, [echo "ccflags-y += $3" >>$file], [])

11
config/macos.m4 Normal file
View File

@ -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"],
[])
])

View File

@ -45,8 +45,14 @@ AC_DEFUN([ZFS_AC_CONFIG_USER_LIBFETCH], [
LIBFETCH_IS_LIBCURL=1 LIBFETCH_IS_LIBCURL=1
if test "$(curl-config --built-shared)" = "yes"; then if test "$(curl-config --built-shared)" = "yes"; then
LIBFETCH_DYNAMIC=1 LIBFETCH_DYNAMIC=1
dnl # why are we hardcoding libnames?
AM_COND_IF([BUILD_MACOS], [
LIBFETCH_SONAME="libcurl.4.dylib"
LIBFETCH_LIBS=""
], [
LIBFETCH_SONAME="libcurl.so.4" LIBFETCH_SONAME="libcurl.so.4"
LIBFETCH_LIBS="-ldl" LIBFETCH_LIBS="-ldl"
])
AC_MSG_RESULT([libcurl]) AC_MSG_RESULT([libcurl])
else else
LIBFETCH_LIBS="$(curl-config --libs)" LIBFETCH_LIBS="$(curl-config --libs)"

View File

@ -24,8 +24,11 @@ AC_DEFUN([ZFS_AC_CONFIG_USER], [
ZFS_AC_CONFIG_USER_LIBATOMIC ZFS_AC_CONFIG_USER_LIBATOMIC
ZFS_AC_CONFIG_USER_LIBFETCH ZFS_AC_CONFIG_USER_LIBFETCH
ZFS_AC_CONFIG_USER_AIO_H ZFS_AC_CONFIG_USER_AIO_H
AM_COND_IF([BUILD_MACOS], [
ZFS_AC_MACOS_IMPURE_ENABLE], [
ZFS_AC_CONFIG_USER_CLOCK_GETTIME ZFS_AC_CONFIG_USER_CLOCK_GETTIME
ZFS_AC_CONFIG_USER_PAM ZFS_AC_CONFIG_USER_PAM
])
ZFS_AC_CONFIG_USER_RUNSTATEDIR ZFS_AC_CONFIG_USER_RUNSTATEDIR
ZFS_AC_CONFIG_USER_MAKEDEV_IN_SYSMACROS ZFS_AC_CONFIG_USER_MAKEDEV_IN_SYSMACROS
ZFS_AC_CONFIG_USER_MAKEDEV_IN_MKDEV ZFS_AC_CONFIG_USER_MAKEDEV_IN_MKDEV

View File

@ -538,6 +538,8 @@ AC_DEFUN([ZFS_AC_DEFAULT_PACKAGE], [
VENDOR=freebsd ; VENDOR=freebsd ;
elif test -f /etc/openEuler-release ; then elif test -f /etc/openEuler-release ; then
VENDOR=openeuler ; VENDOR=openeuler ;
elif test -f /usr/bin/sw_vers ; then
VENDOR=apple ;
else else
VENDOR= ; VENDOR= ;
fi], fi],
@ -563,6 +565,7 @@ AC_DEFUN([ZFS_AC_DEFAULT_PACKAGE], [
debian) DEFAULT_PACKAGE=deb ;; debian) DEFAULT_PACKAGE=deb ;;
freebsd) DEFAULT_PACKAGE=pkg ;; freebsd) DEFAULT_PACKAGE=pkg ;;
openeuler) DEFAULT_PACKAGE=rpm ;; openeuler) DEFAULT_PACKAGE=rpm ;;
apple) DEFAULT_PACKAGE=pkg ;;
*) DEFAULT_PACKAGE=rpm ;; *) DEFAULT_PACKAGE=rpm ;;
esac esac
AC_MSG_RESULT([$DEFAULT_PACKAGE]) AC_MSG_RESULT([$DEFAULT_PACKAGE])
@ -606,6 +609,7 @@ AC_DEFUN([ZFS_AC_DEFAULT_PACKAGE], [
ubuntu) initconfdir=/etc/default ;; ubuntu) initconfdir=/etc/default ;;
debian) initconfdir=/etc/default ;; debian) initconfdir=/etc/default ;;
freebsd) initconfdir=$sysconfdir/rc.conf.d;; freebsd) initconfdir=$sysconfdir/rc.conf.d;;
apple) initconfdir=${prefix}/etc/launchd/launchd.d/ ;;
*) initconfdir=/etc/default ;; *) initconfdir=/etc/default ;;
esac esac
AC_MSG_RESULT([$initconfdir]) AC_MSG_RESULT([$initconfdir])
@ -639,7 +643,7 @@ dnl # Default ZFS package configuration
dnl # dnl #
AC_DEFUN([ZFS_AC_PACKAGE], [ AC_DEFUN([ZFS_AC_PACKAGE], [
ZFS_AC_DEFAULT_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_RPM
ZFS_AC_DPKG ZFS_AC_DPKG
ZFS_AC_ALIEN ZFS_AC_ALIEN