开发者

How do I test for the version of XFIXES in my configure.ac when compiling my X Driver?

开发者 https://www.devze.com 2023-03-15 16:53 出处:网络
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 Se开发者_如何学Crver will have at l

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 Se开发者_如何学Crver 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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号