Whamcloud - gitweb
LU-13891 utils: fix memory leak in llapi_ladvise()
[fs/lustre-release.git] / config / lustre-build-linux.m4
index 5eb844b..3528eda 100644 (file)
@@ -8,26 +8,35 @@ KMODEXT=".ko"
 AC_SUBST(KMODEXT)
 
 makerule="$PWD/build"
-AC_CACHE_CHECK([for external module build target], lb_cv_module_target, [
-lb_cv_module_target=""
-MODULE_TARGET="SUBDIRS"
-rm -f build/conftest.i
-LB_LINUX_TRY_MAKE([], [],
-       [$makerule LUSTRE_KERNEL_TEST=conftest.i],
-       [test -s build/conftest.i],
-       [lb_cv_module_target="SUBDIRS"], [
-               MODULE_TARGET="M"
-               makerule="_module_$PWD/build"
-               LB_LINUX_TRY_MAKE([], [],
-                       [$makerule LUSTRE_KERNEL_TEST=conftest.i],
-                       [test -s build/conftest.i],
-                       [lb_cv_module_target="M"], [
-                               AC_MSG_ERROR([unknown; check config.log for details])
-                       ])
-       ])
+AC_CACHE_CHECK([for external module build target], lb_cv_module_target,
+[
+       lb_cv_module_target=""
+       MODULE_TARGET="SUBDIRS"
+       rm -f build/conftest.i
+       LB_LINUX_TRY_MAKE([], [],
+               [$makerule LUSTRE_KERNEL_TEST=conftest.i],
+               [test -s build/conftest.i],
+               [lb_cv_module_target="SUBDIRS"],[
+       MODULE_TARGET="M"
+       makerule="$PWD/build/"
+       LB_LINUX_TRY_MAKE([], [],
+               [$makerule LUSTRE_KERNEL_TEST=conftest.i],
+               [test -s build/conftest.i],
+               [lb_cv_module_target="M54"], [
+       MODULE_TARGET="M"
+       makerule="_module_$PWD/build"
+       LB_LINUX_TRY_MAKE([], [],
+               [$makerule LUSTRE_KERNEL_TEST=conftest.i],
+               [test -s build/conftest.i],
+               [lb_cv_module_target="M"], [
+                       AC_MSG_ERROR([kernel module make failed; check config.log for details])
+       ])])])
 ])
 AS_IF([test -z "$lb_cv_module_target"],
        [AC_MSG_ERROR([unknown external module build target])],
+[test "x$lb_cv_module_target" = "xM54"],
+       [makerule="$PWD/build"
+       lb_cv_module_target="M"],
 [test "x$lb_cv_module_target" = "xM"],
        [makerule="_module_$PWD/build"])
 MODULE_TARGET=$lb_cv_module_target
@@ -73,56 +82,115 @@ AC_SUBST(LINUXRELEASE)
 # get the release version of linux
 #
 AC_DEFUN([LB_LINUX_RELEASE], [
-LB_LINUX_UTSRELEASE
-
-# ------------ RELEASE --------------------------------
-AC_MSG_CHECKING([for Lustre release])
-AC_ARG_WITH([release],
-       AC_HELP_STRING([--with-release=string],
-               [set the release string (default=$kvers_YYYYMMDDhhmm)]),
-       [RELEASE=$withval], [
-       RELEASE=""
-       AS_IF([test "$DOWNSTREAM_RELEASE"], [RELEASE="${DOWNSTREAM_RELEASE}_"])
-       RELEASE="$RELEASE$(echo $LINUXRELEASE | tr '-' '_')_$BUILDID"])
-AC_MSG_RESULT($RELEASE)
-AC_SUBST(RELEASE)
-
-# check if the kernel is one from RHEL or SUSE
-AC_CACHE_CHECK([for RedHat kernel release number], lb_cv_rhel_kernel_version, [
-lb_cv_rhel_kernel_version=""
-AS_IF([fgrep -q RHEL_RELEASE $LINUX_OBJ/include/$VERSION_HDIR/version.h], [
-       lb_cv_rhel_kernel_version=$(awk '/ RHEL_MAJOR / { print [$]3 }' \
-               $LINUX_OBJ/include/$VERSION_HDIR/version.h)$(awk \
-               '/ RHEL_MINOR / { print [$]3 }' \
-               $LINUX_OBJ/include/$VERSION_HDIR/version.h)
-])
-])
-AS_IF([test -n "$lb_cv_rhel_kernel_version"], [
-       RHEL_KERNEL="yes"
-       RHEL_RELEASE_NO=$lb_cv_rhel_kernel_version
-], [
+       LB_LINUX_UTSRELEASE
+
+       # Define default states
        RHEL_KERNEL="no"
-       LB_CHECK_CONFIG([SUSE_KERNEL], [SUSE_KERNEL="yes"], [SUSE_KERNEL="no"])
-])
+       SUSE_KERNEL="no"
+       UBUNTU_KERNEL="no"
+       DEBIAN_KERNEL="no"
+       # And if any of the above kernels has been detected yet
+       KERNEL_FOUND="no"
+
+       # Check for RedHat first (no need to check KERNEL_FOUND
+       AC_CACHE_CHECK([for RedHat kernel release number], lb_cv_rhel_kernel_version, [
+               lb_cv_rhel_kernel_version=""
+               AS_IF([fgrep -q RHEL_RELEASE $LINUX_OBJ/include/$VERSION_HDIR/version.h], [
+                       lb_cv_rhel_kernel_version=$(awk '/ RHEL_MAJOR / { print [$]3 }' \
+                               $LINUX_OBJ/include/$VERSION_HDIR/version.h)$(awk \
+                               '/ RHEL_MINOR / { print [$]3 }' \
+                               $LINUX_OBJ/include/$VERSION_HDIR/version.h)
+               ])
+       ])
+       AS_IF([test -n "$lb_cv_rhel_kernel_version"], [
+               RHEL_KERNEL="yes"
+               KERNEL_FOUND="yes"
+               RHEL_RELEASE_NO=$lb_cv_rhel_kernel_version
+       ])
 
-AC_MSG_CHECKING([for Linux kernel module package directory])
-AC_ARG_WITH([kmp-moddir],
-       AC_HELP_STRING([--with-kmp-moddir=string],
-               [set the kmod updates or extra directory]),
-       [KMP_MODDIR=$withval],[
-       AS_IF([test x$RHEL_KERNEL = xyes], [KMP_MODDIR="extra"],
-             [test x$SUSE_KERNEL = xyes], [KMP_MODDIR="updates"])])
-AC_MSG_RESULT($KMP_MODDIR)
-AC_SUBST(KMP_MODDIR)
+       # Check for SuSE
+       AS_IF([test "x$KERNEL_FOUND" = "xno"], [
+               LB_CHECK_CONFIG([SUSE_KERNEL], [
+                       SUSE_KERNEL="yes"
+                       KERNEL_FOUND="yes"
+               ], [])
+       ])
 
-moduledir='$(CROSS_PATH)/lib/modules/$(LINUXRELEASE)/$(KMP_MODDIR)/kernel'
-AC_SUBST(moduledir)
+       # Check for Ubuntu
+       AS_IF([test "x$KERNEL_FOUND" = "xno"], [
+               AC_CACHE_CHECK([for Ubuntu kernel signature], lb_cv_ubuntu_kernel_sig, [
+                       lb_cv_ubuntu_kernel_sig="no"
+                       AS_IF([fgrep -q "CONFIG_VERSION_SIGNATURE \"Ubuntu" $LINUX_OBJ/include/generated/autoconf.h], [
+                               lb_cv_ubuntu_kernel_sig="yes"
+                       ])
+               ])
+               AS_IF([test "x$lb_cv_ubuntu_kernel_sig" = "xyes"], [
+                       UBUNTU_KERNEL="yes"
+                       KERNEL_FOUND="yes"
+               ])
+       ])
 
-modulefsdir='$(moduledir)/fs/$(PACKAGE)'
-AC_SUBST(modulefsdir)
+       # Check for Debian
+       AS_IF([test "x$KERNEL_FOUND" = "xno"], [
+               AC_CACHE_CHECK([for Debian kernel signature], lb_cv_debian_kernel_sig, [
+                       lb_cv_debian_kernel_sig="no"
+                       AS_IF([grep -q "LINUX_PACKAGE_ID\s*\"\s*Debian" $LINUX_OBJ/include/generated/package.h], [
+                               lb_cv_debian_kernel_sig="yes"
+                       ])
+               ])
+               AS_IF([test "x$lb_cv_debian_kernel_sig" = "xyes"], [
+                       DEBIAN_KERNEL="yes"
+                       KERNEL_FOUND="yes"
+               ])
+       ])
 
-modulenetdir='$(moduledir)/net/$(PACKAGE)'
-AC_SUBST(modulenetdir)
+       # Check for a ELRepo -ml kernel on RHEL 7/8
+       AS_IF([test "x$KERNEL_FOUND" = "xno"], [
+               AC_CACHE_CHECK([for ELRepo -ml kernel signature on CentOS],
+                               lb_cv_mainline_kernel_sig, [
+                       lb_cv_mainline_kernel_sig="no"
+                       AS_IF([fgrep -q '.el7.' $LINUX_OBJ/include/generated/utsrelease.h], [
+                               lb_cv_mainline_kernel_sig="yes"
+                       ])
+                       AS_IF([fgrep -q '.el8.' $LINUX_OBJ/include/generated/utsrelease.h], [
+                               lb_cv_mainline_kernel_sig="yes"
+                       ])
+               ])
+               AS_IF([test "x$lb_cv_mainline_kernel_sig" = "xyes"], [
+                       RHEL_KERNEL="yes"
+                       KERNEL_FOUND="yes"
+               ])
+       ])
+
+       # If still no kernel was found, a warning is issued
+       AS_IF([test "x$KERNEL_FOUND" = "xno"], [
+               AC_MSG_WARN([Kernel Distro seems to be neither RedHat, SuSE, Ubuntu nor Debian])
+       ])
+
+       AC_MSG_CHECKING([for Linux kernel module package directory])
+       AC_ARG_WITH([kmp-moddir],
+               AC_HELP_STRING([--with-kmp-moddir=string],
+                       [set the kmod updates or extra directory]),
+               [KMP_MODDIR=$withval
+                IN_KERNEL=''],[
+               AS_IF([test x$RHEL_KERNEL = xyes], [KMP_MODDIR="extra/kernel"],
+                     [test x$SUSE_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
+                     [test x$UBUNTU_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
+                     [test x$DEBIAN_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
+                     [AC_MSG_WARN([Kernel Distro seems to be neither RedHat, SuSE, Ubuntu nor Debian])]
+               )
+               IN_KERNEL="${PACKAGE}"])
+       AC_MSG_RESULT($KMP_MODDIR)
+
+       moduledir="/lib/modules/${LINUXRELEASE}/${KMP_MODDIR}"
+
+       modulefsdir="${moduledir}/fs/${IN_KERNEL}"
+       AC_SUBST(modulefsdir)
+
+       modulenetdir="${moduledir}/net/${IN_KERNEL}"
+       AC_SUBST(modulenetdir)
+
+       AC_SUBST(KMP_MODDIR)
 ])
 
 #
@@ -141,49 +209,6 @@ AC_SUBST(SYMVERFILE)
 ])
 
 #
-# LB_LINUX_CROSS
-#
-# check for cross compilation
-#
-AC_DEFUN([LB_LINUX_CROSS], [
-AC_CACHE_CHECK([for cross compilation], lb_cv_cross, [
-lb_cv_cross="no"
-AS_IF([test "x$cross_compiling" = xyes],
-       [AS_CASE([$host_vendor],
-               [k1om | mpss], [
-                       # The K1OM architecture is an extension of the x86 architecture
-                       # and in MPSS 2.1 it's defined in $host_vendor. But in MPSS 3.x
-                       # it's defined in $host_arch. So, try to support both case.
-                       lb_cv_cross=$($CC -v 2>&1 | grep Target: | sed -e 's/Target: //')
-                       AS_IF([test "$lb_cv_cross" != x86_64-k1om-linux -a \
-                                   "$lb_cv_cross" != k1om-mpss-linux], [
-                               AC_MSG_ERROR([Cross compiler not found in PATH.])
-                       ])
-               ])
-       ])
-])
-AS_IF([test "$lb_cv_cross" = x86_64-k1om-linux -o \
-           "$lb_cv_cross" = k1om-mpss-linux], [
-       CROSS_VARS="ARCH=k1om CROSS_COMPILE=${lb_cv_cross}-"
-       CROSS_PATH="${CROSS_PATH:=/opt/lustre/$VERSION/$lb_cv_cross}"
-       CCAS=$CC
-       # need to produce special section for debuginfo extraction
-       LDFLAGS="$LDFLAGS -Wl,--build-id"
-       EXTRA_KLDFLAGS="$EXTRA_KLDFLAGS -Wl,--build-id"
-       AS_IF([test "x$enable_server" != xno], [
-               AC_MSG_WARN([Disabling server (not supported for $lb_cv_cross).])
-               enable_server="no"
-       ])
-       AS_IF([test "x$enable_mpitests" != xno], [
-               AC_MSG_WARN([Disabling MPI tests (not supported for $lb_cv_cross).])
-               enable_mpitests="no"
-       ])
-])
-AC_SUBST(CROSS_VARS)
-AC_SUBST(CROSS_PATH)
-])
-
-#
 # LB_ARG_REPLACE_PATH(PACKAGE, PATH)
 #
 AC_DEFUN([LB_ARG_REPLACE_PATH], [
@@ -228,11 +253,13 @@ AC_DEFUN([LB_ARG_CANON_PATH], [
 # Find paths for linux, handling kernel-source rpms
 #
 AC_DEFUN([LB_LINUX_PATH], [
-for DEFAULT_LINUX in /lib/modules/$(uname -r)/{source,build} /usr/src/linux; do
+for DEFAULT_LINUX in /usr/src/linux-source-* /lib/modules/$(uname -r)/{source,build} /usr/src/linux* $(find /usr/src/kernels/ -maxdepth 1 -name @<:@0-9@:>@\* | xargs -r ls -d | tail -n 1); do
        AS_IF([readlink -q -e $DEFAULT_LINUX >/dev/null], [break])
 done
 if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then
        PATHS="/lib/modules/$(uname -r)/build"
+else
+       PATHS="/usr/src/linux-headers-$(uname -r)"
 fi
 PATHS+=" $DEFAULT_LINUX"
 for DEFAULT_LINUX_OBJ in $PATHS; do
@@ -275,8 +302,6 @@ LB_CHECK_FILE([$LINUX_CONFIG], [],
        [AC_MSG_ERROR([
 
 Kernel config could not be found.
-
-If you are building from a kernel-source rpm consult build/README.kernel-source
 ])
 ])
 AC_SUBST(LINUX_CONFIG)
@@ -288,7 +313,7 @@ LB_CHECK_FILE([/boot/kernel.h],
 
 AC_ARG_WITH([kernel-source-header],
        AC_HELP_STRING([--with-kernel-source-header=path],
-                       [Use a different kernel version header.  Consult build/README.kernel-source for details.]),
+                       [Use a different kernel version header.]),
        [LB_ARG_CANON_PATH([kernel-source-header], [KERNEL_SOURCE_HEADER])])
 
 # ----------- make dep run? ------------------
@@ -349,7 +374,6 @@ Consult build/README.kernel-source for details.
 ])
 
 # this is needed before we can build modules
-LB_LINUX_CROSS
 LB_LINUX_VERSION
 
 # --- check that we can build modules at all
@@ -436,8 +460,7 @@ LC_MODULE_LOADING
 AC_DEFUN([LB_USES_DPKG], [
 AC_CACHE_CHECK([if this distro uses dpkg], lb_cv_uses_dpkg, [
 lb_cv_uses_dpkg="no"
-AS_CASE([$(lsb_release -i -s 2>/dev/null)],
-       [Ubuntu | Debian], [lb_cv_uses_dpkg="yes"])
+AS_CASE([$(which dpkg 2>/dev/null)],[*/dpkg], [lb_cv_uses_dpkg="yes"])
 ])
 uses_dpkg=$lb_cv_uses_dpkg
 ])
@@ -520,6 +543,16 @@ config_im_$1, [
 m4_define([LB_LANG_PROGRAM],
 [
 #include <linux/kernel.h>
+#include <linux/module.h>
+
+#if defined(NEED_LOCKDEP_IS_HELD_DISCARD_CONST) \
+ && defined(CONFIG_LOCKDEP) \
+ && defined(lockdep_is_held)
+#undef lockdep_is_held
+       #define lockdep_is_held(lock) \
+               lock_is_held((struct lockdep_map *)&(lock)->dep_map)
+#endif
+
 $1
 int
 main (void)
@@ -529,7 +562,8 @@ dnl Don't move the `;' right after for the same reason.
 $2
   ;
   return 0;
-}])
+};
+MODULE_LICENSE("GPL");])
 
 #
 # LB_LINUX_COMPILE_IFELSE
@@ -545,8 +579,8 @@ $2
 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
 [m4_ifvaln([$1], [AC_LANG_CONFTEST([AC_LANG_SOURCE([$1])])])dnl
 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
-SUBARCH=$(echo $target_cpu | sed -e 's/powerpc64le/powerpc/' -e 's/powerpc64/powerpc/' -e 's/x86_64/x86/' -e 's/i.86/x86/' -e 's/k1om/x86/')
-AS_IF([AC_TRY_COMMAND(cp conftest.c build && make -d [$2] ${LD:+"LD=$LD"} CC="$CC" -f $PWD/build/Makefile LUSTRE_LINUX_CONFIG=$LINUX_CONFIG LINUXINCLUDE="$EXTRA_OFED_INCLUDE -I$LINUX/arch/$SUBARCH/include -Iinclude -Iarch/$SUBARCH/include/generated -I$LINUX/include -Iinclude2 -I$LINUX/include/uapi -Iinclude/generated -I$LINUX/arch/$SUBARCH/include/uapi -Iarch/$SUBARCH/include/generated/uapi -I$LINUX/include/uapi -Iinclude/generated/uapi ${SPL_OBJ:+-include $SPL_OBJ/spl_config.h} ${ZFS_OBJ:+-include $ZFS_OBJ/zfs_config.h} ${SPL:+-I$SPL -I$SPL/include } ${ZFS:+-I$ZFS -I$ZFS/include} -include $CONFIG_INCLUDE" -o tmp_include_depends -o scripts -o include/config/MARKER -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $CROSS_VARS $MODULE_TARGET=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
+SUBARCH=$(echo $target_cpu | sed -e 's/powerpc.*/powerpc/' -e 's/ppc.*/powerpc/' -e 's/x86_64/x86/' -e 's/i.86/x86/' -e 's/k1om/x86/' -e 's/aarch64.*/arm64/' -e 's/armv7.*/arm/')
+AS_IF([AC_TRY_COMMAND(cp conftest.c build && make -d [$2] LDFLAGS= ${LD:+LD="$LD"} CC="$CC" -f $PWD/build/Makefile LUSTRE_LINUX_CONFIG=$LINUX_CONFIG LINUXINCLUDE="$EXTRA_CHECK_INCLUDE -I$LINUX/arch/$SUBARCH/include -Iinclude -Iarch/$SUBARCH/include/generated -I$LINUX/include -Iinclude2 -I$LINUX/include/uapi -Iinclude/generated -I$LINUX/arch/$SUBARCH/include/uapi -Iarch/$SUBARCH/include/generated/uapi -I$LINUX/include/uapi -Iinclude/generated/uapi ${SPL_OBJ:+-include $SPL_OBJ/spl_config.h} ${ZFS_OBJ:+-include $ZFS_OBJ/zfs_config.h} ${SPL:+-I$SPL/include } ${ZFS:+-I$ZFS -I$ZFS/include -I${SPL:-$ZFS/include/spl}} -include $CONFIG_INCLUDE" KBUILD_EXTRA_SYMBOLS="${ZFS_OBJ:+$ZFS_OBJ/Module.symvers} $KBUILD_EXTRA_SYMBOLS" -o tmp_include_depends -o scripts -o include/config/MARKER -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $MODULE_TARGET=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
        [$4],
        [_AC_MSG_LOG_CONFTEST
 m4_ifvaln([$5],[$5])dnl])
@@ -612,3 +646,182 @@ AC_CACHE_CHECK([for $1], lb_header, [
 AS_VAR_IF([lb_header], [yes], [$2], [$3])[]dnl
 AS_VAR_POPDEF([lb_header])dnl
 ]) # LB_CHECK_LINUX_HEADER
+
+# ------------------------------------------------------------------------------
+# Support 2 stage: parallel compile then checked test results
+# Heavily inspired by OpenZFS
+
+AC_DEFUN([LB2_LINUX_CONFTEST_C], [
+test -d ${TEST_DIR}/$2 || mkdir -p ${TEST_DIR}/$2
+cat confdefs.h - <<_EOF >${TEST_DIR}/$2/$2.c
+$1
+_EOF
+])
+
+#
+# LB2_LINUX_CONFTEST_MAKEFILE
+#
+# $1 - *unique* test case name
+# $2 - additional build flags (ccflags)
+# $3 - external kernel includes for lnet o2ib|gni
+#
+AC_DEFUN([LB2_LINUX_CONFTEST_MAKEFILE], [
+       test -d ${TEST_DIR} || mkdir -p ${TEST_DIR}
+       test -d ${TEST_DIR}/$1 || mkdir -p ${TEST_DIR}/$1
+
+       file=${TEST_DIR}/$1/Makefile
+       EXT_INCLUDE="$3"
+
+       cat - <<_EOF >$file
+# Example command line to manually build source
+# make modules -C $LINUX_OBJ $ARCH_UM M=${TEST_DIR}/$1
+
+${LD:+LD="$LD"}
+CC=$CC
+ZINC=${ZFS}
+SINC=${SPL}
+ZOBJ=${ZFS_OBJ}
+SOBJ=${SPL_OBJ}
+
+LINUXINCLUDE  = $EXT_INCLUDE
+LINUXINCLUDE += -I$LINUX/arch/$SUBARCH/include
+LINUXINCLUDE += -Iinclude -Iarch/$SUBARCH/include/generated
+LINUXINCLUDE += -I$LINUX/include
+LINUXINCLUDE += -Iinclude2
+LINUXINCLUDE += -I$LINUX/include/uapi
+LINUXINCLUDE += -Iinclude/generated
+LINUXINCLUDE += -I$LINUX/arch/$SUBARCH/include/uapi
+LINUXINCLUDE += -Iarch/$SUBARCH/include/generated/uapi
+LINUXINCLUDE += -I$LINUX/include/uapi -Iinclude/generated/uapi
+ifneq (\$(SOBJ),)
+LINUXINCLUDE += -include \$(SOBJ)/spl_config.h
+endif
+ifneq (\$(ZOBJ),)
+LINUXINCLUDE += -include \$(ZOBJ)/zfs_config.h
+endif
+ifneq (\$(SINC),)
+LINUXINCLUDE += -I\$(SINC)/include
+endif
+ifneq (\$(ZINC),)
+LINUXINCLUDE += -I\$(ZINC) -I\$(ZINC)/include
+ifneq (\$(SINC),)
+LINUXINCLUDE += -I\$(SINC)
+else
+LINUXINCLUDE += -I\$(ZINC)/include/spl
+endif
+endif
+LINUXINCLUDE += -include $CONFIG_INCLUDE
+KBUILD_EXTRA_SYMBOLS=${ZFS_OBJ:+$ZFS_OBJ/Module.symvers}
+
+ccflags-y := -Werror-implicit-function-declaration
+_EOF
+
+       # Additional custom CFLAGS as requested.
+       m4_ifval($2, [echo "ccflags-y += $2" >>$file], [])
+
+       # Test case source
+       echo "obj-m := $1.o" >>$file
+       echo "obj-m += $1/" >>${TEST_DIR}/Makefile
+])
+
+
+#
+# LB2_LINUX_COMPILE
+#
+# $1 - build dir
+# $2 - test command
+# $3 - pass command
+# $4 - fail command
+#
+# Used internally by LB2_LINUX_TEST_COMPILE
+#
+AC_DEFUN([LB2_LINUX_COMPILE], [
+       AC_TRY_COMMAND([
+           KBUILD_MODPOST_NOFINAL="yes"
+           make modules -k -j$TEST_JOBS -C $LINUX_OBJ $ARCH_UM
+           M=$1 >$1/build.log 2>&1])
+       AS_IF([AC_TRY_COMMAND([$2])], [$3], [$4])
+])
+
+#
+# LB2_LINUX_TEST_COMPILE
+#
+# Perform a full compile excluding the final modpost phase.
+# $1 - flavor
+# $2 - dirname
+#
+AC_DEFUN([LB2_LINUX_TEST_COMPILE], [
+       LB2_LINUX_COMPILE([$2], [test -f $2/build.log], [
+               mv $2/Makefile $2/Makefile.compile.$1
+               mv $2/build.log $2/build.log.$1
+       ],[
+               AC_MSG_ERROR([
+        *** Unable to compile test source to determine kernel interfaces.])
+       ])
+])
+
+#
+# Perform the compilation of the test cases in two phases.
+#
+# Phase 1) attempt to build the object files for all of the tests
+#          defined by the LB2_LINUX_TEST_SRC macro.
+#
+# Phase 2) disable all tests which failed the initial compilation.
+#
+# This allows us efficiently build the test cases in parallel while
+# remaining resilient to build failures which are expected when
+# detecting the available kernel interfaces.
+#
+# The maximum allowed parallelism can be controlled by setting the
+# TEST_JOBS environment variable which defaults to $(nproc).
+#
+AC_DEFUN([LB2_LINUX_TEST_COMPILE_ALL], [
+       # Phase 1 - Compilation only, final linking is skipped.
+       LB2_LINUX_TEST_COMPILE([$1], [${TEST_DIR}])
+
+       for dir in $(awk '/^obj-m/ { print [$]3 }' \
+           ${TEST_DIR}/Makefile.compile.$1); do
+               name=${dir%/}
+               AS_IF([test -f ${TEST_DIR}/$name/$name.o], [
+                       touch ${TEST_DIR}/$name/$name.ko
+               ])
+       done
+])
+
+#
+# LB2_LINUX_TEST_SRC
+#
+# $1 - *unique* name
+# $2 - global
+# $3 - source
+# $4 - extra cflags
+# $5 - external include paths
+#
+# NOTICE as all of the test cases are compiled in parallel tests may not
+# depend on the results other tests.
+# Each test needs resolve any external dependencies at the time the program
+# source is generated.
+#
+AC_DEFUN([LB2_LINUX_TEST_SRC], [
+       LB2_LINUX_CONFTEST_C([LB_LANG_PROGRAM([[$2]], [[$3]])], [$1_pc])
+       LB2_LINUX_CONFTEST_MAKEFILE([$1_pc], [$4], [$5])
+])
+
+#
+# LB2_LINUX_TEST_RESULT
+#
+# $1 - *unique* name matching the LB2_LINUX_TEST_SRC macro
+# $2 - run on success (valid .ko generated)
+# $3 - run on failure (unable to compile)
+#
+AC_DEFUN([LB2_LINUX_TEST_RESULT], [
+       AS_IF([test -d ${TEST_DIR}/$1_pc], [
+               AS_IF([test -f ${TEST_DIR}/$1_pc/$1_pc.ko], [$2], [$3])
+       ], [
+               AC_MSG_ERROR([
+       *** No matching source for the "$1" test, check that
+       *** both the test source and result macros refer to the same name.
+               ])
+       ])
+])
+