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"],[])
126 # Find paths for linux, handling kernel-source rpms
128 AC_DEFUN([LB_LINUX_PATH],
129 [AC_MSG_CHECKING([for Linux sources])
131 AC_HELP_STRING([--with-linux=path],
132 [set path to Linux source (default=/usr/src/linux)]),
134 if ! [[[ $with_linux = /* ]]]; then
135 AC_MSG_ERROR([You must provide an absolute pathname to the --with-linux= option.])
140 [LINUX=/usr/src/linux])
141 AC_MSG_RESULT([$LINUX])
144 # -------- check for linux --------
145 LB_CHECK_FILE([$LINUX],[],
146 [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
148 # -------- linux objects (for 2.6) --
149 AC_MSG_CHECKING([for Linux objects dir])
150 AC_ARG_WITH([linux-obj],
151 AC_HELP_STRING([--with-linux-obj=path],
152 [set path to Linux objects dir (default=$LINUX)]),
153 [LINUX_OBJ=$with_linux_obj],
155 AC_MSG_RESULT([$LINUX_OBJ])
158 # -------- check for .config --------
159 AC_ARG_WITH([linux-config],
160 [AC_HELP_STRING([--with-linux-config=path],
161 [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
162 [LINUX_CONFIG=$with_linux_config],
163 [LINUX_CONFIG=$LINUX_OBJ/.config])
164 AC_SUBST(LINUX_CONFIG)
166 LB_CHECK_FILE([/boot/kernel.h],
167 [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
168 [LB_CHECK_FILE([/var/adm/running-kernel.h],
169 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
171 AC_ARG_WITH([kernel-source-header],
172 AC_HELP_STRING([--with-kernel-source-header=path],
173 [Use a different kernel version header. Consult build/README.kernel-source for details.]),
174 [KERNEL_SOURCE_HEADER=$with_kernel_source_header])
176 # ------------ .config exists ----------------
177 LB_CHECK_FILE([$LINUX_CONFIG],[],
178 [AC_MSG_ERROR([Kernel config could not be found. If you are building from a kernel-source rpm consult build/README.kernel-source])])
180 # ----------- make dep run? ------------------
181 # at 2.6.19 # $LINUX/include/linux/config.h is removed
182 # and at more old has only one line
183 # include <autoconf.h>
184 LB_CHECK_FILE([$LINUX_OBJ/include/linux/autoconf.h],[],
185 [AC_MSG_ERROR([Run make config in $LINUX.])])
186 LB_CHECK_FILE([$LINUX_OBJ/include/linux/version.h],[],
187 [AC_MSG_ERROR([Run make config in $LINUX.])])
189 # ------------ rhconfig.h includes runtime-generated bits --
190 # red hat kernel-source checks
192 # we know this exists after the check above. if the user
193 # tarred up the tree and ran make dep etc. in it, then
194 # version.h gets overwritten with a standard linux one.
196 if grep rhconfig $LINUX_OBJ/include/linux/version.h >/dev/null ; then
197 # This is a clean kernel-source tree, we need to
198 # enable extensive workarounds to get this to build
200 LB_CHECK_FILE([$KERNEL_SOURCE_HEADER],
201 [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
202 AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
203 AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
204 AC_MSG_WARN([Consult build/README.kernel-source for details.])
206 [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found. Consult build/README.kernel-source for details.])])
207 EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
210 # this is needed before we can build modules
214 # --- check that we can build modules at all
215 AC_MSG_CHECKING([that modules can be built at all])
216 LB_LINUX_TRY_COMPILE([],[],[
220 AC_MSG_WARN([Consult config.log for details.])
221 AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult build/README.kernel-source])
222 AC_MSG_ERROR([Kernel modules cannot be built.])
226 ]) # end of LB_LINUX_PATH
228 # LB_LINUX_SYMVERFILE
229 # SLES 9 uses a different name for this file - unsure about vanilla kernels
230 # around this version, but it matters for servers only.
231 AC_DEFUN([LB_LINUX_SYMVERFILE],
232 [AC_MSG_CHECKING([name of module symbol version file])
233 if grep -q Modules.symvers $LINUX/scripts/Makefile.modpost ; then
234 SYMVERFILE=Modules.symvers
236 SYMVERFILE=Module.symvers
238 AC_MSG_RESULT($SYMVERFILE)
246 # Find modpost and check it
248 AC_DEFUN([LB_LINUX_MODPOST],
250 # Find the modpost utility
251 LB_CHECK_FILE([$LINUX_OBJ/scripts/mod/modpost],
252 [MODPOST=$LINUX_OBJ/scripts/mod/modpost],
253 [LB_CHECK_FILE([$LINUX_OBJ/scripts/modpost],
254 [MODPOST=$LINUX_OBJ/scripts/modpost],
255 AC_MSG_ERROR([modpost not found.])
261 AC_MSG_CHECKING([if modpost can be run])
265 AC_MSG_ERROR([modpost can not be run.])
268 # Check if modpost supports (and therefore requires) -m
269 AC_MSG_CHECKING([if modpost supports -m])
270 if $MODPOST -m 2>/dev/null ; then
277 AC_SUBST(MODPOST_ARGS)
283 # check for a uml kernel
285 AC_DEFUN([LB_LINUX_UML],
289 AC_MSG_CHECKING([if you are running user mode linux for $target_cpu])
290 if test -e $LINUX/include/asm-um ; then
291 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
293 # see notes in Rules.in
300 AC_MSG_RESULT([no (asm-um missing)])
306 # these are like AC_TRY_COMPILE, but try to build modules against the
307 # kernel, inside the build directory
312 # create a conftest.c file
314 AC_DEFUN([LB_LINUX_CONFTEST],
315 [cat >conftest.c <<_ACEOF
321 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
322 # --------------------------------------
323 m4_define([LB_LANG_PROGRAM],
328 dnl Do *not* indent the following line: there may be CPP directives.
329 dnl Don't move the `;' right after for the same reason.
336 # LB_LINUX_COMPILE_IFELSE
338 # like AC_COMPILE_IFELSE
340 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
341 [m4_ifvaln([$1], [LB_LINUX_CONFTEST([$1])])dnl
342 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
343 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])],
345 [_AC_MSG_LOG_CONFTEST
346 m4_ifvaln([$5],[$5])dnl])dnl
347 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
353 # Determine the kernel's idea of the current architecture
355 AC_DEFUN([LB_LINUX_ARCH],
356 [AC_MSG_CHECKING([Linux kernel architecture])
357 AS_IF([rm -f $PWD/build/arch
358 make -s --no-print-directory echoarch -f $PWD/build/Makefile \
359 LUSTRE_LINUX_CONFIG=$LINUX_CONFIG -C $LINUX $ARCH_UM \
360 ARCHFILE=$PWD/build/arch && LINUX_ARCH=`cat $PWD/build/arch`],
361 [AC_MSG_RESULT([$LINUX_ARCH])],
362 [AC_MSG_ERROR([Could not determine the kernel architecture.])])
366 # LB_LINUX_TRY_COMPILE
368 # like AC_TRY_COMPILE
370 AC_DEFUN([LB_LINUX_TRY_COMPILE],
371 [LB_LINUX_COMPILE_IFELSE(
372 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
374 [test -s build/conftest.o],
380 # check if a given config option is defined
382 AC_DEFUN([LB_LINUX_CONFIG],
383 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
384 LB_LINUX_TRY_COMPILE([
385 #include <linux/autoconf.h>
388 #error CONFIG_$1 not #defined
402 # check if a given config option is builtin or as module
404 AC_DEFUN([LB_LINUX_CONFIG_IM],
405 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1 in or as module])
406 LB_LINUX_TRY_COMPILE([
407 #include <linux/autoconf.h>
409 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
410 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
424 # like LB_LINUX_TRY_COMPILE, but with different arguments
426 AC_DEFUN([LB_LINUX_TRY_MAKE],
427 [LB_LINUX_COMPILE_IFELSE([AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])], [$3], [$4], [$5], [$6])])
430 # LB_LINUX_CONFIG_BIG_STACK
432 # check for big stack patch
434 AC_DEFUN([LB_LINUX_CONFIG_BIG_STACK],
435 [if test "x$ARCH_UM" = "x" -a "x$linux25" = "xno" ; then
438 LB_LINUX_CONFIG([STACK_SIZE_16KB],[],[
439 LB_LINUX_CONFIG([STACK_SIZE_32KB],[],[
440 LB_LINUX_CONFIG([STACK_SIZE_64KB],[],[
441 AC_MSG_ERROR([Lustre requires that Linux is configured with at least a 16KB stack.])
451 # LB_CONFIG_OFED_BACKPORTS
453 # include any OFED backport headers in all compile commands
454 # NOTE: this does only include the backport paths, not the OFED headers
455 # adding the OFED headers is done in the lnet portion
456 AC_DEFUN([LB_CONFIG_OFED_BACKPORTS],
457 [AC_MSG_CHECKING([whether to use any OFED backport headers])
460 AC_HELP_STRING([--with-o2ib=path],
461 [build o2iblnd against path]),
464 yes) O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
469 *) O2IBPATHS=$with_o2ib
474 O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
477 if test $ENABLEO2IB -eq 0; then
481 for O2IBPATH in $O2IBPATHS; do
482 if test \( -f ${O2IBPATH}/include/rdma/rdma_cm.h -a \
483 -f ${O2IBPATH}/include/rdma/ib_cm.h -a \
484 -f ${O2IBPATH}/include/rdma/ib_verbs.h -a \
485 -f ${O2IBPATH}/include/rdma/ib_fmr_pool.h \); then
490 if ! $o2ib_found; then
494 2) AC_MSG_ERROR([kernel OpenIB gen2 headers not present]);;
495 3) AC_MSG_ERROR([bad --with-o2ib path]);;
496 *) AC_MSG_ERROR([internal error]);;
499 if test -f $O2IBPATH/config.mk; then
500 . $O2IBPATH/config.mk
501 elif test -f $O2IBPATH/ofed_patch.mk; then
502 . $O2IBPATH/ofed_patch.mk
504 if test -n "$BACKPORT_INCLUDES"; then
505 OFED_BACKPORT_PATH=`echo $BACKPORT_INCLUDES | sed "s#.*/src/ofa_kernel/#$O2IBPATH/#"`
506 EXTRA_LNET_INCLUDE="-I$OFED_BACKPORT_PATH $EXTRA_LNET_INCLUDE"
516 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
517 # so we test if request_module is implemented or not
518 AC_DEFUN([LC_MODULE_LOADING],
519 [AC_MSG_CHECKING([if kernel module loading is possible])
521 #include <linux/kmod.h>
523 int myretval=ENOSYS ;
526 $makerule LUSTRE_KERNEL_TEST=conftest.i
528 grep request_module build/conftest.i | grep -v `grep "int myretval=" build/conftest.i | cut -d= -f2 | cut -d" " -f1` >/dev/null
531 AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
532 [kernel module loading is possible])
536 AC_MSG_WARN([Kernel module loading support is highly recommended.])
542 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
543 # so we test if request_module is implemented or not
544 AC_DEFUN([LC_MODULE_LOADING],
545 [AC_MSG_CHECKING([if kernel module loading is possible])
547 #include <linux/kmod.h>
549 int myretval=ENOSYS ;
552 $makerule LUSTRE_KERNEL_TEST=conftest.i
554 grep request_module build/conftest.i | grep -v `grep "int myretval=" build/conftest.i | cut -d= -f2 | cut -d" " -f1` >/dev/null
557 AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
558 [kernel module loading is possible])
562 AC_MSG_WARN([Kernel module loading support is highly recommended.])
572 AC_DEFUN([LB_PROG_LINUX],
578 LB_LINUX_CONFIG([MODULES],[],[
579 AC_MSG_ERROR([module support is required to build Lustre kernel modules.])
582 LB_LINUX_CONFIG([MODVERSIONS])
584 LB_LINUX_CONFIG([KALLSYMS],[],[
585 if test "x$ARCH_UM" = "x" ; then
586 AC_MSG_ERROR([Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.])
593 #LB_LINUX_CONFIG_BIG_STACK
595 # it's ugly to be doing anything with OFED outside of the lnet module, but
596 # this has to be done here so that the backports path is set before all of
597 # the LN_PROG_LINUX checks are done
598 LB_CONFIG_OFED_BACKPORTS
602 # LB_LINUX_CONDITIONALS
604 # AM_CONDITIONALS for linux
606 AC_DEFUN([LB_LINUX_CONDITIONALS],
607 [AM_CONDITIONAL(LINUX25, test x$linux25 = xyes)
612 # LB_CHECK_SYMBOL_EXPORT
613 # check symbol exported or not
615 # $2 - file(s) for find.
619 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers
621 AC_DEFUN([LB_CHECK_SYMBOL_EXPORT],
622 [AC_MSG_CHECKING([if Linux was built with symbol $1 exported])
623 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/$SYMVERFILE 2>/dev/null
625 if test $rc -ne 0; then
628 grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null
630 if test $rc -eq 0; then
635 if test $export -eq 0; then
649 # Like AC_CHECK_HEADER but checks for a kernel-space header
651 m4_define([LB_CHECK_LINUX_HEADER],
652 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])dnl
653 AC_CACHE_CHECK([for $1], ac_Header,
654 [LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
656 [test -s build/conftest.o],
657 [AS_VAR_SET(ac_Header, [yes])],
658 [AS_VAR_SET(ac_Header, [no])])])
659 AS_IF([test AS_VAR_GET(ac_Header) = yes], [$2], [$3])[]dnl
660 AS_VAR_POPDEF([ac_Header])dnl