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