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