Whamcloud - gitweb
LU-3514 tests: combine dependent sanity tests
[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
9 MODULE_TARGET="SUBDIRS"
10 makerule="$PWD/build"
11 AC_MSG_CHECKING([for external module build support])
12 rm -f build/conftest.i
13 LB_LINUX_TRY_MAKE([],[],
14         [$makerule LUSTRE_KERNEL_TEST=conftest.i],
15         [test -s build/conftest.i],
16         [
17                 AC_MSG_RESULT([no])
18         ],[
19                 makerule="_module_$makerule"
20                 MODULE_TARGET="M"
21                 LB_LINUX_TRY_MAKE([],[],
22                         [$makerule LUSTRE_KERNEL_TEST=conftest.i],
23                         [test -s build/conftest.i],
24                         [
25                                 AC_MSG_RESULT([yes])
26                         ],[
27                                 AC_MSG_ERROR([unknown; check config.log for details])
28                         ])
29         ])
30
31 AC_SUBST(MODULE_TARGET)
32 AC_SUBST(KMODEXT)
33 ])
34
35 #
36 # LB_LINUX_RELEASE
37 #
38 # get the release version of linux
39 #
40 AC_DEFUN([LB_LINUX_RELEASE],
41 [LINUXRELEASE=
42 rm -f build/conftest.i
43 AC_MSG_CHECKING([for Linux release])
44 if test -s $LINUX_OBJ/include/$AUTOCONF_HDIR/utsrelease.h ; then
45         LINUXRELEASEHEADER=$AUTOCONF_HDIR/utsrelease.h
46 else
47         LINUXRELEASEHEADER=$VERSION_HDIR/version.h
48 fi
49 LB_LINUX_TRY_MAKE([
50         #include <$LINUXRELEASEHEADER>
51 ],[
52         char *LINUXRELEASE;
53         LINUXRELEASE=UTS_RELEASE;
54 ],[
55         $makerule LUSTRE_KERNEL_TEST=conftest.i
56 ],[
57         test -s build/conftest.i
58 ],[
59         # LINUXRELEASE="UTS_RELEASE"
60         eval $(grep "LINUXRELEASE=" build/conftest.i)
61 ],[
62         AC_MSG_RESULT([unknown])
63         AC_MSG_ERROR([Could not preprocess test program.  Consult config.log for details.])
64 ])
65 rm -f build/conftest.i
66 if test x$LINUXRELEASE = x ; then
67         AC_MSG_RESULT([unknown])
68         AC_MSG_ERROR([Could not determine Linux release version from $LINUXRELEASEHEADER.])
69 fi
70 AC_MSG_RESULT([$LINUXRELEASE])
71 AC_SUBST(LINUXRELEASE)
72
73 moduledir='$(CROSS_PATH)/lib/modules/$(LINUXRELEASE)/updates/kernel'
74 AC_SUBST(moduledir)
75
76 modulefsdir='$(moduledir)/fs/$(PACKAGE)'
77 AC_SUBST(modulefsdir)
78
79 modulenetdir='$(moduledir)/net/$(PACKAGE)'
80 AC_SUBST(modulenetdir)
81
82 # ------------ RELEASE --------------------------------
83 AC_MSG_CHECKING([for Lustre release])
84 AC_ARG_WITH([release],
85         AC_HELP_STRING([--with-release=string],
86                        [set the release string (default=$kvers_YYYYMMDDhhmm)]),
87         [RELEASE=$withval],
88         RELEASE=""
89         if test -n "$DOWNSTREAM_RELEASE"; then
90                 RELEASE="${DOWNSTREAM_RELEASE}_"
91         fi
92         RELEASE="$RELEASE`echo ${LINUXRELEASE} | tr '-' '_'`_$BUILDID")
93 AC_MSG_RESULT($RELEASE)
94 AC_SUBST(RELEASE)
95
96 # check is redhat/suse kernels
97 AC_MSG_CHECKING([that RedHat kernel])
98 LB_LINUX_TRY_COMPILE([
99                 #include <$VERSION_HDIR/version.h>
100         ],[
101                 #ifndef RHEL_RELEASE_CODE
102                 #error "not redhat kernel"
103                 #endif
104         ],[
105                 RHEL_KERNEL="yes"
106                 AC_MSG_RESULT([yes])
107         ],[
108                 AC_MSG_RESULT([no])
109 ])
110
111 LB_LINUX_CONFIG([SUSE_KERNEL],[SUSE_KERNEL="yes"],[])
112
113 ])
114
115 # LB_ARG_REPLACE_PATH(PACKAGE, PATH)
116 AC_DEFUN([LB_ARG_REPLACE_PATH],[
117         new_configure_args=
118         eval "set x $ac_configure_args"
119         shift
120         for arg; do
121                 case $arg in
122                         --with-[$1]=*)
123                                 arg=--with-[$1]=[$2]
124                                 ;;
125                         *\'*)
126                                 arg=$(printf %s\n ["$arg"] | \
127                                       sed "s/'/'\\\\\\\\''/g")
128                                 ;;
129                 esac
130                 dnl AS_VAR_APPEND([new_configure_args], [" '$arg'"])
131                 new_configure_args="$new_configure_args \"$arg\""
132         done
133         ac_configure_args=$new_configure_args
134 ])
135
136 # this is the work-horse of the next function
137 AC_DEFUN([__LB_ARG_CANON_PATH], [
138         [$3]=$(readlink -f $with_$2)
139         LB_ARG_REPLACE_PATH([$1], $[$3])
140 ])
141
142 # a front-end for the above function that transforms - and . in the
143 # PACKAGE portion of --with-PACKAGE into _ suitable for variable names
144 AC_DEFUN([LB_ARG_CANON_PATH], [
145         __LB_ARG_CANON_PATH([$1], m4_translit([$1], [-.], [__]), [$2])
146 ])
147
148 #
149 #
150 # LB_LINUX_PATH
151 #
152 # Find paths for linux, handling kernel-source rpms
153 #
154 AC_DEFUN([LB_LINUX_PATH],
155 [# prep some default values
156 for DEFAULT_LINUX in /lib/modules/$(uname -r)/{source,build} /usr/src/linux; do
157         if readlink -q -e $DEFAULT_LINUX; then
158                 break
159         fi
160 done
161 if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then
162         PATHS="/lib/modules/$(uname -r)/build"
163 fi
164 PATHS+=" $DEFAULT_LINUX"
165 for DEFAULT_LINUX_OBJ in $PATHS; do
166         if readlink -q -e $DEFAULT_LINUX_OBJ; then
167                 break
168         fi
169 done
170 AC_MSG_CHECKING([for Linux sources])
171 AC_ARG_WITH([linux],
172         AC_HELP_STRING([--with-linux=path],
173                        [set path to Linux source (default=/lib/modules/$(uname -r)/{source,build},/usr/src/linux)]),
174         [LB_ARG_CANON_PATH([linux], [LINUX])
175         DEFAULT_LINUX_OBJ=$LINUX],
176         [LINUX=$DEFAULT_LINUX])
177 AC_MSG_RESULT([$LINUX])
178 AC_SUBST(LINUX)
179
180 # -------- check for linux --------
181 LB_CHECK_FILE([$LINUX],[],
182         [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
183
184 # -------- linux objects (for 2.6) --
185 AC_MSG_CHECKING([for Linux objects dir])
186 AC_ARG_WITH([linux-obj],
187         AC_HELP_STRING([--with-linux-obj=path],
188                         [set path to Linux objects dir (default=/lib/modules/$(uname -r)/build,/usr/src/linux)]),
189         [LB_ARG_CANON_PATH([linux-obj], [LINUX_OBJ])],
190         [LINUX_OBJ=$DEFAULT_LINUX_OBJ])
191
192 AC_MSG_RESULT([$LINUX_OBJ])
193 AC_SUBST(LINUX_OBJ)
194
195 # -------- check for .config --------
196 AC_ARG_WITH([linux-config],
197         [AC_HELP_STRING([--with-linux-config=path],
198                         [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
199         [LB_ARG_CANON_PATH([linux-config], [LINUX_CONFIG])],
200         [LINUX_CONFIG=$LINUX_OBJ/.config])
201 AC_SUBST(LINUX_CONFIG)
202
203 LB_CHECK_FILE([/boot/kernel.h],
204         [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
205         [LB_CHECK_FILE([/var/adm/running-kernel.h],
206                 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
207
208 AC_ARG_WITH([kernel-source-header],
209         AC_HELP_STRING([--with-kernel-source-header=path],
210                         [Use a different kernel version header.  Consult build/README.kernel-source for details.]),
211         [LB_ARG_CANON_PATH([kernel-source-header], [KERNEL_SOURCE_HEADER])])
212
213 # ------------ .config exists ----------------
214 LB_CHECK_FILE([$LINUX_CONFIG],[],
215         [AC_MSG_ERROR([Kernel config could not be found.  If you are building from a kernel-source rpm consult build/README.kernel-source])])
216
217 # ----------- make dep run? ------------------
218 # at 2.6.19 # $LINUX/include/linux/config.h is removed
219 # and at more old has only one line
220 # include <autoconf.h>
221 LB_CHECK_FILE([$LINUX_OBJ/include/generated/autoconf.h],[AUTOCONF_HDIR=generated],
222         [LB_CHECK_FILE([$LINUX_OBJ/include/linux/autoconf.h],[AUTOCONF_HDIR=linux],
223         [AC_MSG_ERROR([Run make config in $LINUX.])])])
224         AC_SUBST(AUTOCONF_HDIR)
225 LB_CHECK_FILE([$LINUX_OBJ/include/linux/version.h], [VERSION_HDIR=linux],
226         [LB_CHECK_FILE([$LINUX_OBJ/include/generated/uapi/linux/version.h],
227                 [VERSION_HDIR=generated/uapi/linux],
228                 [AC_MSG_ERROR([Run make config in $LINUX.])])
229         ])
230         AC_SUBST(VERSION_HDIR)
231
232 # ----------- kconfig.h exists ---------------
233 # kernel 3.1, $LINUX/include/linux/kconfig.h is added
234 # see kernel commit 2a11c8ea20bf850b3a2c60db8c2e7497d28aba99
235 LB_CHECK_FILE([$LINUX_OBJ/include/linux/kconfig.h],
236               [CONFIG_INCLUDE=include/linux/kconfig.h],
237               [CONFIG_INCLUDE=include/$AUTOCONF_HDIR/autoconf.h])
238         AC_SUBST(CONFIG_INCLUDE)
239
240 # ------------ rhconfig.h includes runtime-generated bits --
241 # red hat kernel-source checks
242
243 # we know this exists after the check above.  if the user
244 # tarred up the tree and ran make dep etc. in it, then
245 # version.h gets overwritten with a standard linux one.
246
247 if grep rhconfig $LINUX_OBJ/include/$VERSION_HDIR/version.h >/dev/null ; then
248         # This is a clean kernel-source tree, we need to
249         # enable extensive workarounds to get this to build
250         # modules
251         LB_CHECK_FILE([$KERNEL_SOURCE_HEADER],
252                 [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
253                         AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
254                         AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
255                         AC_MSG_WARN([Consult build/README.kernel-source for details.])
256                 fi],
257                 [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found.  Consult build/README.kernel-source for details.])])
258         EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
259 fi
260
261 # this is needed before we can build modules
262 LB_LINUX_CROSS
263 LB_LINUX_VERSION
264
265 # --- check that we can build modules at all
266 AC_MSG_CHECKING([that modules can be built at all])
267 LB_LINUX_TRY_COMPILE([],[],[
268         AC_MSG_RESULT([yes])
269 ],[
270         AC_MSG_RESULT([no])
271         AC_MSG_WARN([Consult config.log for details.])
272         AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult build/README.kernel-source])
273         AC_MSG_ERROR([Kernel modules cannot be built.])
274 ])
275
276 LB_LINUX_RELEASE
277 ]) # end of LB_LINUX_PATH
278
279 # LB_LINUX_SYMVERFILE
280 # SLES 9 uses a different name for this file - unsure about vanilla kernels
281 # around this version, but it matters for servers only.
282 AC_DEFUN([LB_LINUX_SYMVERFILE],
283         [AC_MSG_CHECKING([name of module symbol version file])
284         if grep -q Modules.symvers $LINUX/scripts/Makefile.modpost ; then
285                 SYMVERFILE=Modules.symvers
286         else
287                 SYMVERFILE=Module.symvers
288         fi
289         AC_MSG_RESULT($SYMVERFILE)
290         AC_SUBST(SYMVERFILE)
291 ])
292
293 #
294 # LB_LINUX_CROSS
295 #
296 # check for cross compilation
297 #
298 AC_DEFUN([LB_LINUX_CROSS],
299         [AC_MSG_CHECKING([for cross compilation])
300 CROSS_VARS=
301 CROSS_PATH=
302 AS_IF([test "x$cross_compiling" = xno], [AC_MSG_RESULT([no])],
303         [case $host_vendor in
304                 # The K1OM architecture is an extension of the x86 architecture.
305                 # So, the $host_arch is x86_64.
306                 k1om)
307                         AC_MSG_RESULT([Intel(R) Xeon Phi(TM)])
308                         CC_TARGET_ARCH=`$CC -v 2>&1 | grep Target: | sed -e 's/Target: //'`
309                         if test $CC_TARGET_ARCH != x86_64-$host_vendor-linux ; then
310                                 AC_MSG_ERROR([Cross compiler not found in PATH.])
311                         fi
312                         CROSS_VARS="ARCH=$host_vendor CROSS_COMPILE=x86_64-$host_vendor-linux-"
313                         CROSS_PATH=${CROSS_PATH:=/opt/intel/mic/lustre/device-k1om}
314                         CCAS=$CC
315                         # need to produce special section for debuginfo extraction
316                         LDFLAGS="${LDFLAGS} -Wl,--build-id"
317                         EXTRA_KLDFLAGS="${EXTRA_KLDFLAGS} -Wl,--build-id"
318                         if test x$enable_server = xyes ; then
319                                 AC_MSG_WARN([Disabling server (not supported for x86_64-$host_vendor-linux).])
320                                 enable_server='no'
321                         fi
322                         ;;
323                 *)
324                         AC_MSG_RESULT([yes, but no changes])
325                         ;;
326         esac
327         ])
328 AC_SUBST(CROSS_VARS)
329 AC_SUBST(CROSS_PATH)
330 ])
331
332 # these are like AC_TRY_COMPILE, but try to build modules against the
333 # kernel, inside the build directory
334
335 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
336 # --------------------------------------
337 m4_define([LB_LANG_PROGRAM],
338 [
339 #include <linux/kernel.h>
340 $1
341 int
342 main (void)
343 {
344 dnl Do *not* indent the following line: there may be CPP directives.
345 dnl Don't move the `;' right after for the same reason.
346 $2
347   ;
348   return 0;
349 }])
350
351 #
352 # LB_LINUX_COMPILE_IFELSE
353 #
354 # like AC_COMPILE_IFELSE
355 #
356 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
357 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
358 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
359 SUBARCH=$(echo $target_cpu | sed -e 's/powerpc64/powerpc/' -e 's/x86_64/x86/' -e 's/i.86/x86/')
360 AS_IF([AC_TRY_COMMAND(cp conftest.c build && make -d [$2] ${LD:+"LD=$LD"} CC="$CC" -f $PWD/build/Makefile LUSTRE_LINUX_CONFIG=$LINUX_CONFIG LINUXINCLUDE="$EXTRA_LNET_INCLUDE -I$LINUX/arch/$SUBARCH/include -I$LINUX/arch/$SUBARCH/include/generated -Iinclude -I$LINUX/include -Iinclude2 -I$LINUX/include/uapi -I$LINUX/include/generated -I$LINUX/arch/$SUBARCH/include/uapi -Iarch/$SUBARCH/include/generated/uapi -I$LINUX/include/uapi -Iinclude/generated/uapi -include $CONFIG_INCLUDE" -o tmp_include_depends -o scripts -o include/config/MARKER -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $CROSS_VARS $MODULE_TARGET=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
361         [$4],
362         [_AC_MSG_LOG_CONFTEST
363 m4_ifvaln([$5],[$5])dnl])
364 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
365 ])
366
367 #
368 # LB_LINUX_ARCH
369 #
370 # Determine the kernel's idea of the current architecture
371 #
372 AC_DEFUN([LB_LINUX_ARCH],
373          [AC_MSG_CHECKING([Linux kernel architecture])
374           AS_IF([rm -f $PWD/build/arch
375                  make -s --no-print-directory echoarch -f $PWD/build/Makefile \
376                      LUSTRE_LINUX_CONFIG=$LINUX_CONFIG -C $LINUX $CROSS_VARS  \
377                      ARCHFILE=$PWD/build/arch && LINUX_ARCH=`cat $PWD/build/arch`],
378                 [AC_MSG_RESULT([$LINUX_ARCH])],
379                 [AC_MSG_ERROR([Could not determine the kernel architecture.])])
380           rm -f build/arch])
381
382 #
383 # LB_LINUX_TRY_COMPILE
384 #
385 # like AC_TRY_COMPILE
386 #
387 AC_DEFUN([LB_LINUX_TRY_COMPILE],
388 [LB_LINUX_COMPILE_IFELSE(
389         [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
390         [modules],
391         [test -s build/conftest.o],
392         [$3], [$4])])
393
394 #
395 # LB_LINUX_CONFIG
396 #
397 # check if a given config option is defined
398 #
399 AC_DEFUN([LB_LINUX_CONFIG],[
400         AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
401         LB_LINUX_TRY_COMPILE([
402                 #include <$AUTOCONF_HDIR/autoconf.h>
403         ],[
404                 #ifndef CONFIG_$1
405                 #error CONFIG_$1 not #defined
406                 #endif
407         ],[
408                 AC_MSG_RESULT([yes])
409                 $2
410         ],[
411                 AC_MSG_RESULT([no])
412                 $3
413         ])
414 ])
415
416 #
417 # LB_LINUX_CONFIG_IM
418 #
419 # check if a given config option is builtin or as module
420 #
421 AC_DEFUN([LB_LINUX_CONFIG_IM],[
422         AC_MSG_CHECKING([if Linux was built with CONFIG_$1 in or as module])
423         LB_LINUX_TRY_COMPILE([
424                 #include <$AUTOCONF_HDIR/autoconf.h>
425         ],[
426                 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
427                 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
428                 #endif
429         ],[
430                 AC_MSG_RESULT([yes])
431                 $2
432         ],[
433                 AC_MSG_RESULT([no])
434                 $3
435         ])
436 ])
437
438 #
439 # LB_LINUX_TRY_MAKE
440 #
441 # like LB_LINUX_TRY_COMPILE, but with different arguments
442 #
443 AC_DEFUN([LB_LINUX_TRY_MAKE],
444         [LB_LINUX_COMPILE_IFELSE(
445                 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
446                 [$3], [$4], [$5], [$6]
447         )]
448 )
449
450 #
451 # LB_CONFIG_COMPAT_RDMA
452 #
453 AC_DEFUN([LB_CONFIG_COMPAT_RDMA],
454 [AC_MSG_CHECKING([whether to use Compat RDMA])
455 # set default
456 AC_ARG_WITH([o2ib],
457         AC_HELP_STRING([--with-o2ib=path],
458                        [build o2iblnd against path]),
459         [
460                 case $with_o2ib in
461                 yes)    O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
462                         ENABLEO2IB=2
463                         ;;
464                 no)     ENABLEO2IB=0
465                         ;;
466                 *)      O2IBPATHS=$with_o2ib
467                         ENABLEO2IB=3
468                         ;;
469                 esac
470         ],[
471                 O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
472                 ENABLEO2IB=1
473         ])
474 if test $ENABLEO2IB -eq 0; then
475         AC_MSG_RESULT([no])
476 else
477         o2ib_found=false
478         for O2IBPATH in $O2IBPATHS; do
479                 if test \( -f ${O2IBPATH}/include/rdma/rdma_cm.h -a \
480                            -f ${O2IBPATH}/include/rdma/ib_cm.h -a \
481                            -f ${O2IBPATH}/include/rdma/ib_verbs.h -a \
482                            -f ${O2IBPATH}/include/rdma/ib_fmr_pool.h \); then
483                         o2ib_found=true
484                         break
485                 fi
486         done
487         compatrdma_found=false
488         if $o2ib_found; then
489                 if test \( -f ${O2IBPATH}/include/linux/compat-2.6.h \); then
490                         compatrdma_found=true
491                         AC_MSG_RESULT([yes])
492                         AC_DEFINE(HAVE_COMPAT_RDMA, 1, [compat rdma found])
493                 else
494                         AC_MSG_RESULT([no])
495                 fi
496         fi
497 fi
498 ])
499
500 #
501 # LB_CONFIG_OFED_BACKPORTS
502 #
503 # include any OFED backport headers in all compile commands
504 # NOTE: this does only include the backport paths, not the OFED headers
505 #       adding the OFED headers is done in the lnet portion
506 AC_DEFUN([LB_CONFIG_OFED_BACKPORTS],
507 [AC_MSG_CHECKING([whether to use any OFED backport headers])
508 if test $ENABLEO2IB -eq 0; then
509         AC_MSG_RESULT([no])
510 else
511         if ! $o2ib_found; then
512                 AC_MSG_RESULT([no])
513                 case $ENABLEO2IB in
514                         1) ;;
515                         2) AC_MSG_ERROR([kernel OpenIB gen2 headers not present]);;
516                         3) AC_MSG_ERROR([bad --with-o2ib path]);;
517                         *) AC_MSG_ERROR([internal error]);;
518                 esac
519         else
520                 if ! $compatrdma_found; then
521                         if test -f $O2IBPATH/config.mk; then
522                                 . $O2IBPATH/config.mk
523                         elif test -f $O2IBPATH/ofed_patch.mk; then
524                                 . $O2IBPATH/ofed_patch.mk
525                         fi
526                 fi
527                 if test -n "$BACKPORT_INCLUDES"; then
528                         OFED_BACKPORT_PATH="$O2IBPATH/${BACKPORT_INCLUDES/*\/kernel_addons/kernel_addons}/"
529                         EXTRA_LNET_INCLUDE="-I$OFED_BACKPORT_PATH $EXTRA_LNET_INCLUDE"
530                         AC_MSG_RESULT([yes])
531                 else
532                         AC_MSG_RESULT([no])
533                 fi
534         fi
535 fi
536 ])
537
538 # LC_MODULE_LOADING
539 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
540 # so we test if request_module is implemented or not
541 AC_DEFUN([LC_MODULE_LOADING],
542 [AC_MSG_CHECKING([if kernel module loading is possible])
543 LB_LINUX_TRY_MAKE([
544         #include <linux/kmod.h>
545 ],[
546         int myretval=ENOSYS ;
547         return myretval;
548 ],[
549         $makerule LUSTRE_KERNEL_TEST=conftest.i
550 ],[dnl
551         grep request_module build/conftest.i |dnl
552                 grep -v `grep "int myretval=" build/conftest.i |dnl
553                         cut -d= -f2 | cut -d" "  -f1`dnl
554                 >/dev/null dnl
555 ],[
556         AC_MSG_RESULT(yes)
557         AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
558                   [kernel module loading is possible])
559 ],[
560         AC_MSG_RESULT(no)
561         AC_MSG_WARN([])
562         AC_MSG_WARN([Kernel module loading support is highly recommended.])
563         AC_MSG_WARN([])
564 ])
565 ])
566
567 #
568 # LB_PROG_LINUX
569 #
570 # linux tests
571 #
572 AC_DEFUN([LB_PROG_LINUX],
573 [LB_LINUX_PATH
574 LB_LINUX_ARCH
575 LB_LINUX_SYMVERFILE
576
577
578 LB_LINUX_CONFIG([MODULES],[],[
579         AC_MSG_ERROR([module support is required to build Lustre kernel modules.])
580 ])
581
582 LB_LINUX_CONFIG([MODVERSIONS])
583
584 LB_LINUX_CONFIG([KALLSYMS],[],[
585         AC_MSG_ERROR([Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.])
586 ])
587
588 # 2.6.28
589 LC_MODULE_LOADING
590
591 LB_CONFIG_COMPAT_RDMA
592
593 # it's ugly to be doing anything with OFED outside of the lnet module, but
594 # this has to be done here so that the backports path is set before all of
595 # the LN_PROG_LINUX checks are done
596 LB_CONFIG_OFED_BACKPORTS
597 ])
598
599 #
600 # LB_CHECK_SYMBOL_EXPORT
601 # check symbol exported or not
602 # $1 - symbol
603 # $2 - file(s) for find.
604 # $3 - do 'yes'
605 # $4 - do 'no'
606 #
607 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers
608 # or check
609 AC_DEFUN([LB_CHECK_SYMBOL_EXPORT],
610 [AC_MSG_CHECKING([if Linux was built with symbol $1 exported])
611 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/$SYMVERFILE 2>/dev/null
612 rc=$?
613 if test $rc -ne 0; then
614         export=0
615         for file in $2; do
616                 grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null
617                 rc=$?
618                 if test $rc -eq 0; then
619                         export=1
620                         break;
621                 fi
622         done
623         if test $export -eq 0; then
624                 AC_MSG_RESULT([no])
625                 $4
626         else
627                 AC_MSG_RESULT([yes])
628                 $3
629         fi
630 else
631         AC_MSG_RESULT([yes])
632         $3
633 fi
634 ])
635
636 #
637 # Like AC_CHECK_HEADER but checks for a kernel-space header
638 #
639 m4_define([LB_CHECK_LINUX_HEADER],
640 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])dnl
641 AC_CACHE_CHECK([for $1], ac_Header,
642                [LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
643                                   [modules],
644                                   [test -s build/conftest.o],
645                                   [AS_VAR_SET(ac_Header, [yes])],
646                                   [AS_VAR_SET(ac_Header, [no])])])
647 AS_IF([test AS_VAR_GET(ac_Header) = yes], [$2], [$3])[]dnl
648 AS_VAR_POPDEF([ac_Header])dnl
649 ])
650
651 #
652 # LB_USES_DPKG
653 #
654 # Determine if the target is a dpkg system or rpm
655 #
656 AC_DEFUN([LB_USES_DPKG],
657 [
658 AC_MSG_CHECKING([if this distro uses dpkg])
659 case `lsb_release -i -s 2>/dev/null` in
660         Ubuntu | Debian)
661                 AC_MSG_RESULT([yes])
662                 uses_dpkg=yes
663                 ;;
664         *)
665                 AC_MSG_RESULT([no])
666                 uses_dpkg=no
667                 ;;
668 esac
669 ])