Autoconf:检查struct成员类型

问题描述 投票:0回答:1

我是autoconf的新手,所以我会问你如何检查是否使用特定类型声明了struct成员。

例如,我应该检查struct posix_acl.a_refcount是否声明为refcount_t而不是atomic_t。

我知道AC函数为ac_fn_c_check_decl和ac_fn_c_check_member,但没有完成此任务。

谢谢!

linux-kernel autoconf
1个回答
1
投票

免责声明:由于在撰写本答案时没有其他答案,这代表了我提供解决方案的最佳尝试,但您可能需要调整一些事项以使其适用于您。买者自负。

你需要使用AC_COMPILE_IFELSE宏和使用atomic_t的代码,如果编译成功,那么你使用的是atomic_t。作为面向未来的,如果refcount_t测试失败,您可能还会为atomic_t添加测试。

例:

# _POSIX_ACL_REFCOUNT_T(type-to-check)
# ------------------------------------
# Checks whether the Linux kernel's `struct posix_acl'
# type uses `type-to-check' for its `a_refcount' member.
# Sets the shell variable `posix_acl_refcount_type' to
# `type-to-check' if that type is used, else the shell
# variable remains unset.
m4_define([_POSIX_ACL_REFCOUNT_T], [
 AC_REQUIRE([AC_PROG_CC])
 AC_MSG_CHECKING([whether struct posix_acl uses $1 for refcounts])
 AC_COMPILE_IFELSE(
  [AC_LANG_SOURCE(
   [#include <uapi/../linux/posix_acl.h>
    struct posix_acl acl;
    $1 v = acl.a_refcount;]
  )],
  [AC_MSG_RESULT([yes])
   AS_VAR_SET([posix_acl_refcount_type], [$1])],
  [AC_MSG_RESULT([no])
 )
])

_POSIX_ACL_REFCOUNT_T([atomic_t])
# If posix_acl_refcount_type isn't set, see if it works with refcount_t.
AS_VAR_SET_IF([posix_acl_refcount_type],
    [],
    [_POSIX_ACL_REFCOUNT_T([refcount_t])]
)
dnl
dnl Add future AS_VAR_SET_IF tests as shown above for the refcount type
dnl before the AS_VAR_SET_IF below, if necessary.
dnl
AS_VAR_SET_IF([posix_acl_refcount_type],
    [],
    [AC_MSG_FAILURE([struct posix_acl uses an unrecognized type for refcounts])]
)
AC_DEFINE([POSIX_ACL_REFCOUNT_T], [$posix_acl_refcount_type],
    [The type used for the a_refcount member of the Linux kernel's posix_acl struct.])

测试假设您已经有一个包含内核源目录的变量,并且在尝试测试之前,在includeCPPFLAGS中指定了内核源代码的CFLAGS目录。您可以在指定的位置添加更多测试,如果在所有这些测试之后仍未定义生成的posix_acl_refcount_type shell变量,则最终的AS_VAR_SET_IF调用将调用AC_MSG_FAILURE以使用指定的错误消息停止configure

请注意,我使用<uapi/../linux/posix_acl.h>专门针对内核的linux/posix_acl.h标头,而不是安装在系统的include目录中的用户空间API uapi/linux/posix_acl.h标头,其中uapi/被剥离,这可能导致上面的编译测试因用户空间API中缺少struct posix_acl而失败。这可能不像我期望的那样工作,可能需要修改。

© www.soinside.com 2019 - 2024. All rights reserved.