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/updates/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 AC_ARG_WITH([release],
99 AC_HELP_STRING([--with-release=string],
100 [set the release string (default=$kvers_YYYYMMDDhhmm)]),
103 if test -n "$DOWNSTREAM_RELEASE"; then
104 RELEASE="${DOWNSTREAM_RELEASE}_"
106 RELEASE="$RELEASE`echo ${LINUXRELEASE} | tr '-' '_'`_$BUILDID")
107 AC_MSG_RESULT($RELEASE)
110 # check is redhat/suse kernels
111 AC_MSG_CHECKING([that RedHat kernel])
112 LB_LINUX_TRY_COMPILE([
113 #include <linux/version.h>
115 #ifndef RHEL_RELEASE_CODE
116 #error "not redhat kernel"
126 LB_LINUX_CONFIG([SUSE_KERNEL],[SUSE_KERNEL="yes"],[])
130 # LB_ARG_REPLACE_PATH(PACKAGE, PATH)
131 AC_DEFUN([LB_ARG_REPLACE_PATH],[
133 eval "set x $ac_configure_args"
141 arg=$(printf %s\n ["$arg"] | \
142 sed "s/'/'\\\\\\\\''/g")
145 dnl AS_VAR_APPEND([new_configure_args], [" '$arg'"])
146 new_configure_args="$new_configure_args \"$arg\""
148 ac_configure_args=$new_configure_args
151 # this is the work-horse of the next function
152 AC_DEFUN([__LB_ARG_CANON_PATH], [
153 [$3]=$(readlink -f $with_$2)
154 LB_ARG_REPLACE_PATH([$1], $[$3])
157 # a front-end for the above function that transforms - and . in the
158 # PACKAGE portion of --with-PACKAGE into _ suitable for variable names
159 AC_DEFUN([LB_ARG_CANON_PATH], [
160 __LB_ARG_CANON_PATH([$1], m4_translit([$1], [-.], [__]), [$2])
167 # Find paths for linux, handling kernel-source rpms
169 AC_DEFUN([LB_LINUX_PATH],
170 [# prep some default values
171 for DEFAULT_LINUX in /lib/modules/$(uname -r)/{source,build} /usr/src/linux; do
172 if readlink -q -e $DEFAULT_LINUX; then
176 if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then
177 PATHS="/lib/modules/$(uname -r)/build"
179 PATHS+=" $DEFAULT_LINUX"
180 for DEFAULT_LINUX_OBJ in $PATHS; do
181 if readlink -q -e $DEFAULT_LINUX_OBJ; then
185 AC_MSG_CHECKING([for Linux sources])
187 AC_HELP_STRING([--with-linux=path],
188 [set path to Linux source (default=/lib/modules/$(uname -r)/{source,build},/usr/src/linux)]),
189 [LB_ARG_CANON_PATH([linux], [LINUX])
190 DEFAULT_LINUX_OBJ=$LINUX],
191 [LINUX=$DEFAULT_LINUX])
192 AC_MSG_RESULT([$LINUX])
195 # -------- check for linux --------
196 LB_CHECK_FILE([$LINUX],[],
197 [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
199 # -------- linux objects (for 2.6) --
200 AC_MSG_CHECKING([for Linux objects dir])
201 AC_ARG_WITH([linux-obj],
202 AC_HELP_STRING([--with-linux-obj=path],
203 [set path to Linux objects dir (default=/lib/modules/$(uname -r)/build,/usr/src/linux)]),
204 [LB_ARG_CANON_PATH([linux-obj], [LINUX_OBJ])],
205 [LINUX_OBJ=$DEFAULT_LINUX_OBJ])
207 AC_MSG_RESULT([$LINUX_OBJ])
210 # -------- check for .config --------
211 AC_ARG_WITH([linux-config],
212 [AC_HELP_STRING([--with-linux-config=path],
213 [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
214 [LB_ARG_CANON_PATH([linux-config], [LINUX_CONFIG])],
215 [LINUX_CONFIG=$LINUX_OBJ/.config])
216 AC_SUBST(LINUX_CONFIG)
218 LB_CHECK_FILE([/boot/kernel.h],
219 [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
220 [LB_CHECK_FILE([/var/adm/running-kernel.h],
221 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
223 AC_ARG_WITH([kernel-source-header],
224 AC_HELP_STRING([--with-kernel-source-header=path],
225 [Use a different kernel version header. Consult build/README.kernel-source for details.]),
226 [LB_ARG_CANON_PATH([kernel-source-header], [KERNEL_SOURCE_HEADER])])
228 # ------------ .config exists ----------------
229 LB_CHECK_FILE([$LINUX_CONFIG],[],
230 [AC_MSG_ERROR([Kernel config could not be found. If you are building from a kernel-source rpm consult build/README.kernel-source])])
232 # ----------- make dep run? ------------------
233 # at 2.6.19 # $LINUX/include/linux/config.h is removed
234 # and at more old has only one line
235 # include <autoconf.h>
236 LB_CHECK_FILE([$LINUX_OBJ/include/linux/autoconf.h],[],
237 [AC_MSG_ERROR([Run make config in $LINUX.])])
238 LB_CHECK_FILE([$LINUX_OBJ/include/linux/version.h],[],
239 [AC_MSG_ERROR([Run make config in $LINUX.])])
241 # ------------ rhconfig.h includes runtime-generated bits --
242 # red hat kernel-source checks
244 # we know this exists after the check above. if the user
245 # tarred up the tree and ran make dep etc. in it, then
246 # version.h gets overwritten with a standard linux one.
248 if grep rhconfig $LINUX_OBJ/include/linux/version.h >/dev/null ; then
249 # This is a clean kernel-source tree, we need to
250 # enable extensive workarounds to get this to build
252 LB_CHECK_FILE([$KERNEL_SOURCE_HEADER],
253 [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
254 AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
255 AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
256 AC_MSG_WARN([Consult build/README.kernel-source for details.])
258 [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found. Consult build/README.kernel-source for details.])])
259 EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
262 # this is needed before we can build modules
266 # --- check that we can build modules at all
267 AC_MSG_CHECKING([that modules can be built at all])
268 LB_LINUX_TRY_COMPILE([],[],[
272 AC_MSG_WARN([Consult config.log for details.])
273 AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult build/README.kernel-source])
274 AC_MSG_ERROR([Kernel modules cannot be built.])
278 ]) # end of LB_LINUX_PATH
280 # LB_LINUX_SYMVERFILE
281 # SLES 9 uses a different name for this file - unsure about vanilla kernels
282 # around this version, but it matters for servers only.
283 AC_DEFUN([LB_LINUX_SYMVERFILE],
284 [AC_MSG_CHECKING([name of module symbol version file])
285 if grep -q Modules.symvers $LINUX/scripts/Makefile.modpost ; then
286 SYMVERFILE=Modules.symvers
288 SYMVERFILE=Module.symvers
290 AC_MSG_RESULT($SYMVERFILE)
298 # Find modpost and check it
300 AC_DEFUN([LB_LINUX_MODPOST],
302 # Find the modpost utility
303 LB_CHECK_FILE([$LINUX_OBJ/scripts/mod/modpost],
304 [MODPOST=$LINUX_OBJ/scripts/mod/modpost],
305 [LB_CHECK_FILE([$LINUX_OBJ/scripts/modpost],
306 [MODPOST=$LINUX_OBJ/scripts/modpost],
307 AC_MSG_ERROR([modpost not found.])
313 AC_MSG_CHECKING([if modpost can be run])
317 AC_MSG_ERROR([modpost can not be run.])
320 # Check if modpost supports (and therefore requires) -m
321 AC_MSG_CHECKING([if modpost supports -m])
322 if $MODPOST -m 2>/dev/null ; then
329 AC_SUBST(MODPOST_ARGS)
335 # check for a uml kernel
337 AC_DEFUN([LB_LINUX_UML],
341 AC_MSG_CHECKING([if you are running user mode linux for $target_cpu])
342 if test -e $LINUX/include/asm-um ; then
343 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
345 # see notes in Rules.in
352 AC_MSG_RESULT([no (asm-um missing)])
358 # these are like AC_TRY_COMPILE, but try to build modules against the
359 # kernel, inside the build directory
361 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
362 # --------------------------------------
363 m4_define([LB_LANG_PROGRAM],
365 #include <linux/kernel.h>
370 dnl Do *not* indent the following line: there may be CPP directives.
371 dnl Don't move the `;' right after for the same reason.
378 # LB_LINUX_COMPILE_IFELSE
380 # like AC_COMPILE_IFELSE
382 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
383 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
384 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
385 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_OBJ/include -I$LINUX/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])],
387 [_AC_MSG_LOG_CONFTEST
388 m4_ifvaln([$5],[$5])dnl])
389 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
395 # Determine the kernel's idea of the current architecture
397 AC_DEFUN([LB_LINUX_ARCH],
398 [AC_MSG_CHECKING([Linux kernel architecture])
399 AS_IF([rm -f $PWD/build/arch
400 make -s --no-print-directory echoarch -f $PWD/build/Makefile \
401 LUSTRE_LINUX_CONFIG=$LINUX_CONFIG -C $LINUX $ARCH_UM \
402 ARCHFILE=$PWD/build/arch && LINUX_ARCH=`cat $PWD/build/arch`],
403 [AC_MSG_RESULT([$LINUX_ARCH])],
404 [AC_MSG_ERROR([Could not determine the kernel architecture.])])
408 # LB_LINUX_TRY_COMPILE
410 # like AC_TRY_COMPILE
412 AC_DEFUN([LB_LINUX_TRY_COMPILE],
413 [LB_LINUX_COMPILE_IFELSE(
414 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
416 [test -s build/conftest.o],
422 # check if a given config option is defined
424 AC_DEFUN([LB_LINUX_CONFIG],
425 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
426 LB_LINUX_TRY_COMPILE([
427 #include <linux/autoconf.h>
430 #error CONFIG_$1 not #defined
444 # check if a given config option is builtin or as module
446 AC_DEFUN([LB_LINUX_CONFIG_IM],
447 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1 in or as module])
448 LB_LINUX_TRY_COMPILE([
449 #include <linux/autoconf.h>
451 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
452 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
466 # like LB_LINUX_TRY_COMPILE, but with different arguments
468 AC_DEFUN([LB_LINUX_TRY_MAKE],
469 [LB_LINUX_COMPILE_IFELSE([AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])], [$3], [$4], [$5], [$6])])
472 # LB_LINUX_CONFIG_BIG_STACK
474 # check for big stack patch
476 AC_DEFUN([LB_LINUX_CONFIG_BIG_STACK],
477 [if test "x$ARCH_UM" = "x" -a "x$linux25" = "xno" ; then
480 LB_LINUX_CONFIG([STACK_SIZE_16KB],[],[
481 LB_LINUX_CONFIG([STACK_SIZE_32KB],[],[
482 LB_LINUX_CONFIG([STACK_SIZE_64KB],[],[
483 AC_MSG_ERROR([Lustre requires that Linux is configured with at least a 16KB stack.])
493 # LB_CONFIG_OFED_BACKPORTS
495 # include any OFED backport headers in all compile commands
496 # NOTE: this does only include the backport paths, not the OFED headers
497 # adding the OFED headers is done in the lnet portion
498 AC_DEFUN([LB_CONFIG_OFED_BACKPORTS],
499 [AC_MSG_CHECKING([whether to use any OFED backport headers])
502 AC_HELP_STRING([--with-o2ib=path],
503 [build o2iblnd against path]),
506 yes) O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
511 *) O2IBPATHS=$with_o2ib
516 O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
519 if test $ENABLEO2IB -eq 0; then
523 for O2IBPATH in $O2IBPATHS; do
524 if test \( -f ${O2IBPATH}/include/rdma/rdma_cm.h -a \
525 -f ${O2IBPATH}/include/rdma/ib_cm.h -a \
526 -f ${O2IBPATH}/include/rdma/ib_verbs.h -a \
527 -f ${O2IBPATH}/include/rdma/ib_fmr_pool.h \); then
532 if ! $o2ib_found; then
536 2) AC_MSG_ERROR([kernel OpenIB gen2 headers not present]);;
537 3) AC_MSG_ERROR([bad --with-o2ib path]);;
538 *) AC_MSG_ERROR([internal error]);;
541 if test -f $O2IBPATH/config.mk; then
542 . $O2IBPATH/config.mk
543 elif test -f $O2IBPATH/ofed_patch.mk; then
544 . $O2IBPATH/ofed_patch.mk
546 if test -n "$BACKPORT_INCLUDES"; then
547 OFED_BACKPORT_PATH="$O2IBPATH/${BACKPORT_INCLUDES/*\/kernel_addons/kernel_addons}/"
548 EXTRA_LNET_INCLUDE="-I$OFED_BACKPORT_PATH $EXTRA_LNET_INCLUDE"
558 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
559 # so we test if request_module is implemented or not
560 AC_DEFUN([LC_MODULE_LOADING],
561 [AC_MSG_CHECKING([if kernel module loading is possible])
563 #include <linux/kmod.h>
565 int myretval=ENOSYS ;
568 $makerule LUSTRE_KERNEL_TEST=conftest.i
570 grep request_module build/conftest.i | grep -v `grep "int myretval=" build/conftest.i | cut -d= -f2 | cut -d" " -f1` >/dev/null
573 AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
574 [kernel module loading is possible])
578 AC_MSG_WARN([Kernel module loading support is highly recommended.])
584 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
585 # so we test if request_module is implemented or not
586 AC_DEFUN([LC_MODULE_LOADING],
587 [AC_MSG_CHECKING([if kernel module loading is possible])
589 #include <linux/kmod.h>
591 int myretval=ENOSYS ;
594 $makerule LUSTRE_KERNEL_TEST=conftest.i
596 grep request_module build/conftest.i | grep -v `grep "int myretval=" build/conftest.i | cut -d= -f2 | cut -d" " -f1` >/dev/null
599 AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
600 [kernel module loading is possible])
604 AC_MSG_WARN([Kernel module loading support is highly recommended.])
614 AC_DEFUN([LB_PROG_LINUX],
620 LB_LINUX_CONFIG([MODULES],[],[
621 AC_MSG_ERROR([module support is required to build Lustre kernel modules.])
624 LB_LINUX_CONFIG([MODVERSIONS])
626 LB_LINUX_CONFIG([KALLSYMS],[],[
627 if test "x$ARCH_UM" = "x" ; then
628 AC_MSG_ERROR([Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.])
635 #LB_LINUX_CONFIG_BIG_STACK
637 # it's ugly to be doing anything with OFED outside of the lnet module, but
638 # this has to be done here so that the backports path is set before all of
639 # the LN_PROG_LINUX checks are done
640 LB_CONFIG_OFED_BACKPORTS
644 # LB_LINUX_CONDITIONALS
646 # AM_CONDITIONALS for linux
648 AC_DEFUN([LB_LINUX_CONDITIONALS],
649 [AM_CONDITIONAL(LINUX25, test x$linux25 = xyes)
654 # LB_CHECK_SYMBOL_EXPORT
655 # check symbol exported or not
657 # $2 - file(s) for find.
661 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers
663 AC_DEFUN([LB_CHECK_SYMBOL_EXPORT],
664 [AC_MSG_CHECKING([if Linux was built with symbol $1 exported])
665 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/$SYMVERFILE 2>/dev/null
667 if test $rc -ne 0; then
670 grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null
672 if test $rc -eq 0; then
677 if test $export -eq 0; then
691 # Like AC_CHECK_HEADER but checks for a kernel-space header
693 m4_define([LB_CHECK_LINUX_HEADER],
694 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])dnl
695 AC_CACHE_CHECK([for $1], ac_Header,
696 [LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
698 [test -s build/conftest.o],
699 [AS_VAR_SET(ac_Header, [yes])],
700 [AS_VAR_SET(ac_Header, [no])])])
701 AS_IF([test AS_VAR_GET(ac_Header) = yes], [$2], [$3])[]dnl
702 AS_VAR_POPDEF([ac_Header])dnl
708 # Determine if the target is a dpkg system or rpm
710 AC_DEFUN([LB_USES_DPKG],
712 AC_MSG_CHECKING([if this distro uses dpkg])
713 case `lsb_release -i -s 2>/dev/null` in