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