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