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/$AUTOCONF_HDIR/utsrelease.h ; then
59 LINUXRELEASEHEADER=$AUTOCONF_HDIR/utsrelease.h
61 LINUXRELEASEHEADER=linux/version.h
64 #include <$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"
125 LB_LINUX_CONFIG([SUSE_KERNEL],[SUSE_KERNEL="yes"],[])
129 # LB_ARG_REPLACE_PATH(PACKAGE, PATH)
130 AC_DEFUN([LB_ARG_REPLACE_PATH],[
132 eval "set x $ac_configure_args"
140 arg=$(printf %s\n ["$arg"] | \
141 sed "s/'/'\\\\\\\\''/g")
144 dnl AS_VAR_APPEND([new_configure_args], [" '$arg'"])
145 new_configure_args="$new_configure_args \"$arg\""
147 ac_configure_args=$new_configure_args
150 # this is the work-horse of the next function
151 AC_DEFUN([__LB_ARG_CANON_PATH], [
152 [$3]=$(readlink -f $with_$2)
153 LB_ARG_REPLACE_PATH([$1], $[$3])
156 # a front-end for the above function that transforms - and . in the
157 # PACKAGE portion of --with-PACKAGE into _ suitable for variable names
158 AC_DEFUN([LB_ARG_CANON_PATH], [
159 __LB_ARG_CANON_PATH([$1], m4_translit([$1], [-.], [__]), [$2])
166 # Find paths for linux, handling kernel-source rpms
168 AC_DEFUN([LB_LINUX_PATH],
169 [# prep some default values
170 for DEFAULT_LINUX in /lib/modules/$(uname -r)/{source,build} /usr/src/linux; do
171 if readlink -q -e $DEFAULT_LINUX; then
175 if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then
176 PATHS="/lib/modules/$(uname -r)/build"
178 PATHS+=" $DEFAULT_LINUX"
179 for DEFAULT_LINUX_OBJ in $PATHS; do
180 if readlink -q -e $DEFAULT_LINUX_OBJ; then
184 AC_MSG_CHECKING([for Linux sources])
186 AC_HELP_STRING([--with-linux=path],
187 [set path to Linux source (default=/lib/modules/$(uname -r)/{source,build},/usr/src/linux)]),
188 [LB_ARG_CANON_PATH([linux], [LINUX])
189 DEFAULT_LINUX_OBJ=$LINUX],
190 [LINUX=$DEFAULT_LINUX])
191 AC_MSG_RESULT([$LINUX])
194 # -------- check for linux --------
195 LB_CHECK_FILE([$LINUX],[],
196 [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
198 # -------- linux objects (for 2.6) --
199 AC_MSG_CHECKING([for Linux objects dir])
200 AC_ARG_WITH([linux-obj],
201 AC_HELP_STRING([--with-linux-obj=path],
202 [set path to Linux objects dir (default=/lib/modules/$(uname -r)/build,/usr/src/linux)]),
203 [LB_ARG_CANON_PATH([linux-obj], [LINUX_OBJ])],
204 [LINUX_OBJ=$DEFAULT_LINUX_OBJ])
206 AC_MSG_RESULT([$LINUX_OBJ])
209 # -------- check for .config --------
210 AC_ARG_WITH([linux-config],
211 [AC_HELP_STRING([--with-linux-config=path],
212 [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
213 [LB_ARG_CANON_PATH([linux-config], [LINUX_CONFIG])],
214 [LINUX_CONFIG=$LINUX_OBJ/.config])
215 AC_SUBST(LINUX_CONFIG)
217 LB_CHECK_FILE([/boot/kernel.h],
218 [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
219 [LB_CHECK_FILE([/var/adm/running-kernel.h],
220 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
222 AC_ARG_WITH([kernel-source-header],
223 AC_HELP_STRING([--with-kernel-source-header=path],
224 [Use a different kernel version header. Consult build/README.kernel-source for details.]),
225 [LB_ARG_CANON_PATH([kernel-source-header], [KERNEL_SOURCE_HEADER])])
227 # ------------ .config exists ----------------
228 LB_CHECK_FILE([$LINUX_CONFIG],[],
229 [AC_MSG_ERROR([Kernel config could not be found. If you are building from a kernel-source rpm consult build/README.kernel-source])])
231 # ----------- make dep run? ------------------
232 # at 2.6.19 # $LINUX/include/linux/config.h is removed
233 # and at more old has only one line
234 # include <autoconf.h>
235 LB_CHECK_FILE([$LINUX_OBJ/include/generated/autoconf.h],[AUTOCONF_HDIR=generated],
236 [LB_CHECK_FILE([$LINUX_OBJ/include/linux/autoconf.h],[AUTOCONF_HDIR=linux],
237 [AC_MSG_ERROR([Run make config in $LINUX.])])])
238 AC_SUBST(AUTOCONF_HDIR)
239 LB_CHECK_FILE([$LINUX_OBJ/include/linux/version.h],[],
240 [AC_MSG_ERROR([Run make config in $LINUX.])])
242 # ----------- kconfig.h exists ---------------
243 # kernel 3.1, $LINUX/include/linux/kconfig.h is added
244 # see kernel commit 2a11c8ea20bf850b3a2c60db8c2e7497d28aba99
245 LB_CHECK_FILE([$LINUX_OBJ/include/linux/kconfig.h],
246 [CONFIG_INCLUDE=include/linux/kconfig.h],
247 [CONFIG_INCLUDE=include/$AUTOCONF_HDIR/autoconf.h])
248 AC_SUBST(CONFIG_INCLUDE)
250 # ------------ rhconfig.h includes runtime-generated bits --
251 # red hat kernel-source checks
253 # we know this exists after the check above. if the user
254 # tarred up the tree and ran make dep etc. in it, then
255 # version.h gets overwritten with a standard linux one.
257 if grep rhconfig $LINUX_OBJ/include/linux/version.h >/dev/null ; then
258 # This is a clean kernel-source tree, we need to
259 # enable extensive workarounds to get this to build
261 LB_CHECK_FILE([$KERNEL_SOURCE_HEADER],
262 [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
263 AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
264 AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
265 AC_MSG_WARN([Consult build/README.kernel-source for details.])
267 [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found. Consult build/README.kernel-source for details.])])
268 EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
271 # this is needed before we can build modules
275 # --- check that we can build modules at all
276 AC_MSG_CHECKING([that modules can be built at all])
277 LB_LINUX_TRY_COMPILE([],[],[
281 AC_MSG_WARN([Consult config.log for details.])
282 AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult build/README.kernel-source])
283 AC_MSG_ERROR([Kernel modules cannot be built.])
287 ]) # end of LB_LINUX_PATH
289 # LB_LINUX_SYMVERFILE
290 # SLES 9 uses a different name for this file - unsure about vanilla kernels
291 # around this version, but it matters for servers only.
292 AC_DEFUN([LB_LINUX_SYMVERFILE],
293 [AC_MSG_CHECKING([name of module symbol version file])
294 if grep -q Modules.symvers $LINUX/scripts/Makefile.modpost ; then
295 SYMVERFILE=Modules.symvers
297 SYMVERFILE=Module.symvers
299 AC_MSG_RESULT($SYMVERFILE)
307 # Find modpost and check it
309 AC_DEFUN([LB_LINUX_MODPOST],
311 # Find the modpost utility
312 LB_CHECK_FILE([$LINUX_OBJ/scripts/mod/modpost],
313 [MODPOST=$LINUX_OBJ/scripts/mod/modpost],
314 [LB_CHECK_FILE([$LINUX_OBJ/scripts/modpost],
315 [MODPOST=$LINUX_OBJ/scripts/modpost],
316 AC_MSG_ERROR([modpost not found.])
322 AC_MSG_CHECKING([if modpost can be run])
326 AC_MSG_ERROR([modpost can not be run.])
329 # Check if modpost supports (and therefore requires) -m
330 AC_MSG_CHECKING([if modpost supports -m])
331 if $MODPOST -m 2>/dev/null ; then
338 AC_SUBST(MODPOST_ARGS)
344 # check for a uml kernel
346 AC_DEFUN([LB_LINUX_UML],
350 AC_MSG_CHECKING([if you are running user mode linux for $target_cpu])
351 if test -e $LINUX/include/asm-um ; then
352 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
354 # see notes in Rules.in
361 AC_MSG_RESULT([no (asm-um missing)])
367 # these are like AC_TRY_COMPILE, but try to build modules against the
368 # kernel, inside the build directory
370 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
371 # --------------------------------------
372 m4_define([LB_LANG_PROGRAM],
374 #include <linux/kernel.h>
379 dnl Do *not* indent the following line: there may be CPP directives.
380 dnl Don't move the `;' right after for the same reason.
387 # LB_LINUX_COMPILE_IFELSE
389 # like AC_COMPILE_IFELSE
391 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
392 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
393 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
394 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/`echo $target_cpu|sed -e 's/ppc.*/powerpc/' -e 's/x86_64/x86/' -e 's/i.86/x86/'`/include -I$LINUX/arch/`echo $target_cpu|sed -e 's/ppc.*/powerpc/' -e 's/x86_64/x86/' -e 's/i.86/x86/'`/include/generated -I$LINUX_OBJ/include -I$LINUX/include -I$LINUX_OBJ/include2 -include $CONFIG_INCLUDE" -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])],
396 [_AC_MSG_LOG_CONFTEST
397 m4_ifvaln([$5],[$5])dnl])
398 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
404 # Determine the kernel's idea of the current architecture
406 AC_DEFUN([LB_LINUX_ARCH],
407 [AC_MSG_CHECKING([Linux kernel architecture])
408 AS_IF([rm -f $PWD/build/arch
409 make -s --no-print-directory echoarch -f $PWD/build/Makefile \
410 LUSTRE_LINUX_CONFIG=$LINUX_CONFIG -C $LINUX $ARCH_UM \
411 ARCHFILE=$PWD/build/arch && LINUX_ARCH=`cat $PWD/build/arch`],
412 [AC_MSG_RESULT([$LINUX_ARCH])],
413 [AC_MSG_ERROR([Could not determine the kernel architecture.])])
417 # LB_LINUX_TRY_COMPILE
419 # like AC_TRY_COMPILE
421 AC_DEFUN([LB_LINUX_TRY_COMPILE],
422 [LB_LINUX_COMPILE_IFELSE(
423 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
425 [test -s build/conftest.o],
431 # check if a given config option is defined
433 AC_DEFUN([LB_LINUX_CONFIG],
434 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
435 LB_LINUX_TRY_COMPILE([
436 #include <$AUTOCONF_HDIR/autoconf.h>
439 #error CONFIG_$1 not #defined
453 # check if a given config option is builtin or as module
455 AC_DEFUN([LB_LINUX_CONFIG_IM],
456 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1 in or as module])
457 LB_LINUX_TRY_COMPILE([
458 #include <$AUTOCONF_HDIR/autoconf.h>
460 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
461 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
475 # like LB_LINUX_TRY_COMPILE, but with different arguments
477 AC_DEFUN([LB_LINUX_TRY_MAKE],
478 [LB_LINUX_COMPILE_IFELSE([AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])], [$3], [$4], [$5], [$6])])
481 # LB_LINUX_CONFIG_BIG_STACK
483 # check for big stack patch
485 AC_DEFUN([LB_LINUX_CONFIG_BIG_STACK],
486 [if test "x$ARCH_UM" = "x" -a "x$linux25" = "xno" ; then
489 LB_LINUX_CONFIG([STACK_SIZE_16KB],[],[
490 LB_LINUX_CONFIG([STACK_SIZE_32KB],[],[
491 LB_LINUX_CONFIG([STACK_SIZE_64KB],[],[
492 AC_MSG_ERROR([Lustre requires that Linux is configured with at least a 16KB stack.])
502 # LB_CONFIG_OFED_BACKPORTS
504 # include any OFED backport headers in all compile commands
505 # NOTE: this does only include the backport paths, not the OFED headers
506 # adding the OFED headers is done in the lnet portion
507 AC_DEFUN([LB_CONFIG_OFED_BACKPORTS],
508 [AC_MSG_CHECKING([whether to use any OFED backport headers])
511 AC_HELP_STRING([--with-o2ib=path],
512 [build o2iblnd against path]),
515 yes) O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
520 *) O2IBPATHS=$with_o2ib
525 O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
528 if test $ENABLEO2IB -eq 0; then
532 for O2IBPATH in $O2IBPATHS; do
533 if test \( -f ${O2IBPATH}/include/rdma/rdma_cm.h -a \
534 -f ${O2IBPATH}/include/rdma/ib_cm.h -a \
535 -f ${O2IBPATH}/include/rdma/ib_verbs.h -a \
536 -f ${O2IBPATH}/include/rdma/ib_fmr_pool.h \); then
541 if ! $o2ib_found; then
545 2) AC_MSG_ERROR([kernel OpenIB gen2 headers not present]);;
546 3) AC_MSG_ERROR([bad --with-o2ib path]);;
547 *) AC_MSG_ERROR([internal error]);;
550 if test -f $O2IBPATH/config.mk; then
551 . $O2IBPATH/config.mk
552 elif test -f $O2IBPATH/ofed_patch.mk; then
553 . $O2IBPATH/ofed_patch.mk
555 if test -n "$BACKPORT_INCLUDES"; then
556 OFED_BACKPORT_PATH="$O2IBPATH/${BACKPORT_INCLUDES/*\/kernel_addons/kernel_addons}/"
557 EXTRA_LNET_INCLUDE="-I$OFED_BACKPORT_PATH $EXTRA_LNET_INCLUDE"
567 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
568 # so we test if request_module is implemented or not
569 AC_DEFUN([LC_MODULE_LOADING],
570 [AC_MSG_CHECKING([if kernel module loading is possible])
572 #include <linux/kmod.h>
574 int myretval=ENOSYS ;
577 $makerule LUSTRE_KERNEL_TEST=conftest.i
579 grep request_module build/conftest.i | grep -v `grep "int myretval=" build/conftest.i | cut -d= -f2 | cut -d" " -f1` >/dev/null
582 AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
583 [kernel module loading is possible])
587 AC_MSG_WARN([Kernel module loading support is highly recommended.])
593 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
594 # so we test if request_module is implemented or not
595 AC_DEFUN([LC_MODULE_LOADING],
596 [AC_MSG_CHECKING([if kernel module loading is possible])
598 #include <linux/kmod.h>
600 int myretval=ENOSYS ;
603 $makerule LUSTRE_KERNEL_TEST=conftest.i
605 grep request_module build/conftest.i | grep -v `grep "int myretval=" build/conftest.i | cut -d= -f2 | cut -d" " -f1` >/dev/null
608 AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
609 [kernel module loading is possible])
613 AC_MSG_WARN([Kernel module loading support is highly recommended.])
623 AC_DEFUN([LB_PROG_LINUX],
629 LB_LINUX_CONFIG([MODULES],[],[
630 AC_MSG_ERROR([module support is required to build Lustre kernel modules.])
633 LB_LINUX_CONFIG([MODVERSIONS])
635 LB_LINUX_CONFIG([KALLSYMS],[],[
636 if test "x$ARCH_UM" = "x" ; then
637 AC_MSG_ERROR([Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.])
644 #LB_LINUX_CONFIG_BIG_STACK
646 # it's ugly to be doing anything with OFED outside of the lnet module, but
647 # this has to be done here so that the backports path is set before all of
648 # the LN_PROG_LINUX checks are done
649 LB_CONFIG_OFED_BACKPORTS
653 # LB_LINUX_CONDITIONALS
655 # AM_CONDITIONALS for linux
657 AC_DEFUN([LB_LINUX_CONDITIONALS],
658 [AM_CONDITIONAL(LINUX25, test x$linux25 = xyes)
663 # LB_CHECK_SYMBOL_EXPORT
664 # check symbol exported or not
666 # $2 - file(s) for find.
670 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers
672 AC_DEFUN([LB_CHECK_SYMBOL_EXPORT],
673 [AC_MSG_CHECKING([if Linux was built with symbol $1 exported])
674 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/$SYMVERFILE 2>/dev/null
676 if test $rc -ne 0; then
679 grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null
681 if test $rc -eq 0; then
686 if test $export -eq 0; then
700 # Like AC_CHECK_HEADER but checks for a kernel-space header
702 m4_define([LB_CHECK_LINUX_HEADER],
703 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])dnl
704 AC_CACHE_CHECK([for $1], ac_Header,
705 [LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
707 [test -s build/conftest.o],
708 [AS_VAR_SET(ac_Header, [yes])],
709 [AS_VAR_SET(ac_Header, [no])])])
710 AS_IF([test AS_VAR_GET(ac_Header) = yes], [$2], [$3])[]dnl
711 AS_VAR_POPDEF([ac_Header])dnl
717 # Determine if the target is a dpkg system or rpm
719 AC_DEFUN([LB_USES_DPKG],
721 AC_MSG_CHECKING([if this distro uses dpkg])
722 case `lsb_release -i -s 2>/dev/null` in