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"], [
34 lb_cv_dequote_CC_VERSION_TEXT=yes
35 LB_LINUX_TRY_MAKE([], [],
36 [$makerule LUSTRE_KERNEL_TEST=conftest.i],
37 [test -s build/conftest.i],
38 [lb_cv_module_target="M517"], [
39 AC_MSG_ERROR([kernel module make failed; check config.log for details])
42 # Linux commit v5.16-rc3-26-g129ab0d2d9f3
43 # added quotes around "$(CONFIG_CC_VERSION_TEXT)", however .config stores
44 # CONFIG_CC_VERSION_TEXT with quotes thus breaking the GNU make Makefile
45 # for external modules.
46 # Workaround by providing a non-quoted value to override the value in .config
47 unset lb_cv_dequote_CC_VERSION_TEXT
48 AC_CACHE_CHECK([for compiler version text], lb_cv_dequote_CC_VERSION_TEXT, [
49 AS_IF([test "x$lb_cv_module_target" = "xM517"],
50 [lb_cv_dequote_CC_VERSION_TEXT=yes],
51 [lb_cv_dequote_CC_VERSION_TEXT=yes])
53 AS_IF([test -z "$lb_cv_module_target"],
54 [AC_MSG_ERROR([unknown external module build target])],
55 [test "x$lb_cv_module_target" = "xM54"],
56 [makerule="$PWD/build"
57 lb_cv_module_target="M"],
58 [test "x$lb_cv_module_target" = "xM58"],
60 lb_cv_module_target="M"],
61 [test "x$lb_cv_module_target" = "xM517"],
63 lb_cv_module_target="M"],
64 [test "x$lb_cv_module_target" = "xM"],
65 [makerule="_module_$PWD/build"])
66 MODULE_TARGET=$lb_cv_module_target
67 AC_SUBST(MODULE_TARGET)
73 # Determine the Linux kernel version string from the utsrelease
75 AC_DEFUN([LB_LINUX_UTSRELEASE], [
76 AC_CACHE_CHECK([for Linux kernel utsrelease], lb_cv_utsrelease, [
78 utsrelease1=$LINUX_OBJ/include/generated/utsrelease.h
79 utsrelease2=$LINUX_OBJ/include/linux/utsrelease.h
80 utsrelease3=$LINUX_OBJ/include/linux/version.h
81 AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1],
82 [utsrelease=$utsrelease1],
83 [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2],
84 [utsrelease=$utsrelease2],
85 [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3],
86 [utsrelease=$utsrelease3])
87 AS_IF([test -n "$utsrelease"],
88 [lb_cv_utsrelease=$(awk -F \" '/ UTS_RELEASE / { print [$]2 }' $utsrelease)],
91 Cannot find UTS_RELEASE definition.
93 This is often provided by the kernel-devel package.
97 AS_IF([test -z "$lb_cv_utsrelease"],
98 [AC_MSG_ERROR([Cannot determine Linux kernel version.])])
99 LINUXRELEASE=$lb_cv_utsrelease
100 AC_SUBST(LINUXRELEASE)
106 # get the release version of linux
108 AC_DEFUN([LB_LINUX_RELEASE], [
111 # Define default states
115 OPENEULER_KERNEL="no"
116 # And if any of the above kernels has been detected yet
119 # Check for RedHat first (no need to check KERNEL_FOUND
120 AC_CACHE_CHECK([for RedHat kernel release number], lb_cv_rhel_kernel_version, [
121 lb_cv_rhel_kernel_version=""
122 AS_IF([fgrep -q RHEL_RELEASE $LINUX_OBJ/include/$VERSION_HDIR/version.h], [
123 lb_cv_rhel_kernel_version=$(awk '/ RHEL_MAJOR / { print [$]3 }' \
124 $LINUX_OBJ/include/$VERSION_HDIR/version.h)$(awk \
125 '/ RHEL_MINOR / { print [$]3 }' \
126 $LINUX_OBJ/include/$VERSION_HDIR/version.h)
129 AS_IF([test -n "$lb_cv_rhel_kernel_version"], [
132 RHEL_RELEASE_NO=$lb_cv_rhel_kernel_version
136 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
137 LB_CHECK_CONFIG([SUSE_KERNEL], [
144 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
145 AC_CACHE_CHECK([for Ubuntu kernel signature], lb_cv_ubuntu_kernel_sig, [
146 lb_cv_ubuntu_kernel_sig="no"
147 AS_IF([fgrep -q "CONFIG_VERSION_SIGNATURE \"Ubuntu" $LINUX_OBJ/include/generated/autoconf.h], [
148 lb_cv_ubuntu_kernel_sig="yes"
151 AS_IF([test "x$lb_cv_ubuntu_kernel_sig" = "xyes"], [
157 # Check for a ELRepo -ml kernel on RHEL 7/8
158 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
159 AC_CACHE_CHECK([for ELRepo -ml kernel signature on CentOS],
160 lb_cv_mainline_kernel_sig, [
161 lb_cv_mainline_kernel_sig="no"
162 AS_IF([fgrep -q '.el7.' $LINUX_OBJ/include/generated/utsrelease.h], [
163 lb_cv_mainline_kernel_sig="yes"
165 AS_IF([fgrep -q '.el8.' $LINUX_OBJ/include/generated/utsrelease.h], [
166 lb_cv_mainline_kernel_sig="yes"
169 AS_IF([test "x$lb_cv_mainline_kernel_sig" = "xyes"], [
175 # Check for openEuler
176 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
177 AC_CACHE_CHECK([for openEuler kernel signature], lb_cv_openeuler_kernel_sig, [
178 lb_cv_openeuler_kernel_sig="no"
179 AS_IF([fgrep -q 'openEuler' $LINUX_OBJ/include/linux/kabi.h], [
180 lb_cv_openeuler_kernel_sig="yes"
183 AS_IF([test "x$lb_cv_openeuler_kernel_sig" = "xyes"], [
184 OPENEULER_KERNEL="yes"
189 # If still no kernel was found, a warning is issued
190 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
191 AC_MSG_WARN([Kernel Distro seems to be neither RedHat, SuSE, openEuler nor Ubuntu])
194 AC_MSG_CHECKING([for Linux kernel module package directory])
195 AC_ARG_WITH([kmp-moddir],
196 AS_HELP_STRING([--with-kmp-moddir=string],
197 [set the kmod updates or extra directory]),
200 AS_IF([test x$RHEL_KERNEL = xyes], [KMP_MODDIR="extra/kernel"],
201 [test x$OPENEULER_KERNEL = xyes], [KMP_MODDIR="extra/kernel"],
202 [test x$SUSE_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
203 [test x$UBUNTU_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
204 [AC_MSG_WARN([Kernel Distro seems to be neither RedHat, SuSE, openEuler nor Ubuntu])]
206 IN_KERNEL="${PACKAGE}"])
207 AC_MSG_RESULT($KMP_MODDIR)
209 moduledir="/lib/modules/${LINUXRELEASE}/${KMP_MODDIR}"
211 modulefsdir="${moduledir}/fs/${IN_KERNEL}"
212 AC_SUBST(modulefsdir)
214 modulenetdir="${moduledir}/net/${IN_KERNEL}"
215 AC_SUBST(modulenetdir)
221 # LB_LINUX_SYMVERFILE
223 # SLES 9 uses a different name for this file - unsure about vanilla kernels
224 # around this version, but it matters for servers only.
225 AC_DEFUN([LB_LINUX_SYMVERFILE], [
226 AC_CACHE_CHECK([for the name of module symbol version file], lb_cv_module_symvers, [
227 AS_IF([grep -q Modules.symvers $LINUX/scripts/Makefile.modpost],
228 [lb_cv_module_symvers=Modules.symvers],
229 [lb_cv_module_symvers=Module.symvers])
231 SYMVERFILE=$lb_cv_module_symvers
236 # LB_ARG_REPLACE_PATH(PACKAGE, PATH)
238 AC_DEFUN([LB_ARG_REPLACE_PATH], [
240 eval set -- $ac_configure_args
244 arg=--with-[$1]=[$2] ;;
246 arg=$(printf %s\n ["$arg"] | sed "s/'/'\\\\\\\\''/g") ;;
248 dnl AS_VAR_APPEND([new_configure_args], [" '$arg'"])
249 new_configure_args="$new_configure_args '$arg'"
251 ac_configure_args=$new_configure_args
255 # __LB_ARG_CANON_PATH
257 # this is the work-horse of the next function
259 AC_DEFUN([__LB_ARG_CANON_PATH], [
260 [$3]=$(readlink -f $with_$2)
261 LB_ARG_REPLACE_PATH([$1], $[$3])
267 # a front-end for the above function that transforms - and . in the
268 # PACKAGE portion of --with-PACKAGE into _ suitable for variable names
270 AC_DEFUN([LB_ARG_CANON_PATH], [
271 __LB_ARG_CANON_PATH([$1], m4_translit([$1], [-.], [__]), [$2])
277 # Find paths for linux, handling kernel-source rpms
279 AC_DEFUN([LB_LINUX_PATH], [
280 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
281 AS_IF([readlink -q -e $DEFAULT_LINUX >/dev/null], [break])
283 if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then
284 PATHS="/lib/modules/$(uname -r)/build"
286 PATHS="/usr/src/linux-headers-$(uname -r)"
288 PATHS+=" $DEFAULT_LINUX"
289 for DEFAULT_LINUX_OBJ in $PATHS; do
290 AS_IF([readlink -q -e $DEFAULT_LINUX_OBJ >/dev/null], [break])
293 AC_MSG_CHECKING([for Linux sources])
295 AS_HELP_STRING([--with-linux=path],
296 [set path to Linux source (default=/lib/modules/$(uname -r)/{source,build},/usr/src/linux)]),
297 [LB_ARG_CANON_PATH([linux], [LINUX])
298 DEFAULT_LINUX_OBJ=$LINUX],
299 [LINUX=$DEFAULT_LINUX])
300 AC_MSG_RESULT([$LINUX])
302 # -------- check for linux --------
303 LB_CHECK_FILE([$LINUX], [],
304 [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
306 # -------- linux objects (for 2.6) --
307 AC_MSG_CHECKING([for Linux objects])
308 AC_ARG_WITH([linux-obj],
309 AS_HELP_STRING([--with-linux-obj=path],
310 [set path to Linux objects (default=/lib/modules/$(uname -r)/build,/usr/src/linux)]),
311 [LB_ARG_CANON_PATH([linux-obj], [LINUX_OBJ])],
312 [LINUX_OBJ=$DEFAULT_LINUX_OBJ])
313 AC_MSG_RESULT([$LINUX_OBJ])
315 ## -------- with linux should point to <kernel>-common on Debian
316 AS_IF([test ${LINUX} == ${LINUX_OBJ} -a ${LINUX} == $(realpath ${LINUX})],[
317 this_arch=$(realpath ${LINUX} | sed 's/-/\n/g' | tail -1)
318 linux_headers_common=$(realpath ${LINUX}|sed "s/-${this_arch}\$/-common/g")
319 AS_IF([test "${this_arch}" != common],[
320 _cah="${linux_headers_common}/include/linux/compiler_attributes.h"
321 _cgh="${linux_headers_common}/include/linux/compiler-gcc.h"
322 AS_IF([test -f "${_cah}" -o -f "${_cgh}"],[
323 AC_MSG_WARN([Setting LINUX to ${linux_headers_common} was ${LINUX}])
324 LINUX=${linux_headers_common}])
329 # -------- check for .config --------
330 AC_ARG_WITH([linux-config],
331 [AS_HELP_STRING([--with-linux-config=path],
332 [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
333 [LB_ARG_CANON_PATH([linux-config], [LINUX_CONFIG])],
334 [LINUX_CONFIG=$LINUX_OBJ/.config])
336 # -------- check if .config exists --
337 LB_CHECK_FILE([$LINUX_CONFIG], [],
340 Kernel config could not be found.
343 AC_SUBST(LINUX_CONFIG)
345 LB_CHECK_FILE([/boot/kernel.h],
346 [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
347 [LB_CHECK_FILE([/var/adm/running-kernel.h],
348 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
350 AC_ARG_WITH([kernel-source-header],
351 AS_HELP_STRING([--with-kernel-source-header=path],
352 [Use a different kernel version header.]),
353 [LB_ARG_CANON_PATH([kernel-source-header], [KERNEL_SOURCE_HEADER])])
355 # ----------- make dep run? ------------------
356 # at 2.6.19 # $LINUX/include/linux/config.h is removed
357 # and at more old has only one line include <autoconf.h>
359 LB_CHECK_FILE([$LINUX_OBJ/include/generated/autoconf.h],
360 [AUTOCONF_HDIR=generated],
361 [LB_CHECK_FILE([$LINUX_OBJ/include/linux/autoconf.h],
362 [AUTOCONF_HDIR=linux],
363 [AC_MSG_ERROR([Run make config in $LINUX.])])])
364 AC_SUBST(AUTOCONF_HDIR)
366 LB_CHECK_FILE([$LINUX_OBJ/include/linux/version.h],
367 [VERSION_HDIR=linux],
368 [LB_CHECK_FILE([$LINUX_OBJ/include/generated/uapi/linux/version.h],
369 [VERSION_HDIR=generated/uapi/linux],
370 [AC_MSG_ERROR([Run make config in $LINUX.])])])
371 AC_SUBST(VERSION_HDIR)
373 # ----------- kconfig.h exists ---------------
374 # kernel 3.1, $LINUX/include/linux/kconfig.h is added
375 # see kernel commit 2a11c8ea20bf850b3a2c60db8c2e7497d28aba99
377 LB_CHECK_FILE([$LINUX/include/linux/kconfig.h],
378 [CONFIG_INCLUDE=$LINUX/include/linux/kconfig.h],
379 [CONFIG_INCLUDE=include/$AUTOCONF_HDIR/autoconf.h])
380 AC_SUBST(CONFIG_INCLUDE)
382 # ------------ rhconfig.h includes runtime-generated bits --
383 # RedHat kernel-source checks
385 # we know this exists after the check above. if the user
386 # tarred up the tree and ran make dep etc. in it, then
387 # version.h gets overwritten with a standard linux one.
389 AS_IF([grep rhconfig $LINUX_OBJ/include/$VERSION_HDIR/version.h >/dev/null], [
390 # This is a clean kernel-source tree, we need to
391 # enable extensive workarounds to get this to build modules
392 LB_CHECK_FILE([$KERNEL_SOURCE_HEADER], [
393 AS_IF([test $KERNEL_SOURCE_HEADER = '/boot/kernel.h'],
396 Using /boot/kernel.h from RUNNING kernel.
398 If this is not what you want, use --with-kernel-source-header.
399 Consult build/README.kernel-source for details.
404 $KERNEL_SOURCE_HEADER not found.
406 Consult build/README.kernel-source for details.
409 EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
412 AS_IF([test -n SUBARCH],
413 [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/')
416 # this is needed before we can build modules
419 # --- Parallel config for kernel v5.17+
420 AS_IF([test "x$lb_cv_dequote_CC_VERSION_TEXT" = "xyes"], [
421 CC_VERSION_TEXT=$(gcc --version | head -n1 | tr ' ()' '.')
422 MAKE_KMOD_ENV="CONFIG_CC_VERSION_TEXT='$CC_VERSION_TEXT'"])
424 # --- check that we can build modules at all
425 LB_CHECK_COMPILE([that modules can be built at all], build_modules,
429 Kernel modules cannot be built. Consult config.log for details.
431 If you are trying to build with a kernel-source rpm,
432 consult build/README.kernel-source
437 ]) # end of LB_LINUX_PATH
442 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
443 # so we test if request_module is implemented or not
444 AC_DEFUN([LC_MODULE_LOADING], [
445 AC_CACHE_CHECK([if Linux kernel module loading is possible], lb_cv_module_loading, [
447 #include <linux/kmod.h>
449 int myretval=ENOSYS ;
452 $makerule LUSTRE_KERNEL_TEST=conftest.i
454 grep request_module build/conftest.i |dnl
455 grep -v `grep "int myretval=" build/conftest.i |dnl
456 cut -d= -f2 | cut -d" " -f1`dnl
458 ], [lb_cv_module_loading="yes"], [lb_cv_module_loading="no"])
460 AS_IF([test "$lb_cv_module_loading" = yes],
461 [AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
462 [kernel module loading is possible])],
465 Kernel module loading support is highly recommended.
471 AC_DEFUN([LB_PROG_LINUX_SRC], [
472 LB2_SRC_CHECK_CONFIG([MODULES])
473 LB2_SRC_CHECK_CONFIG([MODVERSIONS])
476 AC_DEFUN([LB_PROG_LINUX_RESULTS], [
477 LB2_TEST_CHECK_CONFIG([MODULES], [], [AC_MSG_ERROR(
478 [module support is required to build Lustre kernel modules.])
480 LB2_TEST_CHECK_CONFIG([MODVERSIONS],[],[])
488 AC_DEFUN([LB_PROG_LINUX], [
498 # Determine if the target is a dpkg system or rpm
500 AC_DEFUN([LB_USES_DPKG], [
501 AC_CACHE_CHECK([if this distro uses dpkg], lb_cv_uses_dpkg, [
503 AS_CASE([$(which dpkg 2>/dev/null)],[*/dpkg], [lb_cv_uses_dpkg="yes"])
505 uses_dpkg=$lb_cv_uses_dpkg
511 # check symbol exported or not
513 # $2 - file(s) for find.
517 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers or check
519 AC_DEFUN([LB_CHECK_EXPORT], [
520 AS_VAR_PUSHDEF([lb_export], [lb_cv_export_$1])dnl
521 AC_CACHE_CHECK([if Linux kernel exports '$1'], lb_export, [
522 AS_VAR_SET([lb_export], [no])
523 AS_IF([grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX_OBJ/$SYMVERFILE 2>/dev/null],
524 [AS_VAR_SET([lb_export], [yes])],
526 AS_IF([grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null], [
527 AS_VAR_SET([lb_export], [yes])
532 AS_VAR_IF([lb_export], [yes], [$3], [$4])[]dnl
533 AS_VAR_POPDEF([lb_export])dnl
539 # check if a given config option is defined
544 AC_DEFUN([LB_CHECK_CONFIG], [
545 LB_CHECK_COMPILE([if Linux kernel was built with CONFIG_$1],
547 #include <$AUTOCONF_HDIR/autoconf.h>
550 #error CONFIG_$1 not #defined
558 # check if a given config option is builtin or as module
559 # $1 - CONFIG_<name> or CONFIG_<name>_MODULE
563 AC_DEFUN([LB_CHECK_CONFIG_IM], [
564 LB_CHECK_COMPILE([if Linux kernel was built with CONFIG_$1 in or as module],
566 #include <$AUTOCONF_HDIR/autoconf.h>
568 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
569 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
572 ]) # LB_CHECK_CONFIG_IM
575 # these are like AC_TRY_COMPILE, but try to build modules against the
576 # kernel, inside the build directory
580 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
581 # --------------------------------------
583 m4_define([LB_LANG_PROGRAM],
585 #include <linux/kernel.h>
586 #include <linux/module.h>
588 #if defined(NEED_LOCKDEP_IS_HELD_DISCARD_CONST) \
589 && defined(CONFIG_LOCKDEP) \
590 && defined(lockdep_is_held)
591 #undef lockdep_is_held
592 #define lockdep_is_held(lock) \
593 lock_is_held((struct lockdep_map *)&(lock)->dep_map)
600 dnl Do *not* indent the following line: there may be CPP directives.
601 dnl Don't move the `;' right after for the same reason.
606 MODULE_LICENSE("GPL");])
609 # LB_LINUX_COMPILE_IFELSE
611 # like AC_COMPILE_IFELSE
613 # $1 - AC_LANG_SOURCE()
619 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
620 [m4_ifvaln([$1], [AC_LANG_CONFTEST([AC_LANG_SOURCE([$1])])])dnl
621 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
622 AS_IF([AC_TRY_COMMAND(cp conftest.c build && make -d [$2] DEQUOTE_CC_VERSION_TEXT=$lb_cv_dequote_CC_VERSION_TEXT 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])],
624 [_AC_MSG_LOG_CONFTEST
625 m4_ifvaln([$5],[$5])dnl])
626 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
630 # LB_LINUX_TRY_COMPILE
632 # like AC_TRY_COMPILE
634 AC_DEFUN([LB_LINUX_TRY_COMPILE], [
635 LB_LINUX_COMPILE_IFELSE(
636 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
637 [modules], [test -s build/conftest.o],
644 # like LB_LINUX_TRY_COMPILE, but with different arguments
646 AC_DEFUN([LB_LINUX_TRY_MAKE], [
647 LB_LINUX_COMPILE_IFELSE(
648 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
649 [$3], [$4], [$5], [$6])
654 # $1 - checking message
661 AC_DEFUN([LB_CHECK_COMPILE], [
662 AS_VAR_PUSHDEF([lb_compile], [lb_cv_compile_$2])dnl
663 AC_CACHE_CHECK([$1], lb_compile, [
664 LB_LINUX_TRY_COMPILE([$3], [$4],
665 [AS_VAR_SET([lb_compile], [yes])],
666 [AS_VAR_SET([lb_compile], [no])])
668 AS_VAR_IF([lb_compile], [yes], [$5], [$6])[]dnl
669 AS_VAR_POPDEF([lb_compile])dnl
670 ]) # LB_CHECK_COMPILE
673 # LB_CHECK_LINUX_HEADER
675 # Like AC_CHECK_HEADER but checks for a kernel-space header
677 AC_DEFUN([LB_CHECK_LINUX_HEADER], [
678 AS_VAR_PUSHDEF([lb_header], [lb_cv_header_$1])
679 AC_CACHE_CHECK([for $1], lb_header, [
680 LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
681 [modules], [test -s build/conftest.o],
682 [AS_VAR_SET([lb_header], [yes])],
683 [AS_VAR_SET([lb_header], [no])])
685 AS_VAR_IF([lb_header], [yes], [$2], [$3])
686 AS_VAR_POPDEF([lb_header])
687 ]) # LB_CHECK_LINUX_HEADER
689 # ------------------------------------------------------------------------------
690 # Support 2 stage: parallel compile then checked test results
691 # Heavily inspired by OpenZFS
693 # When converting tests from an LB_CHECK_COMPILE to use an
694 # LB2_LINUX_TEST_SRC and LB2_LINUX_TEST_RESULT pairing the primary
695 # consideration if dependencies on the results of LB2_LINUX_TEST_RESULT
696 # or LB2_TEST_CHECK_CONFIG[_IM] are used by annother compile test.
697 # Such dependencies should be avoided without a clear understanding
698 # of when the test result is actually available.
699 # The serial LB_CHECK_* test produces immediate results
700 # where as the LB2_ variant is not available until an intermediate
701 # LB2_LINUX_TEST_COMPILE_ALL has been executed.
703 # Currently all of the non-conditional LB_CHECK_COMPILE and
704 # LB_CHECK_CONFIG[_IM] cases are executed before any of the
705 # LB2_LINUX_TEST_SRC, or LB2_SRC_CHECK_CONFIG[_IM] code snippets
706 # are written. [Reference LB_CONFIG_MODULES for more details]
708 # This allows such LB2_*_SRC_* test cases to rely on
709 # prior LB_CHECK_* results, provided such results are preserved
710 # in the global configure name space. Likewise an LB2_LINUX_TEST_RESULT
711 # or LB2_TEST_CHECK_CONFIG[_IM] may conditionally execute a further
712 # LB_CHECK_* if required. Although it would be typcially be faster
713 # to run a few compile tests and conditionally ignore the results
714 # the reduced configure time may not always out weight the added
717 # It is worth noting that the LB_CHECK_COMPILE macros second argument
718 # is used as the configure test cache name. While is has been important
719 # that this name be globally unique it is even more important in the
720 # parallel case. The is somewhat alleviated by the sanity check in the
721 # LB2_LINUX_TEST_RESULT macro as it will abort with an error if
722 # the cache name does not exist. However care should be taken
723 # that the cache name is a globally unique identifier.
725 # Non-unique cases that are otherwise correct can be identified in the
726 # configure output when a results include ".. (cached)". This indicates
727 # either a duplicate LB_CHECK_* execution which is not critical or a
728 # duplicate identifier which needs to be corrected.
730 # At this point the number of LB_ and LB2_ examples should be
731 # sufficient for the casual developer to perform cut-paste-modify
732 # without serious confusion or complication.
733 # ------------------------------------------------------------------------------
735 AC_DEFUN([LB2_LINUX_CONFTEST_C], [
736 TEST_DIR=${TEST_DIR:-${ac_pwd}/_lpb}
737 test -d ${TEST_DIR}/$2 || mkdir -p ${TEST_DIR}/$2
738 cat confdefs.h - <<_EOF >${TEST_DIR}/$2/$2.c
744 # LB2_LINUX_CONFTEST_MAKEFILE
746 # $1 - *unique* test case name
747 # $2 - additional build flags (ccflags)
748 # $3 - external kernel includes for lnet o2ib|gni
749 # $4 - extra symbol in Psuedo.symvers (optional)
751 AC_DEFUN([LB2_LINUX_CONFTEST_MAKEFILE], [
752 TEST_DIR=${TEST_DIR:-${ac_pwd}/_lpb}
753 test -d ${TEST_DIR} || mkdir -p ${TEST_DIR}
754 test -d ${TEST_DIR}/$1 || mkdir -p ${TEST_DIR}/$1
756 file=${TEST_DIR}/$1/Makefile
760 if test "${EXT_SYMBOL}x" != "x" ; then
761 PSYM_FILE=${TEST_DIR}/$1/Psuedo.symvers
762 echo -e "0x12345678\t${EXT_SYMBOL}\tvmlinux\tEXPORT_SYMBOL\t" > ${PSYM_FILE}
765 if test "x$O2IBPATH" != "x"; then
766 if test "x$O2IBPATH" != "x$LINUX_OBJ"; then
767 XTRA_SYM="$O2IBPATH/Module.symvers"
772 # Example command line to manually build source
773 # make modules -C $LINUX_OBJ $ARCH_UM M=${TEST_DIR}/$1 $MAKE_KMOD_ENV
783 LINUXINCLUDE = $EXT_INCLUDE
784 LINUXINCLUDE += -I$LINUX/arch/$SUBARCH/include
785 LINUXINCLUDE += -Iinclude -Iarch/$SUBARCH/include/generated
786 LINUXINCLUDE += -I$LINUX/include
787 LINUXINCLUDE += -Iinclude2
788 LINUXINCLUDE += -I$LINUX/include/uapi
789 LINUXINCLUDE += -Iinclude/generated
790 LINUXINCLUDE += -I$LINUX/arch/$SUBARCH/include/uapi
791 LINUXINCLUDE += -Iarch/$SUBARCH/include/generated/uapi
792 LINUXINCLUDE += -I$LINUX/include/uapi -Iinclude/generated/uapi
794 LINUXINCLUDE += -include \$(SOBJ)/spl_config.h
797 LINUXINCLUDE += -include \$(ZOBJ)/zfs_config.h
800 LINUXINCLUDE += -I\$(SINC)/include
803 LINUXINCLUDE += -I\$(ZINC) -I\$(ZINC)/include
805 LINUXINCLUDE += -I\$(SINC)
807 LINUXINCLUDE += -I\$(ZINC)/include/spl
810 LINUXINCLUDE += -include $CONFIG_INCLUDE
811 KBUILD_EXTRA_SYMBOLS += ${ZFS_OBJ:+$ZFS_OBJ/Module.symvers}
812 KBUILD_EXTRA_SYMBOLS += ${XTRA_SYM}
814 KBUILD_EXTRA_SYMBOLS += \$(PSYM)
817 ccflags-y := -Werror-implicit-function-declaration
820 # Additional custom CFLAGS as requested.
821 m4_ifval($2, [echo "ccflags-y += $2" >>$file], [])
824 echo "obj-m := $1.o" >>$file
825 echo "obj-m += $1/" >>${TEST_DIR}/Makefile
829 # LB2_LINUX_TEST_COMPILE
831 # Perform a full compile excluding the final modpost phase.
835 AC_DEFUN([LB2_LINUX_TEST_COMPILE], [
838 J=${TEST_JOBS:-$(nproc)}
840 AC_MSG_NOTICE([Making $1 in $D])
841 AC_MSG_NOTICE([KBUILD_MODPOST_NOFINAL="yes" make modules -k -j${J} -C $LINUX_OBJ $ARCH_UM M=${D} $MAKE_KMOD_ENV])
843 AC_TRY_COMMAND([KBUILD_MODPOST_NOFINAL="yes"
844 make modules -k -j${J} -C $LINUX_OBJ $ARCH_UM M=${D} $MAKE_KMOD_ENV >${L} 2>&1])
845 AS_IF([test -f ${L}],
846 [AS_IF([test -f $2/Makefile],
847 [mv $2/Makefile $2/Makefile.compile.$1])],
848 [AC_MSG_ERROR([*** Unable to compile test source ... $3])
853 # Perform the compilation of the test cases in two phases.
855 # Phase 1) attempt to build the object files for all of the tests
856 # defined by the LB2_LINUX_TEST_SRC macro.
858 # Phase 2) disable all tests which failed the initial compilation.
860 # This allows us efficiently build the test cases in parallel while
861 # remaining resilient to build failures which are expected when
862 # detecting the available kernel interfaces.
864 # The maximum allowed parallelism can be controlled by setting the
865 # TEST_JOBS environment variable which defaults to $(nproc).
867 AC_DEFUN([LB2_LINUX_TEST_COMPILE_ALL], [
868 TEST_DIR=${TEST_DIR:-${ac_pwd}/_lpb}
869 # Phase 1 - Compilation only, final linking is skipped.
870 LB2_LINUX_TEST_COMPILE([$1], [${TEST_DIR}], [$2])
871 for dir in $(awk '/^obj-m/ { print [$]3 }' \
872 ${TEST_DIR}/Makefile.compile.$1); do
874 touch ${TEST_DIR}/$name/$name.tested
885 # $5 - external include paths
886 # $6 - fake symvers entry
888 # NOTICE as all of the test cases are compiled in parallel tests may not
889 # depend on the results other tests.
890 # Each test needs resolve any external dependencies at the time the program
891 # source is generated.
893 AC_DEFUN([LB2_LINUX_TEST_SRC], [
894 TEST_DIR=${TEST_DIR:-${ac_pwd}/_lpb}
895 AS_VAR_PUSHDEF([lb_test], [lb_cv_test_$1])
896 # Skip test write and build steps if the result is already known.
897 LB2_LINUX_CONFTEST_C([LB_LANG_PROGRAM([[$2]], [[$3]])], [$1_pc])
898 LB2_LINUX_CONFTEST_MAKEFILE([$1_pc], [$4], [$5], [$6])
899 AS_VAR_POPDEF([lb_test])
903 # LB2_LINUX_TEST_RESULT
905 # $1 - *unique* name matching the LB2_LINUX_TEST_SRC macro
906 # $2 - run on success (valid .ko generated)
907 # $3 - run on failure (unable to compile)
909 AC_DEFUN([LB2_LINUX_TEST_RESULT],[
910 TEST_DIR=${TEST_DIR:-${ac_pwd}/_lpb}
911 AS_VAR_PUSHDEF([lb_test], [lb_cv_test_$1])
912 D="$(realpath ${TEST_DIR})"
915 AS_IF([test -d ${T}], [
916 # test source exists, was the compile test run?
917 AS_IF([test -f ${O}.tested],[
918 # compile test was run.
920 # compile test was NOT run. Re-compile everything.
921 AC_MSG_NOTICE([** Rebuilding all tests **])
923 J=${TEST_JOBS:-$(nproc)}
924 for mf in $(ls -1 ${TEST_DIR}/Makefile.compile.*); do
925 ln -sf $mf ${D}/Makefile
926 KBUILD_MODPOST_NOFINAL="yes"
927 make modules -k -j${J} -C $LINUX_OBJ $ARCH_UM M=${D} >> rebuild.log 2>&1
929 for dir in $(awk '/^obj-m/ { print [$]3 }' ${D}/$mf); do
931 AC_MSG_NOTICE([touch ${D}/$name/$name.tested])
932 touch ${D}/$name/$name.tested
936 # compile test was NOT run. Re-compile everything.
939 # test source does not exist:
941 *** No matching source for the "$1" test, check that
942 *** both the test source and result macros refer to the same name.
945 # Abort if key does not exist
946 AS_IF([test -f ${O}.tested], [],
947 [AC_MSG_ERROR([*** Compile test for $1 was not run.])])
948 # If test was compiled and if we got an object ...
949 AS_IF([test -f ${O}.o], [touch ${O}.ko])
950 # key is valid. Cache should be valid, set the variable
951 AC_CACHE_CHECK([for $1], lb_test,
952 AS_IF([test -f ${O}.ko],
953 AS_VAR_SET([lb_test], [yes]),
954 AS_VAR_SET([lb_test], [no])))
955 # Read the variable and run the caller's actions for yes (arg2) or no (arg3)
956 AS_VAR_IF([lb_test], [yes], $2, $3)
957 AS_VAR_POPDEF([lb_test])
958 ]) # LB2_LINUX_TEST_RESULT
961 # LB2_SRC_CHECK_CONFIG
963 # generate source to check if a given config option is defined
967 AC_DEFUN([LB2_SRC_CHECK_CONFIG], [
968 LB2_LINUX_TEST_SRC([config_$1], [
969 #include <$AUTOCONF_HDIR/autoconf.h>
972 #error CONFIG_$1 not #defined
975 ]) # LB2_SRC_CHECK_CONFIG
978 # LB2_TEST_CHECK_CONFIG
980 # test result compile test from LB2_SRC_CHECK_CONFIG
986 AC_DEFUN([LB2_TEST_CHECK_CONFIG], [
987 AC_MSG_CHECKING([if Linux kernel was built with CONFIG_$1])
988 LB2_LINUX_TEST_RESULT([config_$1], [
993 ]) # LB2_TEST_CHECK_CONFIG
996 # LB2_SRC_CHECK_CONFIG_IM
998 # generate source to check if a given config option is defined as built-in
1001 # $1 - CONFIG_<name> or CONFIG_<name>_MODULE
1003 AC_DEFUN([LB2_SRC_CHECK_CONFIG_IM], [
1004 LB2_LINUX_TEST_SRC([config_im_$1], [
1005 #include <$AUTOCONF_HDIR/autoconf.h>
1007 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
1008 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
1011 ]) # LB2_SRC_CHECK_CONFIG_IM
1015 # LB2_TEST_CHECK_CONFIG_IM
1017 # test result compile test from LB2_SRC_CHECK_CONFIG_IM
1019 # $1 - CONFIG_<name>
1023 AC_DEFUN([LB2_TEST_CHECK_CONFIG_IM], [
1024 AC_MSG_CHECKING([if Linux kernel enabled CONFIG_$1 as built-in or module])
1025 LB2_LINUX_TEST_RESULT([config_im_$1], [
1030 ]) # LB2_TEST_CHECK_CONFIG_IM