4 # Set things accordingly for a 2.5 kernel
6 AC_DEFUN([LB_LINUX_VERSION],
7 [LB_CHECK_FILE([$LINUX/include/linux/namei.h],
15 AC_MSG_CHECKING([if you are using Linux 2.6])
16 AC_MSG_RESULT([$linux25])
18 MODULE_TARGET="SUBDIRS"
19 if test $linux25 = "yes" ; then
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],
29 makerule="_module_$makerule"
31 LB_LINUX_TRY_MAKE([],[],
32 [$makerule LUSTRE_KERNEL_TEST=conftest.i],
33 [test -s build/conftest.i],
37 AC_MSG_ERROR([unknown; check config.log for details])
41 makerule="_dir_$PWD/build"
44 AC_SUBST(MODULE_TARGET)
52 # get the release version of linux
54 AC_DEFUN([LB_LINUX_RELEASE],
56 rm -f build/conftest.i
57 AC_MSG_CHECKING([for Linux release])
58 if test -s $LINUX_OBJ/include/linux/utsrelease.h ; then
59 LINUXRELEASEHEADER=utsrelease.h
61 LINUXRELEASEHEADER=version.h
64 #include <linux/$LINUXRELEASEHEADER>
67 LINUXRELEASE=UTS_RELEASE;
69 $makerule LUSTRE_KERNEL_TEST=conftest.i
71 test -s build/conftest.i
73 # LINUXRELEASE="UTS_RELEASE"
74 eval $(grep "LINUXRELEASE=" build/conftest.i)
76 AC_MSG_RESULT([unknown])
77 AC_MSG_ERROR([Could not preprocess test program. Consult config.log for details.])
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.])
84 AC_MSG_RESULT([$LINUXRELEASE])
85 AC_SUBST(LINUXRELEASE)
87 moduledir='/lib/modules/'$LINUXRELEASE/kernel
90 modulefsdir='$(moduledir)/fs/$(PACKAGE)'
93 modulenetdir='$(moduledir)/net/$(PACKAGE)'
94 AC_SUBST(modulenetdir)
96 # ------------ RELEASE --------------------------------
97 AC_MSG_CHECKING([for Lustre release])
98 RELEASE="`echo ${LINUXRELEASE} | tr '-' '_'`_`date +%Y%m%d%H%M`"
99 AC_MSG_RESULT($RELEASE)
102 # check is redhat/suse kernels
103 AC_MSG_CHECKING([that RedHat kernel])
104 LB_LINUX_TRY_COMPILE([
105 #include <linux/version.h>
107 #ifndef RHEL_RELEASE_CODE
108 #error "not redhat kernel"
118 LB_LINUX_CONFIG([SUSE_KERNEL],[SUSE_KERNEL="yes"],[])
122 # LB_ARG_REPLACE_PATH(PACKAGE, PATH)
123 AC_DEFUN([LB_ARG_REPLACE_PATH],[
125 eval "set x $ac_configure_args"
133 arg=$(printf %s\n ["$arg"] | \
134 sed "s/'/'\\\\\\\\''/g")
137 dnl AS_VAR_APPEND([new_configure_args], [" '$arg'"])
138 new_configure_args="$new_configure_args \"$arg\""
140 ac_configure_args=$new_configure_args
143 # this is the work-horse of the next function
144 AC_DEFUN([__LB_ARG_CANON_PATH], [
145 [$3]=$(readlink -f $with_$2)
146 LB_ARG_REPLACE_PATH([$1], $[$3])
149 # a front-end for the above function that transforms - and . in the
150 # PACKAGE portion of --with-PACKAGE into _ suitable for variable names
151 AC_DEFUN([LB_ARG_CANON_PATH], [
152 __LB_ARG_CANON_PATH([$1], m4_translit([$1], [-.], [__]), [$2])
159 # Find paths for linux, handling kernel-source rpms
161 AC_DEFUN([LB_LINUX_PATH],
162 [AC_MSG_CHECKING([for Linux sources])
164 AC_HELP_STRING([--with-linux=path],
165 [set path to Linux source (default=/usr/src/linux)]),
166 [LB_ARG_CANON_PATH([linux], [LINUX])],
167 [LINUX=/usr/src/linux])
168 AC_MSG_RESULT([$LINUX])
171 # -------- check for linux --------
172 LB_CHECK_FILE([$LINUX],[],
173 [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
175 # -------- linux objects (for 2.6) --
176 AC_MSG_CHECKING([for Linux objects dir])
177 AC_ARG_WITH([linux-obj],
178 AC_HELP_STRING([--with-linux-obj=path],
179 [set path to Linux objects dir (default=$LINUX)]),
180 [LB_ARG_CANON_PATH([linux-obj], [LINUX_OBJ])],
182 AC_MSG_RESULT([$LINUX_OBJ])
185 # -------- check for .config --------
186 AC_ARG_WITH([linux-config],
187 [AC_HELP_STRING([--with-linux-config=path],
188 [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
189 [LB_ARG_CANON_PATH([linux-config], [LINUX_CONFIG])],
190 [LINUX_CONFIG=$LINUX_OBJ/.config])
191 AC_SUBST(LINUX_CONFIG)
193 LB_CHECK_FILE([/boot/kernel.h],
194 [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
195 [LB_CHECK_FILE([/var/adm/running-kernel.h],
196 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
198 AC_ARG_WITH([kernel-source-header],
199 AC_HELP_STRING([--with-kernel-source-header=path],
200 [Use a different kernel version header. Consult build/README.kernel-source for details.]),
201 [LB_ARG_CANON_PATH([kernel-source-header], [KERNEL_SOURCE_HEADER])])
203 # ------------ .config exists ----------------
204 LB_CHECK_FILE([$LINUX_CONFIG],[],
205 [AC_MSG_ERROR([Kernel config could not be found. If you are building from a kernel-source rpm consult build/README.kernel-source])])
207 # ----------- make dep run? ------------------
208 # at 2.6.19 # $LINUX/include/linux/config.h is removed
209 # and at more old has only one line
210 # include <autoconf.h>
211 LB_CHECK_FILE([$LINUX_OBJ/include/linux/autoconf.h],[],
212 [AC_MSG_ERROR([Run make config in $LINUX.])])
213 LB_CHECK_FILE([$LINUX_OBJ/include/linux/version.h],[],
214 [AC_MSG_ERROR([Run make config in $LINUX.])])
216 # ------------ rhconfig.h includes runtime-generated bits --
217 # red hat kernel-source checks
219 # we know this exists after the check above. if the user
220 # tarred up the tree and ran make dep etc. in it, then
221 # version.h gets overwritten with a standard linux one.
223 if grep rhconfig $LINUX_OBJ/include/linux/version.h >/dev/null ; then
224 # This is a clean kernel-source tree, we need to
225 # enable extensive workarounds to get this to build
227 LB_CHECK_FILE([$KERNEL_SOURCE_HEADER],
228 [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
229 AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
230 AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
231 AC_MSG_WARN([Consult build/README.kernel-source for details.])
233 [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found. Consult build/README.kernel-source for details.])])
234 EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
237 # this is needed before we can build modules
241 # --- check that we can build modules at all
242 AC_MSG_CHECKING([that modules can be built at all])
243 LB_LINUX_TRY_COMPILE([],[],[
247 AC_MSG_WARN([Consult config.log for details.])
248 AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult build/README.kernel-source])
249 AC_MSG_ERROR([Kernel modules cannot be built.])
253 ]) # end of LB_LINUX_PATH
255 # LB_LINUX_SYMVERFILE
256 # SLES 9 uses a different name for this file - unsure about vanilla kernels
257 # around this version, but it matters for servers only.
258 AC_DEFUN([LB_LINUX_SYMVERFILE],
259 [AC_MSG_CHECKING([name of module symbol version file])
260 if grep -q Modules.symvers $LINUX/scripts/Makefile.modpost ; then
261 SYMVERFILE=Modules.symvers
263 SYMVERFILE=Module.symvers
265 AC_MSG_RESULT($SYMVERFILE)
273 # Find modpost and check it
275 AC_DEFUN([LB_LINUX_MODPOST],
277 # Find the modpost utility
278 LB_CHECK_FILE([$LINUX_OBJ/scripts/mod/modpost],
279 [MODPOST=$LINUX_OBJ/scripts/mod/modpost],
280 [LB_CHECK_FILE([$LINUX_OBJ/scripts/modpost],
281 [MODPOST=$LINUX_OBJ/scripts/modpost],
282 AC_MSG_ERROR([modpost not found.])
288 AC_MSG_CHECKING([if modpost can be run])
292 AC_MSG_ERROR([modpost can not be run.])
295 # Check if modpost supports (and therefore requires) -m
296 AC_MSG_CHECKING([if modpost supports -m])
297 if $MODPOST -m 2>/dev/null ; then
304 AC_SUBST(MODPOST_ARGS)
310 # check for a uml kernel
312 AC_DEFUN([LB_LINUX_UML],
316 AC_MSG_CHECKING([if you are running user mode linux for $target_cpu])
317 if test -e $LINUX/include/asm-um ; then
318 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
320 # see notes in Rules.in
327 AC_MSG_RESULT([no (asm-um missing)])
333 # these are like AC_TRY_COMPILE, but try to build modules against the
334 # kernel, inside the build directory
339 # create a conftest.c file
341 AC_DEFUN([LB_LINUX_CONFTEST],
342 [cat >conftest.c <<_ACEOF
348 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
349 # --------------------------------------
350 m4_define([LB_LANG_PROGRAM],
355 dnl Do *not* indent the following line: there may be CPP directives.
356 dnl Don't move the `;' right after for the same reason.
363 # LB_LINUX_COMPILE_IFELSE
365 # like AC_COMPILE_IFELSE
367 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
368 [m4_ifvaln([$1], [LB_LINUX_CONFTEST([$1])])dnl
369 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
370 AS_IF([AC_TRY_COMMAND(cp conftest.c build && make -d [$2] ${LD:+"LD=$LD"} CC="$CC" -f $PWD/build/Makefile LUSTRE_LINUX_CONFIG=$LINUX_CONFIG LINUXINCLUDE="$EXTRA_LNET_INCLUDE -I$LINUX/arch/`uname -m|sed -e 's/ppc.*/powerpc/' -e 's/x86_64/x86/' -e 's/i.86/x86/'`/include -I$LINUX/include -I$LINUX_OBJ/include -I$LINUX_OBJ/include2 -include include/linux/autoconf.h" -o tmp_include_depends -o scripts -o include/config/MARKER -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM $MODULE_TARGET=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
372 [_AC_MSG_LOG_CONFTEST
373 m4_ifvaln([$5],[$5])dnl])
374 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 # Determine the kernel's idea of the current architecture
382 AC_DEFUN([LB_LINUX_ARCH],
383 [AC_MSG_CHECKING([Linux kernel architecture])
384 AS_IF([rm -f $PWD/build/arch
385 make -s --no-print-directory echoarch -f $PWD/build/Makefile \
386 LUSTRE_LINUX_CONFIG=$LINUX_CONFIG -C $LINUX $ARCH_UM \
387 ARCHFILE=$PWD/build/arch && LINUX_ARCH=`cat $PWD/build/arch`],
388 [AC_MSG_RESULT([$LINUX_ARCH])],
389 [AC_MSG_ERROR([Could not determine the kernel architecture.])])
393 # LB_LINUX_TRY_COMPILE
395 # like AC_TRY_COMPILE
397 AC_DEFUN([LB_LINUX_TRY_COMPILE],
398 [LB_LINUX_COMPILE_IFELSE(
399 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
401 [test -s build/conftest.o],
407 # check if a given config option is defined
409 AC_DEFUN([LB_LINUX_CONFIG],
410 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
411 LB_LINUX_TRY_COMPILE([
412 #include <linux/autoconf.h>
415 #error CONFIG_$1 not #defined
429 # check if a given config option is builtin or as module
431 AC_DEFUN([LB_LINUX_CONFIG_IM],
432 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1 in or as module])
433 LB_LINUX_TRY_COMPILE([
434 #include <linux/autoconf.h>
436 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
437 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
451 # like LB_LINUX_TRY_COMPILE, but with different arguments
453 AC_DEFUN([LB_LINUX_TRY_MAKE],
454 [LB_LINUX_COMPILE_IFELSE([AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])], [$3], [$4], [$5], [$6])])
457 # LB_LINUX_CONFIG_BIG_STACK
459 # check for big stack patch
461 AC_DEFUN([LB_LINUX_CONFIG_BIG_STACK],
462 [if test "x$ARCH_UM" = "x" -a "x$linux25" = "xno" ; then
465 LB_LINUX_CONFIG([STACK_SIZE_16KB],[],[
466 LB_LINUX_CONFIG([STACK_SIZE_32KB],[],[
467 LB_LINUX_CONFIG([STACK_SIZE_64KB],[],[
468 AC_MSG_ERROR([Lustre requires that Linux is configured with at least a 16KB stack.])
478 # LB_CONFIG_OFED_BACKPORTS
480 # include any OFED backport headers in all compile commands
481 # NOTE: this does only include the backport paths, not the OFED headers
482 # adding the OFED headers is done in the lnet portion
483 AC_DEFUN([LB_CONFIG_OFED_BACKPORTS],
484 [AC_MSG_CHECKING([whether to use any OFED backport headers])
487 AC_HELP_STRING([--with-o2ib=path],
488 [build o2iblnd against path]),
491 yes) O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
496 *) O2IBPATHS=$with_o2ib
501 O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
504 if test $ENABLEO2IB -eq 0; then
508 for O2IBPATH in $O2IBPATHS; do
509 if test \( -f ${O2IBPATH}/include/rdma/rdma_cm.h -a \
510 -f ${O2IBPATH}/include/rdma/ib_cm.h -a \
511 -f ${O2IBPATH}/include/rdma/ib_verbs.h -a \
512 -f ${O2IBPATH}/include/rdma/ib_fmr_pool.h \); then
517 if ! $o2ib_found; then
521 2) AC_MSG_ERROR([kernel OpenIB gen2 headers not present]);;
522 3) AC_MSG_ERROR([bad --with-o2ib path]);;
523 *) AC_MSG_ERROR([internal error]);;
526 if test -f $O2IBPATH/config.mk; then
527 . $O2IBPATH/config.mk
528 elif test -f $O2IBPATH/ofed_patch.mk; then
529 . $O2IBPATH/ofed_patch.mk
531 if test -n "$BACKPORT_INCLUDES"; then
532 OFED_BACKPORT_PATH=`echo $BACKPORT_INCLUDES | sed "s#.*/src/ofa_kernel/#$O2IBPATH/#"`
533 EXTRA_LNET_INCLUDE="-I$OFED_BACKPORT_PATH $EXTRA_LNET_INCLUDE"
543 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
544 # so we test if request_module is implemented or not
545 AC_DEFUN([LC_MODULE_LOADING],
546 [AC_MSG_CHECKING([if kernel module loading is possible])
548 #include <linux/kmod.h>
550 int myretval=ENOSYS ;
553 $makerule LUSTRE_KERNEL_TEST=conftest.i
555 grep request_module build/conftest.i | grep -v `grep "int myretval=" build/conftest.i | cut -d= -f2 | cut -d" " -f1` >/dev/null
558 AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
559 [kernel module loading is possible])
563 AC_MSG_WARN([Kernel module loading support is highly recommended.])
573 AC_DEFUN([LB_PROG_LINUX],
579 LB_LINUX_CONFIG([MODULES],[],[
580 AC_MSG_ERROR([module support is required to build Lustre kernel modules.])
583 LB_LINUX_CONFIG([MODVERSIONS])
585 LB_LINUX_CONFIG([KALLSYMS],[],[
586 if test "x$ARCH_UM" = "x" ; then
587 AC_MSG_ERROR([Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.])
594 #LB_LINUX_CONFIG_BIG_STACK
596 # it's ugly to be doing anything with OFED outside of the lnet module, but
597 # this has to be done here so that the backports path is set before all of
598 # the LN_PROG_LINUX checks are done
599 LB_CONFIG_OFED_BACKPORTS
603 # LB_LINUX_CONDITIONALS
605 # AM_CONDITIONALS for linux
607 AC_DEFUN([LB_LINUX_CONDITIONALS],
608 [AM_CONDITIONAL(LINUX25, test x$linux25 = xyes)
613 # LB_CHECK_SYMBOL_EXPORT
614 # check symbol exported or not
616 # $2 - file(s) for find.
620 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers
622 AC_DEFUN([LB_CHECK_SYMBOL_EXPORT],
623 [AC_MSG_CHECKING([if Linux was built with symbol $1 exported])
624 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/$SYMVERFILE 2>/dev/null
626 if test $rc -ne 0; then
629 grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null
631 if test $rc -eq 0; then
636 if test $export -eq 0; then
650 # Like AC_CHECK_HEADER but checks for a kernel-space header
652 m4_define([LB_CHECK_LINUX_HEADER],
653 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])dnl
654 AC_CACHE_CHECK([for $1], ac_Header,
655 [LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
657 [test -s build/conftest.o],
658 [AS_VAR_SET(ac_Header, [yes])],
659 [AS_VAR_SET(ac_Header, [no])])])
660 AS_IF([test AS_VAR_GET(ac_Header) = yes], [$2], [$3])[]dnl
661 AS_VAR_POPDEF([ac_Header])dnl