Re: [Linuxwacom-devel] [PATCH input-wacom 1/3] Allow user to specify kernel directory or version independently

2015-12-09 Thread Ping Cheng
On Fri, Dec 4, 2015 at 3:06 PM, Jason Gerecke  wrote:
> It should be possible to point the ./configure script at a kernel source
> tree and have it work without needing to also specifiy exactly what
> kernel version its looking at. This patch modifies configure.ac so that
> the MODUTS is only set to the output of `uname -r` if neither a kernel
> location nor version is given, and so the "sanity check" process which
> compares the kernel version is able to set MODUTS if it hasn't already
> been.
>
> Signed-off-by: Jason Gerecke 

This patch makes compilation across versions a lot easier! The whole set is:

Tested-by: Ping Cheng 

Ping

> ---
>  configure.ac | 138 
> ---
>  1 file changed, 75 insertions(+), 63 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index cad0258..2e3af9d 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -24,48 +24,11 @@ fi
>  AC_MSG_RESULT($WCM_ISLINUX)
>
>  dnl  kernel source, module versioning, etc
> -WCM_ENV_KERNEL=no
> +WCM_ENV_KERNEL=
>  WCM_KERNEL_DIR=
>  WCM_KERNEL_VER=
>  MODUTS=
>
> -dnl Check which version of the driver we should compile
> -AC_ARG_WITH(kernel-version,
> -   AS_HELP_STRING([--with-kernel-version=version], [Specify kernel 
> version]),
> -   [MODUTS="$withval"],
> -   [MODUTS=`uname -r`])
> -
> -AC_MSG_CHECKING(kernel version)
> -AC_MSG_RESULT([$MODUTS])
> -MINOR=`echo $MODUTS | sed 's/[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\).*/\1/'`
> -if echo $MODUTS | grep "^2.4" >/dev/null; then
> -   AC_MSG_ERROR([kernel 2.4.x is not supported])
> -elif echo $MODUTS | grep "^2.6" >/dev/null; then
> -   if test $MINOR -ge 26; then
> -   case $MINOR in
> -   26|27|28|29|30|31|32|33|34|35) 
> WCM_KERNEL_VER="2.6.30";;
> -   36|37) WCM_KERNEL_VER="2.6.36";;
> -   *) WCM_KERNEL_VER="2.6.38";;
> -   esac
> -   else
> -   AC_MSG_ERROR([use the kernel driver included in the 
> 'linuxwacom' package for kernels older than 2.6.26])
> -   fi
> -elif echo $MODUTS | grep "^3." >/dev/null; then
> -   MINOR=`echo $MODUTS | sed 's/[[0-9]]*\.\([[0-9]]*\).*/\1/'`
> -   if test $MINOR -ge 17; then
> -   WCM_KERNEL_VER="3.17"
> -   elif test $MINOR -ge 7; then
> -   WCM_KERNEL_VER="3.7"
> -   else
> -   WCM_KERNEL_VER="2.6.38"
> -   fi
> -elif echo $MODUTS | grep "^4." >/dev/null; then
> -   WCM_KERNEL_VER="3.17"
> -else
> -   AC_MSG_ERROR(kernel version $MODUTS not supported)
> -fi
> -
> -dnl Check for kernel build environment
>  AC_DEFUN([WCM_ISBUILDDIR], [\
>  \( -f "$1/.config" -o \
> -f "$1/include/config/auto.conf" -o \
> @@ -76,13 +39,28 @@ AC_ARG_WITH(kernel,
> AS_HELP_STRING([--with-kernel=dir], [Specify kernel source 
> directory]),
> [WCM_KERNEL_DIR="$withval"])
>
> +AC_ARG_WITH(kernel-version,
> +   AS_HELP_STRING([--with-kernel-version=version], [Specify kernel 
> version]),
> +   [MODUTS="$withval"])
> +
> +
> +dnl Assume the user wants to build for the running kernel version if neither
> +dnl the kernel directory nor version has been specified
> +if test "$WCM_KERNEL_DIR" = "yes" -o -z "$WCM_KERNEL_DIR"; then
> +   if test "$MODUTS" = "yes" -o -z "$MODUTS"; then
> +   MODUTS=`uname -r`
> +   fi
> +fi
> +
> +dnl Discover the kernel source location if not already set
>  AC_MSG_CHECKING(for kernel source/headers)
>  if test "$WCM_KERNEL_DIR" = "yes" -o -z "$WCM_KERNEL_DIR"; then
> +   if test "$MODUTS" = "yes" -o -z "$MODUTS"; then X=`uname -r`; else 
> X="$MODUTS"; fi
> AC_DEFUN([SEARCH_DIRECTORIES], [[
> - [/lib/modules/$MODUTS/source],
> - [/lib/modules/$MODUTS/build],
> + [/lib/modules/$X/source],
> + [/lib/modules/$X/build],
>   [/usr/src/linux],
> - [/usr/src/linux-$MODUTS],
> + [/usr/src/linux-$X],
>   [/usr/src/linux-2.6]
> ]])
> WCM_KERNEL_DIR=
> @@ -91,37 +69,71 @@ if test "$WCM_KERNEL_DIR" = "yes" -o -z 
> "$WCM_KERNEL_DIR"; then
> if test -z "$WCM_KERNEL_DIR"; then
> if test WCM_ISBUILDDIR(ROOTDIR); then
> WCM_KERNEL_DIR="ROOTDIR"
> -   AC_MSG_RESULT($WCM_KERNEL_DIR)
> fi
> fi
> ])
> +fi
> +if test -z "$WCM_KERNEL_DIR"; then
> +   AC_MSG_RESULT([not found])
> +   AC_MSG_WARN([Unable to find build config in any of: 
> SEARCH_DIRECTORIES])
> +fi
> +AC_MSG_RESULT([$WCM_KERNEL_DIR])
> +if test \! WCM_ISBUILDDIR($WCM_KERNEL_DIR); then
> +   AC_MSG_WARN([Kernel directory does not appear to have needed config 
> files])
> +   WCM_ENV_KERNEL="no"
> +fi
>
> -   if test -z "$WCM_KERNEL_DIR"; then
> -   AC_MSG_RESULT([not found])
> - 

[Linuxwacom-devel] [PATCH input-wacom 1/3] Allow user to specify kernel directory or version independently

2015-12-04 Thread Jason Gerecke
It should be possible to point the ./configure script at a kernel source
tree and have it work without needing to also specifiy exactly what
kernel version its looking at. This patch modifies configure.ac so that
the MODUTS is only set to the output of `uname -r` if neither a kernel
location nor version is given, and so the "sanity check" process which
compares the kernel version is able to set MODUTS if it hasn't already
been.

Signed-off-by: Jason Gerecke 
---
 configure.ac | 138 ---
 1 file changed, 75 insertions(+), 63 deletions(-)

diff --git a/configure.ac b/configure.ac
index cad0258..2e3af9d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,48 +24,11 @@ fi
 AC_MSG_RESULT($WCM_ISLINUX)
 
 dnl  kernel source, module versioning, etc
-WCM_ENV_KERNEL=no
+WCM_ENV_KERNEL=
 WCM_KERNEL_DIR=
 WCM_KERNEL_VER=
 MODUTS=
 
-dnl Check which version of the driver we should compile
-AC_ARG_WITH(kernel-version,
-   AS_HELP_STRING([--with-kernel-version=version], [Specify kernel 
version]),
-   [MODUTS="$withval"],
-   [MODUTS=`uname -r`])
-
-AC_MSG_CHECKING(kernel version)
-AC_MSG_RESULT([$MODUTS])
-MINOR=`echo $MODUTS | sed 's/[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\).*/\1/'`
-if echo $MODUTS | grep "^2.4" >/dev/null; then
-   AC_MSG_ERROR([kernel 2.4.x is not supported])
-elif echo $MODUTS | grep "^2.6" >/dev/null; then
-   if test $MINOR -ge 26; then
-   case $MINOR in
-   26|27|28|29|30|31|32|33|34|35) WCM_KERNEL_VER="2.6.30";;
-   36|37) WCM_KERNEL_VER="2.6.36";;
-   *) WCM_KERNEL_VER="2.6.38";;
-   esac
-   else
-   AC_MSG_ERROR([use the kernel driver included in the 
'linuxwacom' package for kernels older than 2.6.26])
-   fi
-elif echo $MODUTS | grep "^3." >/dev/null; then
-   MINOR=`echo $MODUTS | sed 's/[[0-9]]*\.\([[0-9]]*\).*/\1/'`
-   if test $MINOR -ge 17; then
-   WCM_KERNEL_VER="3.17"
-   elif test $MINOR -ge 7; then
-   WCM_KERNEL_VER="3.7"
-   else
-   WCM_KERNEL_VER="2.6.38"
-   fi
-elif echo $MODUTS | grep "^4." >/dev/null; then
-   WCM_KERNEL_VER="3.17"
-else
-   AC_MSG_ERROR(kernel version $MODUTS not supported)
-fi
-
-dnl Check for kernel build environment
 AC_DEFUN([WCM_ISBUILDDIR], [\
 \( -f "$1/.config" -o \
-f "$1/include/config/auto.conf" -o \
@@ -76,13 +39,28 @@ AC_ARG_WITH(kernel,
AS_HELP_STRING([--with-kernel=dir], [Specify kernel source directory]),
[WCM_KERNEL_DIR="$withval"])
 
+AC_ARG_WITH(kernel-version,
+   AS_HELP_STRING([--with-kernel-version=version], [Specify kernel 
version]),
+   [MODUTS="$withval"])
+
+
+dnl Assume the user wants to build for the running kernel version if neither
+dnl the kernel directory nor version has been specified
+if test "$WCM_KERNEL_DIR" = "yes" -o -z "$WCM_KERNEL_DIR"; then
+   if test "$MODUTS" = "yes" -o -z "$MODUTS"; then
+   MODUTS=`uname -r`
+   fi
+fi
+
+dnl Discover the kernel source location if not already set
 AC_MSG_CHECKING(for kernel source/headers)
 if test "$WCM_KERNEL_DIR" = "yes" -o -z "$WCM_KERNEL_DIR"; then
+   if test "$MODUTS" = "yes" -o -z "$MODUTS"; then X=`uname -r`; else 
X="$MODUTS"; fi
AC_DEFUN([SEARCH_DIRECTORIES], [[
- [/lib/modules/$MODUTS/source],
- [/lib/modules/$MODUTS/build],
+ [/lib/modules/$X/source],
+ [/lib/modules/$X/build],
  [/usr/src/linux],
- [/usr/src/linux-$MODUTS],
+ [/usr/src/linux-$X],
  [/usr/src/linux-2.6]
]])
WCM_KERNEL_DIR=
@@ -91,37 +69,71 @@ if test "$WCM_KERNEL_DIR" = "yes" -o -z "$WCM_KERNEL_DIR"; 
then
if test -z "$WCM_KERNEL_DIR"; then
if test WCM_ISBUILDDIR(ROOTDIR); then
WCM_KERNEL_DIR="ROOTDIR"
-   AC_MSG_RESULT($WCM_KERNEL_DIR)
fi
fi
])
+fi
+if test -z "$WCM_KERNEL_DIR"; then
+   AC_MSG_RESULT([not found])
+   AC_MSG_WARN([Unable to find build config in any of: SEARCH_DIRECTORIES])
+fi
+AC_MSG_RESULT([$WCM_KERNEL_DIR])
+if test \! WCM_ISBUILDDIR($WCM_KERNEL_DIR); then
+   AC_MSG_WARN([Kernel directory does not appear to have needed config 
files])
+   WCM_ENV_KERNEL="no"
+fi
 
-   if test -z "$WCM_KERNEL_DIR"; then
-   AC_MSG_RESULT([not found])
-   AC_MSG_NOTICE([Unable to find build config in any of: 
SEARCH_DIRECTORIES])
-   fi
-elif test "$WCM_KERNEL_DIR" != "no"; then
-   AC_MSG_RESULT([$WCM_KERNEL_DIR])
-   if test \! WCM_ISBUILDDIR($WCM_KERNEL_DIR); then
-   AC_MSG_NOTICE([Kernel directory does not appear to have needed 
config files])
-   fi
+dnl Discover the kernel source version if not already set
+AC_MSG_CHECKING(kernel version)
+SRC_VERSION=[$(sed -n