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>
108 #error "not redhat kernel"
117 AC_MSG_CHECKING([that SuSe kernel])
118 LB_LINUX_TRY_COMPILE([
119 #include <linux/version.h>
121 #ifndef SLE_VERSION_CODE
122 #error "not sles kernel"
137 # Find paths for linux, handling kernel-source rpms
139 AC_DEFUN([LB_LINUX_PATH],
140 [AC_MSG_CHECKING([for Linux sources])
142 AC_HELP_STRING([--with-linux=path],
143 [set path to Linux source (default=/usr/src/linux)]),
145 [LINUX=/usr/src/linux])
146 AC_MSG_RESULT([$LINUX])
149 # -------- check for linux --------
150 LB_CHECK_FILE([$LINUX],[],
151 [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
153 # -------- linux objects (for 2.6) --
154 AC_MSG_CHECKING([for Linux objects dir])
155 AC_ARG_WITH([linux-obj],
156 AC_HELP_STRING([--with-linux-obj=path],
157 [set path to Linux objects dir (default=$LINUX)]),
158 [LINUX_OBJ=$with_linux_obj],
160 AC_MSG_RESULT([$LINUX_OBJ])
163 # -------- check for .config --------
164 AC_ARG_WITH([linux-config],
165 [AC_HELP_STRING([--with-linux-config=path],
166 [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
167 [LINUX_CONFIG=$with_linux_config],
168 [LINUX_CONFIG=$LINUX_OBJ/.config])
169 AC_SUBST(LINUX_CONFIG)
171 LB_CHECK_FILE([/boot/kernel.h],
172 [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
173 [LB_CHECK_FILE([/var/adm/running-kernel.h],
174 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
176 AC_ARG_WITH([kernel-source-header],
177 AC_HELP_STRING([--with-kernel-source-header=path],
178 [Use a different kernel version header. Consult build/README.kernel-source for details.]),
179 [KERNEL_SOURCE_HEADER=$with_kernel_source_header])
181 # ------------ .config exists ----------------
182 LB_CHECK_FILE([$LINUX_CONFIG],[],
183 [AC_MSG_ERROR([Kernel config could not be found. If you are building from a kernel-source rpm consult build/README.kernel-source])])
185 # ----------- make dep run? ------------------
186 # at 2.6.19 # $LINUX/include/linux/config.h is removed
187 # and at more old has only one line
188 # include <autoconf.h>
189 LB_CHECK_FILES([$LINUX_OBJ/include/linux/autoconf.h
190 $LINUX_OBJ/include/linux/version.h
192 [AC_MSG_ERROR([Run make config in $LINUX.])])
194 # ------------ rhconfig.h includes runtime-generated bits --
195 # red hat kernel-source checks
197 # we know this exists after the check above. if the user
198 # tarred up the tree and ran make dep etc. in it, then
199 # version.h gets overwritten with a standard linux one.
201 if grep rhconfig $LINUX_OBJ/include/linux/version.h >/dev/null ; then
202 # This is a clean kernel-source tree, we need to
203 # enable extensive workarounds to get this to build
205 LB_CHECK_FILE([$KERNEL_SOURCE_HEADER],
206 [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
207 AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
208 AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
209 AC_MSG_WARN([Consult build/README.kernel-source for details.])
211 [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found. Consult build/README.kernel-source for details.])])
212 EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
215 # this is needed before we can build modules
219 # --- check that we can build modules at all
220 AC_MSG_CHECKING([that modules can be built at all])
221 LB_LINUX_TRY_COMPILE([],[],[
225 AC_MSG_WARN([Consult config.log for details.])
226 AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult build/README.kernel-source])
227 AC_MSG_ERROR([Kernel modules cannot be built.])
231 ]) # end of LB_LINUX_PATH
233 # LB_LINUX_SYMVERFILE
234 # SLES 9 uses a different name for this file - unsure about vanilla kernels
235 # around this version, but it matters for servers only.
236 AC_DEFUN([LB_LINUX_SYMVERFILE],
237 [AC_MSG_CHECKING([name of module symbol version file])
238 if grep -q Modules.symvers $LINUX/scripts/Makefile.modpost ; then
239 SYMVERFILE=Modules.symvers
241 SYMVERFILE=Module.symvers
243 AC_MSG_RESULT($SYMVERFILE)
251 # Find modpost and check it
253 AC_DEFUN([LB_LINUX_MODPOST],
255 # Find the modpost utility
256 LB_CHECK_FILE([$LINUX_OBJ/scripts/mod/modpost],
257 [MODPOST=$LINUX_OBJ/scripts/mod/modpost],
258 [LB_CHECK_FILE([$LINUX_OBJ/scripts/modpost],
259 [MODPOST=$LINUX_OBJ/scripts/modpost],
260 AC_MSG_ERROR([modpost not found.])
266 AC_MSG_CHECKING([if modpost can be run])
270 AC_MSG_ERROR([modpost can not be run.])
273 # Check if modpost supports (and therefore requires) -m
274 AC_MSG_CHECKING([if modpost supports -m])
275 if $MODPOST -m 2>/dev/null ; then
282 AC_SUBST(MODPOST_ARGS)
288 # check for a uml kernel
290 AC_DEFUN([LB_LINUX_UML],
294 AC_MSG_CHECKING([if you are running user mode linux for $target_cpu])
295 if test -e $LINUX/include/asm-um ; then
296 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
298 # see notes in Rules.in
302 AC_MSG_RESULT([no (asm doesn't point at asm-um)])
305 AC_MSG_RESULT([no (asm-um missing)])
311 # these are like AC_TRY_COMPILE, but try to build modules against the
312 # kernel, inside the build directory
317 # create a conftest.c file
319 AC_DEFUN([LB_LINUX_CONFTEST],
320 [cat >conftest.c <<_ACEOF
326 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
327 # --------------------------------------
328 m4_define([LB_LANG_PROGRAM],
333 dnl Do *not* indent the following line: there may be CPP directives.
334 dnl Don't move the `;' right after for the same reason.
341 # LB_LINUX_COMPILE_IFELSE
343 # like AC_COMPILE_IFELSE
345 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
346 [m4_ifvaln([$1], [LB_LINUX_CONFTEST([$1])])dnl
347 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
348 test -n "$LD" && LDOPT="LD=$LD"
349 AS_IF([AC_TRY_COMMAND(cp conftest.c build && make -d [$2] $LDOPT CC="$CC" -f $PWD/build/Makefile LUSTRE_LINUX_CONFIG=$LINUX_CONFIG LINUXINCLUDE="$EXTRA_LNET_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])],
351 [_AC_MSG_LOG_CONFTEST
352 m4_ifvaln([$5],[$5])dnl])dnl
353 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
359 # Determine the kernel's idea of the current architecture
361 AC_DEFUN([LB_LINUX_ARCH],
362 [AC_MSG_CHECKING([Linux kernel architecture])
363 AS_IF([rm -f $PWD/build/arch
364 make -s --no-print-directory echoarch -f $PWD/build/Makefile \
365 LUSTRE_LINUX_CONFIG=$LINUX_CONFIG -C $LINUX_OBJ $ARCH_UM \
366 ARCHFILE=$PWD/build/arch && LINUX_ARCH=`cat $PWD/build/arch`],
367 [AC_MSG_RESULT([$LINUX_ARCH])],
368 [AC_MSG_ERROR([Could not determine the kernel architecture.])])
372 # LB_LINUX_TRY_COMPILE
374 # like AC_TRY_COMPILE
376 AC_DEFUN([LB_LINUX_TRY_COMPILE],
377 [LB_LINUX_COMPILE_IFELSE(
378 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
380 [test -s build/conftest.o],
386 # check if a given config option is defined
388 AC_DEFUN([LB_LINUX_CONFIG],
389 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
390 LB_LINUX_TRY_COMPILE([
391 #include <linux/autoconf.h>
394 #error CONFIG_$1 not #defined
408 # check if a given config option is builtin or as module
410 AC_DEFUN([LB_LINUX_CONFIG_IM],
411 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1 in or as module])
412 LB_LINUX_TRY_COMPILE([
413 #include <linux/autoconf.h>
415 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
416 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
430 # like LB_LINUX_TRY_COMPILE, but with different arguments
432 AC_DEFUN([LB_LINUX_TRY_MAKE],
433 [LB_LINUX_COMPILE_IFELSE([AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])], [$3], [$4], [$5], [$6])])
436 # LB_LINUX_CONFIG_BIG_STACK
438 # check for big stack patch
440 AC_DEFUN([LB_LINUX_CONFIG_BIG_STACK],
441 [if test "x$ARCH_UM" = "x" -a "x$linux25" = "xno" ; then
444 LB_LINUX_CONFIG([STACK_SIZE_16KB],[],[
445 LB_LINUX_CONFIG([STACK_SIZE_32KB],[],[
446 LB_LINUX_CONFIG([STACK_SIZE_64KB],[],[
447 AC_MSG_ERROR([Lustre requires that Linux is configured with at least a 16KB stack.])
461 AC_DEFUN([LB_PROG_LINUX],
467 LB_LINUX_CONFIG([MODULES],[],[
468 AC_MSG_ERROR([module support is required to build Lustre kernel modules.])
471 LB_LINUX_CONFIG([MODVERSIONS])
473 LB_LINUX_CONFIG([PREEMPT],[
474 AC_MSG_ERROR([Lustre does not support kernels with preempt enabled.])
477 LB_LINUX_CONFIG([KALLSYMS],[],[
478 if test "x$ARCH_UM" = "x" ; then
479 AC_MSG_ERROR([Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.])
483 LB_LINUX_CONFIG([KMOD],[],[
485 AC_MSG_WARN([Kernel module loading support is highly recommended.])
489 #LB_LINUX_CONFIG_BIG_STACK
494 # LB_LINUX_CONDITIONALS
496 # AM_CONDITIONALS for linux
498 AC_DEFUN([LB_LINUX_CONDITIONALS],
499 [AM_CONDITIONAL(LINUX25, test x$linux25 = xyes)
504 # LB_CHECK_SYMBOL_EXPORT
505 # check symbol exported or not
507 # $2 - file(s) for find.
511 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers
513 AC_DEFUN([LB_CHECK_SYMBOL_EXPORT],
514 [AC_MSG_CHECKING([if Linux was built with symbol $1 is exported])
515 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/$SYMVERFILE 2>/dev/null
517 if test $rc -ne 0; then
520 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
522 if test $rc -eq 0; then
527 if test $export -eq 0; then