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