From 0b40abe79e44c98adbbd5adb80ac2f10e6d1316a Mon Sep 17 00:00:00 2001
From: Simon Wilkinson <sxw@inf.ed.ac.uk>
Date: Tue, 27 Apr 2010 17:41:22 +0100
Subject: [PATCH 2/8] Linux: Add general autoconf macro for Linux kernel

Add AC_CHECK_LINUX_BUILD() to do a standardised Linux build, which
takes a "checking" message, the autoconf variable to use to cache
the results, headers and code to run, preprocessor variable to
define, and a description of that variable.

Reviewed-on: http://gerrit.openafs.org/1854
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
(cherry picked from commit a89d6b029d059d01b8bbfc18b9ee6e3f5a964b85)

Change-Id: I75c5efbf69b54e0f0b1aedcb157992e13c6a8aa7
[andersk@mit.edu: Remove reimplementation of existing check macros]
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Reviewed-on: http://gerrit.openafs.org/3993
Reviewed-by: Simon Wilkinson <sxw@inf.ed.ac.uk>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Russ Allbery <rra@stanford.edu>
Reviewed-on: http://gerrit.openafs.org/4038
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
---
 src/cf/linux-test1.m4 |   28 ++++++++++++++++++----------
 src/cf/linux-test4.m4 |   11 +++++------
 2 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/src/cf/linux-test1.m4 b/src/cf/linux-test1.m4
index 2da3bb8..3115cdb 100644
--- a/src/cf/linux-test1.m4
+++ b/src/cf/linux-test1.m4
@@ -85,16 +85,24 @@ AC_DEFUN([LINUX_KBUILD_USES_EXTRA_CFLAGS], [
     CPPFLAGS="$save_CPPFLAGS"
     AC_MSG_RESULT($ac_linux_kbuild_requires_extra_cflags)])
 
+dnl AC_CHECK_LINUX_BUILD([msg], [var], [includes], [code], [define])
+AC_DEFUN([AC_CHECK_LINUX_BUILD],
+ [AS_VAR_PUSHDEF([ac_linux_build], [$2])dnl
+  AC_CACHE_CHECK([$1], [ac_linux_build],
+   [AC_TRY_KBUILD([$3], [$4],
+		  AS_VAR_SET([ac_linux_build], [yes]),
+		  AS_VAR_SET([ac_linux_build], [no]))
+   ])
+  AS_IF([test AS_VAR_GET([ac_linux_build]) = yes],
+        [AC_DEFINE([$5],1,[$6])])
+ ])
+
 dnl AC_CHECK_LINUX_STRUCT([structure], [element], [includes])
 AC_DEFUN([AC_CHECK_LINUX_STRUCT],
- [AS_VAR_PUSHDEF([ac_linux_struct], [ac_cv_linux_struct_$1_has_$2])dnl
-  AC_CACHE_CHECK([for $2 in struct $1], [ac_linux_struct],
-   [AC_TRY_KBUILD([#include <linux/$3>],
-		  [struct $1 _test; printk("%x\n", &_test.$2); ],
-		  AS_VAR_SET([ac_linux_struct], [yes]),
-		  AS_VAR_SET([ac_linux_struct], [no]))
-   ])
-  AS_IF([test AS_VAR_GET([ac_linux_struct]) = yes],
-	[AC_DEFINE(AS_TR_CPP(STRUCT_$1_HAS_$2), 1,
-		   [Define if kernel struct $1 has the $2 element])])
+ [AC_CHECK_LINUX_BUILD([for $2 in struct $1],
+		       [ac_cv_linux_struct_$1_has_$2],
+		       [#include <linux/$3>],
+		       [struct $1 _test; printk("%x\n", &_test.$2); ],
+		       AS_TR_CPP(STRUCT_$1_HAS_$2),
+		       [Define if kernel struct $1 has the $2 element])
  ])
diff --git a/src/cf/linux-test4.m4 b/src/cf/linux-test4.m4
index 89fccf5..3f22f7a 100644
--- a/src/cf/linux-test4.m4
+++ b/src/cf/linux-test4.m4
@@ -675,18 +675,17 @@ struct nameidata _nameidata;
 
 
 AC_DEFUN([LINUX_IOP_I_PERMISSION_TAKES_NAMEIDATA], [
-  AC_MSG_CHECKING([whether inode_operations.permission takes a nameidata])
-  AC_CACHE_VAL([ac_cv_linux_func_i_permission_takes_nameidata], [
-    AC_TRY_KBUILD(
+  AC_CHECK_LINUX_BUILD([whether inode_operations.permission takes a nameidata],
+		       [ac_cv_linux_func_i_permission_takes_nameidata],
 [#include <linux/fs.h>
 #include <linux/namei.h>],
 [struct inode _inode;
 struct dentry _dentry;
 struct nameidata _nameidata;
 (void)_inode.i_op->permission(&_inode, 0, &_nameidata);],
-      ac_cv_linux_func_i_permission_takes_nameidata=yes,
-      ac_cv_linux_func_i_permission_takes_nameidata=no)])
-  AC_MSG_RESULT($ac_cv_linux_func_i_permission_takes_nameidata)])
+		       [IOP_PERMISSION_TAKES_NAMEIDATA],
+		       [define if your iops.permission takes a nameidata argument])
+])
 
 
 AC_DEFUN([LINUX_IOP_I_PUT_LINK_TAKES_COOKIE], [
-- 
1.7.3.4

