Whamcloud - gitweb
LU-11880 build: allow Debian build on Raspbian
[fs/lustre-release.git] / config / lustre-build-linux.m4
index 1224fdb..9941045 100644 (file)
@@ -73,46 +73,81 @@ AC_SUBST(LINUXRELEASE)
 # get the release version of linux
 #
 AC_DEFUN([LB_LINUX_RELEASE], [
-LB_LINUX_UTSRELEASE
+       LB_LINUX_UTSRELEASE
 
-# check if the kernel is one from RHEL or SUSE
-AC_CACHE_CHECK([for RedHat kernel release number], lb_cv_rhel_kernel_version, [
-lb_cv_rhel_kernel_version=""
-AS_IF([fgrep -q RHEL_RELEASE $LINUX_OBJ/include/$VERSION_HDIR/version.h], [
-       lb_cv_rhel_kernel_version=$(awk '/ RHEL_MAJOR / { print [$]3 }' \
-               $LINUX_OBJ/include/$VERSION_HDIR/version.h)$(awk \
-               '/ RHEL_MINOR / { print [$]3 }' \
-               $LINUX_OBJ/include/$VERSION_HDIR/version.h)
-])
-])
-AS_IF([test -n "$lb_cv_rhel_kernel_version"], [
-       RHEL_KERNEL="yes"
-       RHEL_RELEASE_NO=$lb_cv_rhel_kernel_version
-], [
+       # Define default states
        RHEL_KERNEL="no"
-       LB_CHECK_CONFIG([SUSE_KERNEL], [SUSE_KERNEL="yes"], [SUSE_KERNEL="no"])
-])
+       SUSE_KERNEL="no"
+       UBUNTU_KERNEL="no"
+       # And if any of the above kernels has been detected yet
+       KERNEL_FOUND="no"
+
+       # Check for RedHat first (no need to check KERNEL_FOUND
+       AC_CACHE_CHECK([for RedHat kernel release number], lb_cv_rhel_kernel_version, [
+               lb_cv_rhel_kernel_version=""
+               AS_IF([fgrep -q RHEL_RELEASE $LINUX_OBJ/include/$VERSION_HDIR/version.h], [
+                       lb_cv_rhel_kernel_version=$(awk '/ RHEL_MAJOR / { print [$]3 }' \
+                               $LINUX_OBJ/include/$VERSION_HDIR/version.h)$(awk \
+                               '/ RHEL_MINOR / { print [$]3 }' \
+                               $LINUX_OBJ/include/$VERSION_HDIR/version.h)
+               ])
+       ])
+       AS_IF([test -n "$lb_cv_rhel_kernel_version"], [
+               RHEL_KERNEL="yes"
+               KERNEL_FOUND="yes"
+               RHEL_RELEASE_NO=$lb_cv_rhel_kernel_version
+       ])
+
+       # Check for SuSE
+       AS_IF([test "x$KERNEL_FOUND" = "xno"], [
+               LB_CHECK_CONFIG([SUSE_KERNEL], [
+                       SUSE_KERNEL="yes"
+                       KERNEL_FOUND="yes"
+               ], [])
+       ])
+
+       # Check for Ubuntu
+       AS_IF([test "x$KERNEL_FOUND" = "xno"], [
+               AC_CACHE_CHECK([for Ubuntu kernel signature], lb_cv_ubuntu_kernel_sig, [
+                       lb_cv_ubuntu_kernel_sig="no"
+                       AS_IF([fgrep -q "CONFIG_VERSION_SIGNATURE \"Ubuntu" $LINUX_OBJ/include/generated/autoconf.h], [
+                               lb_cv_ubuntu_kernel_sig="yes"
+                       ])
+               ])
+               AS_IF([test "x$lb_cv_ubuntu_kernel_sig" = "xyes"], [
+                       UBUNTU_KERNEL="yes"
+                       KERNEL_FOUND="yes"
+               ])
+       ])
+
+       # If still no kernel was found, a warning is issued
+       AS_IF([test "x$KERNEL_FOUND" = "xno"], [
+               AC_MSG_WARN([Kernel Distro seems to be neither RedHat, SuSE nor Ubuntu])
+       ])
 
-AC_MSG_CHECKING([for Linux kernel module package directory])
-AC_ARG_WITH([kmp-moddir],
-       AC_HELP_STRING([--with-kmp-moddir=string],
-               [set the kmod updates or extra directory]),
-       [KMP_MODDIR=$withval
-        IN_KERNEL=''],[
-       AS_IF([test x$RHEL_KERNEL = xyes], [KMP_MODDIR="extra/kernel"],
-             [test x$SUSE_KERNEL = xyes], [KMP_MODDIR="updates/kernel"])
-       IN_KERNEL="${PACKAGE}"])
-AC_MSG_RESULT($KMP_MODDIR)
+       AC_MSG_CHECKING([for Linux kernel module package directory])
+       AC_ARG_WITH([kmp-moddir],
+               AC_HELP_STRING([--with-kmp-moddir=string],
+                       [set the kmod updates or extra directory]),
+               [KMP_MODDIR=$withval
+                IN_KERNEL=''],[
+               AS_IF([test x$RHEL_KERNEL = xyes], [KMP_MODDIR="extra/kernel"],
+                         [test x$SUSE_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
+                         [test x$UBUNTU_KERNEL = xyes], [KMP_MODDIR="updates/kernel"],
+                         [AC_MSG_WARN([Kernel Distro seems to be neither RedHat, SuSE nor Ubuntu])]
+               )
+               IN_KERNEL="${PACKAGE}"])
+       AC_MSG_RESULT($KMP_MODDIR)
 
-moduledir="/lib/modules/${LINUXRELEASE}/${KMP_MODDIR}"
+       moduledir="/lib/modules/${LINUXRELEASE}/${KMP_MODDIR}"
 
-modulefsdir="${moduledir}/fs/${IN_KERNEL}"
-AC_SUBST(modulefsdir)
+       modulefsdir="${moduledir}/fs/${IN_KERNEL}"
+       AC_SUBST(modulefsdir)
 
-modulenetdir="${moduledir}/net/${IN_KERNEL}"
-AC_SUBST(modulenetdir)
+       modulenetdir="${moduledir}/net/${IN_KERNEL}"
+       AC_SUBST(modulenetdir)
 
-AC_SUBST(KMP_MODDIR)
+       AC_SUBST(KMP_MODDIR)
 ])
 
 #
@@ -175,11 +210,13 @@ AC_DEFUN([LB_ARG_CANON_PATH], [
 # Find paths for linux, handling kernel-source rpms
 #
 AC_DEFUN([LB_LINUX_PATH], [
-for DEFAULT_LINUX in /lib/modules/$(uname -r)/{source,build} /usr/src/linux; do
+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
        AS_IF([readlink -q -e $DEFAULT_LINUX >/dev/null], [break])
 done
 if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then
        PATHS="/lib/modules/$(uname -r)/build"
+else
+       PATHS="/usr/src/linux-headers-$(uname -r)"
 fi
 PATHS+=" $DEFAULT_LINUX"
 for DEFAULT_LINUX_OBJ in $PATHS; do
@@ -382,8 +419,7 @@ LC_MODULE_LOADING
 AC_DEFUN([LB_USES_DPKG], [
 AC_CACHE_CHECK([if this distro uses dpkg], lb_cv_uses_dpkg, [
 lb_cv_uses_dpkg="no"
-AS_CASE([$(lsb_release -i -s 2>/dev/null)],
-       [Ubuntu | Debian], [lb_cv_uses_dpkg="yes"])
+AS_CASE([$(which dpkg 2>/dev/null)],[*/dpkg], [lb_cv_uses_dpkg="yes"])
 ])
 uses_dpkg=$lb_cv_uses_dpkg
 ])
@@ -466,6 +502,7 @@ config_im_$1, [
 m4_define([LB_LANG_PROGRAM],
 [
 #include <linux/kernel.h>
+#include <linux/module.h>
 $1
 int
 main (void)
@@ -475,7 +512,8 @@ dnl Don't move the `;' right after for the same reason.
 $2
   ;
   return 0;
-}])
+};
+MODULE_LICENSE("GPL");])
 
 #
 # LB_LINUX_COMPILE_IFELSE
@@ -491,7 +529,7 @@ $2
 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
 [m4_ifvaln([$1], [AC_LANG_CONFTEST([AC_LANG_SOURCE([$1])])])dnl
 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
-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/')
+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/')
 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])],
        [$4],
        [_AC_MSG_LOG_CONFTEST