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 # check if the kernel is one from RHEL or SUSE
79 AC_CACHE_CHECK([for RedHat kernel release number], lb_cv_rhel_kernel_version, [
80 lb_cv_rhel_kernel_version=""
81 AS_IF([fgrep -q RHEL_RELEASE $LINUX_OBJ/include/$VERSION_HDIR/version.h], [
82 lb_cv_rhel_kernel_version=$(awk '/ RHEL_MAJOR / { print [$]3 }' \
83 $LINUX_OBJ/include/$VERSION_HDIR/version.h)$(awk \
84 '/ RHEL_MINOR / { print [$]3 }' \
85 $LINUX_OBJ/include/$VERSION_HDIR/version.h)
88 AS_IF([test -n "$lb_cv_rhel_kernel_version"], [
90 RHEL_RELEASE_NO=$lb_cv_rhel_kernel_version
93 LB_CHECK_CONFIG([SUSE_KERNEL], [SUSE_KERNEL="yes"], [SUSE_KERNEL="no"])
96 AC_MSG_CHECKING([for Linux kernel module package directory])
97 AC_ARG_WITH([kmp-moddir],
98 AC_HELP_STRING([--with-kmp-moddir=string],
99 [set the kmod updates or extra directory]),
102 AS_IF([test x$RHEL_KERNEL = xyes], [KMP_MODDIR="extra/kernel"],
103 [test x$SUSE_KERNEL = xyes], [KMP_MODDIR="updates/kernel"])
104 IN_KERNEL="${PACKAGE}"])
105 AC_MSG_RESULT($KMP_MODDIR)
107 moduledir="/lib/modules/${LINUXRELEASE}/${KMP_MODDIR}"
109 modulefsdir="${moduledir}/fs/${IN_KERNEL}"
110 AC_SUBST(modulefsdir)
112 modulenetdir="${moduledir}/net/${IN_KERNEL}"
113 AC_SUBST(modulenetdir)
119 # LB_LINUX_SYMVERFILE
121 # SLES 9 uses a different name for this file - unsure about vanilla kernels
122 # around this version, but it matters for servers only.
123 AC_DEFUN([LB_LINUX_SYMVERFILE], [
124 AC_CACHE_CHECK([for the name of module symbol version file], lb_cv_module_symvers, [
125 AS_IF([grep -q Modules.symvers $LINUX/scripts/Makefile.modpost],
126 [lb_cv_module_symvers=Modules.symvers],
127 [lb_cv_module_symvers=Module.symvers])
129 SYMVERFILE=$lb_cv_module_symvers
134 # LB_ARG_REPLACE_PATH(PACKAGE, PATH)
136 AC_DEFUN([LB_ARG_REPLACE_PATH], [
138 eval set -- $ac_configure_args
142 arg=--with-[$1]=[$2] ;;
144 arg=$(printf %s\n ["$arg"] | sed "s/'/'\\\\\\\\''/g") ;;
146 dnl AS_VAR_APPEND([new_configure_args], [" '$arg'"])
147 new_configure_args="$new_configure_args '$arg'"
149 ac_configure_args=$new_configure_args
153 # __LB_ARG_CANON_PATH
155 # this is the work-horse of the next function
157 AC_DEFUN([__LB_ARG_CANON_PATH], [
158 [$3]=$(readlink -f $with_$2)
159 LB_ARG_REPLACE_PATH([$1], $[$3])
165 # a front-end for the above function that transforms - and . in the
166 # PACKAGE portion of --with-PACKAGE into _ suitable for variable names
168 AC_DEFUN([LB_ARG_CANON_PATH], [
169 __LB_ARG_CANON_PATH([$1], m4_translit([$1], [-.], [__]), [$2])
175 # Find paths for linux, handling kernel-source rpms
177 AC_DEFUN([LB_LINUX_PATH], [
178 for DEFAULT_LINUX in /lib/modules/$(uname -r)/{source,build} /usr/src/linux; do
179 AS_IF([readlink -q -e $DEFAULT_LINUX >/dev/null], [break])
181 if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then
182 PATHS="/lib/modules/$(uname -r)/build"
184 PATHS+=" $DEFAULT_LINUX"
185 for DEFAULT_LINUX_OBJ in $PATHS; do
186 AS_IF([readlink -q -e $DEFAULT_LINUX_OBJ >/dev/null], [break])
189 AC_MSG_CHECKING([for Linux sources])
191 AC_HELP_STRING([--with-linux=path],
192 [set path to Linux source (default=/lib/modules/$(uname -r)/{source,build},/usr/src/linux)]),
193 [LB_ARG_CANON_PATH([linux], [LINUX])
194 DEFAULT_LINUX_OBJ=$LINUX],
195 [LINUX=$DEFAULT_LINUX])
196 AC_MSG_RESULT([$LINUX])
199 # -------- check for linux --------
200 LB_CHECK_FILE([$LINUX], [],
201 [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
203 # -------- linux objects (for 2.6) --
204 AC_MSG_CHECKING([for Linux objects])
205 AC_ARG_WITH([linux-obj],
206 AC_HELP_STRING([--with-linux-obj=path],
207 [set path to Linux objects (default=/lib/modules/$(uname -r)/build,/usr/src/linux)]),
208 [LB_ARG_CANON_PATH([linux-obj], [LINUX_OBJ])],
209 [LINUX_OBJ=$DEFAULT_LINUX_OBJ])
210 AC_MSG_RESULT([$LINUX_OBJ])
213 # -------- check for .config --------
214 AC_ARG_WITH([linux-config],
215 [AC_HELP_STRING([--with-linux-config=path],
216 [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
217 [LB_ARG_CANON_PATH([linux-config], [LINUX_CONFIG])],
218 [LINUX_CONFIG=$LINUX_OBJ/.config])
220 # -------- check if .config exists --
221 LB_CHECK_FILE([$LINUX_CONFIG], [],
224 Kernel config could not be found.
226 If you are building from a kernel-source rpm consult build/README.kernel-source
229 AC_SUBST(LINUX_CONFIG)
231 LB_CHECK_FILE([/boot/kernel.h],
232 [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
233 [LB_CHECK_FILE([/var/adm/running-kernel.h],
234 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
236 AC_ARG_WITH([kernel-source-header],
237 AC_HELP_STRING([--with-kernel-source-header=path],
238 [Use a different kernel version header. Consult build/README.kernel-source for details.]),
239 [LB_ARG_CANON_PATH([kernel-source-header], [KERNEL_SOURCE_HEADER])])
241 # ----------- make dep run? ------------------
242 # at 2.6.19 # $LINUX/include/linux/config.h is removed
243 # and at more old has only one line include <autoconf.h>
245 LB_CHECK_FILE([$LINUX_OBJ/include/generated/autoconf.h],
246 [AUTOCONF_HDIR=generated],
247 [LB_CHECK_FILE([$LINUX_OBJ/include/linux/autoconf.h],
248 [AUTOCONF_HDIR=linux],
249 [AC_MSG_ERROR([Run make config in $LINUX.])])])
250 AC_SUBST(AUTOCONF_HDIR)
252 LB_CHECK_FILE([$LINUX_OBJ/include/linux/version.h],
253 [VERSION_HDIR=linux],
254 [LB_CHECK_FILE([$LINUX_OBJ/include/generated/uapi/linux/version.h],
255 [VERSION_HDIR=generated/uapi/linux],
256 [AC_MSG_ERROR([Run make config in $LINUX.])])])
257 AC_SUBST(VERSION_HDIR)
259 # ----------- kconfig.h exists ---------------
260 # kernel 3.1, $LINUX/include/linux/kconfig.h is added
261 # see kernel commit 2a11c8ea20bf850b3a2c60db8c2e7497d28aba99
263 LB_CHECK_FILE([$LINUX/include/linux/kconfig.h],
264 [CONFIG_INCLUDE=$LINUX/include/linux/kconfig.h],
265 [CONFIG_INCLUDE=include/$AUTOCONF_HDIR/autoconf.h])
266 AC_SUBST(CONFIG_INCLUDE)
268 # ------------ rhconfig.h includes runtime-generated bits --
269 # RedHat kernel-source checks
271 # we know this exists after the check above. if the user
272 # tarred up the tree and ran make dep etc. in it, then
273 # version.h gets overwritten with a standard linux one.
275 AS_IF([grep rhconfig $LINUX_OBJ/include/$VERSION_HDIR/version.h >/dev/null], [
276 # This is a clean kernel-source tree, we need to
277 # enable extensive workarounds to get this to build modules
278 LB_CHECK_FILE([$KERNEL_SOURCE_HEADER], [
279 AS_IF([test $KERNEL_SOURCE_HEADER = '/boot/kernel.h'],
282 Using /boot/kernel.h from RUNNING kernel.
284 If this is not what you want, use --with-kernel-source-header.
285 Consult build/README.kernel-source for details.
290 $KERNEL_SOURCE_HEADER not found.
292 Consult build/README.kernel-source for details.
295 EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
298 # this is needed before we can build modules
301 # --- check that we can build modules at all
302 LB_CHECK_COMPILE([that modules can be built at all], build_modules,
306 Kernel modules cannot be built. Consult config.log for details.
308 If you are trying to build with a kernel-source rpm,
309 consult build/README.kernel-source
314 ]) # end of LB_LINUX_PATH
319 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
320 # so we test if request_module is implemented or not
321 AC_DEFUN([LC_MODULE_LOADING], [
322 AC_CACHE_CHECK([if Linux kernel module loading is possible], lb_cv_module_loading, [
324 #include <linux/kmod.h>
326 int myretval=ENOSYS ;
329 $makerule LUSTRE_KERNEL_TEST=conftest.i
331 grep request_module build/conftest.i |dnl
332 grep -v `grep "int myretval=" build/conftest.i |dnl
333 cut -d= -f2 | cut -d" " -f1`dnl
335 ], [lb_cv_module_loading="yes"], [lb_cv_module_loading="no"])
337 AS_IF([test "$lb_cv_module_loading" = yes],
338 [AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
339 [kernel module loading is possible])],
342 Kernel module loading support is highly recommended.
353 AC_DEFUN([LB_PROG_LINUX], [
357 LB_CHECK_CONFIG([MODULES], [], [
360 module support is required to build Lustre kernel modules.
364 LB_CHECK_CONFIG([MODVERSIONS])
366 LB_CHECK_CONFIG([KALLSYMS], [], [
369 Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.
380 # Determine if the target is a dpkg system or rpm
382 AC_DEFUN([LB_USES_DPKG], [
383 AC_CACHE_CHECK([if this distro uses dpkg], lb_cv_uses_dpkg, [
385 AS_CASE([$(lsb_release -i -s 2>/dev/null)],
386 [Ubuntu | Debian], [lb_cv_uses_dpkg="yes"])
388 uses_dpkg=$lb_cv_uses_dpkg
394 # check symbol exported or not
396 # $2 - file(s) for find.
400 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers or check
402 AC_DEFUN([LB_CHECK_EXPORT], [
403 AS_VAR_PUSHDEF([lb_export], [lb_cv_export_$1])dnl
404 AC_CACHE_CHECK([if Linux kernel exports '$1'], lb_export, [
405 AS_VAR_SET([lb_export], [no])
406 AS_IF([grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX_OBJ/$SYMVERFILE 2>/dev/null],
407 [AS_VAR_SET([lb_export], [yes])],
409 AS_IF([grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null], [
410 AS_VAR_SET([lb_export], [yes])
415 AS_VAR_IF([lb_export], [yes], [$3], [$4])[]dnl
416 AS_VAR_POPDEF([lb_export])dnl
422 # check if a given config option is defined
427 AC_DEFUN([LB_CHECK_CONFIG], [
428 LB_CHECK_COMPILE([if Linux kernel was built with CONFIG_$1],
430 #include <$AUTOCONF_HDIR/autoconf.h>
433 #error CONFIG_$1 not #defined
441 # check if a given config option is builtin or as module
442 # $1 - CONFIG_<name> or CONFIG_<name>_MODULE
446 AC_DEFUN([LB_CHECK_CONFIG_IM], [
447 LB_CHECK_COMPILE([if Linux kernel was built with CONFIG_$1 in or as module],
449 #include <$AUTOCONF_HDIR/autoconf.h>
451 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
452 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
455 ]) # LB_CHECK_CONFIG_IM
458 # these are like AC_TRY_COMPILE, but try to build modules against the
459 # kernel, inside the build directory
463 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
464 # --------------------------------------
466 m4_define([LB_LANG_PROGRAM],
468 #include <linux/kernel.h>
473 dnl Do *not* indent the following line: there may be CPP directives.
474 dnl Don't move the `;' right after for the same reason.
481 # LB_LINUX_COMPILE_IFELSE
483 # like AC_COMPILE_IFELSE
485 # $1 - AC_LANG_SOURCE()
491 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
492 [m4_ifvaln([$1], [AC_LANG_CONFTEST([AC_LANG_SOURCE([$1])])])dnl
493 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
494 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/')
495 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 -I$SPL/include } ${ZFS:+-I$ZFS -I$ZFS/include} -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])],
497 [_AC_MSG_LOG_CONFTEST
498 m4_ifvaln([$5],[$5])dnl])
499 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
503 # LB_LINUX_TRY_COMPILE
505 # like AC_TRY_COMPILE
507 AC_DEFUN([LB_LINUX_TRY_COMPILE], [
508 LB_LINUX_COMPILE_IFELSE(
509 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
510 [modules], [test -s build/conftest.o],
517 # like LB_LINUX_TRY_COMPILE, but with different arguments
519 AC_DEFUN([LB_LINUX_TRY_MAKE], [
520 LB_LINUX_COMPILE_IFELSE(
521 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
522 [$3], [$4], [$5], [$6])
527 # $1 - checking message
534 AC_DEFUN([LB_CHECK_COMPILE], [
535 AS_VAR_PUSHDEF([lb_compile], [lb_cv_compile_$2])dnl
536 AC_CACHE_CHECK([$1], lb_compile, [
537 LB_LINUX_TRY_COMPILE([$3], [$4],
538 [AS_VAR_SET([lb_compile], [yes])],
539 [AS_VAR_SET([lb_compile], [no])])
541 AS_VAR_IF([lb_compile], [yes], [$5], [$6])[]dnl
542 AS_VAR_POPDEF([lb_compile])dnl
543 ]) # LB_CHECK_COMPILE
546 # LB_CHECK_LINUX_HEADER
548 # Like AC_CHECK_HEADER but checks for a kernel-space header
550 m4_define([LB_CHECK_LINUX_HEADER], [
551 AS_VAR_PUSHDEF([lb_header], [lb_cv_header_$1])dnl
552 AC_CACHE_CHECK([for $1], lb_header, [
553 LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
554 [modules], [test -s build/conftest.o],
555 [AS_VAR_SET([lb_header], [yes])],
556 [AS_VAR_SET([lb_header], [no])])
558 AS_VAR_IF([lb_header], [yes], [$2], [$3])[]dnl
559 AS_VAR_POPDEF([lb_header])dnl
560 ]) # LB_CHECK_LINUX_HEADER