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
95 # And if any of the above kernels has been detected yet
98 # Check for RedHat first (no need to check KERNEL_FOUND
99 AC_CACHE_CHECK([for RedHat kernel release number], lb_cv_rhel_kernel_version, [
100 lb_cv_rhel_kernel_version=""
101 AS_IF([fgrep -q RHEL_RELEASE $LINUX_OBJ/include/$VERSION_HDIR/version.h], [
102 lb_cv_rhel_kernel_version=$(awk '/ RHEL_MAJOR / { print [$]3 }' \
103 $LINUX_OBJ/include/$VERSION_HDIR/version.h)$(awk \
104 '/ RHEL_MINOR / { print [$]3 }' \
105 $LINUX_OBJ/include/$VERSION_HDIR/version.h)
108 AS_IF([test -n "$lb_cv_rhel_kernel_version"], [
111 RHEL_RELEASE_NO=$lb_cv_rhel_kernel_version
115 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
116 LB_CHECK_CONFIG([SUSE_KERNEL], [
123 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
124 AC_CACHE_CHECK([for Ubuntu kernel signature], lb_cv_ubuntu_kernel_sig, [
125 lb_cv_ubuntu_kernel_sig="no"
126 AS_IF([fgrep -q "CONFIG_VERSION_SIGNATURE \"Ubuntu" $LINUX_OBJ/include/generated/autoconf.h], [
127 lb_cv_ubuntu_kernel_sig="yes"
130 AS_IF([test "x$lb_cv_ubuntu_kernel_sig" = "xyes"], [
136 # Check for a ELRepo -ml kernel on RHEL 7/8
137 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
138 AC_CACHE_CHECK([for ELRepo -ml kernel signature on CentOS],
139 lb_cv_mainline_kernel_sig, [
140 lb_cv_mainline_kernel_sig="no"
141 AS_IF([fgrep -q '.el7.' $LINUX_OBJ/include/generated/utsrelease.h], [
142 lb_cv_mainline_kernel_sig="yes"
144 AS_IF([fgrep -q '.el8.' $LINUX_OBJ/include/generated/utsrelease.h], [
145 lb_cv_mainline_kernel_sig="yes"
148 AS_IF([test "x$lb_cv_mainline_kernel_sig" = "xyes"], [
154 # If still no kernel was found, a warning is issued
155 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
156 AC_MSG_WARN([Kernel Distro seems to be neither RedHat, SuSE nor Ubuntu])
159 AC_MSG_CHECKING([for Linux kernel module package directory])
160 AC_ARG_WITH([kmp-moddir],
161 AS_HELP_STRING([--with-kmp-moddir=string],
162 [set the kmod updates or extra directory]),
165 AS_IF([test x$RHEL_KERNEL = xyes], [KMP_MODDIR="extra/kernel"],
166 [test x$SUSE_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
167 [test x$UBUNTU_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
168 [AC_MSG_WARN([Kernel Distro seems to be neither RedHat, SuSE nor Ubuntu])]
170 IN_KERNEL="${PACKAGE}"])
171 AC_MSG_RESULT($KMP_MODDIR)
173 moduledir="/lib/modules/${LINUXRELEASE}/${KMP_MODDIR}"
175 modulefsdir="${moduledir}/fs/${IN_KERNEL}"
176 AC_SUBST(modulefsdir)
178 modulenetdir="${moduledir}/net/${IN_KERNEL}"
179 AC_SUBST(modulenetdir)
185 # LB_LINUX_SYMVERFILE
187 # SLES 9 uses a different name for this file - unsure about vanilla kernels
188 # around this version, but it matters for servers only.
189 AC_DEFUN([LB_LINUX_SYMVERFILE], [
190 AC_CACHE_CHECK([for the name of module symbol version file], lb_cv_module_symvers, [
191 AS_IF([grep -q Modules.symvers $LINUX/scripts/Makefile.modpost],
192 [lb_cv_module_symvers=Modules.symvers],
193 [lb_cv_module_symvers=Module.symvers])
195 SYMVERFILE=$lb_cv_module_symvers
200 # LB_ARG_REPLACE_PATH(PACKAGE, PATH)
202 AC_DEFUN([LB_ARG_REPLACE_PATH], [
204 eval set -- $ac_configure_args
208 arg=--with-[$1]=[$2] ;;
210 arg=$(printf %s\n ["$arg"] | sed "s/'/'\\\\\\\\''/g") ;;
212 dnl AS_VAR_APPEND([new_configure_args], [" '$arg'"])
213 new_configure_args="$new_configure_args '$arg'"
215 ac_configure_args=$new_configure_args
219 # __LB_ARG_CANON_PATH
221 # this is the work-horse of the next function
223 AC_DEFUN([__LB_ARG_CANON_PATH], [
224 [$3]=$(readlink -f $with_$2)
225 LB_ARG_REPLACE_PATH([$1], $[$3])
231 # a front-end for the above function that transforms - and . in the
232 # PACKAGE portion of --with-PACKAGE into _ suitable for variable names
234 AC_DEFUN([LB_ARG_CANON_PATH], [
235 __LB_ARG_CANON_PATH([$1], m4_translit([$1], [-.], [__]), [$2])
241 # Find paths for linux, handling kernel-source rpms
243 AC_DEFUN([LB_LINUX_PATH], [
244 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
245 AS_IF([readlink -q -e $DEFAULT_LINUX >/dev/null], [break])
247 if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then
248 PATHS="/lib/modules/$(uname -r)/build"
250 PATHS="/usr/src/linux-headers-$(uname -r)"
252 PATHS+=" $DEFAULT_LINUX"
253 for DEFAULT_LINUX_OBJ in $PATHS; do
254 AS_IF([readlink -q -e $DEFAULT_LINUX_OBJ >/dev/null], [break])
257 AC_MSG_CHECKING([for Linux sources])
259 AS_HELP_STRING([--with-linux=path],
260 [set path to Linux source (default=/lib/modules/$(uname -r)/{source,build},/usr/src/linux)]),
261 [LB_ARG_CANON_PATH([linux], [LINUX])
262 DEFAULT_LINUX_OBJ=$LINUX],
263 [LINUX=$DEFAULT_LINUX])
264 AC_MSG_RESULT([$LINUX])
266 # -------- check for linux --------
267 LB_CHECK_FILE([$LINUX], [],
268 [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
270 # -------- linux objects (for 2.6) --
271 AC_MSG_CHECKING([for Linux objects])
272 AC_ARG_WITH([linux-obj],
273 AS_HELP_STRING([--with-linux-obj=path],
274 [set path to Linux objects (default=/lib/modules/$(uname -r)/build,/usr/src/linux)]),
275 [LB_ARG_CANON_PATH([linux-obj], [LINUX_OBJ])],
276 [LINUX_OBJ=$DEFAULT_LINUX_OBJ])
277 AC_MSG_RESULT([$LINUX_OBJ])
279 ## -------- with linux should point to <kernel>-common on Debian
280 AS_IF([test ${LINUX} == ${LINUX_OBJ} -a ${LINUX} == $(realpath ${LINUX})],[
281 this_arch=$(realpath ${LINUX} | sed 's/-/\n/g' | tail -1)
282 linux_headers_common=$(realpath ${LINUX}|sed "s/-${this_arch}\$/-common/g")
283 AS_IF([test "${this_arch}" != common],[
284 _cah="${linux_headers_common}/include/linux/compiler_attributes.h"
285 _cgh="${linux_headers_common}/include/linux/compiler-gcc.h"
286 AS_IF([test -f "${_cah}" -o -f "${_cgh}"],[
287 AC_MSG_WARN([Setting LINUX to ${linux_headers_common} was ${LINUX}])
288 LINUX=${linux_headers_common}])
293 # -------- check for .config --------
294 AC_ARG_WITH([linux-config],
295 [AS_HELP_STRING([--with-linux-config=path],
296 [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
297 [LB_ARG_CANON_PATH([linux-config], [LINUX_CONFIG])],
298 [LINUX_CONFIG=$LINUX_OBJ/.config])
300 # -------- check if .config exists --
301 LB_CHECK_FILE([$LINUX_CONFIG], [],
304 Kernel config could not be found.
307 AC_SUBST(LINUX_CONFIG)
309 LB_CHECK_FILE([/boot/kernel.h],
310 [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
311 [LB_CHECK_FILE([/var/adm/running-kernel.h],
312 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
314 AC_ARG_WITH([kernel-source-header],
315 AS_HELP_STRING([--with-kernel-source-header=path],
316 [Use a different kernel version header.]),
317 [LB_ARG_CANON_PATH([kernel-source-header], [KERNEL_SOURCE_HEADER])])
319 # ----------- make dep run? ------------------
320 # at 2.6.19 # $LINUX/include/linux/config.h is removed
321 # and at more old has only one line include <autoconf.h>
323 LB_CHECK_FILE([$LINUX_OBJ/include/generated/autoconf.h],
324 [AUTOCONF_HDIR=generated],
325 [LB_CHECK_FILE([$LINUX_OBJ/include/linux/autoconf.h],
326 [AUTOCONF_HDIR=linux],
327 [AC_MSG_ERROR([Run make config in $LINUX.])])])
328 AC_SUBST(AUTOCONF_HDIR)
330 LB_CHECK_FILE([$LINUX_OBJ/include/linux/version.h],
331 [VERSION_HDIR=linux],
332 [LB_CHECK_FILE([$LINUX_OBJ/include/generated/uapi/linux/version.h],
333 [VERSION_HDIR=generated/uapi/linux],
334 [AC_MSG_ERROR([Run make config in $LINUX.])])])
335 AC_SUBST(VERSION_HDIR)
337 # ----------- kconfig.h exists ---------------
338 # kernel 3.1, $LINUX/include/linux/kconfig.h is added
339 # see kernel commit 2a11c8ea20bf850b3a2c60db8c2e7497d28aba99
341 LB_CHECK_FILE([$LINUX/include/linux/kconfig.h],
342 [CONFIG_INCLUDE=$LINUX/include/linux/kconfig.h],
343 [CONFIG_INCLUDE=include/$AUTOCONF_HDIR/autoconf.h])
344 AC_SUBST(CONFIG_INCLUDE)
346 # ------------ rhconfig.h includes runtime-generated bits --
347 # RedHat kernel-source checks
349 # we know this exists after the check above. if the user
350 # tarred up the tree and ran make dep etc. in it, then
351 # version.h gets overwritten with a standard linux one.
353 AS_IF([grep rhconfig $LINUX_OBJ/include/$VERSION_HDIR/version.h >/dev/null], [
354 # This is a clean kernel-source tree, we need to
355 # enable extensive workarounds to get this to build modules
356 LB_CHECK_FILE([$KERNEL_SOURCE_HEADER], [
357 AS_IF([test $KERNEL_SOURCE_HEADER = '/boot/kernel.h'],
360 Using /boot/kernel.h from RUNNING kernel.
362 If this is not what you want, use --with-kernel-source-header.
363 Consult build/README.kernel-source for details.
368 $KERNEL_SOURCE_HEADER not found.
370 Consult build/README.kernel-source for details.
373 EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
376 # this is needed before we can build modules
379 # --- check that we can build modules at all
380 LB_CHECK_COMPILE([that modules can be built at all], build_modules,
384 Kernel modules cannot be built. Consult config.log for details.
386 If you are trying to build with a kernel-source rpm,
387 consult build/README.kernel-source
392 ]) # end of LB_LINUX_PATH
397 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
398 # so we test if request_module is implemented or not
399 AC_DEFUN([LC_MODULE_LOADING], [
400 AC_CACHE_CHECK([if Linux kernel module loading is possible], lb_cv_module_loading, [
402 #include <linux/kmod.h>
404 int myretval=ENOSYS ;
407 $makerule LUSTRE_KERNEL_TEST=conftest.i
409 grep request_module build/conftest.i |dnl
410 grep -v `grep "int myretval=" build/conftest.i |dnl
411 cut -d= -f2 | cut -d" " -f1`dnl
413 ], [lb_cv_module_loading="yes"], [lb_cv_module_loading="no"])
415 AS_IF([test "$lb_cv_module_loading" = yes],
416 [AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
417 [kernel module loading is possible])],
420 Kernel module loading support is highly recommended.
431 AC_DEFUN([LB_PROG_LINUX], [
435 LB_CHECK_CONFIG([MODULES], [], [
438 module support is required to build Lustre kernel modules.
442 LB_CHECK_CONFIG([MODVERSIONS])
451 # Determine if the target is a dpkg system or rpm
453 AC_DEFUN([LB_USES_DPKG], [
454 AC_CACHE_CHECK([if this distro uses dpkg], lb_cv_uses_dpkg, [
456 AS_CASE([$(which dpkg 2>/dev/null)],[*/dpkg], [lb_cv_uses_dpkg="yes"])
458 uses_dpkg=$lb_cv_uses_dpkg
464 # check symbol exported or not
466 # $2 - file(s) for find.
470 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers or check
472 AC_DEFUN([LB_CHECK_EXPORT], [
473 AS_VAR_PUSHDEF([lb_export], [lb_cv_export_$1])dnl
474 AC_CACHE_CHECK([if Linux kernel exports '$1'], lb_export, [
475 AS_VAR_SET([lb_export], [no])
476 AS_IF([grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX_OBJ/$SYMVERFILE 2>/dev/null],
477 [AS_VAR_SET([lb_export], [yes])],
479 AS_IF([grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null], [
480 AS_VAR_SET([lb_export], [yes])
485 AS_VAR_IF([lb_export], [yes], [$3], [$4])[]dnl
486 AS_VAR_POPDEF([lb_export])dnl
492 # check if a given config option is defined
497 AC_DEFUN([LB_CHECK_CONFIG], [
498 LB_CHECK_COMPILE([if Linux kernel was built with CONFIG_$1],
500 #include <$AUTOCONF_HDIR/autoconf.h>
503 #error CONFIG_$1 not #defined
511 # check if a given config option is builtin or as module
512 # $1 - CONFIG_<name> or CONFIG_<name>_MODULE
516 AC_DEFUN([LB_CHECK_CONFIG_IM], [
517 LB_CHECK_COMPILE([if Linux kernel was built with CONFIG_$1 in or as module],
519 #include <$AUTOCONF_HDIR/autoconf.h>
521 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
522 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
525 ]) # LB_CHECK_CONFIG_IM
528 # these are like AC_TRY_COMPILE, but try to build modules against the
529 # kernel, inside the build directory
533 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
534 # --------------------------------------
536 m4_define([LB_LANG_PROGRAM],
538 #include <linux/kernel.h>
539 #include <linux/module.h>
541 #if defined(NEED_LOCKDEP_IS_HELD_DISCARD_CONST) \
542 && defined(CONFIG_LOCKDEP) \
543 && defined(lockdep_is_held)
544 #undef lockdep_is_held
545 #define lockdep_is_held(lock) \
546 lock_is_held((struct lockdep_map *)&(lock)->dep_map)
553 dnl Do *not* indent the following line: there may be CPP directives.
554 dnl Don't move the `;' right after for the same reason.
559 MODULE_LICENSE("GPL");])
562 # LB_LINUX_COMPILE_IFELSE
564 # like AC_COMPILE_IFELSE
566 # $1 - AC_LANG_SOURCE()
572 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
573 [m4_ifvaln([$1], [AC_LANG_CONFTEST([AC_LANG_SOURCE([$1])])])dnl
574 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
575 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/')
576 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])],
578 [_AC_MSG_LOG_CONFTEST
579 m4_ifvaln([$5],[$5])dnl])
580 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
584 # LB_LINUX_TRY_COMPILE
586 # like AC_TRY_COMPILE
588 AC_DEFUN([LB_LINUX_TRY_COMPILE], [
589 LB_LINUX_COMPILE_IFELSE(
590 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
591 [modules], [test -s build/conftest.o],
598 # like LB_LINUX_TRY_COMPILE, but with different arguments
600 AC_DEFUN([LB_LINUX_TRY_MAKE], [
601 LB_LINUX_COMPILE_IFELSE(
602 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
603 [$3], [$4], [$5], [$6])
608 # $1 - checking message
615 AC_DEFUN([LB_CHECK_COMPILE], [
616 AS_VAR_PUSHDEF([lb_compile], [lb_cv_compile_$2])dnl
617 AC_CACHE_CHECK([$1], lb_compile, [
618 LB_LINUX_TRY_COMPILE([$3], [$4],
619 [AS_VAR_SET([lb_compile], [yes])],
620 [AS_VAR_SET([lb_compile], [no])])
622 AS_VAR_IF([lb_compile], [yes], [$5], [$6])[]dnl
623 AS_VAR_POPDEF([lb_compile])dnl
624 ]) # LB_CHECK_COMPILE
627 # LB_CHECK_LINUX_HEADER
629 # Like AC_CHECK_HEADER but checks for a kernel-space header
631 m4_define([LB_CHECK_LINUX_HEADER], [
632 AS_VAR_PUSHDEF([lb_header], [lb_cv_header_$1])dnl
633 AC_CACHE_CHECK([for $1], lb_header, [
634 LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
635 [modules], [test -s build/conftest.o],
636 [AS_VAR_SET([lb_header], [yes])],
637 [AS_VAR_SET([lb_header], [no])])
639 AS_VAR_IF([lb_header], [yes], [$2], [$3])[]dnl
640 AS_VAR_POPDEF([lb_header])dnl
641 ]) # LB_CHECK_LINUX_HEADER
643 # ------------------------------------------------------------------------------
644 # Support 2 stage: parallel compile then checked test results
645 # Heavily inspired by OpenZFS
647 AC_DEFUN([LB2_LINUX_CONFTEST_C], [
648 test -d ${TEST_DIR}/$2 || mkdir -p ${TEST_DIR}/$2
649 cat confdefs.h - <<_EOF >${TEST_DIR}/$2/$2.c
655 # LB2_LINUX_CONFTEST_MAKEFILE
657 # $1 - *unique* test case name
658 # $2 - additional build flags (ccflags)
659 # $3 - external kernel includes for lnet o2ib|gni
661 AC_DEFUN([LB2_LINUX_CONFTEST_MAKEFILE], [
662 test -d ${TEST_DIR} || mkdir -p ${TEST_DIR}
663 test -d ${TEST_DIR}/$1 || mkdir -p ${TEST_DIR}/$1
665 file=${TEST_DIR}/$1/Makefile
669 # Example command line to manually build source
670 # make modules -C $LINUX_OBJ $ARCH_UM M=${TEST_DIR}/$1
679 LINUXINCLUDE = $EXT_INCLUDE
680 LINUXINCLUDE += -I$LINUX/arch/$SUBARCH/include
681 LINUXINCLUDE += -Iinclude -Iarch/$SUBARCH/include/generated
682 LINUXINCLUDE += -I$LINUX/include
683 LINUXINCLUDE += -Iinclude2
684 LINUXINCLUDE += -I$LINUX/include/uapi
685 LINUXINCLUDE += -Iinclude/generated
686 LINUXINCLUDE += -I$LINUX/arch/$SUBARCH/include/uapi
687 LINUXINCLUDE += -Iarch/$SUBARCH/include/generated/uapi
688 LINUXINCLUDE += -I$LINUX/include/uapi -Iinclude/generated/uapi
690 LINUXINCLUDE += -include \$(SOBJ)/spl_config.h
693 LINUXINCLUDE += -include \$(ZOBJ)/zfs_config.h
696 LINUXINCLUDE += -I\$(SINC)/include
699 LINUXINCLUDE += -I\$(ZINC) -I\$(ZINC)/include
701 LINUXINCLUDE += -I\$(SINC)
703 LINUXINCLUDE += -I\$(ZINC)/include/spl
706 LINUXINCLUDE += -include $CONFIG_INCLUDE
707 KBUILD_EXTRA_SYMBOLS=${ZFS_OBJ:+$ZFS_OBJ/Module.symvers}
709 ccflags-y := -Werror-implicit-function-declaration
712 # Additional custom CFLAGS as requested.
713 m4_ifval($2, [echo "ccflags-y += $2" >>$file], [])
716 echo "obj-m := $1.o" >>$file
717 echo "obj-m += $1/" >>${TEST_DIR}/Makefile
729 # Used internally by LB2_LINUX_TEST_COMPILE
731 AC_DEFUN([LB2_LINUX_COMPILE], [
733 KBUILD_MODPOST_NOFINAL="yes"
734 make modules -k -j$TEST_JOBS -C $LINUX_OBJ $ARCH_UM
735 M=$1 >$1/build.log 2>&1])
736 AS_IF([AC_TRY_COMMAND([$2])], [$3], [$4])
740 # LB2_LINUX_TEST_COMPILE
742 # Perform a full compile excluding the final modpost phase.
746 AC_DEFUN([LB2_LINUX_TEST_COMPILE], [
747 LB2_LINUX_COMPILE([$2], [test -f $2/build.log], [
748 mv $2/Makefile $2/Makefile.compile.$1
749 mv $2/build.log $2/build.log.$1
752 *** Unable to compile test source to determine kernel interfaces.])
757 # Perform the compilation of the test cases in two phases.
759 # Phase 1) attempt to build the object files for all of the tests
760 # defined by the LB2_LINUX_TEST_SRC macro.
762 # Phase 2) disable all tests which failed the initial compilation.
764 # This allows us efficiently build the test cases in parallel while
765 # remaining resilient to build failures which are expected when
766 # detecting the available kernel interfaces.
768 # The maximum allowed parallelism can be controlled by setting the
769 # TEST_JOBS environment variable which defaults to $(nproc).
771 AC_DEFUN([LB2_LINUX_TEST_COMPILE_ALL], [
772 # Phase 1 - Compilation only, final linking is skipped.
773 LB2_LINUX_TEST_COMPILE([$1], [${TEST_DIR}])
775 for dir in $(awk '/^obj-m/ { print [$]3 }' \
776 ${TEST_DIR}/Makefile.compile.$1); do
778 AS_IF([test -f ${TEST_DIR}/$name/$name.o], [
779 touch ${TEST_DIR}/$name/$name.ko
791 # $5 - external include paths
793 # NOTICE as all of the test cases are compiled in parallel tests may not
794 # depend on the results other tests.
795 # Each test needs resolve any external dependencies at the time the program
796 # source is generated.
798 AC_DEFUN([LB2_LINUX_TEST_SRC], [
799 LB2_LINUX_CONFTEST_C([LB_LANG_PROGRAM([[$2]], [[$3]])], [$1_pc])
800 LB2_LINUX_CONFTEST_MAKEFILE([$1_pc], [$4], [$5])
804 # LB2_LINUX_TEST_RESULT
806 # $1 - *unique* name matching the LB2_LINUX_TEST_SRC macro
807 # $2 - run on success (valid .ko generated)
808 # $3 - run on failure (unable to compile)
810 AC_DEFUN([LB2_LINUX_TEST_RESULT], [
811 AS_IF([test -d ${TEST_DIR}/$1_pc], [
812 AS_IF([test -f ${TEST_DIR}/$1_pc/$1_pc.ko], [$2], [$3])
815 *** No matching source for the "$1" test, check that
816 *** both the test source and result macros refer to the same name.