【问题标题】:Autoconf: check struct member typeAutoconf:检查结构成员类型
【发布时间】:2018-09-12 13:35:37
【问题描述】:

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

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

我知道 AC 函数有 ac_fn_c_check_declac_fn_c_check_member,但没有一个能完成这项任务。

谢谢!

【问题讨论】:

    标签: linux-kernel autoconf


    【解决方案1】:

    免责声明:由于在编写此答案时没有其他答案,因此这是我提供解决方案的最佳尝试,但您可能需要进行调整以使其适合您。警告购买者。

    您需要将AC_COMPILE_IFELSE 宏与使用atomic_t 的代码一起使用,如果编译成功,那么您使用的是atomic_t。作为面向未来的测试,如果 atomic_t 测试失败,您还可以为 refcount_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.])
    

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

    请注意,我使用&lt;uapi/../linux/posix_acl.h&gt; 专门针对内核的linux/posix_acl.h 标头,而不是安装在系统包含目录中的用户空间API uapi/linux/posix_acl.h 标头,其中uapi/ 被剥离,这可能会导致上面的编译测试由于用户空间 API 中缺少 struct posix_acl 而失败。这可能无法按我预期的方式工作,可能需要修改。

    【讨论】:

      猜你喜欢
      • 2013-03-14
      • 2013-11-12
      • 1970-01-01
      • 1970-01-01
      • 2021-03-08
      • 1970-01-01
      • 2018-07-01
      • 2022-07-11
      • 1970-01-01
      相关资源
      最近更新 更多