4 # Set things accordingly for a linux kernel
6 AC_DEFUN([LB_LINUX_VERSION], [
11 AC_CACHE_CHECK([for external module build target], lb_cv_module_target,
13 lb_cv_module_target=""
14 rm -f build/conftest.i
17 LB_LINUX_TRY_MAKE([], [],
18 [$makerule LUSTRE_KERNEL_TEST=conftest.i],
19 [test -s build/conftest.i],
20 [lb_cv_module_target="M54"], [
22 makerule="_module_$PWD/build"
23 LB_LINUX_TRY_MAKE([], [],
24 [$makerule LUSTRE_KERNEL_TEST=conftest.i],
25 [test -s build/conftest.i],
26 [lb_cv_module_target="M"], [
29 LB_LINUX_TRY_MAKE([], [],
30 [$makerule LUSTRE_KERNEL_TEST=conftest.i],
31 [test -s build/conftest.i],
32 [lb_cv_module_target="M58"], [
33 AC_MSG_ERROR([kernel module make failed; check config.log for details])
36 AS_IF([test -z "$lb_cv_module_target"],
37 [AC_MSG_ERROR([unknown external module build target])],
38 [test "x$lb_cv_module_target" = "xM54"],
39 [makerule="$PWD/build"
40 lb_cv_module_target="M"],
41 [test "x$lb_cv_module_target" = "xM58"],
43 lb_cv_module_target="M"],
44 [test "x$lb_cv_module_target" = "xM"],
45 [makerule="_module_$PWD/build"])
46 MODULE_TARGET=$lb_cv_module_target
47 AC_SUBST(MODULE_TARGET)
53 # Determine the Linux kernel version string from the utsrelease
55 AC_DEFUN([LB_LINUX_UTSRELEASE], [
56 AC_CACHE_CHECK([for Linux kernel utsrelease], lb_cv_utsrelease, [
58 utsrelease1=$LINUX_OBJ/include/generated/utsrelease.h
59 utsrelease2=$LINUX_OBJ/include/linux/utsrelease.h
60 utsrelease3=$LINUX_OBJ/include/linux/version.h
61 AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1],
62 [utsrelease=$utsrelease1],
63 [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2],
64 [utsrelease=$utsrelease2],
65 [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3],
66 [utsrelease=$utsrelease3])
67 AS_IF([test -n "$utsrelease"],
68 [lb_cv_utsrelease=$(awk -F \" '/ UTS_RELEASE / { print [$]2 }' $utsrelease)],
71 Cannot find UTS_RELEASE definition.
73 This is often provided by the kernel-devel package.
77 AS_IF([test -z "$lb_cv_utsrelease"],
78 [AC_MSG_ERROR([Cannot determine Linux kernel version.])])
79 LINUXRELEASE=$lb_cv_utsrelease
80 AC_SUBST(LINUXRELEASE)
86 # get the release version of linux
88 AC_DEFUN([LB_LINUX_RELEASE], [
91 # Define default states
96 # And if any of the above kernels has been detected yet
99 # Check for RedHat first (no need to check KERNEL_FOUND
100 AC_CACHE_CHECK([for RedHat kernel release number], lb_cv_rhel_kernel_version, [
101 lb_cv_rhel_kernel_version=""
102 AS_IF([fgrep -q RHEL_RELEASE $LINUX_OBJ/include/$VERSION_HDIR/version.h], [
103 lb_cv_rhel_kernel_version=$(awk '/ RHEL_MAJOR / { print [$]3 }' \
104 $LINUX_OBJ/include/$VERSION_HDIR/version.h)$(awk \
105 '/ RHEL_MINOR / { print [$]3 }' \
106 $LINUX_OBJ/include/$VERSION_HDIR/version.h)
109 AS_IF([test -n "$lb_cv_rhel_kernel_version"], [
112 RHEL_RELEASE_NO=$lb_cv_rhel_kernel_version
116 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
117 LB_CHECK_CONFIG([SUSE_KERNEL], [
124 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
125 AC_CACHE_CHECK([for Ubuntu kernel signature], lb_cv_ubuntu_kernel_sig, [
126 lb_cv_ubuntu_kernel_sig="no"
127 AS_IF([fgrep -q "CONFIG_VERSION_SIGNATURE \"Ubuntu" $LINUX_OBJ/include/generated/autoconf.h], [
128 lb_cv_ubuntu_kernel_sig="yes"
131 AS_IF([test "x$lb_cv_ubuntu_kernel_sig" = "xyes"], [
137 # Check for a ELRepo -ml kernel on RHEL 7/8
138 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
139 AC_CACHE_CHECK([for ELRepo -ml kernel signature on CentOS],
140 lb_cv_mainline_kernel_sig, [
141 lb_cv_mainline_kernel_sig="no"
142 AS_IF([fgrep -q '.el7.' $LINUX_OBJ/include/generated/utsrelease.h], [
143 lb_cv_mainline_kernel_sig="yes"
145 AS_IF([fgrep -q '.el8.' $LINUX_OBJ/include/generated/utsrelease.h], [
146 lb_cv_mainline_kernel_sig="yes"
149 AS_IF([test "x$lb_cv_mainline_kernel_sig" = "xyes"], [
155 # Check for openEuler
156 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
157 AC_CACHE_CHECK([for openEuler kernel signature], lb_cv_openeuler_kernel_sig, [
158 lb_cv_openeuler_kernel_sig="no"
159 AS_IF([fgrep -q 'openEuler' $LINUX_OBJ/include/linux/kabi.h], [
160 lb_cv_openeuler_kernel_sig="yes"
163 AS_IF([test "x$lb_cv_openeuler_kernel_sig" = "xyes"], [
164 OPENEULER_KERNEL="yes"
169 # If still no kernel was found, a warning is issued
170 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
171 AC_MSG_WARN([Kernel Distro seems to be neither RedHat, SuSE, openEuler nor Ubuntu])
174 AC_MSG_CHECKING([for Linux kernel module package directory])
175 AC_ARG_WITH([kmp-moddir],
176 AS_HELP_STRING([--with-kmp-moddir=string],
177 [set the kmod updates or extra directory]),
180 AS_IF([test x$RHEL_KERNEL = xyes], [KMP_MODDIR="extra/kernel"],
181 [test x$OPENEULER_KERNEL = xyes], [KMP_MODDIR="extra/kernel"],
182 [test x$SUSE_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
183 [test x$UBUNTU_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
184 [AC_MSG_WARN([Kernel Distro seems to be neither RedHat, SuSE, openEuler nor Ubuntu])]
186 IN_KERNEL="${PACKAGE}"])
187 AC_MSG_RESULT($KMP_MODDIR)
189 moduledir="/lib/modules/${LINUXRELEASE}/${KMP_MODDIR}"
191 modulefsdir="${moduledir}/fs/${IN_KERNEL}"
192 AC_SUBST(modulefsdir)
194 modulenetdir="${moduledir}/net/${IN_KERNEL}"
195 AC_SUBST(modulenetdir)
201 # LB_LINUX_SYMVERFILE
203 # SLES 9 uses a different name for this file - unsure about vanilla kernels
204 # around this version, but it matters for servers only.
205 AC_DEFUN([LB_LINUX_SYMVERFILE], [
206 AC_CACHE_CHECK([for the name of module symbol version file], lb_cv_module_symvers, [
207 AS_IF([grep -q Modules.symvers $LINUX/scripts/Makefile.modpost],
208 [lb_cv_module_symvers=Modules.symvers],
209 [lb_cv_module_symvers=Module.symvers])
211 SYMVERFILE=$lb_cv_module_symvers
216 # LB_ARG_REPLACE_PATH(PACKAGE, PATH)
218 AC_DEFUN([LB_ARG_REPLACE_PATH], [
220 eval set -- $ac_configure_args
224 arg=--with-[$1]=[$2] ;;
226 arg=$(printf %s\n ["$arg"] | sed "s/'/'\\\\\\\\''/g") ;;
228 dnl AS_VAR_APPEND([new_configure_args], [" '$arg'"])
229 new_configure_args="$new_configure_args '$arg'"
231 ac_configure_args=$new_configure_args
235 # __LB_ARG_CANON_PATH
237 # this is the work-horse of the next function
239 AC_DEFUN([__LB_ARG_CANON_PATH], [
240 [$3]=$(readlink -f $with_$2)
241 LB_ARG_REPLACE_PATH([$1], $[$3])
247 # a front-end for the above function that transforms - and . in the
248 # PACKAGE portion of --with-PACKAGE into _ suitable for variable names
250 AC_DEFUN([LB_ARG_CANON_PATH], [
251 __LB_ARG_CANON_PATH([$1], m4_translit([$1], [-.], [__]), [$2])
257 # Find paths for linux, handling kernel-source rpms
259 AC_DEFUN([LB_LINUX_PATH], [
260 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
261 AS_IF([readlink -q -e $DEFAULT_LINUX >/dev/null], [break])
263 if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then
264 PATHS="/lib/modules/$(uname -r)/build"
266 PATHS="/usr/src/linux-headers-$(uname -r)"
268 PATHS+=" $DEFAULT_LINUX"
269 for DEFAULT_LINUX_OBJ in $PATHS; do
270 AS_IF([readlink -q -e $DEFAULT_LINUX_OBJ >/dev/null], [break])
273 AC_MSG_CHECKING([for Linux sources])
275 AS_HELP_STRING([--with-linux=path],
276 [set path to Linux source (default=/lib/modules/$(uname -r)/{source,build},/usr/src/linux)]),
277 [LB_ARG_CANON_PATH([linux], [LINUX])
278 DEFAULT_LINUX_OBJ=$LINUX],
279 [LINUX=$DEFAULT_LINUX])
280 AC_MSG_RESULT([$LINUX])
282 # -------- check for linux --------
283 LB_CHECK_FILE([$LINUX], [],
284 [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
286 # -------- linux objects (for 2.6) --
287 AC_MSG_CHECKING([for Linux objects])
288 AC_ARG_WITH([linux-obj],
289 AS_HELP_STRING([--with-linux-obj=path],
290 [set path to Linux objects (default=/lib/modules/$(uname -r)/build,/usr/src/linux)]),
291 [LB_ARG_CANON_PATH([linux-obj], [LINUX_OBJ])],
292 [LINUX_OBJ=$DEFAULT_LINUX_OBJ])
293 AC_MSG_RESULT([$LINUX_OBJ])
295 ## -------- with linux should point to <kernel>-common on Debian
296 AS_IF([test ${LINUX} == ${LINUX_OBJ} -a ${LINUX} == $(realpath ${LINUX})],[
297 this_arch=$(realpath ${LINUX} | sed 's/-/\n/g' | tail -1)
298 linux_headers_common=$(realpath ${LINUX}|sed "s/-${this_arch}\$/-common/g")
299 AS_IF([test "${this_arch}" != common],[
300 _cah="${linux_headers_common}/include/linux/compiler_attributes.h"
301 _cgh="${linux_headers_common}/include/linux/compiler-gcc.h"
302 AS_IF([test -f "${_cah}" -o -f "${_cgh}"],[
303 AC_MSG_WARN([Setting LINUX to ${linux_headers_common} was ${LINUX}])
304 LINUX=${linux_headers_common}])
309 # -------- check for .config --------
310 AC_ARG_WITH([linux-config],
311 [AS_HELP_STRING([--with-linux-config=path],
312 [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
313 [LB_ARG_CANON_PATH([linux-config], [LINUX_CONFIG])],
314 [LINUX_CONFIG=$LINUX_OBJ/.config])
316 # -------- check if .config exists --
317 LB_CHECK_FILE([$LINUX_CONFIG], [],
320 Kernel config could not be found.
323 AC_SUBST(LINUX_CONFIG)
325 LB_CHECK_FILE([/boot/kernel.h],
326 [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
327 [LB_CHECK_FILE([/var/adm/running-kernel.h],
328 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
330 AC_ARG_WITH([kernel-source-header],
331 AS_HELP_STRING([--with-kernel-source-header=path],
332 [Use a different kernel version header.]),
333 [LB_ARG_CANON_PATH([kernel-source-header], [KERNEL_SOURCE_HEADER])])
335 # ----------- make dep run? ------------------
336 # at 2.6.19 # $LINUX/include/linux/config.h is removed
337 # and at more old has only one line include <autoconf.h>
339 LB_CHECK_FILE([$LINUX_OBJ/include/generated/autoconf.h],
340 [AUTOCONF_HDIR=generated],
341 [LB_CHECK_FILE([$LINUX_OBJ/include/linux/autoconf.h],
342 [AUTOCONF_HDIR=linux],
343 [AC_MSG_ERROR([Run make config in $LINUX.])])])
344 AC_SUBST(AUTOCONF_HDIR)
346 LB_CHECK_FILE([$LINUX_OBJ/include/linux/version.h],
347 [VERSION_HDIR=linux],
348 [LB_CHECK_FILE([$LINUX_OBJ/include/generated/uapi/linux/version.h],
349 [VERSION_HDIR=generated/uapi/linux],
350 [AC_MSG_ERROR([Run make config in $LINUX.])])])
351 AC_SUBST(VERSION_HDIR)
353 # ----------- kconfig.h exists ---------------
354 # kernel 3.1, $LINUX/include/linux/kconfig.h is added
355 # see kernel commit 2a11c8ea20bf850b3a2c60db8c2e7497d28aba99
357 LB_CHECK_FILE([$LINUX/include/linux/kconfig.h],
358 [CONFIG_INCLUDE=$LINUX/include/linux/kconfig.h],
359 [CONFIG_INCLUDE=include/$AUTOCONF_HDIR/autoconf.h])
360 AC_SUBST(CONFIG_INCLUDE)
362 # ------------ rhconfig.h includes runtime-generated bits --
363 # RedHat kernel-source checks
365 # we know this exists after the check above. if the user
366 # tarred up the tree and ran make dep etc. in it, then
367 # version.h gets overwritten with a standard linux one.
369 AS_IF([grep rhconfig $LINUX_OBJ/include/$VERSION_HDIR/version.h >/dev/null], [
370 # This is a clean kernel-source tree, we need to
371 # enable extensive workarounds to get this to build modules
372 LB_CHECK_FILE([$KERNEL_SOURCE_HEADER], [
373 AS_IF([test $KERNEL_SOURCE_HEADER = '/boot/kernel.h'],
376 Using /boot/kernel.h from RUNNING kernel.
378 If this is not what you want, use --with-kernel-source-header.
379 Consult build/README.kernel-source for details.
384 $KERNEL_SOURCE_HEADER not found.
386 Consult build/README.kernel-source for details.
389 EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
392 # this is needed before we can build modules
395 # --- check that we can build modules at all
396 LB_CHECK_COMPILE([that modules can be built at all], build_modules,
400 Kernel modules cannot be built. Consult config.log for details.
402 If you are trying to build with a kernel-source rpm,
403 consult build/README.kernel-source
408 ]) # end of LB_LINUX_PATH
413 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
414 # so we test if request_module is implemented or not
415 AC_DEFUN([LC_MODULE_LOADING], [
416 AC_CACHE_CHECK([if Linux kernel module loading is possible], lb_cv_module_loading, [
418 #include <linux/kmod.h>
420 int myretval=ENOSYS ;
423 $makerule LUSTRE_KERNEL_TEST=conftest.i
425 grep request_module build/conftest.i |dnl
426 grep -v `grep "int myretval=" build/conftest.i |dnl
427 cut -d= -f2 | cut -d" " -f1`dnl
429 ], [lb_cv_module_loading="yes"], [lb_cv_module_loading="no"])
431 AS_IF([test "$lb_cv_module_loading" = yes],
432 [AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
433 [kernel module loading is possible])],
436 Kernel module loading support is highly recommended.
442 AC_DEFUN([LB_PROG_LINUX_SRC], [
443 LB2_SRC_CHECK_CONFIG([MODULES])
444 LB2_SRC_CHECK_CONFIG([MODVERSIONS])
447 AC_DEFUN([LB_PROG_LINUX_RESULTS], [
448 LB2_TEST_CHECK_CONFIG([MODULES], [], [AC_MSG_ERROR(
449 [module support is required to build Lustre kernel modules.])
451 LB2_TEST_CHECK_CONFIG([MODVERSIONS],[],[])
459 AC_DEFUN([LB_PROG_LINUX], [
469 # Determine if the target is a dpkg system or rpm
471 AC_DEFUN([LB_USES_DPKG], [
472 AC_CACHE_CHECK([if this distro uses dpkg], lb_cv_uses_dpkg, [
474 AS_CASE([$(which dpkg 2>/dev/null)],[*/dpkg], [lb_cv_uses_dpkg="yes"])
476 uses_dpkg=$lb_cv_uses_dpkg
482 # check symbol exported or not
484 # $2 - file(s) for find.
488 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers or check
490 AC_DEFUN([LB_CHECK_EXPORT], [
491 AS_VAR_PUSHDEF([lb_export], [lb_cv_export_$1])dnl
492 AC_CACHE_CHECK([if Linux kernel exports '$1'], lb_export, [
493 AS_VAR_SET([lb_export], [no])
494 AS_IF([grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX_OBJ/$SYMVERFILE 2>/dev/null],
495 [AS_VAR_SET([lb_export], [yes])],
497 AS_IF([grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null], [
498 AS_VAR_SET([lb_export], [yes])
503 AS_VAR_IF([lb_export], [yes], [$3], [$4])[]dnl
504 AS_VAR_POPDEF([lb_export])dnl
510 # check if a given config option is defined
515 AC_DEFUN([LB_CHECK_CONFIG], [
516 LB_CHECK_COMPILE([if Linux kernel was built with CONFIG_$1],
518 #include <$AUTOCONF_HDIR/autoconf.h>
521 #error CONFIG_$1 not #defined
529 # check if a given config option is builtin or as module
530 # $1 - CONFIG_<name> or CONFIG_<name>_MODULE
534 AC_DEFUN([LB_CHECK_CONFIG_IM], [
535 LB_CHECK_COMPILE([if Linux kernel was built with CONFIG_$1 in or as module],
537 #include <$AUTOCONF_HDIR/autoconf.h>
539 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
540 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
543 ]) # LB_CHECK_CONFIG_IM
546 # these are like AC_TRY_COMPILE, but try to build modules against the
547 # kernel, inside the build directory
551 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
552 # --------------------------------------
554 m4_define([LB_LANG_PROGRAM],
556 #include <linux/kernel.h>
557 #include <linux/module.h>
559 #if defined(NEED_LOCKDEP_IS_HELD_DISCARD_CONST) \
560 && defined(CONFIG_LOCKDEP) \
561 && defined(lockdep_is_held)
562 #undef lockdep_is_held
563 #define lockdep_is_held(lock) \
564 lock_is_held((struct lockdep_map *)&(lock)->dep_map)
571 dnl Do *not* indent the following line: there may be CPP directives.
572 dnl Don't move the `;' right after for the same reason.
577 MODULE_LICENSE("GPL");])
580 # LB_LINUX_COMPILE_IFELSE
582 # like AC_COMPILE_IFELSE
584 # $1 - AC_LANG_SOURCE()
590 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
591 [m4_ifvaln([$1], [AC_LANG_CONFTEST([AC_LANG_SOURCE([$1])])])dnl
592 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
593 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$ZFS/include/os/linux/kernel -I$ZFS/include/os/linux/spl -I$ZFS/include/os/linux/zfs -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])],
595 [_AC_MSG_LOG_CONFTEST
596 m4_ifvaln([$5],[$5])dnl])
597 rm -f build/conftest.o build/conftest.mod.c build/conftest.mod.o build/conftest.ko m4_ifval([$1], [build/conftest.c conftest.c])[]dnl
601 # LB_LINUX_TRY_COMPILE
603 # like AC_TRY_COMPILE
605 AC_DEFUN([LB_LINUX_TRY_COMPILE], [
606 LB_LINUX_COMPILE_IFELSE(
607 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
608 [modules], [test -s build/conftest.o],
615 # like LB_LINUX_TRY_COMPILE, but with different arguments
617 AC_DEFUN([LB_LINUX_TRY_MAKE], [
618 LB_LINUX_COMPILE_IFELSE(
619 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
620 [$3], [$4], [$5], [$6])
625 # $1 - checking message
632 AC_DEFUN([LB_CHECK_COMPILE], [
633 AS_VAR_PUSHDEF([lb_compile], [lb_cv_compile_$2])dnl
634 AC_CACHE_CHECK([$1], lb_compile, [
635 LB_LINUX_TRY_COMPILE([$3], [$4],
636 [AS_VAR_SET([lb_compile], [yes])],
637 [AS_VAR_SET([lb_compile], [no])])
639 AS_VAR_IF([lb_compile], [yes], [$5], [$6])[]dnl
640 AS_VAR_POPDEF([lb_compile])dnl
641 ]) # LB_CHECK_COMPILE
644 # LB_CHECK_LINUX_HEADER
646 # Like AC_CHECK_HEADER but checks for a kernel-space header
648 AC_DEFUN([LB_CHECK_LINUX_HEADER], [
649 AS_VAR_PUSHDEF([lb_header], [lb_cv_header_$1])
650 AC_CACHE_CHECK([for $1], lb_header, [
651 LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
652 [modules], [test -s build/conftest.o],
653 [AS_VAR_SET([lb_header], [yes])],
654 [AS_VAR_SET([lb_header], [no])])
656 AS_VAR_IF([lb_header], [yes], [$2], [$3])
657 AS_VAR_POPDEF([lb_header])
658 ]) # LB_CHECK_LINUX_HEADER
660 # ------------------------------------------------------------------------------
661 # Support 2 stage: parallel compile then checked test results
662 # Heavily inspired by OpenZFS
664 # When converting tests from an LB_CHECK_COMPILE to use an
665 # LB2_LINUX_TEST_SRC and LB2_LINUX_TEST_RESULT pairing the primary
666 # consideration if dependencies on the results of LB2_LINUX_TEST_RESULT
667 # or LB2_TEST_CHECK_CONFIG[_IM] are used by annother compile test.
668 # Such dependencies should be avoided without a clear understanding
669 # of when the test result is actually available.
670 # The serial LB_CHECK_* test produces immediate results
671 # where as the LB2_ variant is not available until an intermediate
672 # LB2_LINUX_TEST_COMPILE_ALL has been executed.
674 # Currently all of the non-conditional LB_CHECK_COMPILE and
675 # LB_CHECK_CONFIG[_IM] cases are executed before any of the
676 # LB2_LINUX_TEST_SRC, or LB2_SRC_CHECK_CONFIG[_IM] code snippets
677 # are written. [Reference LB_CONFIG_MODULES for more details]
679 # This allows such LB2_*_SRC_* test cases to rely on
680 # prior LB_CHECK_* results, provided such results are preserved
681 # in the global configure name space. Likewise an LB2_LINUX_TEST_RESULT
682 # or LB2_TEST_CHECK_CONFIG[_IM] may conditionally execute a further
683 # LB_CHECK_* if required. Although it would be typcially be faster
684 # to run a few compile tests and conditionally ignore the results
685 # the reduced configure time may not always out weight the added
688 # It is worth noting that the LB_CHECK_COMPILE macros second argument
689 # is used as the configure test cache name. While is has been important
690 # that this name be globally unique it is even more important in the
691 # parallel case. The is somewhat alleviated by the sanity check in the
692 # LB2_LINUX_TEST_RESULT macro as it will abort with an error if
693 # the cache name does not exist. However care should be taken
694 # that the cache name is a globally unique identifier.
696 # Non-unique cases that are otherwise correct can be identified in the
697 # configure output when a results include ".. (cached)". This indicates
698 # either a duplicate LB_CHECK_* execution which is not critical or a
699 # duplicate identifier which needs to be corrected.
701 # At this point the number of LB_ and LB2_ examples should be
702 # sufficient for the casual developer to perform cut-paste-modify
703 # without serious confusion or complication.
704 # ------------------------------------------------------------------------------
706 AC_DEFUN([LB2_LINUX_CONFTEST_C], [
707 TEST_DIR=${TEST_DIR:-${ac_pwd}/_lpb}
708 test -d ${TEST_DIR}/$2 || mkdir -p ${TEST_DIR}/$2
709 cat confdefs.h - <<_EOF >${TEST_DIR}/$2/$2.c
715 # LB2_LINUX_CONFTEST_MAKEFILE
717 # $1 - *unique* test case name
718 # $2 - additional build flags (ccflags)
719 # $3 - external kernel includes for lnet o2ib|gni
720 # $4 - extra symbol in Psuedo.symvers (optional)
722 AC_DEFUN([LB2_LINUX_CONFTEST_MAKEFILE], [
723 TEST_DIR=${TEST_DIR:-${ac_pwd}/_lpb}
724 test -d ${TEST_DIR} || mkdir -p ${TEST_DIR}
725 test -d ${TEST_DIR}/$1 || mkdir -p ${TEST_DIR}/$1
727 file=${TEST_DIR}/$1/Makefile
731 if test "${EXT_SYMBOL}x" != "x" ; then
732 PSYM_FILE=${TEST_DIR}/$1/Psuedo.symvers
733 echo -e "0x12345678\t${EXT_SYMBOL}\tvmlinux\tEXPORT_SYMBOL\t" > ${PSYM_FILE}
736 if test "x$O2IBPATH" != "x"; then
737 if test "x$O2IBPATH" != "x$LINUX_OBJ"; then
738 XTRA_SYM="$O2IBPATH/Module.symvers"
743 # Example command line to manually build source
744 # make modules -C $LINUX_OBJ $ARCH_UM M=${TEST_DIR}/$1
754 LINUXINCLUDE = $EXT_INCLUDE
755 LINUXINCLUDE += -I$LINUX/arch/$SUBARCH/include
756 LINUXINCLUDE += -Iinclude -Iarch/$SUBARCH/include/generated
757 LINUXINCLUDE += -I$LINUX/include
758 LINUXINCLUDE += -Iinclude2
759 LINUXINCLUDE += -I$LINUX/include/uapi
760 LINUXINCLUDE += -Iinclude/generated
761 LINUXINCLUDE += -I$LINUX/arch/$SUBARCH/include/uapi
762 LINUXINCLUDE += -Iarch/$SUBARCH/include/generated/uapi
763 LINUXINCLUDE += -I$LINUX/include/uapi -Iinclude/generated/uapi
765 LINUXINCLUDE += -include \$(SOBJ)/spl_config.h
768 LINUXINCLUDE += -include \$(ZOBJ)/zfs_config.h
771 LINUXINCLUDE += -I\$(SINC)/include
774 LINUXINCLUDE += -I\$(ZINC) -I\$(ZINC)/include
776 LINUXINCLUDE += -I\$(SINC)
778 LINUXINCLUDE += -I\$(ZINC)/include/spl
781 LINUXINCLUDE += -include $CONFIG_INCLUDE
782 KBUILD_EXTRA_SYMBOLS += ${ZFS_OBJ:+$ZFS_OBJ/Module.symvers}
783 KBUILD_EXTRA_SYMBOLS += ${XTRA_SYM}
785 KBUILD_EXTRA_SYMBOLS += \$(PSYM)
788 ccflags-y := -Werror-implicit-function-declaration
791 # Additional custom CFLAGS as requested.
792 m4_ifval($2, [echo "ccflags-y += $2" >>$file], [])
795 echo "obj-m := $1.o" >>$file
796 echo "obj-m += $1/" >>${TEST_DIR}/Makefile
800 # LB2_LINUX_TEST_COMPILE
802 # Perform a full compile excluding the final modpost phase.
806 AC_DEFUN([LB2_LINUX_TEST_COMPILE], [
809 J=${TEST_JOBS:-$(nproc)}
811 AC_MSG_NOTICE([Making $1 in $D])
812 AC_MSG_NOTICE([KBUILD_MODPOST_NOFINAL="yes" make modules -k -j${J} -C $LINUX_OBJ $ARCH_UM M=${D}])
814 AC_TRY_COMMAND([KBUILD_MODPOST_NOFINAL="yes"
815 make modules -k -j${J} -C $LINUX_OBJ $ARCH_UM M=${D} >${L} 2>&1])
816 AS_IF([test -f ${L}],
817 [AS_IF([test -f $2/Makefile],
818 [mv $2/Makefile $2/Makefile.compile.$1])],
819 [AC_MSG_ERROR([*** Unable to compile test source ... $3])
824 # Perform the compilation of the test cases in two phases.
826 # Phase 1) attempt to build the object files for all of the tests
827 # defined by the LB2_LINUX_TEST_SRC macro.
829 # Phase 2) disable all tests which failed the initial compilation.
831 # This allows us efficiently build the test cases in parallel while
832 # remaining resilient to build failures which are expected when
833 # detecting the available kernel interfaces.
835 # The maximum allowed parallelism can be controlled by setting the
836 # TEST_JOBS environment variable which defaults to $(nproc).
838 AC_DEFUN([LB2_LINUX_TEST_COMPILE_ALL], [
839 TEST_DIR=${TEST_DIR:-${ac_pwd}/_lpb}
840 # Phase 1 - Compilation only, final linking is skipped.
841 LB2_LINUX_TEST_COMPILE([$1], [${TEST_DIR}], [$2])
842 for dir in $(awk '/^obj-m/ { print [$]3 }' \
843 ${TEST_DIR}/Makefile.compile.$1); do
845 touch ${TEST_DIR}/$name/$name.tested
856 # $5 - external include paths
857 # $6 - fake symvers entry
859 # NOTICE as all of the test cases are compiled in parallel tests may not
860 # depend on the results other tests.
861 # Each test needs resolve any external dependencies at the time the program
862 # source is generated.
864 AC_DEFUN([LB2_LINUX_TEST_SRC], [
865 TEST_DIR=${TEST_DIR:-${ac_pwd}/_lpb}
866 AS_VAR_PUSHDEF([lb_test], [lb_cv_test_$1])
867 # Skip test write and build steps if the result is already known.
868 LB2_LINUX_CONFTEST_C([LB_LANG_PROGRAM([[$2]], [[$3]])], [$1_pc])
869 LB2_LINUX_CONFTEST_MAKEFILE([$1_pc], [$4], [$5], [$6])
870 AS_VAR_POPDEF([lb_test])
874 # LB2_LINUX_TEST_RESULT
876 # $1 - *unique* name matching the LB2_LINUX_TEST_SRC macro
877 # $2 - run on success (valid .ko generated)
878 # $3 - run on failure (unable to compile)
880 AC_DEFUN([LB2_LINUX_TEST_RESULT],[
881 TEST_DIR=${TEST_DIR:-${ac_pwd}/_lpb}
882 AS_VAR_PUSHDEF([lb_test], [lb_cv_test_$1])
883 D="$(realpath ${TEST_DIR})"
886 AS_IF([test -d ${T}], [
887 # test source exists, was the compile test run?
888 AS_IF([test -f ${O}.tested],[
889 # compile test was run.
891 # compile test was NOT run. Re-compile everything.
892 AC_MSG_NOTICE([** Rebuilding all tests **])
894 J=${TEST_JOBS:-$(nproc)}
895 for mf in $(ls -1 ${TEST_DIR}/Makefile.compile.*); do
896 ln -sf $mf ${D}/Makefile
897 KBUILD_MODPOST_NOFINAL="yes"
898 make modules -k -j${J} -C $LINUX_OBJ $ARCH_UM M=${D} >> rebuild.log 2>&1
900 for dir in $(awk '/^obj-m/ { print [$]3 }' ${D}/$mf); do
902 AC_MSG_NOTICE([touch ${D}/$name/$name.tested])
903 touch ${D}/$name/$name.tested
907 # compile test was NOT run. Re-compile everything.
910 # test source does not exist:
912 *** No matching source for the "$1" test, check that
913 *** both the test source and result macros refer to the same name.
916 # Abort if key does not exist
917 AS_IF([test -f ${O}.tested], [],
918 [AC_MSG_ERROR([*** Compile test for $1 was not run.])])
919 # If test was compiled and if we got an object ...
920 AS_IF([test -f ${O}.o], [touch ${O}.ko])
921 # key is valid. Cache should be valid, set the variable
922 AC_CACHE_CHECK([for $1], lb_test,
923 AS_IF([test -f ${O}.ko],
924 AS_VAR_SET([lb_test], [yes]),
925 AS_VAR_SET([lb_test], [no])))
926 # Read the variable and run the caller's actions for yes (arg2) or no (arg3)
927 AS_VAR_IF([lb_test], [yes], $2, $3)
928 AS_VAR_POPDEF([lb_test])
929 ]) # LB2_LINUX_TEST_RESULT
932 # LB2_SRC_CHECK_CONFIG
934 # generate source to check if a given config option is defined
938 AC_DEFUN([LB2_SRC_CHECK_CONFIG], [
939 LB2_LINUX_TEST_SRC([config_$1], [
940 #include <$AUTOCONF_HDIR/autoconf.h>
943 #error CONFIG_$1 not #defined
946 ]) # LB2_SRC_CHECK_CONFIG
949 # LB2_TEST_CHECK_CONFIG
951 # test result compile test from LB2_SRC_CHECK_CONFIG
957 AC_DEFUN([LB2_TEST_CHECK_CONFIG], [
958 AC_MSG_CHECKING([if Linux kernel was built with CONFIG_$1])
959 LB2_LINUX_TEST_RESULT([config_$1], [
964 ]) # LB2_TEST_CHECK_CONFIG
967 # LB2_SRC_CHECK_CONFIG_IM
969 # generate source to check if a given config option is defined as built-in
972 # $1 - CONFIG_<name> or CONFIG_<name>_MODULE
974 AC_DEFUN([LB2_SRC_CHECK_CONFIG_IM], [
975 LB2_LINUX_TEST_SRC([config_im_$1], [
976 #include <$AUTOCONF_HDIR/autoconf.h>
978 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
979 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
982 ]) # LB2_SRC_CHECK_CONFIG_IM
986 # LB2_TEST_CHECK_CONFIG_IM
988 # test result compile test from LB2_SRC_CHECK_CONFIG_IM
994 AC_DEFUN([LB2_TEST_CHECK_CONFIG_IM], [
995 AC_MSG_CHECKING([if Linux kernel enabled CONFIG_$1 as built-in or module])
996 LB2_LINUX_TEST_RESULT([config_im_$1], [
1001 ]) # LB2_TEST_CHECK_CONFIG_IM