编译 X 驱动程序时,如何在 configure.ac 中测试 XFIXES 的版本?

发布于 2024-11-17 04:20:11 字数 645 浏览 8 评论 0原文

我正在为 X 编写一个视频设备驱动程序,它需要 XFIXES 扩展提供的一些功能。现在,我非常确定 X Server 的所有目标版本都将至少安装 XFIXES 版本 2,但我真的很想在我的 configure.ac 文件中测试这一点,以在用户尝试时发出警告为非常旧版本的服务器或(由于某种原因)未包含 XFIXES 的服务器编译我的驱动程序。现在我只是这样做:

# Essentially this is just supposed to check if the server currently supports
# V2 or better of the XFIXES protocol, and to define XFIXES if it does.
AC_CHECK_HEADER(X11/extensions/Xfixes.h,
    HAVE_XFIXES="yes"; 
    AC_DEFINE([HAVE_XFIXES],[1],[XFixes Proto Found]),,
    [#include <X11/Xlib.h>])
# should have a better test for this
if test "x${HAVE_XFIXES}" = "xyes"; then
  AC_DEFINE([XFIXES],[1],[XFixes >= 2.0])
fi

I'm writing a video device driver for X, and it needs some features provided by the XFIXES Extension. Now, I'm pretty sure that all of my target versions of the X Server will have at least version 2 of XFIXES installed, but I'd really like to test for that in my configure.ac file to warn the user if they try to compile my driver for a really old version of the server or for one in which (for some reason) XFIXES wasn't included. Right now I'm just doing this:

# Essentially this is just supposed to check if the server currently supports
# V2 or better of the XFIXES protocol, and to define XFIXES if it does.
AC_CHECK_HEADER(X11/extensions/Xfixes.h,
    HAVE_XFIXES="yes"; 
    AC_DEFINE([HAVE_XFIXES],[1],[XFixes Proto Found]),,
    [#include <X11/Xlib.h>])
# should have a better test for this
if test "x${HAVE_XFIXES}" = "xyes"; then
  AC_DEFINE([XFIXES],[1],[XFixes >= 2.0])
fi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吾性傲以野 2024-11-24 04:20:11

您可以使用 AC_CHECK_FUNC检查库中是否存在特定函数。您之前必须已在该库上运行过 AC_CHECK_LIB 才能正常工作。

You can use AC_CHECK_FUNC to check for the presence of specific functions in a library. You must have previously run AC_CHECK_LIB on that library for this to work.

独闯女儿国 2024-11-24 04:20:11

像这样的事情:

AC_CACHE_CHECK([for Xfixes >= 2.0], [foo_have_xfixes_2],
[AC_LINK_IFELSE([AC_LANG_PROGRAM(
                [[#include <X11/Xlib.h>
                  #include <X11/extensions/Xfixes.h>]],
                [[#if !(XFIXES_MAJOR >= 2)
                  #error XFIXES_LT_2
                  #endif]])],
                [foo_have_xfixes_2=yes], [foo_have_xfixes_2=no])])

if test "x${foo_have_xfixes_2}" = "xyes"; then
  AC_DEFINE([XFIXES],[1],[XFixes >= 2.0])
else
  AC_MSG_WARN("XFixes >= 2.0 not present")
fi

编辑——我现在有点明白问题了。我们将在此基础上构建初始解决方案。
现在我知道我们不能使用 XFIXES_MAJOR (或类似的东西),请使用您关心的结构本身作为测试的结构定义。对于此示例,我假设该结构是 XFixesCursorImage,因为当 XFIXES_MAJOR >= 2 时,它具有一些新组件(例如,名称)。希望定义相同结构的有效服务器标头也将具有这些组件新组件:

AC_CACHE_CHECK([for Xfixes >= 2.0], [foo_have_xfixes_2],
[AC_LINK_IFELSE([AC_LANG_PROGRAM(
                [[#include <???>
                  XFixesCursorImage bar;]],
                [[bar.name = "bar";]])],
                [foo_have_xfixes_2=yes], [foo_have_xfixes_2=no])])

if test "x${foo_have_xfixes_2}" = "xyes"; then
  AC_DEFINE([XFIXES],[1],[XFixes >= 2.0])
else
  AC_MSG_WARN("XFixes >= 2.0 not present")
fi

包含标头现在应该是标头的服务器版本。这个想法是服务器标头中 XFIXES_MAJOR < 2 将没有该组件并且编译将会失败。如果违反该假设,则该方法也将不起作用。

Something like this:

AC_CACHE_CHECK([for Xfixes >= 2.0], [foo_have_xfixes_2],
[AC_LINK_IFELSE([AC_LANG_PROGRAM(
                [[#include <X11/Xlib.h>
                  #include <X11/extensions/Xfixes.h>]],
                [[#if !(XFIXES_MAJOR >= 2)
                  #error XFIXES_LT_2
                  #endif]])],
                [foo_have_xfixes_2=yes], [foo_have_xfixes_2=no])])

if test "x${foo_have_xfixes_2}" = "xyes"; then
  AC_DEFINE([XFIXES],[1],[XFixes >= 2.0])
else
  AC_MSG_WARN("XFixes >= 2.0 not present")
fi

EDIT -- I now kinda get the problem. We'll build on the initial solution here.
Now that I know we cannot use XFIXES_MAJOR (or something like it), use the struct definition for a struct you care about itself as the test. For this example I'll assume the struct is XFixesCursorImage since it has some new components (e.g., name) when XFIXES_MAJOR >= 2. Hopefully, a valid server header defining the same struct will also have those new components:

AC_CACHE_CHECK([for Xfixes >= 2.0], [foo_have_xfixes_2],
[AC_LINK_IFELSE([AC_LANG_PROGRAM(
                [[#include <???>
                  XFixesCursorImage bar;]],
                [[bar.name = "bar";]])],
                [foo_have_xfixes_2=yes], [foo_have_xfixes_2=no])])

if test "x${foo_have_xfixes_2}" = "xyes"; then
  AC_DEFINE([XFIXES],[1],[XFixes >= 2.0])
else
  AC_MSG_WARN("XFixes >= 2.0 not present")
fi

The include header should now be the server version of the header. The idea is that the server header where XFIXES_MAJOR < 2 will not have that component and compiling it will fail. If that assumption is violated, this approach won't work either.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文