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