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