Whamcloud - gitweb
LU-16949 lnet: get monitor thread to update ping buffer
[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         rm -f build/conftest.i
15         MODULE_TARGET="M"
16         makerule="$PWD/build"
17         LB_LINUX_TRY_MAKE([], [],
18                 [$makerule LUSTRE_KERNEL_TEST=conftest.i],
19                 [test -s build/conftest.i],
20                 [lb_cv_module_target="M54"], [
21         MODULE_TARGET="M"
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"], [
27         MODULE_TARGET="M"
28         makerule=""
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         makerule=""
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])
40         ])])])])
41 ])
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])
52 ])
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"],
59         [makerule=""
60         lb_cv_module_target="M"],
61 [test "x$lb_cv_module_target" = "xM517"],
62         [makerule=""
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)
68 ])
69
70 #
71 # LB_LINUX_UTSRELEASE
72 #
73 # Determine the Linux kernel version string from the utsrelease
74 #
75 AC_DEFUN([LB_LINUX_UTSRELEASE], [
76 AC_CACHE_CHECK([for Linux kernel utsrelease], lb_cv_utsrelease, [
77 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)],
89         [AC_MSG_ERROR([
90
91 Cannot find UTS_RELEASE definition.
92
93 This is often provided by the kernel-devel package.
94 ])
95         ])
96 ])
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)
101 ])
102
103 #
104 # LB_LINUX_RELEASE
105 #
106 # get the release version of linux
107 #
108 AC_DEFUN([LB_LINUX_RELEASE], [
109         LB_LINUX_UTSRELEASE
110
111         # Define default states
112         RHEL_KERNEL="no"
113         SUSE_KERNEL="no"
114         UBUNTU_KERNEL="no"
115         DEBIAN_KERNEL="no"
116         OPENEULER_KERNEL="no"
117         # And if any of the above kernels has been detected yet
118         KERNEL_FOUND="no"
119
120         # Check for RedHat first (no need to check KERNEL_FOUND
121         AC_CACHE_CHECK([for RedHat kernel release number], lb_cv_rhel_kernel_version, [
122                 lb_cv_rhel_kernel_version=""
123                 AS_IF([fgrep -q RHEL_RELEASE $LINUX_OBJ/include/$VERSION_HDIR/version.h], [
124                         lb_cv_rhel_kernel_version=$(awk '/ RHEL_MAJOR / { print [$]3 }' \
125                                 $LINUX_OBJ/include/$VERSION_HDIR/version.h)$(awk \
126                                 '/ RHEL_MINOR / { print [$]3 }' \
127                                 $LINUX_OBJ/include/$VERSION_HDIR/version.h)
128                 ])
129         ])
130         AS_IF([test -n "$lb_cv_rhel_kernel_version"], [
131                 RHEL_KERNEL="yes"
132                 KERNEL_FOUND="yes"
133                 RHEL_RELEASE_NO=$lb_cv_rhel_kernel_version
134         ])
135
136         # Check for SuSE
137         AS_IF([test "x$KERNEL_FOUND" = "xno"], [
138                 LB_CHECK_CONFIG([SUSE_KERNEL], [
139                         SUSE_KERNEL="yes"
140                         KERNEL_FOUND="yes"
141                 ], [])
142         ])
143
144         # Check for Ubuntu
145         AS_IF([test "x$KERNEL_FOUND" = "xno"], [
146                 AC_CACHE_CHECK([for Ubuntu kernel signature], lb_cv_ubuntu_kernel_sig, [
147                         lb_cv_ubuntu_kernel_sig="no"
148                         AS_IF([fgrep -q "CONFIG_VERSION_SIGNATURE \"Ubuntu" $LINUX_OBJ/include/generated/autoconf.h], [
149                                 lb_cv_ubuntu_kernel_sig="yes"
150                         ])
151                 ])
152                 AS_IF([test "x$lb_cv_ubuntu_kernel_sig" = "xyes"], [
153                         UBUNTU_KERNEL="yes"
154                         KERNEL_FOUND="yes"
155                 ])
156         ])
157
158         AS_IF([test "x$KERNEL_FOUND" = "xno"], [
159                 AC_CACHE_CHECK([for Debian kernel signature], lb_cv_debian_kernel_sig, [
160                         lb_cv_debian_kernel_sig="no"
161                         AS_IF([grep -q "LINUX_PACKAGE_ID\s*\"\s*Debian" $LINUX_OBJ/include/generated/package.h], [
162                                 lb_cv_debian_kernel_sig="yes"
163                         ])
164                 ])
165                 AS_IF([test "x$lb_cv_debian_kernel_sig" = "xyes"], [
166                         DEBIAN_KERNEL="yes"
167                         KERNEL_FOUND="yes"
168                 ])
169         ])
170
171         # Check for a ELRepo -ml kernel on RHEL 7/8
172         AS_IF([test "x$KERNEL_FOUND" = "xno"], [
173                 AC_CACHE_CHECK([for ELRepo -ml kernel signature on CentOS],
174                                 lb_cv_mainline_kernel_sig, [
175                         lb_cv_mainline_kernel_sig="no"
176                         AS_IF([fgrep -q '.el7.' $LINUX_OBJ/include/generated/utsrelease.h], [
177                                 lb_cv_mainline_kernel_sig="yes"
178                         ])
179                         AS_IF([fgrep -q '.el8.' $LINUX_OBJ/include/generated/utsrelease.h], [
180                                 lb_cv_mainline_kernel_sig="yes"
181                         ])
182                 ])
183                 AS_IF([test "x$lb_cv_mainline_kernel_sig" = "xyes"], [
184                         RHEL_KERNEL="yes"
185                         KERNEL_FOUND="yes"
186                 ])
187         ])
188
189         # Check for openEuler
190         AS_IF([test "x$KERNEL_FOUND" = "xno"], [
191                 AC_CACHE_CHECK([for openEuler kernel version number], lb_cv_openeuler_kernel_version, [
192                         lb_cv_openeuler_kernel_version=""
193                         AS_IF([fgrep -q OPENEULER_VERSION $LINUX_OBJ/include/$VERSION_HDIR/version.h], [
194                                 lb_cv_openeuler_kernel_version=$(awk '/ OPENEULER_MAJOR / { print [$]3 }' \
195                                         $LINUX_OBJ/include/$VERSION_HDIR/version.h).$(awk \
196                                         '/ OPENEULER_MINOR / { print [$]3 }' \
197                                         $LINUX_OBJ/include/$VERSION_HDIR/version.h)
198                         ])
199                 ])
200                 AS_IF([test -n "$lb_cv_openeuler_kernel_version"], [
201                         OPENEULER_KERNEL="yes"
202                         KERNEL_FOUND="yes"
203                         OPENEULER_VERSION_NO=$lb_cv_openeuler_kernel_version
204                 ])
205         ])
206
207         # If still no kernel was found, a warning is issued
208         AS_IF([test "x$KERNEL_FOUND" = "xno"], [
209                 AC_MSG_WARN([Kernel Distro seems to be neither RedHat, SuSE, openEuler, Ubuntu nor Debian])
210         ])
211
212         AC_MSG_CHECKING([for Linux kernel module package directory])
213         AC_ARG_WITH([kmp-moddir],
214                 AS_HELP_STRING([--with-kmp-moddir=string],
215                         [set the kmod updates or extra directory]),
216                 [KMP_MODDIR=$withval
217                  IN_KERNEL=''],[
218                 AS_IF([test x$RHEL_KERNEL = xyes], [KMP_MODDIR="extra/kernel"],
219                       [test x$OPENEULER_KERNEL = xyes], [KMP_MODDIR="extra/kernel"],
220                       [test x$SUSE_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
221                       [test x$UBUNTU_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
222                       [test x$DEBIAN_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
223                       [AC_MSG_WARN([Kernel Distro seems to be neither RedHat, SuSE, openEuler, Ubuntu nor Debian])]
224                 )
225                 IN_KERNEL="${PACKAGE}"])
226         AC_MSG_RESULT($KMP_MODDIR)
227
228         moduledir="/lib/modules/${LINUXRELEASE}/${KMP_MODDIR}"
229
230         modulefsdir="${moduledir}/fs/${IN_KERNEL}"
231         AC_SUBST(modulefsdir)
232
233         modulenetdir="${moduledir}/net/${IN_KERNEL}"
234         AC_SUBST(modulenetdir)
235
236         AC_SUBST(KMP_MODDIR)
237 ])
238
239 #
240 # LB_LINUX_SYMVERFILE
241 #
242 # SLES 9 uses a different name for this file - unsure about vanilla kernels
243 # around this version, but it matters for servers only.
244 AC_DEFUN([LB_LINUX_SYMVERFILE], [
245 AC_CACHE_CHECK([for the name of module symbol version file], lb_cv_module_symvers, [
246 AS_IF([grep -q Modules.symvers $LINUX/scripts/Makefile.modpost],
247         [lb_cv_module_symvers=Modules.symvers],
248         [lb_cv_module_symvers=Module.symvers])
249 ])
250 SYMVERFILE=$lb_cv_module_symvers
251 AC_SUBST(SYMVERFILE)
252 ])
253
254 #
255 # LB_ARG_REPLACE_PATH(PACKAGE, PATH)
256 #
257 AC_DEFUN([LB_ARG_REPLACE_PATH], [
258 new_configure_args=
259 eval set -- $ac_configure_args
260 for arg; do
261         case $arg in
262                 --with-[$1]=*)
263                         arg=--with-[$1]=[$2] ;;
264                 *\'*)
265                         arg=$(printf %s\n ["$arg"] | sed "s/'/'\\\\\\\\''/g") ;;
266         esac
267         dnl AS_VAR_APPEND([new_configure_args], [" '$arg'"])
268         new_configure_args="$new_configure_args '$arg'"
269 done
270 ac_configure_args=$new_configure_args
271 ])
272
273 #
274 # __LB_ARG_CANON_PATH
275 #
276 # this is the work-horse of the next function
277 #
278 AC_DEFUN([__LB_ARG_CANON_PATH], [
279         [$3]=$(readlink -f $with_$2)
280         LB_ARG_REPLACE_PATH([$1], $[$3])
281 ])
282
283 #
284 # LB_ARG_CANON_PATH
285 #
286 # a front-end for the above function that transforms - and . in the
287 # PACKAGE portion of --with-PACKAGE into _ suitable for variable names
288 #
289 AC_DEFUN([LB_ARG_CANON_PATH], [
290         __LB_ARG_CANON_PATH([$1], m4_translit([$1], [-.], [__]), [$2])
291 ])
292
293 #
294 # LB_LINUX_PATH
295 #
296 # Find paths for linux, handling kernel-source rpms
297 #
298 AC_DEFUN([LB_LINUX_PATH], [
299 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
300         AS_IF([readlink -q -e $DEFAULT_LINUX >/dev/null], [break])
301 done
302 if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then
303         PATHS="/lib/modules/$(uname -r)/build"
304 else
305         PATHS="/usr/src/linux-headers-$(uname -r)"
306 fi
307 PATHS+=" $DEFAULT_LINUX"
308 for DEFAULT_LINUX_OBJ in $PATHS; do
309         AS_IF([readlink -q -e $DEFAULT_LINUX_OBJ >/dev/null], [break])
310 done
311
312 AC_MSG_CHECKING([for Linux sources])
313 AC_ARG_WITH([linux],
314         AS_HELP_STRING([--with-linux=path],
315                        [set path to Linux source (default=/lib/modules/$(uname -r)/{source,build},/usr/src/linux)]),
316         [LB_ARG_CANON_PATH([linux], [LINUX])
317         DEFAULT_LINUX_OBJ=$LINUX],
318         [LINUX=$DEFAULT_LINUX])
319 AC_MSG_RESULT([$LINUX])
320
321 # -------- check for linux --------
322 LB_CHECK_FILE([$LINUX], [],
323         [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
324
325 # -------- linux objects (for 2.6) --
326 AC_MSG_CHECKING([for Linux objects])
327 AC_ARG_WITH([linux-obj],
328         AS_HELP_STRING([--with-linux-obj=path],
329                         [set path to Linux objects (default=/lib/modules/$(uname -r)/build,/usr/src/linux)]),
330         [LB_ARG_CANON_PATH([linux-obj], [LINUX_OBJ])],
331         [LINUX_OBJ=$DEFAULT_LINUX_OBJ])
332 AC_MSG_RESULT([$LINUX_OBJ])
333
334 ## -------- with linux should point to <kernel>-common on Debian
335 AS_IF([test ${LINUX} == ${LINUX_OBJ} -a ${LINUX} == $(realpath ${LINUX})],[
336         this_arch=$(realpath ${LINUX} | sed 's/-/\n/g' | tail -1)
337         linux_headers_common=$(realpath ${LINUX}|sed "s/-${this_arch}\$/-common/g")
338         AS_IF([test "${this_arch}" != common],[
339                 _cah="${linux_headers_common}/include/linux/compiler_attributes.h"
340                 _cgh="${linux_headers_common}/include/linux/compiler-gcc.h"
341                 AS_IF([test -f "${_cah}" -o -f "${_cgh}"],[
342                         AC_MSG_WARN([Setting LINUX to ${linux_headers_common} was ${LINUX}])
343                         LINUX=${linux_headers_common}])
344                 ])
345         ])
346 AC_SUBST(LINUX)
347 AC_SUBST(LINUX_OBJ)
348 # -------- check for .config --------
349 AC_ARG_WITH([linux-config],
350         [AS_HELP_STRING([--with-linux-config=path],
351                         [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
352         [LB_ARG_CANON_PATH([linux-config], [LINUX_CONFIG])],
353         [LINUX_CONFIG=$LINUX_OBJ/.config])
354
355 # -------- check if .config exists --
356 LB_CHECK_FILE([$LINUX_CONFIG], [],
357         [AC_MSG_ERROR([
358
359 Kernel config could not be found.
360 ])
361 ])
362 AC_SUBST(LINUX_CONFIG)
363
364 LB_CHECK_FILE([/boot/kernel.h],
365         [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
366         [LB_CHECK_FILE([/var/adm/running-kernel.h],
367                 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
368
369 AC_ARG_WITH([kernel-source-header],
370         AS_HELP_STRING([--with-kernel-source-header=path],
371                         [Use a different kernel version header.]),
372         [LB_ARG_CANON_PATH([kernel-source-header], [KERNEL_SOURCE_HEADER])])
373
374 # ----------- make dep run? ------------------
375 # at 2.6.19 # $LINUX/include/linux/config.h is removed
376 # and at more old has only one line include <autoconf.h>
377 #
378 LB_CHECK_FILE([$LINUX_OBJ/include/generated/autoconf.h],
379         [AUTOCONF_HDIR=generated],
380         [LB_CHECK_FILE([$LINUX_OBJ/include/linux/autoconf.h],
381                 [AUTOCONF_HDIR=linux],
382                 [AC_MSG_ERROR([Run make config in $LINUX.])])])
383 AC_SUBST(AUTOCONF_HDIR)
384
385 LB_CHECK_FILE([$LINUX_OBJ/include/linux/version.h],
386         [VERSION_HDIR=linux],
387         [LB_CHECK_FILE([$LINUX_OBJ/include/generated/uapi/linux/version.h],
388                 [VERSION_HDIR=generated/uapi/linux],
389                 [AC_MSG_ERROR([Run make config in $LINUX.])])])
390 AC_SUBST(VERSION_HDIR)
391
392 # ----------- kconfig.h exists ---------------
393 # kernel 3.1, $LINUX/include/linux/kconfig.h is added
394 # see kernel commit 2a11c8ea20bf850b3a2c60db8c2e7497d28aba99
395 #
396 LB_CHECK_FILE([$LINUX/include/linux/kconfig.h],
397               [CONFIG_INCLUDE=$LINUX/include/linux/kconfig.h],
398               [CONFIG_INCLUDE=include/$AUTOCONF_HDIR/autoconf.h])
399 AC_SUBST(CONFIG_INCLUDE)
400
401 # ------------ rhconfig.h includes runtime-generated bits --
402 # RedHat kernel-source checks
403
404 # we know this exists after the check above.  if the user
405 # tarred up the tree and ran make dep etc. in it, then
406 # version.h gets overwritten with a standard linux one.
407
408 AS_IF([grep rhconfig $LINUX_OBJ/include/$VERSION_HDIR/version.h >/dev/null], [
409         # This is a clean kernel-source tree, we need to
410         # enable extensive workarounds to get this to build modules
411         LB_CHECK_FILE([$KERNEL_SOURCE_HEADER], [
412                 AS_IF([test $KERNEL_SOURCE_HEADER = '/boot/kernel.h'],
413                         [AC_MSG_WARN([
414
415 Using /boot/kernel.h from RUNNING kernel.
416
417 If this is not what you want, use --with-kernel-source-header.
418 Consult build/README.kernel-source for details.
419 ])
420                 ])],
421                 [AC_MSG_ERROR([
422
423 $KERNEL_SOURCE_HEADER not found.
424
425 Consult build/README.kernel-source for details.
426 ])
427                 ])
428         EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
429 ])
430
431 AS_IF([test -n SUBARCH],
432 [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/')
433 ])
434
435 # this is needed before we can build modules
436 LB_LINUX_VERSION
437
438 # --- Parallel config for kernel v5.17+
439 AS_IF([test "x$lb_cv_dequote_CC_VERSION_TEXT" = "xyes"], [
440         CC_VERSION_TEXT=$($CC --version | head -n1 | tr ' ()' '.')
441         MAKE_KMOD_ENV="CONFIG_CC_VERSION_TEXT='$CC_VERSION_TEXT'"])
442
443 # --- check that we can build modules at all
444 LB_CHECK_COMPILE([that modules can be built at all], build_modules,
445         [], [], [], [
446         AC_MSG_ERROR([
447
448 Kernel modules cannot be built. Consult config.log for details.
449
450 If you are trying to build with a kernel-source rpm,
451 consult build/README.kernel-source
452 ])
453 ])
454
455 LB_LINUX_RELEASE
456 ]) # end of LB_LINUX_PATH
457
458 #
459 # LC_MODULE_LOADING
460 #
461 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
462 # so we test if request_module is implemented or not
463 AC_DEFUN([LC_MODULE_LOADING], [
464 AC_CACHE_CHECK([if Linux kernel module loading is possible], lb_cv_module_loading, [
465 LB_LINUX_TRY_MAKE([
466         #include <linux/kmod.h>
467 ], [
468         int myretval=ENOSYS ;
469         return myretval;
470 ], [
471         $makerule LUSTRE_KERNEL_TEST=conftest.i
472 ], [dnl
473         grep request_module build/conftest.i |dnl
474                 grep -v `grep "int myretval=" build/conftest.i |dnl
475                         cut -d= -f2 | cut -d" "  -f1`dnl
476                 >/dev/null dnl
477 ], [lb_cv_module_loading="yes"], [lb_cv_module_loading="no"])
478 ])
479 AS_IF([test "$lb_cv_module_loading" = yes],
480         [AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
481                 [kernel module loading is possible])],
482         [AC_MSG_WARN([
483
484 Kernel module loading support is highly recommended.
485
486 ])
487         ])
488 ])
489
490 AC_DEFUN([LB_PROG_LINUX_SRC], [
491         LB2_SRC_CHECK_CONFIG([MODULES])
492         LB2_SRC_CHECK_CONFIG([MODVERSIONS])
493 ])
494
495 AC_DEFUN([LB_PROG_LINUX_RESULTS], [
496         LB2_TEST_CHECK_CONFIG([MODULES], [], [AC_MSG_ERROR(
497                 [module support is required to build Lustre kernel modules.])
498         ])
499         LB2_TEST_CHECK_CONFIG([MODVERSIONS],[],[])
500 ])
501
502 #
503 # LB_PROG_LINUX
504 #
505 # linux tests
506 #
507 AC_DEFUN([LB_PROG_LINUX], [
508 LB_LINUX_PATH
509 LB_LINUX_SYMVERFILE
510 # 2.6.28
511 LC_MODULE_LOADING
512 ])
513
514 #
515 # LB_USES_DPKG
516 #
517 # Determine if the target is a dpkg system or rpm
518 #
519 AC_DEFUN([LB_USES_DPKG], [
520 AC_CACHE_CHECK([if this distro uses dpkg], lb_cv_uses_dpkg, [
521 lb_cv_uses_dpkg="no"
522 AS_CASE([$(which dpkg 2>/dev/null)],[*/dpkg], [lb_cv_uses_dpkg="yes"])
523 ])
524 uses_dpkg=$lb_cv_uses_dpkg
525 ])
526
527 #
528 # LB_CHECK_EXPORT
529 #
530 # check symbol exported or not
531 # $1 - symbol
532 # $2 - file(s) for find.
533 # $3 - do 'yes'
534 # $4 - do 'no'
535 #
536 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers or check
537 #
538 AC_DEFUN([LB_CHECK_EXPORT], [
539 AS_VAR_PUSHDEF([lb_export], [lb_cv_export_$1])dnl
540 AC_CACHE_CHECK([if Linux kernel exports '$1'], lb_export, [
541 AS_VAR_SET([lb_export], [no])
542 AS_IF([grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX_OBJ/$SYMVERFILE 2>/dev/null],
543         [AS_VAR_SET([lb_export], [yes])],
544         [for file in $2; do
545                 AS_IF([grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null], [
546                         AS_VAR_SET([lb_export], [yes])
547                         break
548                 ])
549         done])
550 ])
551 AS_VAR_IF([lb_export], [yes], [$3], [$4])[]dnl
552 AS_VAR_POPDEF([lb_export])dnl
553 ]) # LB_CHECK_EXPORT
554
555 #
556 # LB_CHECK_CONFIG
557 #
558 # check if a given config option is defined
559 # $1 - CONFIG_<name>
560 # $2 - do 'yes'
561 # $3 - do 'no'
562 #
563 AC_DEFUN([LB_CHECK_CONFIG], [
564 LB_CHECK_COMPILE([if Linux kernel was built with CONFIG_$1],
565 config_$1, [
566         #include <$AUTOCONF_HDIR/autoconf.h>
567 ], [
568         #ifndef CONFIG_$1
569         #error CONFIG_$1 not #defined
570         #endif
571 ], [$2], [$3])
572 ]) # LB_CHECK_CONFIG
573
574 #
575 # LB_CHECK_CONFIG_IM
576 #
577 # check if a given config option is builtin or as module
578 # $1 - CONFIG_<name> or CONFIG_<name>_MODULE
579 # $2 - do 'yes'
580 # $3 - do 'no'
581 #
582 AC_DEFUN([LB_CHECK_CONFIG_IM], [
583 LB_CHECK_COMPILE([if Linux kernel was built with CONFIG_$1 in or as module],
584 config_im_$1, [
585         #include <$AUTOCONF_HDIR/autoconf.h>
586 ], [
587         #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
588         #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
589         #endif
590 ], [$2], [$3])
591 ]) # LB_CHECK_CONFIG_IM
592
593 #
594 # these are like AC_TRY_COMPILE, but try to build modules against the
595 # kernel, inside the build directory
596 #
597
598 #
599 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
600 # --------------------------------------
601 #
602 m4_define([LB_LANG_PROGRAM],
603 [
604 #include <linux/kernel.h>
605 #include <linux/module.h>
606
607 #if defined(NEED_LOCKDEP_IS_HELD_DISCARD_CONST) \
608  && defined(CONFIG_LOCKDEP) \
609  && defined(lockdep_is_held)
610 #undef lockdep_is_held
611         #define lockdep_is_held(lock) \
612                 lock_is_held((struct lockdep_map *)&(lock)->dep_map)
613 #endif
614
615 $1
616 int
617 main (void)
618 {
619 dnl Do *not* indent the following line: there may be CPP directives.
620 dnl Don't move the `;' right after for the same reason.
621 $2
622   ;
623   return 0;
624 };
625 MODULE_LICENSE("GPL");])
626
627 #
628 # LB_LINUX_COMPILE_IFELSE
629 #
630 # like AC_COMPILE_IFELSE
631 #
632 # $1 - AC_LANG_SOURCE()
633 # $2 - make target
634 # $3 - check command
635 # $4 - do 'yes'
636 # $5 - do 'no'
637 #
638 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
639 [m4_ifvaln([$1], [AC_LANG_CONFTEST([AC_LANG_SOURCE([$1])])])dnl
640 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
641 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])],
642         [$4],
643         [_AC_MSG_LOG_CONFTEST
644 m4_ifvaln([$5],[$5])dnl])
645 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
646 ])
647
648 #
649 # LB_LINUX_TRY_COMPILE
650 #
651 # like AC_TRY_COMPILE
652 #
653 AC_DEFUN([LB_LINUX_TRY_COMPILE], [
654 LB_LINUX_COMPILE_IFELSE(
655         [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
656         [modules], [test -s build/conftest.o],
657         [$3], [$4])
658 ])
659
660 #
661 # LB_LINUX_TRY_MAKE
662 #
663 # like LB_LINUX_TRY_COMPILE, but with different arguments
664 #
665 AC_DEFUN([LB_LINUX_TRY_MAKE], [
666 LB_LINUX_COMPILE_IFELSE(
667         [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
668         [$3], [$4], [$5], [$6])
669 ])
670
671 #
672 # LB_CHECK_COMPILE
673 # $1 - checking message
674 # $2 - variable name
675 # $3 - header
676 # $4 - body
677 # $5 - do 'yes'
678 # $6 - do 'no'
679 #
680 AC_DEFUN([LB_CHECK_COMPILE], [
681 AS_VAR_PUSHDEF([lb_compile], [lb_cv_compile_$2])dnl
682 AC_CACHE_CHECK([$1], lb_compile, [
683         LB_LINUX_TRY_COMPILE([$3], [$4],
684                 [AS_VAR_SET([lb_compile], [yes])],
685                 [AS_VAR_SET([lb_compile], [no])])
686 ])
687 AS_VAR_IF([lb_compile], [yes], [$5], [$6])[]dnl
688 AS_VAR_POPDEF([lb_compile])dnl
689 ]) # LB_CHECK_COMPILE
690
691 #
692 # LB_CHECK_LINUX_HEADER
693 #
694 # Like AC_CHECK_HEADER but checks for a kernel-space header
695 #
696 AC_DEFUN([LB_CHECK_LINUX_HEADER], [
697         AS_VAR_PUSHDEF([lb_header], [lb_cv_header_$1])
698         AC_CACHE_CHECK([for $1], lb_header, [
699                 LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
700                         [modules], [test -s build/conftest.o],
701                         [AS_VAR_SET([lb_header], [yes])],
702                         [AS_VAR_SET([lb_header], [no])])
703         ])
704         AS_VAR_IF([lb_header], [yes], [$2], [$3])
705         AS_VAR_POPDEF([lb_header])
706 ]) # LB_CHECK_LINUX_HEADER
707
708 # ------------------------------------------------------------------------------
709 # Support 2 stage: parallel compile then checked test results
710 # Heavily inspired by OpenZFS
711
712 # When converting tests from an LB_CHECK_COMPILE to use an
713 # LB2_LINUX_TEST_SRC and LB2_LINUX_TEST_RESULT pairing the primary
714 # consideration if dependencies on the results of LB2_LINUX_TEST_RESULT
715 # or LB2_TEST_CHECK_CONFIG[_IM] are used by annother compile test.
716 # Such dependencies should be avoided without a clear understanding
717 # of when the test result is actually available.
718 # The serial LB_CHECK_* test produces immediate results
719 # where as the LB2_ variant is not available until an intermediate
720 # LB2_LINUX_TEST_COMPILE_ALL has been executed.
721 #
722 # Currently all of the non-conditional LB_CHECK_COMPILE and
723 # LB_CHECK_CONFIG[_IM] cases are executed before any of the
724 # LB2_LINUX_TEST_SRC, or LB2_SRC_CHECK_CONFIG[_IM] code snippets
725 # are written. [Reference LB_CONFIG_MODULES for more details]
726 #
727 # This allows such LB2_*_SRC_* test cases to rely on
728 # prior LB_CHECK_* results, provided such results are preserved
729 # in the global configure name space. Likewise an LB2_LINUX_TEST_RESULT
730 # or LB2_TEST_CHECK_CONFIG[_IM] may conditionally execute a further
731 # LB_CHECK_* if required. Although it would be typcially be faster
732 # to run a few compile tests and conditionally ignore the results
733 # the reduced configure time may not always out weight the added
734 # complexity.
735 #
736 # It is worth noting that the LB_CHECK_COMPILE macros second argument
737 # is used as the configure test cache name. While is has been important
738 # that this name be globally unique it is even more important in the
739 # parallel case. The is somewhat alleviated by the sanity check in the
740 # LB2_LINUX_TEST_RESULT macro as it will abort with an error if
741 # the cache name does not exist. However care should be taken
742 # that the cache name is a globally unique identifier.
743 #
744 # Non-unique cases that are otherwise correct can be identified in the
745 # configure output when a results include ".. (cached)". This indicates
746 # either a duplicate LB_CHECK_* execution which is not critical or a
747 # duplicate identifier which needs to be corrected.
748 #
749 # At this point the number of LB_ and LB2_ examples should be
750 # sufficient for the casual developer to perform cut-paste-modify
751 # without serious confusion or complication.
752 # ------------------------------------------------------------------------------
753
754 AC_DEFUN([LB2_LINUX_CONFTEST_C], [
755 TEST_DIR=${TEST_DIR:-${ac_pwd}/_lpb}
756 test -d ${TEST_DIR}/$2 || mkdir -p ${TEST_DIR}/$2
757 cat confdefs.h - <<_EOF >${TEST_DIR}/$2/$2.c
758 $1
759 _EOF
760 ])
761
762 #
763 # LB2_LINUX_CONFTEST_MAKEFILE
764 #
765 # $1 - *unique* test case name
766 # $2 - additional build flags (ccflags)
767 # $3 - external kernel includes for lnet o2ib|gni
768 # $4 - extra symbol in Psuedo.symvers (optional)
769 #
770 AC_DEFUN([LB2_LINUX_CONFTEST_MAKEFILE], [
771         TEST_DIR=${TEST_DIR:-${ac_pwd}/_lpb}
772         test -d ${TEST_DIR} || mkdir -p ${TEST_DIR}
773         test -d ${TEST_DIR}/$1 || mkdir -p ${TEST_DIR}/$1
774
775         file=${TEST_DIR}/$1/Makefile
776         EXT_INCLUDE="$3"
777         EXT_SYMBOL="$4"
778         PSYM_FILE=""
779         if test "${EXT_SYMBOL}x" != "x" ; then
780                 PSYM_FILE=${TEST_DIR}/$1/Psuedo.symvers
781                 echo -e "0x12345678\t${EXT_SYMBOL}\tvmlinux\tEXPORT_SYMBOL\t" > ${PSYM_FILE}
782         fi
783         XTRA_SYM=
784         if test "x$O2IBPATH" != "x"; then
785                 if test "x$O2IBPATH" != "x$LINUX_OBJ"; then
786                         XTRA_SYM="$O2IBPATH/Module.symvers"
787                 fi
788         fi
789
790         cat - <<_EOF >$file
791 # Example command line to manually build source
792 # make modules -C $LINUX_OBJ $ARCH_UM M=${TEST_DIR}/$1 $MAKE_KMOD_ENV
793
794 ${LD:+LD="$LD"}
795 CC=$CC
796 ZINC=${ZFS}
797 SINC=${SPL}
798 ZOBJ=${ZFS_OBJ}
799 SOBJ=${SPL_OBJ}
800 PSYM=${PSYM_FILE}
801
802 LINUXINCLUDE  = $EXT_INCLUDE
803 LINUXINCLUDE += -I$LINUX/arch/$SUBARCH/include
804 LINUXINCLUDE += -Iinclude -Iarch/$SUBARCH/include/generated
805 LINUXINCLUDE += -I$LINUX/include
806 LINUXINCLUDE += -Iinclude2
807 LINUXINCLUDE += -I$LINUX/include/uapi
808 LINUXINCLUDE += -Iinclude/generated
809 LINUXINCLUDE += -I$LINUX/arch/$SUBARCH/include/uapi
810 LINUXINCLUDE += -Iarch/$SUBARCH/include/generated/uapi
811 LINUXINCLUDE += -I$LINUX/include/uapi -Iinclude/generated/uapi
812 ifneq (\$(SOBJ),)
813 LINUXINCLUDE += -include \$(SOBJ)/spl_config.h
814 endif
815 ifneq (\$(ZOBJ),)
816 LINUXINCLUDE += -include \$(ZOBJ)/zfs_config.h
817 endif
818 ifneq (\$(SINC),)
819 LINUXINCLUDE += -I\$(SINC)/include
820 endif
821 ifneq (\$(ZINC),)
822 LINUXINCLUDE += -I\$(ZINC) -I\$(ZINC)/include
823 ifneq (\$(SINC),)
824 LINUXINCLUDE += -I\$(SINC)
825 else
826 LINUXINCLUDE += -I\$(ZINC)/include/spl
827 endif
828 endif
829 LINUXINCLUDE += -include $CONFIG_INCLUDE
830 KBUILD_EXTRA_SYMBOLS += ${ZFS_OBJ:+$ZFS_OBJ/Module.symvers}
831 KBUILD_EXTRA_SYMBOLS += ${XTRA_SYM}
832 ifneq (\$(PSYM),)
833 KBUILD_EXTRA_SYMBOLS += \$(PSYM)
834 endif
835
836 ccflags-y := -Werror-implicit-function-declaration
837 _EOF
838
839         # Additional custom CFLAGS as requested.
840         m4_ifval($2, [echo "ccflags-y += $2" >>$file], [])
841
842         # Test case source
843         echo "obj-m := $1.o" >>$file
844         echo "obj-m += $1/" >>${TEST_DIR}/Makefile
845 ])
846
847 #
848 # LB2_LINUX_TEST_COMPILE
849 #
850 # Perform a full compile excluding the final modpost phase.
851 # $1 - flavor
852 # $2 - dirname
853 #
854 AC_DEFUN([LB2_LINUX_TEST_COMPILE], [
855         D="$(realpath [$2])"
856         L="$D/build.log.$1"
857         J=${TEST_JOBS:-$(nproc)}
858
859         AC_MSG_NOTICE([Making $1 in $D])
860         AC_MSG_NOTICE([KBUILD_MODPOST_NOFINAL="yes" make modules CC="$CC" -k -j${J} -C $LINUX_OBJ $ARCH_UM M=${D} $MAKE_KMOD_ENV])
861
862         AC_TRY_COMMAND([KBUILD_MODPOST_NOFINAL="yes"
863                 make modules CC="$CC" -k -j${J} -C $LINUX_OBJ $ARCH_UM M=${D} $MAKE_KMOD_ENV >${L} 2>&1])
864         AS_IF([test -f ${L}],
865               [AS_IF([test -f $2/Makefile],
866                      [mv $2/Makefile $2/Makefile.compile.$1])],
867               [AC_MSG_ERROR([*** Unable to compile test source ... $3])
868         ])
869 ])
870
871 #
872 # Perform the compilation of the test cases in two phases.
873 #
874 # Phase 1) attempt to build the object files for all of the tests
875 #          defined by the LB2_LINUX_TEST_SRC macro.
876 #
877 # Phase 2) disable all tests which failed the initial compilation.
878 #
879 # This allows us efficiently build the test cases in parallel while
880 # remaining resilient to build failures which are expected when
881 # detecting the available kernel interfaces.
882 #
883 # The maximum allowed parallelism can be controlled by setting the
884 # TEST_JOBS environment variable which defaults to $(nproc).
885 #
886 AC_DEFUN([LB2_LINUX_TEST_COMPILE_ALL], [
887         TEST_DIR=${TEST_DIR:-${ac_pwd}/_lpb}
888         # Phase 1 - Compilation only, final linking is skipped.
889         LB2_LINUX_TEST_COMPILE([$1], [${TEST_DIR}], [$2])
890         for dir in $(awk '/^obj-m/ { print [$]3 }' \
891             ${TEST_DIR}/Makefile.compile.$1); do
892                 name=${dir%/}
893                 touch ${TEST_DIR}/$name/$name.tested
894         done
895 ])
896
897 #
898 # LB2_LINUX_TEST_SRC
899 #
900 # $1 - *unique* name
901 # $2 - global
902 # $3 - source
903 # $4 - extra cflags
904 # $5 - external include paths
905 # $6 - fake symvers entry
906 #
907 # NOTICE as all of the test cases are compiled in parallel tests may not
908 # depend on the results other tests.
909 # Each test needs resolve any external dependencies at the time the program
910 # source is generated.
911 #
912 AC_DEFUN([LB2_LINUX_TEST_SRC], [
913         TEST_DIR=${TEST_DIR:-${ac_pwd}/_lpb}
914         AS_VAR_PUSHDEF([lb_test], [lb_cv_test_$1])
915         # Skip test write and build steps if the result is already known.
916         LB2_LINUX_CONFTEST_C([LB_LANG_PROGRAM([[$2]], [[$3]])], [$1_pc])
917         LB2_LINUX_CONFTEST_MAKEFILE([$1_pc], [$4], [$5], [$6])
918         AS_VAR_POPDEF([lb_test])
919 ])
920
921 #
922 # LB2_LINUX_TEST_RESULT
923 #
924 # $1 - *unique* name matching the LB2_LINUX_TEST_SRC macro
925 # $2 - run on success (valid .ko generated)
926 # $3 - run on failure (unable to compile)
927 # $4 - compile only
928 #
929 AC_DEFUN([LB2_LINUX_TEST_RESULT],[
930         TEST_DIR=${TEST_DIR:-${ac_pwd}/_lpb}
931         AS_VAR_PUSHDEF([lb_test], [lb_cv_test_$1])
932         D="$(realpath ${TEST_DIR})"
933         T=${D}/$1_pc
934         O=${T}/$1_pc
935         AS_IF([test -d ${T}], [
936                 # test source exists, was the compile test run?
937                 AS_IF([test -f ${O}.tested],[
938                         # compile test was run.
939                 ],[
940                         # compile test was NOT run. Re-compile everything.
941                         AC_MSG_NOTICE([** Rebuilding all tests **])
942
943                         J=${TEST_JOBS:-$(nproc)}
944                         for mf in $(ls -1 ${TEST_DIR}/Makefile.compile.*); do
945                                 ln -sf $mf ${D}/Makefile
946                                 KBUILD_MODPOST_NOFINAL="yes"
947                                 make modules CC="$CC" -k -j${J} -C $LINUX_OBJ $ARCH_UM M=${D} >> rebuild.log 2>&1
948
949                                 for dir in $(awk '/^obj-m/ { print [$]3 }' ${D}/$mf); do
950                                         name=${dir%/}
951                                         AC_MSG_NOTICE([touch ${D}/$name/$name.tested])
952                                         touch ${D}/$name/$name.tested
953                                 done
954                                 rm ${D}/Makefile
955                         done
956                         # compile test was NOT run. Re-compile everything.
957                 ])
958         ],[
959                 # test source does not exist:
960                 AC_MSG_ERROR([
961 *** No matching source for the "$1" test, check that
962 *** both the test source and result macros refer to the same name.
963                 ])
964         ])
965         # Abort if key does not exist
966         AS_IF([test -f ${O}.tested], [],
967                 [AC_MSG_ERROR([*** Compile test for $1 was not run.])])
968         # Default is to expect only the <module>.o be generated.
969         NEED_KO=0
970         # Require the <module>.ko file when "module" is passed
971         AS_IF([test "X'$4'" == "X'module'"], [NEED_KO=1])
972         # If test was compiled and if we got an object ...
973         AS_IF([test ${NEED_KO} -eq 0], [AS_IF([test ! -f ${O}.ko], [AS_IF(
974                 [test -f ${O}.o], [touch ${O}.ko])])])
975         # key is valid. Cache should be valid, set the variable
976         AC_CACHE_CHECK([for $1], lb_test,
977                 AS_IF([test -f ${O}.ko],
978                         AS_VAR_SET([lb_test], [yes]),
979                         AS_VAR_SET([lb_test], [no])))
980         # Read the variable and run the caller's actions for yes (arg2) or no (arg3)
981         AS_VAR_IF([lb_test], [yes], $2, $3)
982         AS_VAR_POPDEF([lb_test])
983 ]) # LB2_LINUX_TEST_RESULT
984
985 #
986 # LB2_SRC_CHECK_CONFIG
987 #
988 # generate source to check if a given config option is defined
989 #
990 #   $1 - CONFIG_<name>
991 #
992 AC_DEFUN([LB2_SRC_CHECK_CONFIG], [
993         LB2_LINUX_TEST_SRC([config_$1], [
994                 #include <$AUTOCONF_HDIR/autoconf.h>
995         ], [
996                 #ifndef CONFIG_$1
997                 #error CONFIG_$1 not #defined
998                 #endif
999         ])
1000 ]) # LB2_SRC_CHECK_CONFIG
1001
1002 #
1003 # LB2_TEST_CHECK_CONFIG
1004 #
1005 # test result compile test from LB2_SRC_CHECK_CONFIG
1006 #
1007 #   $1 - CONFIG_<name>
1008 #   $2 - do 'yes'
1009 #   $3 - do 'no'
1010 #
1011 AC_DEFUN([LB2_TEST_CHECK_CONFIG], [
1012         AC_MSG_CHECKING([if Linux kernel was built with CONFIG_$1])
1013         LB2_LINUX_TEST_RESULT([config_$1], [
1014                 $2
1015         ],[
1016                 $3
1017         ])
1018 ]) # LB2_TEST_CHECK_CONFIG
1019
1020 #
1021 # LB2_SRC_CHECK_CONFIG_IM
1022 #
1023 # generate source to check if a given config option is defined as built-in
1024 # or as a module.
1025 #
1026 #    $1 - CONFIG_<name> or CONFIG_<name>_MODULE
1027 #
1028 AC_DEFUN([LB2_SRC_CHECK_CONFIG_IM], [
1029         LB2_LINUX_TEST_SRC([config_im_$1], [
1030                 #include <$AUTOCONF_HDIR/autoconf.h>
1031         ], [
1032                 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
1033                 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
1034                 #endif
1035         ])
1036 ]) # LB2_SRC_CHECK_CONFIG_IM
1037
1038
1039 #
1040 # LB2_TEST_CHECK_CONFIG_IM
1041 #
1042 # test result compile test from LB2_SRC_CHECK_CONFIG_IM
1043 #
1044 #   $1 - CONFIG_<name>
1045 #   $2 - do 'yes'
1046 #   $3 - do 'no'
1047 #
1048 AC_DEFUN([LB2_TEST_CHECK_CONFIG_IM], [
1049         AC_MSG_CHECKING([if Linux kernel enabled CONFIG_$1 as built-in or module])
1050         LB2_LINUX_TEST_RESULT([config_im_$1], [
1051                 $2
1052         ],[
1053                 $3
1054         ])
1055 ]) # LB2_TEST_CHECK_CONFIG_IM