Whamcloud - gitweb
LU-12634 build: Recognize ELRepo -ml mainline kernel
[fs/lustre-release.git] / config / lustre-build-linux.m4
1 #
2 # LB_LINUX_VERSION
3 #
4 # Set things accordingly for a linux kernel
5 #
6 AC_DEFUN([LB_LINUX_VERSION], [
7 KMODEXT=".ko"
8 AC_SUBST(KMODEXT)
9
10 makerule="$PWD/build"
11 AC_CACHE_CHECK([for external module build target], lb_cv_module_target, [
12 lb_cv_module_target=""
13 MODULE_TARGET="SUBDIRS"
14 rm -f build/conftest.i
15 LB_LINUX_TRY_MAKE([], [],
16         [$makerule LUSTRE_KERNEL_TEST=conftest.i],
17         [test -s build/conftest.i],
18         [lb_cv_module_target="SUBDIRS"], [
19                 MODULE_TARGET="M"
20                 makerule="_module_$PWD/build"
21                 LB_LINUX_TRY_MAKE([], [],
22                         [$makerule LUSTRE_KERNEL_TEST=conftest.i],
23                         [test -s build/conftest.i],
24                         [lb_cv_module_target="M"], [
25                                 AC_MSG_ERROR([unknown; check config.log for details])
26                         ])
27         ])
28 ])
29 AS_IF([test -z "$lb_cv_module_target"],
30         [AC_MSG_ERROR([unknown external module build target])],
31 [test "x$lb_cv_module_target" = "xM"],
32         [makerule="_module_$PWD/build"])
33 MODULE_TARGET=$lb_cv_module_target
34 AC_SUBST(MODULE_TARGET)
35 ])
36
37 #
38 # LB_LINUX_UTSRELEASE
39 #
40 # Determine the Linux kernel version string from the utsrelease
41 #
42 AC_DEFUN([LB_LINUX_UTSRELEASE], [
43 AC_CACHE_CHECK([for Linux kernel utsrelease], lb_cv_utsrelease, [
44 lb_cv_utsrelease=""
45 utsrelease1=$LINUX_OBJ/include/generated/utsrelease.h
46 utsrelease2=$LINUX_OBJ/include/linux/utsrelease.h
47 utsrelease3=$LINUX_OBJ/include/linux/version.h
48 AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1],
49         [utsrelease=$utsrelease1],
50 [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2],
51         [utsrelease=$utsrelease2],
52 [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3],
53         [utsrelease=$utsrelease3])
54 AS_IF([test -n "$utsrelease"],
55         [lb_cv_utsrelease=$(awk -F \" '/ UTS_RELEASE / { print [$]2 }' $utsrelease)],
56         [AC_MSG_ERROR([
57
58 Cannot find UTS_RELEASE definition.
59
60 This is often provided by the kernel-devel package.
61 ])
62         ])
63 ])
64 AS_IF([test -z "$lb_cv_utsrelease"],
65         [AC_MSG_ERROR([Cannot determine Linux kernel version.])])
66 LINUXRELEASE=$lb_cv_utsrelease
67 AC_SUBST(LINUXRELEASE)
68 ])
69
70 #
71 # LB_LINUX_RELEASE
72 #
73 # get the release version of linux
74 #
75 AC_DEFUN([LB_LINUX_RELEASE], [
76         LB_LINUX_UTSRELEASE
77
78         # Define default states
79         RHEL_KERNEL="no"
80         SUSE_KERNEL="no"
81         UBUNTU_KERNEL="no"
82         DEBIAN_KERNEL="no"
83         # And if any of the above kernels has been detected yet
84         KERNEL_FOUND="no"
85
86         # Check for RedHat first (no need to check KERNEL_FOUND
87         AC_CACHE_CHECK([for RedHat kernel release number], lb_cv_rhel_kernel_version, [
88                 lb_cv_rhel_kernel_version=""
89                 AS_IF([fgrep -q RHEL_RELEASE $LINUX_OBJ/include/$VERSION_HDIR/version.h], [
90                         lb_cv_rhel_kernel_version=$(awk '/ RHEL_MAJOR / { print [$]3 }' \
91                                 $LINUX_OBJ/include/$VERSION_HDIR/version.h)$(awk \
92                                 '/ RHEL_MINOR / { print [$]3 }' \
93                                 $LINUX_OBJ/include/$VERSION_HDIR/version.h)
94                 ])
95         ])
96         AS_IF([test -n "$lb_cv_rhel_kernel_version"], [
97                 RHEL_KERNEL="yes"
98                 KERNEL_FOUND="yes"
99                 RHEL_RELEASE_NO=$lb_cv_rhel_kernel_version
100         ])
101
102         # Check for SuSE
103         AS_IF([test "x$KERNEL_FOUND" = "xno"], [
104                 LB_CHECK_CONFIG([SUSE_KERNEL], [
105                         SUSE_KERNEL="yes"
106                         KERNEL_FOUND="yes"
107                 ], [])
108         ])
109
110         # Check for Ubuntu
111         AS_IF([test "x$KERNEL_FOUND" = "xno"], [
112                 AC_CACHE_CHECK([for Ubuntu kernel signature], lb_cv_ubuntu_kernel_sig, [
113                         lb_cv_ubuntu_kernel_sig="no"
114                         AS_IF([fgrep -q "CONFIG_VERSION_SIGNATURE \"Ubuntu" $LINUX_OBJ/include/generated/autoconf.h], [
115                                 lb_cv_ubuntu_kernel_sig="yes"
116                         ])
117                 ])
118                 AS_IF([test "x$lb_cv_ubuntu_kernel_sig" = "xyes"], [
119                         UBUNTU_KERNEL="yes"
120                         KERNEL_FOUND="yes"
121                 ])
122         ])
123
124         # Check for Debian
125         AS_IF([test "x$KERNEL_FOUND" = "xno"], [
126                 AC_CACHE_CHECK([for Debian kernel signature], lb_cv_debian_kernel_sig, [
127                         lb_cv_debian_kernel_sig="no"
128                         AS_IF([grep -q "LINUX_PACKAGE_ID\s*\"\s*Debian" $LINUX_OBJ/include/generated/package.h], [
129                                 lb_cv_debian_kernel_sig="yes"
130                         ])
131                 ])
132                 AS_IF([test "x$lb_cv_debian_kernel_sig" = "xyes"], [
133                         DEBIAN_KERNEL="yes"
134                         KERNEL_FOUND="yes"
135                 ])
136         ])
137
138         # Check for a ELRepo -ml kernel on RHEL 7/8
139         AS_IF([test "x$KERNEL_FOUND" = "xno"], [
140                 AC_CACHE_CHECK([for ELRepo -ml kernel signature on CentOS],
141                                 lb_cv_mainline_kernel_sig, [
142                         lb_cv_mainline_kernel_sig="no"
143                         AS_IF([fgrep -q '.el7.' $LINUX_OBJ/include/generated/utsrelease.h], [
144                                 lb_cv_mainline_kernel_sig="yes"
145                         ])
146                         AS_IF([fgrep -q '.el8.' $LINUX_OBJ/include/generated/utsrelease.h], [
147                                 lb_cv_mainline_kernel_sig="yes"
148                         ])
149                 ])
150                 AS_IF([test "x$lb_cv_mainline_kernel_sig" = "xyes"], [
151                         MAINLINE_KERNEL="yes"
152                         KERNEL_FOUND="yes"
153                 ])
154         ])
155
156         # If still no kernel was found, a warning is issued
157         AS_IF([test "x$KERNEL_FOUND" = "xno"], [
158                 AC_MSG_WARN([Kernel Distro seems to be neither RedHat, SuSE, Ubuntu nor Debian])
159         ])
160
161         AC_MSG_CHECKING([for Linux kernel module package directory])
162         AC_ARG_WITH([kmp-moddir],
163                 AC_HELP_STRING([--with-kmp-moddir=string],
164                         [set the kmod updates or extra directory]),
165                 [KMP_MODDIR=$withval
166                  IN_KERNEL=''],[
167                 AS_IF([test x$RHEL_KERNEL = xyes], [KMP_MODDIR="extra/kernel"],
168                       [test x$MAINLINE_KERNEL = xyes], [KMP_MODDIR="extra/kernel"],
169                       [test x$SUSE_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
170                       [test x$UBUNTU_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
171                       [test x$DEBIAN_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
172                       [AC_MSG_WARN([Kernel Distro seems to be neither RedHat, SuSE, Ubuntu nor Debian])]
173                 )
174                 IN_KERNEL="${PACKAGE}"])
175         AC_MSG_RESULT($KMP_MODDIR)
176
177         moduledir="/lib/modules/${LINUXRELEASE}/${KMP_MODDIR}"
178
179         modulefsdir="${moduledir}/fs/${IN_KERNEL}"
180         AC_SUBST(modulefsdir)
181
182         modulenetdir="${moduledir}/net/${IN_KERNEL}"
183         AC_SUBST(modulenetdir)
184
185         AC_SUBST(KMP_MODDIR)
186 ])
187
188 #
189 # LB_LINUX_SYMVERFILE
190 #
191 # SLES 9 uses a different name for this file - unsure about vanilla kernels
192 # around this version, but it matters for servers only.
193 AC_DEFUN([LB_LINUX_SYMVERFILE], [
194 AC_CACHE_CHECK([for the name of module symbol version file], lb_cv_module_symvers, [
195 AS_IF([grep -q Modules.symvers $LINUX/scripts/Makefile.modpost],
196         [lb_cv_module_symvers=Modules.symvers],
197         [lb_cv_module_symvers=Module.symvers])
198 ])
199 SYMVERFILE=$lb_cv_module_symvers
200 AC_SUBST(SYMVERFILE)
201 ])
202
203 #
204 # LB_ARG_REPLACE_PATH(PACKAGE, PATH)
205 #
206 AC_DEFUN([LB_ARG_REPLACE_PATH], [
207 new_configure_args=
208 eval set -- $ac_configure_args
209 for arg; do
210         case $arg in
211                 --with-[$1]=*)
212                         arg=--with-[$1]=[$2] ;;
213                 *\'*)
214                         arg=$(printf %s\n ["$arg"] | sed "s/'/'\\\\\\\\''/g") ;;
215         esac
216         dnl AS_VAR_APPEND([new_configure_args], [" '$arg'"])
217         new_configure_args="$new_configure_args '$arg'"
218 done
219 ac_configure_args=$new_configure_args
220 ])
221
222 #
223 # __LB_ARG_CANON_PATH
224 #
225 # this is the work-horse of the next function
226 #
227 AC_DEFUN([__LB_ARG_CANON_PATH], [
228         [$3]=$(readlink -f $with_$2)
229         LB_ARG_REPLACE_PATH([$1], $[$3])
230 ])
231
232 #
233 # LB_ARG_CANON_PATH
234 #
235 # a front-end for the above function that transforms - and . in the
236 # PACKAGE portion of --with-PACKAGE into _ suitable for variable names
237 #
238 AC_DEFUN([LB_ARG_CANON_PATH], [
239         __LB_ARG_CANON_PATH([$1], m4_translit([$1], [-.], [__]), [$2])
240 ])
241
242 #
243 # LB_LINUX_PATH
244 #
245 # Find paths for linux, handling kernel-source rpms
246 #
247 AC_DEFUN([LB_LINUX_PATH], [
248 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
249         AS_IF([readlink -q -e $DEFAULT_LINUX >/dev/null], [break])
250 done
251 if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then
252         PATHS="/lib/modules/$(uname -r)/build"
253 else
254         PATHS="/usr/src/linux-headers-$(uname -r)"
255 fi
256 PATHS+=" $DEFAULT_LINUX"
257 for DEFAULT_LINUX_OBJ in $PATHS; do
258         AS_IF([readlink -q -e $DEFAULT_LINUX_OBJ >/dev/null], [break])
259 done
260
261 AC_MSG_CHECKING([for Linux sources])
262 AC_ARG_WITH([linux],
263         AC_HELP_STRING([--with-linux=path],
264                        [set path to Linux source (default=/lib/modules/$(uname -r)/{source,build},/usr/src/linux)]),
265         [LB_ARG_CANON_PATH([linux], [LINUX])
266         DEFAULT_LINUX_OBJ=$LINUX],
267         [LINUX=$DEFAULT_LINUX])
268 AC_MSG_RESULT([$LINUX])
269 AC_SUBST(LINUX)
270
271 # -------- check for linux --------
272 LB_CHECK_FILE([$LINUX], [],
273         [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
274
275 # -------- linux objects (for 2.6) --
276 AC_MSG_CHECKING([for Linux objects])
277 AC_ARG_WITH([linux-obj],
278         AC_HELP_STRING([--with-linux-obj=path],
279                         [set path to Linux objects (default=/lib/modules/$(uname -r)/build,/usr/src/linux)]),
280         [LB_ARG_CANON_PATH([linux-obj], [LINUX_OBJ])],
281         [LINUX_OBJ=$DEFAULT_LINUX_OBJ])
282 AC_MSG_RESULT([$LINUX_OBJ])
283 AC_SUBST(LINUX_OBJ)
284
285 # -------- check for .config --------
286 AC_ARG_WITH([linux-config],
287         [AC_HELP_STRING([--with-linux-config=path],
288                         [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
289         [LB_ARG_CANON_PATH([linux-config], [LINUX_CONFIG])],
290         [LINUX_CONFIG=$LINUX_OBJ/.config])
291
292 # -------- check if .config exists --
293 LB_CHECK_FILE([$LINUX_CONFIG], [],
294         [AC_MSG_ERROR([
295
296 Kernel config could not be found.
297 ])
298 ])
299 AC_SUBST(LINUX_CONFIG)
300
301 LB_CHECK_FILE([/boot/kernel.h],
302         [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
303         [LB_CHECK_FILE([/var/adm/running-kernel.h],
304                 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
305
306 AC_ARG_WITH([kernel-source-header],
307         AC_HELP_STRING([--with-kernel-source-header=path],
308                         [Use a different kernel version header.]),
309         [LB_ARG_CANON_PATH([kernel-source-header], [KERNEL_SOURCE_HEADER])])
310
311 # ----------- make dep run? ------------------
312 # at 2.6.19 # $LINUX/include/linux/config.h is removed
313 # and at more old has only one line include <autoconf.h>
314 #
315 LB_CHECK_FILE([$LINUX_OBJ/include/generated/autoconf.h],
316         [AUTOCONF_HDIR=generated],
317         [LB_CHECK_FILE([$LINUX_OBJ/include/linux/autoconf.h],
318                 [AUTOCONF_HDIR=linux],
319                 [AC_MSG_ERROR([Run make config in $LINUX.])])])
320 AC_SUBST(AUTOCONF_HDIR)
321
322 LB_CHECK_FILE([$LINUX_OBJ/include/linux/version.h],
323         [VERSION_HDIR=linux],
324         [LB_CHECK_FILE([$LINUX_OBJ/include/generated/uapi/linux/version.h],
325                 [VERSION_HDIR=generated/uapi/linux],
326                 [AC_MSG_ERROR([Run make config in $LINUX.])])])
327 AC_SUBST(VERSION_HDIR)
328
329 # ----------- kconfig.h exists ---------------
330 # kernel 3.1, $LINUX/include/linux/kconfig.h is added
331 # see kernel commit 2a11c8ea20bf850b3a2c60db8c2e7497d28aba99
332 #
333 LB_CHECK_FILE([$LINUX/include/linux/kconfig.h],
334               [CONFIG_INCLUDE=$LINUX/include/linux/kconfig.h],
335               [CONFIG_INCLUDE=include/$AUTOCONF_HDIR/autoconf.h])
336 AC_SUBST(CONFIG_INCLUDE)
337
338 # ------------ rhconfig.h includes runtime-generated bits --
339 # RedHat kernel-source checks
340
341 # we know this exists after the check above.  if the user
342 # tarred up the tree and ran make dep etc. in it, then
343 # version.h gets overwritten with a standard linux one.
344
345 AS_IF([grep rhconfig $LINUX_OBJ/include/$VERSION_HDIR/version.h >/dev/null], [
346         # This is a clean kernel-source tree, we need to
347         # enable extensive workarounds to get this to build modules
348         LB_CHECK_FILE([$KERNEL_SOURCE_HEADER], [
349                 AS_IF([test $KERNEL_SOURCE_HEADER = '/boot/kernel.h'],
350                         [AC_MSG_WARN([
351
352 Using /boot/kernel.h from RUNNING kernel.
353
354 If this is not what you want, use --with-kernel-source-header.
355 Consult build/README.kernel-source for details.
356 ])
357                 ])],
358                 [AC_MSG_ERROR([
359
360 $KERNEL_SOURCE_HEADER not found.
361
362 Consult build/README.kernel-source for details.
363 ])
364                 ])
365         EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
366 ])
367
368 # this is needed before we can build modules
369 LB_LINUX_VERSION
370
371 # --- check that we can build modules at all
372 LB_CHECK_COMPILE([that modules can be built at all], build_modules,
373         [], [], [], [
374         AC_MSG_ERROR([
375
376 Kernel modules cannot be built. Consult config.log for details.
377
378 If you are trying to build with a kernel-source rpm,
379 consult build/README.kernel-source
380 ])
381 ])
382
383 LB_LINUX_RELEASE
384 ]) # end of LB_LINUX_PATH
385
386 #
387 # LC_MODULE_LOADING
388 #
389 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
390 # so we test if request_module is implemented or not
391 AC_DEFUN([LC_MODULE_LOADING], [
392 AC_CACHE_CHECK([if Linux kernel module loading is possible], lb_cv_module_loading, [
393 LB_LINUX_TRY_MAKE([
394         #include <linux/kmod.h>
395 ], [
396         int myretval=ENOSYS ;
397         return myretval;
398 ], [
399         $makerule LUSTRE_KERNEL_TEST=conftest.i
400 ], [dnl
401         grep request_module build/conftest.i |dnl
402                 grep -v `grep "int myretval=" build/conftest.i |dnl
403                         cut -d= -f2 | cut -d" "  -f1`dnl
404                 >/dev/null dnl
405 ], [lb_cv_module_loading="yes"], [lb_cv_module_loading="no"])
406 ])
407 AS_IF([test "$lb_cv_module_loading" = yes],
408         [AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
409                 [kernel module loading is possible])],
410         [AC_MSG_WARN([
411
412 Kernel module loading support is highly recommended.
413
414 ])
415         ])
416 ])
417
418 #
419 # LB_PROG_LINUX
420 #
421 # linux tests
422 #
423 AC_DEFUN([LB_PROG_LINUX], [
424 LB_LINUX_PATH
425 LB_LINUX_SYMVERFILE
426
427 LB_CHECK_CONFIG([MODULES], [], [
428         AC_MSG_ERROR([
429
430 module support is required to build Lustre kernel modules.
431 ])
432         ])
433
434 LB_CHECK_CONFIG([MODVERSIONS])
435
436 LB_CHECK_CONFIG([KALLSYMS], [], [
437         AC_MSG_ERROR([
438
439 Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.
440 ])
441         ])
442
443 # 2.6.28
444 LC_MODULE_LOADING
445 ])
446
447 #
448 # LB_USES_DPKG
449 #
450 # Determine if the target is a dpkg system or rpm
451 #
452 AC_DEFUN([LB_USES_DPKG], [
453 AC_CACHE_CHECK([if this distro uses dpkg], lb_cv_uses_dpkg, [
454 lb_cv_uses_dpkg="no"
455 AS_CASE([$(which dpkg 2>/dev/null)],[*/dpkg], [lb_cv_uses_dpkg="yes"])
456 ])
457 uses_dpkg=$lb_cv_uses_dpkg
458 ])
459
460 #
461 # LB_CHECK_EXPORT
462 #
463 # check symbol exported or not
464 # $1 - symbol
465 # $2 - file(s) for find.
466 # $3 - do 'yes'
467 # $4 - do 'no'
468 #
469 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers or check
470 #
471 AC_DEFUN([LB_CHECK_EXPORT], [
472 AS_VAR_PUSHDEF([lb_export], [lb_cv_export_$1])dnl
473 AC_CACHE_CHECK([if Linux kernel exports '$1'], lb_export, [
474 AS_VAR_SET([lb_export], [no])
475 AS_IF([grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX_OBJ/$SYMVERFILE 2>/dev/null],
476         [AS_VAR_SET([lb_export], [yes])],
477         [for file in $2; do
478                 AS_IF([grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null], [
479                         AS_VAR_SET([lb_export], [yes])
480                         break
481                 ])
482         done])
483 ])
484 AS_VAR_IF([lb_export], [yes], [$3], [$4])[]dnl
485 AS_VAR_POPDEF([lb_export])dnl
486 ]) # LB_CHECK_EXPORT
487
488 #
489 # LB_CHECK_CONFIG
490 #
491 # check if a given config option is defined
492 # $1 - CONFIG_<name>
493 # $2 - do 'yes'
494 # $3 - do 'no'
495 #
496 AC_DEFUN([LB_CHECK_CONFIG], [
497 LB_CHECK_COMPILE([if Linux kernel was built with CONFIG_$1],
498 config_$1, [
499         #include <$AUTOCONF_HDIR/autoconf.h>
500 ], [
501         #ifndef CONFIG_$1
502         #error CONFIG_$1 not #defined
503         #endif
504 ], [$2], [$3])
505 ]) # LB_CHECK_CONFIG
506
507 #
508 # LB_CHECK_CONFIG_IM
509 #
510 # check if a given config option is builtin or as module
511 # $1 - CONFIG_<name> or CONFIG_<name>_MODULE
512 # $2 - do 'yes'
513 # $3 - do 'no'
514 #
515 AC_DEFUN([LB_CHECK_CONFIG_IM], [
516 LB_CHECK_COMPILE([if Linux kernel was built with CONFIG_$1 in or as module],
517 config_im_$1, [
518         #include <$AUTOCONF_HDIR/autoconf.h>
519 ], [
520         #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
521         #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
522         #endif
523 ], [$2], [$3])
524 ]) # LB_CHECK_CONFIG_IM
525
526 #
527 # these are like AC_TRY_COMPILE, but try to build modules against the
528 # kernel, inside the build directory
529 #
530
531 #
532 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
533 # --------------------------------------
534 #
535 m4_define([LB_LANG_PROGRAM],
536 [
537 #include <linux/kernel.h>
538 #include <linux/module.h>
539 $1
540 int
541 main (void)
542 {
543 dnl Do *not* indent the following line: there may be CPP directives.
544 dnl Don't move the `;' right after for the same reason.
545 $2
546   ;
547   return 0;
548 };
549 MODULE_LICENSE("GPL");])
550
551 #
552 # LB_LINUX_COMPILE_IFELSE
553 #
554 # like AC_COMPILE_IFELSE
555 #
556 # $1 - AC_LANG_SOURCE()
557 # $2 - make target
558 # $3 - check command
559 # $4 - do 'yes'
560 # $5 - do 'no'
561 #
562 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
563 [m4_ifvaln([$1], [AC_LANG_CONFTEST([AC_LANG_SOURCE([$1])])])dnl
564 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
565 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/')
566 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} -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])],
567         [$4],
568         [_AC_MSG_LOG_CONFTEST
569 m4_ifvaln([$5],[$5])dnl])
570 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
571 ])
572
573 #
574 # LB_LINUX_TRY_COMPILE
575 #
576 # like AC_TRY_COMPILE
577 #
578 AC_DEFUN([LB_LINUX_TRY_COMPILE], [
579 LB_LINUX_COMPILE_IFELSE(
580         [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
581         [modules], [test -s build/conftest.o],
582         [$3], [$4])
583 ])
584
585 #
586 # LB_LINUX_TRY_MAKE
587 #
588 # like LB_LINUX_TRY_COMPILE, but with different arguments
589 #
590 AC_DEFUN([LB_LINUX_TRY_MAKE], [
591 LB_LINUX_COMPILE_IFELSE(
592         [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
593         [$3], [$4], [$5], [$6])
594 ])
595
596 #
597 # LB_CHECK_COMPILE
598 # $1 - checking message
599 # $2 - variable name
600 # $3 - header
601 # $4 - body
602 # $5 - do 'yes'
603 # $6 - do 'no'
604 #
605 AC_DEFUN([LB_CHECK_COMPILE], [
606 AS_VAR_PUSHDEF([lb_compile], [lb_cv_compile_$2])dnl
607 AC_CACHE_CHECK([$1], lb_compile, [
608         LB_LINUX_TRY_COMPILE([$3], [$4],
609                 [AS_VAR_SET([lb_compile], [yes])],
610                 [AS_VAR_SET([lb_compile], [no])])
611 ])
612 AS_VAR_IF([lb_compile], [yes], [$5], [$6])[]dnl
613 AS_VAR_POPDEF([lb_compile])dnl
614 ]) # LB_CHECK_COMPILE
615
616 #
617 # LB_CHECK_LINUX_HEADER
618 #
619 # Like AC_CHECK_HEADER but checks for a kernel-space header
620 #
621 m4_define([LB_CHECK_LINUX_HEADER], [
622 AS_VAR_PUSHDEF([lb_header], [lb_cv_header_$1])dnl
623 AC_CACHE_CHECK([for $1], lb_header, [
624         LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
625                 [modules], [test -s build/conftest.o],
626                 [AS_VAR_SET([lb_header], [yes])],
627                 [AS_VAR_SET([lb_header], [no])])
628 ])
629 AS_VAR_IF([lb_header], [yes], [$2], [$3])[]dnl
630 AS_VAR_POPDEF([lb_header])dnl
631 ]) # LB_CHECK_LINUX_HEADER