自动确认:检查结构成员类型



我是自动conf的新手,所以我会问你如何检查结构成员是否用特定类型声明。

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

我知道空调的功能是ac_fn_c_check_declac_fn_c_check_member,但没有一个能完成这项任务。

谢谢!

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

您需要将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_typeshell 变量,则最终的AS_VAR_SET_IF调用将调用AC_MSG_FAILURE以停止configure并显示指定的错误消息。

请注意,我使用<uapi/../linux/posix_acl.h>专门针对内核的linux/posix_acl.h标头,而不是安装在系统包含目录中的用户空间 APIuapi/linux/posix_acl.h标头,并剥离了uapi/,这可能会导致上述编译测试失败,因为用户空间 API 中缺少struct posix_acl。 这可能不符合我预期的方式,可能需要修改。

最新更新