4 # Set things accordingly for a linux kernel
6 AC_DEFUN([LB_LINUX_VERSION], [
11 AC_CACHE_CHECK([for external module build target], lb_cv_module_target, [
12 lb_cv_module_target=""
13 MODULE_TARGET="SUBDIRS"
14 rm -f build/conftest.i
15 LB_LINUX_TRY_MAKE([], [],
16 [$makerule LUSTRE_KERNEL_TEST=conftest.i],
17 [test -s build/conftest.i],
18 [lb_cv_module_target="SUBDIRS"], [
20 makerule="_module_$PWD/build"
21 LB_LINUX_TRY_MAKE([], [],
22 [$makerule LUSTRE_KERNEL_TEST=conftest.i],
23 [test -s build/conftest.i],
24 [lb_cv_module_target="M"], [
25 AC_MSG_ERROR([unknown; check config.log for details])
29 AS_IF([test -z "$lb_cv_module_target"],
30 [AC_MSG_ERROR([unknown external module build target])],
31 [test "x$lb_cv_module_target" = "xM"],
32 [makerule="_module_$PWD/build"])
33 MODULE_TARGET=$lb_cv_module_target
34 AC_SUBST(MODULE_TARGET)
40 # Determine the Linux kernel version string from the utsrelease
42 AC_DEFUN([LB_LINUX_UTSRELEASE], [
43 AC_CACHE_CHECK([for Linux kernel utsrelease], lb_cv_utsrelease, [
45 utsrelease1=$LINUX_OBJ/include/generated/utsrelease.h
46 utsrelease2=$LINUX_OBJ/include/linux/utsrelease.h
47 utsrelease3=$LINUX_OBJ/include/linux/version.h
48 AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1],
49 [utsrelease=$utsrelease1],
50 [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2],
51 [utsrelease=$utsrelease2],
52 [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3],
53 [utsrelease=$utsrelease3])
54 AS_IF([test -n "$utsrelease"],
55 [lb_cv_utsrelease=$(awk -F \" '/ UTS_RELEASE / { print [$]2 }' $utsrelease)],
58 Cannot find UTS_RELEASE definition.
60 This is often provided by the kernel-devel package.
64 AS_IF([test -z "$lb_cv_utsrelease"],
65 [AC_MSG_ERROR([Cannot determine Linux kernel version.])])
66 LINUXRELEASE=$lb_cv_utsrelease
67 AC_SUBST(LINUXRELEASE)
73 # get the release version of linux
75 AC_DEFUN([LB_LINUX_RELEASE], [
78 # Define default states
83 # And if any of the above kernels has been detected yet
86 # Check for RedHat first (no need to check KERNEL_FOUND
87 AC_CACHE_CHECK([for RedHat kernel release number], lb_cv_rhel_kernel_version, [
88 lb_cv_rhel_kernel_version=""
89 AS_IF([fgrep -q RHEL_RELEASE $LINUX_OBJ/include/$VERSION_HDIR/version.h], [
90 lb_cv_rhel_kernel_version=$(awk '/ RHEL_MAJOR / { print [$]3 }' \
91 $LINUX_OBJ/include/$VERSION_HDIR/version.h)$(awk \
92 '/ RHEL_MINOR / { print [$]3 }' \
93 $LINUX_OBJ/include/$VERSION_HDIR/version.h)
96 AS_IF([test -n "$lb_cv_rhel_kernel_version"], [
99 RHEL_RELEASE_NO=$lb_cv_rhel_kernel_version
103 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
104 LB_CHECK_CONFIG([SUSE_KERNEL], [
111 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
112 AC_CACHE_CHECK([for Ubuntu kernel signature], lb_cv_ubuntu_kernel_sig, [
113 lb_cv_ubuntu_kernel_sig="no"
114 AS_IF([fgrep -q "CONFIG_VERSION_SIGNATURE \"Ubuntu" $LINUX_OBJ/include/generated/autoconf.h], [
115 lb_cv_ubuntu_kernel_sig="yes"
118 AS_IF([test "x$lb_cv_ubuntu_kernel_sig" = "xyes"], [
125 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
126 AC_CACHE_CHECK([for Debian kernel signature], lb_cv_debian_kernel_sig, [
127 lb_cv_debian_kernel_sig="no"
128 AS_IF([grep -q "LINUX_PACKAGE_ID\s*\"\s*Debian" $LINUX_OBJ/include/generated/package.h], [
129 lb_cv_debian_kernel_sig="yes"
132 AS_IF([test "x$lb_cv_debian_kernel_sig" = "xyes"], [
138 # If still no kernel was found, a warning is issued
139 AS_IF([test "x$KERNEL_FOUND" = "xno"], [
140 AC_MSG_WARN([Kernel Distro seems to be neither RedHat, SuSE, Ubuntu nor Debian])
143 AC_MSG_CHECKING([for Linux kernel module package directory])
144 AC_ARG_WITH([kmp-moddir],
145 AC_HELP_STRING([--with-kmp-moddir=string],
146 [set the kmod updates or extra directory]),
149 AS_IF([test x$RHEL_KERNEL = xyes], [KMP_MODDIR="extra/kernel"],
150 [test x$SUSE_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
151 [test x$UBUNTU_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
152 [test x$DEBIAN_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
153 [AC_MSG_WARN([Kernel Distro seems to be neither RedHat, SuSE, Ubuntu nor Debian])]
155 IN_KERNEL="${PACKAGE}"])
156 AC_MSG_RESULT($KMP_MODDIR)
158 moduledir="/lib/modules/${LINUXRELEASE}/${KMP_MODDIR}"
160 modulefsdir="${moduledir}/fs/${IN_KERNEL}"
161 AC_SUBST(modulefsdir)
163 modulenetdir="${moduledir}/net/${IN_KERNEL}"
164 AC_SUBST(modulenetdir)
170 # LB_LINUX_SYMVERFILE
172 # SLES 9 uses a different name for this file - unsure about vanilla kernels
173 # around this version, but it matters for servers only.
174 AC_DEFUN([LB_LINUX_SYMVERFILE], [
175 AC_CACHE_CHECK([for the name of module symbol version file], lb_cv_module_symvers, [
176 AS_IF([grep -q Modules.symvers $LINUX/scripts/Makefile.modpost],
177 [lb_cv_module_symvers=Modules.symvers],
178 [lb_cv_module_symvers=Module.symvers])
180 SYMVERFILE=$lb_cv_module_symvers
185 # LB_ARG_REPLACE_PATH(PACKAGE, PATH)
187 AC_DEFUN([LB_ARG_REPLACE_PATH], [
189 eval set -- $ac_configure_args
193 arg=--with-[$1]=[$2] ;;
195 arg=$(printf %s\n ["$arg"] | sed "s/'/'\\\\\\\\''/g") ;;
197 dnl AS_VAR_APPEND([new_configure_args], [" '$arg'"])
198 new_configure_args="$new_configure_args '$arg'"
200 ac_configure_args=$new_configure_args
204 # __LB_ARG_CANON_PATH
206 # this is the work-horse of the next function
208 AC_DEFUN([__LB_ARG_CANON_PATH], [
209 [$3]=$(readlink -f $with_$2)
210 LB_ARG_REPLACE_PATH([$1], $[$3])
216 # a front-end for the above function that transforms - and . in the
217 # PACKAGE portion of --with-PACKAGE into _ suitable for variable names
219 AC_DEFUN([LB_ARG_CANON_PATH], [
220 __LB_ARG_CANON_PATH([$1], m4_translit([$1], [-.], [__]), [$2])
226 # Find paths for linux, handling kernel-source rpms
228 AC_DEFUN([LB_LINUX_PATH], [
229 for DEFAULT_LINUX in /usr/src/linux-source-* /lib/modules/$(uname -r)/{source,build} /usr/src/linux $(find /usr/src/kernels/ -maxdepth 1 -name @<:@0-9@:>@\* | xargs -r ls -d | tail -n 1); do
230 AS_IF([readlink -q -e $DEFAULT_LINUX >/dev/null], [break])
232 if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then
233 PATHS="/lib/modules/$(uname -r)/build"
235 PATHS="/usr/src/linux-headers-$(uname -r)"
237 PATHS+=" $DEFAULT_LINUX"
238 for DEFAULT_LINUX_OBJ in $PATHS; do
239 AS_IF([readlink -q -e $DEFAULT_LINUX_OBJ >/dev/null], [break])
242 AC_MSG_CHECKING([for Linux sources])
244 AC_HELP_STRING([--with-linux=path],
245 [set path to Linux source (default=/lib/modules/$(uname -r)/{source,build},/usr/src/linux)]),
246 [LB_ARG_CANON_PATH([linux], [LINUX])
247 DEFAULT_LINUX_OBJ=$LINUX],
248 [LINUX=$DEFAULT_LINUX])
249 AC_MSG_RESULT([$LINUX])
252 # -------- check for linux --------
253 LB_CHECK_FILE([$LINUX], [],
254 [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
256 # -------- linux objects (for 2.6) --
257 AC_MSG_CHECKING([for Linux objects])
258 AC_ARG_WITH([linux-obj],
259 AC_HELP_STRING([--with-linux-obj=path],
260 [set path to Linux objects (default=/lib/modules/$(uname -r)/build,/usr/src/linux)]),
261 [LB_ARG_CANON_PATH([linux-obj], [LINUX_OBJ])],
262 [LINUX_OBJ=$DEFAULT_LINUX_OBJ])
263 AC_MSG_RESULT([$LINUX_OBJ])
266 # -------- check for .config --------
267 AC_ARG_WITH([linux-config],
268 [AC_HELP_STRING([--with-linux-config=path],
269 [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
270 [LB_ARG_CANON_PATH([linux-config], [LINUX_CONFIG])],
271 [LINUX_CONFIG=$LINUX_OBJ/.config])
273 # -------- check if .config exists --
274 LB_CHECK_FILE([$LINUX_CONFIG], [],
277 Kernel config could not be found.
280 AC_SUBST(LINUX_CONFIG)
282 LB_CHECK_FILE([/boot/kernel.h],
283 [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
284 [LB_CHECK_FILE([/var/adm/running-kernel.h],
285 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
287 AC_ARG_WITH([kernel-source-header],
288 AC_HELP_STRING([--with-kernel-source-header=path],
289 [Use a different kernel version header.]),
290 [LB_ARG_CANON_PATH([kernel-source-header], [KERNEL_SOURCE_HEADER])])
292 # ----------- make dep run? ------------------
293 # at 2.6.19 # $LINUX/include/linux/config.h is removed
294 # and at more old has only one line include <autoconf.h>
296 LB_CHECK_FILE([$LINUX_OBJ/include/generated/autoconf.h],
297 [AUTOCONF_HDIR=generated],
298 [LB_CHECK_FILE([$LINUX_OBJ/include/linux/autoconf.h],
299 [AUTOCONF_HDIR=linux],
300 [AC_MSG_ERROR([Run make config in $LINUX.])])])
301 AC_SUBST(AUTOCONF_HDIR)
303 LB_CHECK_FILE([$LINUX_OBJ/include/linux/version.h],
304 [VERSION_HDIR=linux],
305 [LB_CHECK_FILE([$LINUX_OBJ/include/generated/uapi/linux/version.h],
306 [VERSION_HDIR=generated/uapi/linux],
307 [AC_MSG_ERROR([Run make config in $LINUX.])])])
308 AC_SUBST(VERSION_HDIR)
310 # ----------- kconfig.h exists ---------------
311 # kernel 3.1, $LINUX/include/linux/kconfig.h is added
312 # see kernel commit 2a11c8ea20bf850b3a2c60db8c2e7497d28aba99
314 LB_CHECK_FILE([$LINUX/include/linux/kconfig.h],
315 [CONFIG_INCLUDE=$LINUX/include/linux/kconfig.h],
316 [CONFIG_INCLUDE=include/$AUTOCONF_HDIR/autoconf.h])
317 AC_SUBST(CONFIG_INCLUDE)
319 # ------------ rhconfig.h includes runtime-generated bits --
320 # RedHat kernel-source checks
322 # we know this exists after the check above. if the user
323 # tarred up the tree and ran make dep etc. in it, then
324 # version.h gets overwritten with a standard linux one.
326 AS_IF([grep rhconfig $LINUX_OBJ/include/$VERSION_HDIR/version.h >/dev/null], [
327 # This is a clean kernel-source tree, we need to
328 # enable extensive workarounds to get this to build modules
329 LB_CHECK_FILE([$KERNEL_SOURCE_HEADER], [
330 AS_IF([test $KERNEL_SOURCE_HEADER = '/boot/kernel.h'],
333 Using /boot/kernel.h from RUNNING kernel.
335 If this is not what you want, use --with-kernel-source-header.
336 Consult build/README.kernel-source for details.
341 $KERNEL_SOURCE_HEADER not found.
343 Consult build/README.kernel-source for details.
346 EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
349 # this is needed before we can build modules
352 # --- check that we can build modules at all
353 LB_CHECK_COMPILE([that modules can be built at all], build_modules,
357 Kernel modules cannot be built. Consult config.log for details.
359 If you are trying to build with a kernel-source rpm,
360 consult build/README.kernel-source
365 ]) # end of LB_LINUX_PATH
370 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
371 # so we test if request_module is implemented or not
372 AC_DEFUN([LC_MODULE_LOADING], [
373 AC_CACHE_CHECK([if Linux kernel module loading is possible], lb_cv_module_loading, [
375 #include <linux/kmod.h>
377 int myretval=ENOSYS ;
380 $makerule LUSTRE_KERNEL_TEST=conftest.i
382 grep request_module build/conftest.i |dnl
383 grep -v `grep "int myretval=" build/conftest.i |dnl
384 cut -d= -f2 | cut -d" " -f1`dnl
386 ], [lb_cv_module_loading="yes"], [lb_cv_module_loading="no"])
388 AS_IF([test "$lb_cv_module_loading" = yes],
389 [AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
390 [kernel module loading is possible])],
393 Kernel module loading support is highly recommended.
404 AC_DEFUN([LB_PROG_LINUX], [
408 LB_CHECK_CONFIG([MODULES], [], [
411 module support is required to build Lustre kernel modules.
415 LB_CHECK_CONFIG([MODVERSIONS])
417 LB_CHECK_CONFIG([KALLSYMS], [], [
420 Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.
431 # Determine if the target is a dpkg system or rpm
433 AC_DEFUN([LB_USES_DPKG], [
434 AC_CACHE_CHECK([if this distro uses dpkg], lb_cv_uses_dpkg, [
436 AS_CASE([$(which dpkg 2>/dev/null)],[*/dpkg], [lb_cv_uses_dpkg="yes"])
438 uses_dpkg=$lb_cv_uses_dpkg
444 # check symbol exported or not
446 # $2 - file(s) for find.
450 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers or check
452 AC_DEFUN([LB_CHECK_EXPORT], [
453 AS_VAR_PUSHDEF([lb_export], [lb_cv_export_$1])dnl
454 AC_CACHE_CHECK([if Linux kernel exports '$1'], lb_export, [
455 AS_VAR_SET([lb_export], [no])
456 AS_IF([grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX_OBJ/$SYMVERFILE 2>/dev/null],
457 [AS_VAR_SET([lb_export], [yes])],
459 AS_IF([grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null], [
460 AS_VAR_SET([lb_export], [yes])
465 AS_VAR_IF([lb_export], [yes], [$3], [$4])[]dnl
466 AS_VAR_POPDEF([lb_export])dnl
472 # check if a given config option is defined
477 AC_DEFUN([LB_CHECK_CONFIG], [
478 LB_CHECK_COMPILE([if Linux kernel was built with CONFIG_$1],
480 #include <$AUTOCONF_HDIR/autoconf.h>
483 #error CONFIG_$1 not #defined
491 # check if a given config option is builtin or as module
492 # $1 - CONFIG_<name> or CONFIG_<name>_MODULE
496 AC_DEFUN([LB_CHECK_CONFIG_IM], [
497 LB_CHECK_COMPILE([if Linux kernel was built with CONFIG_$1 in or as module],
499 #include <$AUTOCONF_HDIR/autoconf.h>
501 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
502 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
505 ]) # LB_CHECK_CONFIG_IM
508 # these are like AC_TRY_COMPILE, but try to build modules against the
509 # kernel, inside the build directory
513 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
514 # --------------------------------------
516 m4_define([LB_LANG_PROGRAM],
518 #include <linux/kernel.h>
519 #include <linux/module.h>
524 dnl Do *not* indent the following line: there may be CPP directives.
525 dnl Don't move the `;' right after for the same reason.
530 MODULE_LICENSE("GPL");])
533 # LB_LINUX_COMPILE_IFELSE
535 # like AC_COMPILE_IFELSE
537 # $1 - AC_LANG_SOURCE()
543 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
544 [m4_ifvaln([$1], [AC_LANG_CONFTEST([AC_LANG_SOURCE([$1])])])dnl
545 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
546 SUBARCH=$(echo $target_cpu | sed -e 's/powerpc.*/powerpc/' -e 's/ppc.*/powerpc/' -e 's/x86_64/x86/' -e 's/i.86/x86/' -e 's/k1om/x86/' -e 's/aarch64.*/arm64/' -e 's/armv7.*/arm/')
547 AS_IF([AC_TRY_COMMAND(cp conftest.c build && make -d [$2] LDFLAGS= ${LD:+LD="$LD"} CC="$CC" -f $PWD/build/Makefile LUSTRE_LINUX_CONFIG=$LINUX_CONFIG LINUXINCLUDE="$EXTRA_CHECK_INCLUDE -I$LINUX/arch/$SUBARCH/include -Iinclude -Iarch/$SUBARCH/include/generated -I$LINUX/include -Iinclude2 -I$LINUX/include/uapi -Iinclude/generated -I$LINUX/arch/$SUBARCH/include/uapi -Iarch/$SUBARCH/include/generated/uapi -I$LINUX/include/uapi -Iinclude/generated/uapi ${SPL_OBJ:+-include $SPL_OBJ/spl_config.h} ${ZFS_OBJ:+-include $ZFS_OBJ/zfs_config.h} ${SPL:+-I$SPL/include } ${ZFS:+-I$ZFS -I$ZFS/include -I${SPL:-$ZFS/include/spl}} -include $CONFIG_INCLUDE" KBUILD_EXTRA_SYMBOLS=${ZFS_OBJ:+$ZFS_OBJ/Module.symvers} -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])],
549 [_AC_MSG_LOG_CONFTEST
550 m4_ifvaln([$5],[$5])dnl])
551 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
555 # LB_LINUX_TRY_COMPILE
557 # like AC_TRY_COMPILE
559 AC_DEFUN([LB_LINUX_TRY_COMPILE], [
560 LB_LINUX_COMPILE_IFELSE(
561 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
562 [modules], [test -s build/conftest.o],
569 # like LB_LINUX_TRY_COMPILE, but with different arguments
571 AC_DEFUN([LB_LINUX_TRY_MAKE], [
572 LB_LINUX_COMPILE_IFELSE(
573 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
574 [$3], [$4], [$5], [$6])
579 # $1 - checking message
586 AC_DEFUN([LB_CHECK_COMPILE], [
587 AS_VAR_PUSHDEF([lb_compile], [lb_cv_compile_$2])dnl
588 AC_CACHE_CHECK([$1], lb_compile, [
589 LB_LINUX_TRY_COMPILE([$3], [$4],
590 [AS_VAR_SET([lb_compile], [yes])],
591 [AS_VAR_SET([lb_compile], [no])])
593 AS_VAR_IF([lb_compile], [yes], [$5], [$6])[]dnl
594 AS_VAR_POPDEF([lb_compile])dnl
595 ]) # LB_CHECK_COMPILE
598 # LB_CHECK_LINUX_HEADER
600 # Like AC_CHECK_HEADER but checks for a kernel-space header
602 m4_define([LB_CHECK_LINUX_HEADER], [
603 AS_VAR_PUSHDEF([lb_header], [lb_cv_header_$1])dnl
604 AC_CACHE_CHECK([for $1], lb_header, [
605 LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
606 [modules], [test -s build/conftest.o],
607 [AS_VAR_SET([lb_header], [yes])],
608 [AS_VAR_SET([lb_header], [no])])
610 AS_VAR_IF([lb_header], [yes], [$2], [$3])[]dnl
611 AS_VAR_POPDEF([lb_header])dnl
612 ]) # LB_CHECK_LINUX_HEADER