Whamcloud - gitweb
0833328ceddb26ef5cbbae8ad76d91103aef5d13
[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_MSG_ERROR([Run make config in $LINUX.])])])
238         AC_SUBST(AUTOCONF_HDIR)
239 LB_CHECK_FILE([$LINUX_OBJ/include/linux/version.h],[],
240         [AC_MSG_ERROR([Run make config in $LINUX.])])
241
242 # ------------ rhconfig.h includes runtime-generated bits --
243 # red hat kernel-source checks
244
245 # we know this exists after the check above.  if the user
246 # tarred up the tree and ran make dep etc. in it, then
247 # version.h gets overwritten with a standard linux one.
248
249 if grep rhconfig $LINUX_OBJ/include/linux/version.h >/dev/null ; then
250         # This is a clean kernel-source tree, we need to
251         # enable extensive workarounds to get this to build
252         # modules
253         LB_CHECK_FILE([$KERNEL_SOURCE_HEADER],
254                 [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
255                         AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
256                         AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
257                         AC_MSG_WARN([Consult build/README.kernel-source for details.])
258                 fi],
259                 [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found.  Consult build/README.kernel-source for details.])])
260         EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
261 fi
262
263 # this is needed before we can build modules
264 LB_LINUX_UML
265 LB_LINUX_VERSION
266
267 # --- check that we can build modules at all
268 AC_MSG_CHECKING([that modules can be built at all])
269 LB_LINUX_TRY_COMPILE([],[],[
270         AC_MSG_RESULT([yes])
271 ],[
272         AC_MSG_RESULT([no])
273         AC_MSG_WARN([Consult config.log for details.])
274         AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult build/README.kernel-source])
275         AC_MSG_ERROR([Kernel modules cannot be built.])
276 ])
277
278 LB_LINUX_RELEASE
279 ]) # end of LB_LINUX_PATH
280
281 # LB_LINUX_SYMVERFILE
282 # SLES 9 uses a different name for this file - unsure about vanilla kernels
283 # around this version, but it matters for servers only.
284 AC_DEFUN([LB_LINUX_SYMVERFILE],
285         [AC_MSG_CHECKING([name of module symbol version file])
286         if grep -q Modules.symvers $LINUX/scripts/Makefile.modpost ; then
287                 SYMVERFILE=Modules.symvers
288         else
289                 SYMVERFILE=Module.symvers
290         fi
291         AC_MSG_RESULT($SYMVERFILE)
292         AC_SUBST(SYMVERFILE)
293 ])
294
295 #
296 #
297 # LB_LINUX_MODPOST
298 #
299 # Find modpost and check it
300 #
301 AC_DEFUN([LB_LINUX_MODPOST],
302 [
303 # Find the modpost utility
304 LB_CHECK_FILE([$LINUX_OBJ/scripts/mod/modpost],
305         [MODPOST=$LINUX_OBJ/scripts/mod/modpost],
306         [LB_CHECK_FILE([$LINUX_OBJ/scripts/modpost],
307                 [MODPOST=$LINUX_OBJ/scripts/modpost],
308                 AC_MSG_ERROR([modpost not found.])
309         )]
310 )
311 AC_SUBST(MODPOST)
312
313 # Ensure it can run
314 AC_MSG_CHECKING([if modpost can be run])
315 if $MODPOST ; then
316         AC_MSG_RESULT([yes])
317 else
318         AC_MSG_ERROR([modpost can not be run.])
319 fi
320
321 # Check if modpost supports (and therefore requires) -m
322 AC_MSG_CHECKING([if modpost supports -m])
323 if $MODPOST -m 2>/dev/null ; then
324         AC_MSG_RESULT([yes])
325         MODPOST_ARGS=-m
326 else
327         AC_MSG_RESULT([no])
328         MODPOST_ARGS=""
329 fi
330 AC_SUBST(MODPOST_ARGS)
331 ])
332
333 #
334 # LB_LINUX_UML
335 #
336 # check for a uml kernel
337 #
338 AC_DEFUN([LB_LINUX_UML],
339 [ARCH_UM=
340 UML_CFLAGS=
341
342 AC_MSG_CHECKING([if you are running user mode linux for $target_cpu])
343 if test -e $LINUX/include/asm-um ; then
344         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
345                 ARCH_UM='ARCH=um'
346                 # see notes in Rules.in
347                 UML_CFLAGS='-O0'
348                 AC_MSG_RESULT(yes)
349         else
350                 AC_MSG_RESULT([no])
351         fi
352 else
353         AC_MSG_RESULT([no (asm-um missing)])
354 fi
355 AC_SUBST(ARCH_UM)
356 AC_SUBST(UML_CFLAGS)
357 ])
358
359 # these are like AC_TRY_COMPILE, but try to build modules against the
360 # kernel, inside the build directory
361
362 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
363 # --------------------------------------
364 m4_define([LB_LANG_PROGRAM],
365 [
366 #include <linux/kernel.h>
367 $1
368 int
369 main (void)
370 {
371 dnl Do *not* indent the following line: there may be CPP directives.
372 dnl Don't move the `;' right after for the same reason.
373 $2
374   ;
375   return 0;
376 }])
377
378 #
379 # LB_LINUX_COMPILE_IFELSE
380 #
381 # like AC_COMPILE_IFELSE
382 #
383 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
384 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
385 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
386 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])],
387         [$4],
388         [_AC_MSG_LOG_CONFTEST
389 m4_ifvaln([$5],[$5])dnl])
390 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
391 ])
392
393 #
394 # LB_LINUX_ARCH
395 #
396 # Determine the kernel's idea of the current architecture
397 #
398 AC_DEFUN([LB_LINUX_ARCH],
399          [AC_MSG_CHECKING([Linux kernel architecture])
400           AS_IF([rm -f $PWD/build/arch
401                  make -s --no-print-directory echoarch -f $PWD/build/Makefile \
402                      LUSTRE_LINUX_CONFIG=$LINUX_CONFIG -C $LINUX $ARCH_UM \
403                      ARCHFILE=$PWD/build/arch && LINUX_ARCH=`cat $PWD/build/arch`],
404                 [AC_MSG_RESULT([$LINUX_ARCH])],
405                 [AC_MSG_ERROR([Could not determine the kernel architecture.])])
406           rm -f build/arch])
407
408 #
409 # LB_LINUX_TRY_COMPILE
410 #
411 # like AC_TRY_COMPILE
412 #
413 AC_DEFUN([LB_LINUX_TRY_COMPILE],
414 [LB_LINUX_COMPILE_IFELSE(
415         [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
416         [modules],
417         [test -s build/conftest.o],
418         [$3], [$4])])
419
420 #
421 # LB_LINUX_CONFIG
422 #
423 # check if a given config option is defined
424 #
425 AC_DEFUN([LB_LINUX_CONFIG],
426 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
427 LB_LINUX_TRY_COMPILE([
428 #include <$AUTOCONF_HDIR/autoconf.h>
429 ],[
430 #ifndef CONFIG_$1
431 #error CONFIG_$1 not #defined
432 #endif
433 ],[
434 AC_MSG_RESULT([yes])
435 $2
436 ],[
437 AC_MSG_RESULT([no])
438 $3
439 ])
440 ])
441
442 #
443 # LB_LINUX_CONFIG_IM
444 #
445 # check if a given config option is builtin or as module
446 #
447 AC_DEFUN([LB_LINUX_CONFIG_IM],
448 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1 in or as module])
449 LB_LINUX_TRY_COMPILE([
450 #include <$AUTOCONF_HDIR/autoconf.h>
451 ],[
452 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
453 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
454 #endif
455 ],[
456 AC_MSG_RESULT([yes])
457 $2
458 ],[
459 AC_MSG_RESULT([no])
460 $3
461 ])
462 ])
463
464 #
465 # LB_LINUX_TRY_MAKE
466 #
467 # like LB_LINUX_TRY_COMPILE, but with different arguments
468 #
469 AC_DEFUN([LB_LINUX_TRY_MAKE],
470 [LB_LINUX_COMPILE_IFELSE([AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])], [$3], [$4], [$5], [$6])])
471
472 #
473 # LB_LINUX_CONFIG_BIG_STACK
474 #
475 # check for big stack patch
476 #
477 AC_DEFUN([LB_LINUX_CONFIG_BIG_STACK],
478 [if test "x$ARCH_UM" = "x" -a "x$linux25" = "xno" ; then
479         case $target_cpu in
480                 i?86 | x86_64)
481                         LB_LINUX_CONFIG([STACK_SIZE_16KB],[],[
482                                 LB_LINUX_CONFIG([STACK_SIZE_32KB],[],[
483                                         LB_LINUX_CONFIG([STACK_SIZE_64KB],[],[
484                                                 AC_MSG_ERROR([Lustre requires that Linux is configured with at least a 16KB stack.])
485                                         ])
486                                 ])
487                         ])
488                         ;;
489         esac
490 fi
491 ])
492
493 #
494 # LB_CONFIG_OFED_BACKPORTS
495 #
496 # include any OFED backport headers in all compile commands
497 # NOTE: this does only include the backport paths, not the OFED headers
498 #       adding the OFED headers is done in the lnet portion
499 AC_DEFUN([LB_CONFIG_OFED_BACKPORTS],
500 [AC_MSG_CHECKING([whether to use any OFED backport headers])
501 # set default
502 AC_ARG_WITH([o2ib],
503         AC_HELP_STRING([--with-o2ib=path],
504                        [build o2iblnd against path]),
505         [
506                 case $with_o2ib in
507                 yes)    O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
508                         ENABLEO2IB=2
509                         ;;
510                 no)     ENABLEO2IB=0
511                         ;;
512                 *)      O2IBPATHS=$with_o2ib
513                         ENABLEO2IB=3
514                         ;;
515                 esac
516         ],[
517                 O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
518                 ENABLEO2IB=1
519         ])
520 if test $ENABLEO2IB -eq 0; then
521         AC_MSG_RESULT([no])
522 else
523         o2ib_found=false
524         for O2IBPATH in $O2IBPATHS; do
525                 if test \( -f ${O2IBPATH}/include/rdma/rdma_cm.h -a \
526                            -f ${O2IBPATH}/include/rdma/ib_cm.h -a \
527                            -f ${O2IBPATH}/include/rdma/ib_verbs.h -a \
528                            -f ${O2IBPATH}/include/rdma/ib_fmr_pool.h \); then
529                         o2ib_found=true
530                         break
531                 fi
532         done
533         if ! $o2ib_found; then
534                 AC_MSG_RESULT([no])
535                 case $ENABLEO2IB in
536                         1) ;;
537                         2) AC_MSG_ERROR([kernel OpenIB gen2 headers not present]);;
538                         3) AC_MSG_ERROR([bad --with-o2ib path]);;
539                         *) AC_MSG_ERROR([internal error]);;
540                 esac
541         else
542                 if test -f $O2IBPATH/config.mk; then
543                         . $O2IBPATH/config.mk
544                 elif test -f $O2IBPATH/ofed_patch.mk; then
545                         . $O2IBPATH/ofed_patch.mk
546                 fi
547                 if test -n "$BACKPORT_INCLUDES"; then
548                         OFED_BACKPORT_PATH="$O2IBPATH/${BACKPORT_INCLUDES/*\/kernel_addons/kernel_addons}/"
549                         EXTRA_LNET_INCLUDE="-I$OFED_BACKPORT_PATH $EXTRA_LNET_INCLUDE"
550                         AC_MSG_RESULT([yes])
551                 else
552                         AC_MSG_RESULT([no])
553                 fi
554         fi
555 fi
556 ])
557
558 # LC_MODULE_LOADING
559 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
560 # so we test if request_module is implemented or not
561 AC_DEFUN([LC_MODULE_LOADING],
562 [AC_MSG_CHECKING([if kernel module loading is possible])
563 LB_LINUX_TRY_MAKE([
564         #include <linux/kmod.h>
565 ],[
566         int myretval=ENOSYS ;
567         return myretval;
568 ],[
569         $makerule LUSTRE_KERNEL_TEST=conftest.i
570 ],[
571         grep request_module build/conftest.i | grep -v `grep "int myretval=" build/conftest.i | cut -d= -f2 | cut -d" "  -f1` >/dev/null
572 ],[
573         AC_MSG_RESULT(yes)
574         AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
575                 [kernel module loading is possible])
576 ],[
577         AC_MSG_RESULT(no)
578         AC_MSG_WARN([])
579         AC_MSG_WARN([Kernel module loading support is highly recommended.])
580         AC_MSG_WARN([])
581 ])
582 ])
583
584 # LC_MODULE_LOADING
585 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
586 # so we test if request_module is implemented or not
587 AC_DEFUN([LC_MODULE_LOADING],
588 [AC_MSG_CHECKING([if kernel module loading is possible])
589 LB_LINUX_TRY_MAKE([
590         #include <linux/kmod.h>
591 ],[
592         int myretval=ENOSYS ;
593         return myretval;
594 ],[
595         $makerule LUSTRE_KERNEL_TEST=conftest.i
596 ],[
597         grep request_module build/conftest.i | grep -v `grep "int myretval=" build/conftest.i | cut -d= -f2 | cut -d" "  -f1` >/dev/null
598 ],[
599         AC_MSG_RESULT(yes)
600         AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
601                 [kernel module loading is possible])
602 ],[
603         AC_MSG_RESULT(no)
604         AC_MSG_WARN([])
605         AC_MSG_WARN([Kernel module loading support is highly recommended.])
606         AC_MSG_WARN([])
607 ])
608 ])
609
610 #
611 # LB_PROG_LINUX
612 #
613 # linux tests
614 #
615 AC_DEFUN([LB_PROG_LINUX],
616 [LB_LINUX_PATH
617 LB_LINUX_ARCH
618 LB_LINUX_SYMVERFILE
619
620
621 LB_LINUX_CONFIG([MODULES],[],[
622         AC_MSG_ERROR([module support is required to build Lustre kernel modules.])
623 ])
624
625 LB_LINUX_CONFIG([MODVERSIONS])
626
627 LB_LINUX_CONFIG([KALLSYMS],[],[
628 if test "x$ARCH_UM" = "x" ; then
629         AC_MSG_ERROR([Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.])
630 fi
631 ])
632
633 # 2.6.28
634 LC_MODULE_LOADING
635
636 #LB_LINUX_CONFIG_BIG_STACK
637
638 # it's ugly to be doing anything with OFED outside of the lnet module, but
639 # this has to be done here so that the backports path is set before all of
640 # the LN_PROG_LINUX checks are done
641 LB_CONFIG_OFED_BACKPORTS
642 ])
643
644 #
645 # LB_LINUX_CONDITIONALS
646 #
647 # AM_CONDITIONALS for linux
648 #
649 AC_DEFUN([LB_LINUX_CONDITIONALS],
650 [AM_CONDITIONAL(LINUX25, test x$linux25 = xyes)
651 ])
652
653
654 #
655 # LB_CHECK_SYMBOL_EXPORT
656 # check symbol exported or not
657 # $1 - symbol
658 # $2 - file(s) for find.
659 # $3 - do 'yes'
660 # $4 - do 'no'
661 #
662 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers
663 # or check
664 AC_DEFUN([LB_CHECK_SYMBOL_EXPORT],
665 [AC_MSG_CHECKING([if Linux was built with symbol $1 exported])
666 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/$SYMVERFILE 2>/dev/null
667 rc=$?
668 if test $rc -ne 0; then
669     export=0
670     for file in $2; do
671         grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null
672         rc=$?
673         if test $rc -eq 0; then
674                 export=1
675                 break;
676         fi
677     done
678     if test $export -eq 0; then
679         AC_MSG_RESULT([no])
680         $4
681     else
682         AC_MSG_RESULT([yes])
683         $3
684     fi
685 else
686     AC_MSG_RESULT([yes])
687     $3
688 fi
689 ])
690
691 #
692 # Like AC_CHECK_HEADER but checks for a kernel-space header
693 #
694 m4_define([LB_CHECK_LINUX_HEADER],
695 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])dnl
696 AC_CACHE_CHECK([for $1], ac_Header,
697                [LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
698                                   [modules],
699                                   [test -s build/conftest.o],
700                                   [AS_VAR_SET(ac_Header, [yes])],
701                                   [AS_VAR_SET(ac_Header, [no])])])
702 AS_IF([test AS_VAR_GET(ac_Header) = yes], [$2], [$3])[]dnl
703 AS_VAR_POPDEF([ac_Header])dnl
704 ])
705
706 #
707 # LB_USES_DPKG
708 #
709 # Determine if the target is a dpkg system or rpm
710 #
711 AC_DEFUN([LB_USES_DPKG],
712 [
713 AC_MSG_CHECKING([if this distro uses dpkg])
714 case `lsb_release -i -s 2>/dev/null` in
715         Ubuntu | Debian)
716                 AC_MSG_RESULT([yes])
717                 uses_dpkg=yes
718                 ;;
719         *)
720                 AC_MSG_RESULT([no])
721                 uses_dpkg=no
722                 ;;
723 esac
724 ])