4 # Set things accordingly for a linux kernel
6 AC_DEFUN([LB_LINUX_VERSION],[
9 MODULE_TARGET="SUBDIRS"
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],
19 makerule="_module_$makerule"
21 LB_LINUX_TRY_MAKE([],[],
22 [$makerule LUSTRE_KERNEL_TEST=conftest.i],
23 [test -s build/conftest.i],
27 AC_MSG_ERROR([unknown; check config.log for details])
31 AC_SUBST(MODULE_TARGET)
38 # get the release version of linux
40 AC_DEFUN([LB_LINUX_RELEASE],
42 rm -f build/conftest.i
43 AC_MSG_CHECKING([for Linux release])
44 if test -s $LINUX_OBJ/include/$AUTOCONF_HDIR/utsrelease.h ; then
45 LINUXRELEASEHEADER=$AUTOCONF_HDIR/utsrelease.h
47 LINUXRELEASEHEADER=linux/version.h
50 #include <$LINUXRELEASEHEADER>
53 LINUXRELEASE=UTS_RELEASE;
55 $makerule LUSTRE_KERNEL_TEST=conftest.i
57 test -s build/conftest.i
59 # LINUXRELEASE="UTS_RELEASE"
60 eval $(grep "LINUXRELEASE=" build/conftest.i)
62 AC_MSG_RESULT([unknown])
63 AC_MSG_ERROR([Could not preprocess test program. Consult config.log for details.])
65 rm -f build/conftest.i
66 if test x$LINUXRELEASE = x ; then
67 AC_MSG_RESULT([unknown])
68 AC_MSG_ERROR([Could not determine Linux release version from linux/version.h.])
70 AC_MSG_RESULT([$LINUXRELEASE])
71 AC_SUBST(LINUXRELEASE)
73 moduledir='/lib/modules/'$LINUXRELEASE/updates/kernel
76 modulefsdir='$(moduledir)/fs/$(PACKAGE)'
79 modulenetdir='$(moduledir)/net/$(PACKAGE)'
80 AC_SUBST(modulenetdir)
82 # ------------ RELEASE --------------------------------
83 AC_MSG_CHECKING([for Lustre release])
84 AC_ARG_WITH([release],
85 AC_HELP_STRING([--with-release=string],
86 [set the release string (default=$kvers_YYYYMMDDhhmm)]),
89 if test -n "$DOWNSTREAM_RELEASE"; then
90 RELEASE="${DOWNSTREAM_RELEASE}_"
92 RELEASE="$RELEASE`echo ${LINUXRELEASE} | tr '-' '_'`_$BUILDID")
93 AC_MSG_RESULT($RELEASE)
96 # check is redhat/suse kernels
97 AC_MSG_CHECKING([that RedHat kernel])
98 LB_LINUX_TRY_COMPILE([
99 #include <linux/version.h>
101 #ifndef RHEL_RELEASE_CODE
102 #error "not redhat kernel"
111 LB_LINUX_CONFIG([SUSE_KERNEL],[SUSE_KERNEL="yes"],[])
115 # LB_ARG_REPLACE_PATH(PACKAGE, PATH)
116 AC_DEFUN([LB_ARG_REPLACE_PATH],[
118 eval "set x $ac_configure_args"
126 arg=$(printf %s\n ["$arg"] | \
127 sed "s/'/'\\\\\\\\''/g")
130 dnl AS_VAR_APPEND([new_configure_args], [" '$arg'"])
131 new_configure_args="$new_configure_args \"$arg\""
133 ac_configure_args=$new_configure_args
136 # this is the work-horse of the next function
137 AC_DEFUN([__LB_ARG_CANON_PATH], [
138 [$3]=$(readlink -f $with_$2)
139 LB_ARG_REPLACE_PATH([$1], $[$3])
142 # a front-end for the above function that transforms - and . in the
143 # PACKAGE portion of --with-PACKAGE into _ suitable for variable names
144 AC_DEFUN([LB_ARG_CANON_PATH], [
145 __LB_ARG_CANON_PATH([$1], m4_translit([$1], [-.], [__]), [$2])
152 # Find paths for linux, handling kernel-source rpms
154 AC_DEFUN([LB_LINUX_PATH],
155 [# prep some default values
156 for DEFAULT_LINUX in /lib/modules/$(uname -r)/{source,build} /usr/src/linux; do
157 if readlink -q -e $DEFAULT_LINUX; then
161 if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then
162 PATHS="/lib/modules/$(uname -r)/build"
164 PATHS+=" $DEFAULT_LINUX"
165 for DEFAULT_LINUX_OBJ in $PATHS; do
166 if readlink -q -e $DEFAULT_LINUX_OBJ; then
170 AC_MSG_CHECKING([for Linux sources])
172 AC_HELP_STRING([--with-linux=path],
173 [set path to Linux source (default=/lib/modules/$(uname -r)/{source,build},/usr/src/linux)]),
174 [LB_ARG_CANON_PATH([linux], [LINUX])
175 DEFAULT_LINUX_OBJ=$LINUX],
176 [LINUX=$DEFAULT_LINUX])
177 AC_MSG_RESULT([$LINUX])
180 # -------- check for linux --------
181 LB_CHECK_FILE([$LINUX],[],
182 [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
184 # -------- linux objects (for 2.6) --
185 AC_MSG_CHECKING([for Linux objects dir])
186 AC_ARG_WITH([linux-obj],
187 AC_HELP_STRING([--with-linux-obj=path],
188 [set path to Linux objects dir (default=/lib/modules/$(uname -r)/build,/usr/src/linux)]),
189 [LB_ARG_CANON_PATH([linux-obj], [LINUX_OBJ])],
190 [LINUX_OBJ=$DEFAULT_LINUX_OBJ])
192 AC_MSG_RESULT([$LINUX_OBJ])
195 # -------- check for .config --------
196 AC_ARG_WITH([linux-config],
197 [AC_HELP_STRING([--with-linux-config=path],
198 [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
199 [LB_ARG_CANON_PATH([linux-config], [LINUX_CONFIG])],
200 [LINUX_CONFIG=$LINUX_OBJ/.config])
201 AC_SUBST(LINUX_CONFIG)
203 LB_CHECK_FILE([/boot/kernel.h],
204 [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
205 [LB_CHECK_FILE([/var/adm/running-kernel.h],
206 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
208 AC_ARG_WITH([kernel-source-header],
209 AC_HELP_STRING([--with-kernel-source-header=path],
210 [Use a different kernel version header. Consult build/README.kernel-source for details.]),
211 [LB_ARG_CANON_PATH([kernel-source-header], [KERNEL_SOURCE_HEADER])])
213 # ------------ .config exists ----------------
214 LB_CHECK_FILE([$LINUX_CONFIG],[],
215 [AC_MSG_ERROR([Kernel config could not be found. If you are building from a kernel-source rpm consult build/README.kernel-source])])
217 # ----------- make dep run? ------------------
218 # at 2.6.19 # $LINUX/include/linux/config.h is removed
219 # and at more old has only one line
220 # include <autoconf.h>
221 LB_CHECK_FILE([$LINUX_OBJ/include/generated/autoconf.h],[AUTOCONF_HDIR=generated],
222 [LB_CHECK_FILE([$LINUX_OBJ/include/linux/autoconf.h],[AUTOCONF_HDIR=linux],
223 [AC_MSG_ERROR([Run make config in $LINUX.])])])
224 AC_SUBST(AUTOCONF_HDIR)
225 LB_CHECK_FILE([$LINUX_OBJ/include/linux/version.h],[],
226 [AC_MSG_ERROR([Run make config in $LINUX.])])
228 # ----------- kconfig.h exists ---------------
229 # kernel 3.1, $LINUX/include/linux/kconfig.h is added
230 # see kernel commit 2a11c8ea20bf850b3a2c60db8c2e7497d28aba99
231 LB_CHECK_FILE([$LINUX_OBJ/include/linux/kconfig.h],
232 [CONFIG_INCLUDE=include/linux/kconfig.h],
233 [CONFIG_INCLUDE=include/$AUTOCONF_HDIR/autoconf.h])
234 AC_SUBST(CONFIG_INCLUDE)
236 # ------------ rhconfig.h includes runtime-generated bits --
237 # red hat kernel-source checks
239 # we know this exists after the check above. if the user
240 # tarred up the tree and ran make dep etc. in it, then
241 # version.h gets overwritten with a standard linux one.
243 if grep rhconfig $LINUX_OBJ/include/linux/version.h >/dev/null ; then
244 # This is a clean kernel-source tree, we need to
245 # enable extensive workarounds to get this to build
247 LB_CHECK_FILE([$KERNEL_SOURCE_HEADER],
248 [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
249 AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
250 AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
251 AC_MSG_WARN([Consult build/README.kernel-source for details.])
253 [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found. Consult build/README.kernel-source for details.])])
254 EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
257 # this is needed before we can build modules
260 # --- check that we can build modules at all
261 AC_MSG_CHECKING([that modules can be built at all])
262 LB_LINUX_TRY_COMPILE([],[],[
266 AC_MSG_WARN([Consult config.log for details.])
267 AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult build/README.kernel-source])
268 AC_MSG_ERROR([Kernel modules cannot be built.])
272 ]) # end of LB_LINUX_PATH
274 # LB_LINUX_SYMVERFILE
275 # SLES 9 uses a different name for this file - unsure about vanilla kernels
276 # around this version, but it matters for servers only.
277 AC_DEFUN([LB_LINUX_SYMVERFILE],
278 [AC_MSG_CHECKING([name of module symbol version file])
279 if grep -q Modules.symvers $LINUX/scripts/Makefile.modpost ; then
280 SYMVERFILE=Modules.symvers
282 SYMVERFILE=Module.symvers
284 AC_MSG_RESULT($SYMVERFILE)
288 # these are like AC_TRY_COMPILE, but try to build modules against the
289 # kernel, inside the build directory
291 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
292 # --------------------------------------
293 m4_define([LB_LANG_PROGRAM],
295 #include <linux/kernel.h>
300 dnl Do *not* indent the following line: there may be CPP directives.
301 dnl Don't move the `;' right after for the same reason.
308 # LB_LINUX_COMPILE_IFELSE
310 # like AC_COMPILE_IFELSE
312 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
313 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
314 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
315 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/powerpc64/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" $MODULE_TARGET=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
317 [_AC_MSG_LOG_CONFTEST
318 m4_ifvaln([$5],[$5])dnl])
319 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
325 # Determine the kernel's idea of the current architecture
327 AC_DEFUN([LB_LINUX_ARCH],
328 [AC_MSG_CHECKING([Linux kernel architecture])
329 AS_IF([rm -f $PWD/build/arch
330 make -s --no-print-directory echoarch -f $PWD/build/Makefile \
331 LUSTRE_LINUX_CONFIG=$LINUX_CONFIG -C $LINUX \
332 ARCHFILE=$PWD/build/arch && LINUX_ARCH=`cat $PWD/build/arch`],
333 [AC_MSG_RESULT([$LINUX_ARCH])],
334 [AC_MSG_ERROR([Could not determine the kernel architecture.])])
338 # LB_LINUX_TRY_COMPILE
340 # like AC_TRY_COMPILE
342 AC_DEFUN([LB_LINUX_TRY_COMPILE],
343 [LB_LINUX_COMPILE_IFELSE(
344 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
346 [test -s build/conftest.o],
352 # check if a given config option is defined
354 AC_DEFUN([LB_LINUX_CONFIG],[
355 AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
356 LB_LINUX_TRY_COMPILE([
357 #include <$AUTOCONF_HDIR/autoconf.h>
360 #error CONFIG_$1 not #defined
374 # check if a given config option is builtin or as module
376 AC_DEFUN([LB_LINUX_CONFIG_IM],[
377 AC_MSG_CHECKING([if Linux was built with CONFIG_$1 in or as module])
378 LB_LINUX_TRY_COMPILE([
379 #include <$AUTOCONF_HDIR/autoconf.h>
381 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
382 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
396 # like LB_LINUX_TRY_COMPILE, but with different arguments
398 AC_DEFUN([LB_LINUX_TRY_MAKE],
399 [LB_LINUX_COMPILE_IFELSE(
400 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
401 [$3], [$4], [$5], [$6]
406 # LB_CONFIG_COMPAT_RDMA
408 AC_DEFUN([LB_CONFIG_COMPAT_RDMA],
409 [AC_MSG_CHECKING([whether to use Compat RDMA])
412 AC_HELP_STRING([--with-o2ib=path],
413 [build o2iblnd against path]),
416 yes) O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
421 *) O2IBPATHS=$with_o2ib
426 O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
429 if test $ENABLEO2IB -eq 0; then
433 for O2IBPATH in $O2IBPATHS; do
434 if test \( -f ${O2IBPATH}/include/rdma/rdma_cm.h -a \
435 -f ${O2IBPATH}/include/rdma/ib_cm.h -a \
436 -f ${O2IBPATH}/include/rdma/ib_verbs.h -a \
437 -f ${O2IBPATH}/include/rdma/ib_fmr_pool.h \); then
442 compatrdma_found=false
444 if test \( -f ${O2IBPATH}/include/linux/compat-2.6.h \); then
445 compatrdma_found=true
447 AC_DEFINE(HAVE_COMPAT_RDMA, 1, [compat rdma found])
456 # LB_CONFIG_OFED_BACKPORTS
458 # include any OFED backport headers in all compile commands
459 # NOTE: this does only include the backport paths, not the OFED headers
460 # adding the OFED headers is done in the lnet portion
461 AC_DEFUN([LB_CONFIG_OFED_BACKPORTS],
462 [AC_MSG_CHECKING([whether to use any OFED backport headers])
463 if test $ENABLEO2IB -eq 0; then
466 if ! $o2ib_found; then
470 2) AC_MSG_ERROR([kernel OpenIB gen2 headers not present]);;
471 3) AC_MSG_ERROR([bad --with-o2ib path]);;
472 *) AC_MSG_ERROR([internal error]);;
475 if ! $compatrdma_found; then
476 if test -f $O2IBPATH/config.mk; then
477 . $O2IBPATH/config.mk
478 elif test -f $O2IBPATH/ofed_patch.mk; then
479 . $O2IBPATH/ofed_patch.mk
482 if test -n "$BACKPORT_INCLUDES"; then
483 OFED_BACKPORT_PATH="$O2IBPATH/${BACKPORT_INCLUDES/*\/kernel_addons/kernel_addons}/"
484 EXTRA_LNET_INCLUDE="-I$OFED_BACKPORT_PATH $EXTRA_LNET_INCLUDE"
494 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
495 # so we test if request_module is implemented or not
496 AC_DEFUN([LC_MODULE_LOADING],
497 [AC_MSG_CHECKING([if kernel module loading is possible])
499 #include <linux/kmod.h>
501 int myretval=ENOSYS ;
504 $makerule LUSTRE_KERNEL_TEST=conftest.i
506 grep request_module build/conftest.i |dnl
507 grep -v `grep "int myretval=" build/conftest.i |dnl
508 cut -d= -f2 | cut -d" " -f1`dnl
512 AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
513 [kernel module loading is possible])
517 AC_MSG_WARN([Kernel module loading support is highly recommended.])
527 AC_DEFUN([LB_PROG_LINUX],
533 LB_LINUX_CONFIG([MODULES],[],[
534 AC_MSG_ERROR([module support is required to build Lustre kernel modules.])
537 LB_LINUX_CONFIG([MODVERSIONS])
539 LB_LINUX_CONFIG([KALLSYMS],[],[
540 AC_MSG_ERROR([Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.])
546 LB_CONFIG_COMPAT_RDMA
548 # it's ugly to be doing anything with OFED outside of the lnet module, but
549 # this has to be done here so that the backports path is set before all of
550 # the LN_PROG_LINUX checks are done
551 LB_CONFIG_OFED_BACKPORTS
555 # LB_CHECK_SYMBOL_EXPORT
556 # check symbol exported or not
558 # $2 - file(s) for find.
562 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers
564 AC_DEFUN([LB_CHECK_SYMBOL_EXPORT],
565 [AC_MSG_CHECKING([if Linux was built with symbol $1 exported])
566 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/$SYMVERFILE 2>/dev/null
568 if test $rc -ne 0; then
571 grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null
573 if test $rc -eq 0; then
578 if test $export -eq 0; then
592 # Like AC_CHECK_HEADER but checks for a kernel-space header
594 m4_define([LB_CHECK_LINUX_HEADER],
595 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])dnl
596 AC_CACHE_CHECK([for $1], ac_Header,
597 [LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
599 [test -s build/conftest.o],
600 [AS_VAR_SET(ac_Header, [yes])],
601 [AS_VAR_SET(ac_Header, [no])])])
602 AS_IF([test AS_VAR_GET(ac_Header) = yes], [$2], [$3])[]dnl
603 AS_VAR_POPDEF([ac_Header])dnl
609 # Determine if the target is a dpkg system or rpm
611 AC_DEFUN([LB_USES_DPKG],
613 AC_MSG_CHECKING([if this distro uses dpkg])
614 case `lsb_release -i -s 2>/dev/null` in