Discussion:
Searching headers mapping to the same HAVE_header variable
Julien ÉLIE
2013-12-12 21:02:44 UTC
Permalink
Hi all,

When using AC_CHECK_HEADERS([filename]), a HAVE_FILENAME (with uppercase chars)
variable is defined to 1 if the filename header is found.
Characters not suitable for a variable name in filename are mapped to underscores.

I have a question about how to deal with looking for two different headers that
lead to the same HAVE_FILENAME variable.
For instance: how to properly search for gdbm/ndbm.h and gdbm-ndbm.h?

Using:

AC_CHECK_HEADERS([gdbm/ndbm.h gdbm-ndbm.h], [break])

does not help much.
As the result of the search is cached in $ac_cv_header_filename, maybe
using the following piece of code is the expected way to deal with the issue?


AC_CHECK_HEADER([gdbm/ndbm.h])
AS_IF([test x"$ac_cv_header_gdbm_ndbm_h" != xno],
[AC_DEFINE([HAVE_GDBM_NDBM_H], [1],
[Define if you have the <gdbm/ndbm.h> header file.])],
[AS_UNSET([ac_cv_header_gdbm_ndbm_h])
AC_CHECK_HEADER([gdbm-ndbm.h])
AS_IF([test x"$ac_cv_header_gdbm_ndbm_h" != xno],
[AC_DEFINE([HAVE_GDBM_NDBM_H_DASH], [1],
[Define if you have the <gdbm-ndbm.h> header file.])])])



If you know a better way to do that, I would be interested in hearing it.
Thanks beforehand,
--
Julien ÉLIE

« – Nous ne connaissons pas leur langue, donc, sous aucun prétexte
il ne faut parler aux Goths !
– Mais on peut leur taper dessus ? » (Astérix)
Eric Blake
2013-12-12 21:11:31 UTC
Permalink
Post by Julien ÉLIE
Hi all,
When using AC_CHECK_HEADERS([filename]), a HAVE_FILENAME (with uppercase chars)
variable is defined to 1 if the filename header is found.
Characters not suitable for a variable name in filename are mapped to underscores.
I have a question about how to deal with looking for two different headers that
lead to the same HAVE_FILENAME variable.
For instance: how to properly search for gdbm/ndbm.h and gdbm-ndbm.h?
Ugh, there's no clean way to do that with the standard macros. Who
named these header files, and can they be convinced to improve their
naming in the future?
Post by Julien ÉLIE
AC_CHECK_HEADERS([gdbm/ndbm.h gdbm-ndbm.h], [break])
does not help much.
Unfortunately true.
Post by Julien ÉLIE
As the result of the search is cached in $ac_cv_header_filename, maybe
using the following piece of code is the expected way to deal with the issue?
Yep, multiple AC_CHECK_HEADER with manual actions on success is the best
you can do, rather than AC_CHECK_HEADERS and its automatic actions.
Post by Julien ÉLIE
AC_CHECK_HEADER([gdbm/ndbm.h])
Unfortunately, AC_CHECK_HEADER short-circuits if the cache is already
populated. And since the collision is not just on the HAVE_GDBM_NDBM_H
preprocessor name, but ALSO on the $ac_cv_header_gdbm_ndbm_h shell
variable, you are liable to get wrong behavior on secondary runs when
caching is enabled ('./configure -C'). To properly distinguish between
the two names, you'll have to completely ignore the pre-set cache names,
and instead wrap the check inside a cache name that you control.
Post by Julien ÉLIE
AS_IF([test x"$ac_cv_header_gdbm_ndbm_h" != xno],
[AC_DEFINE([HAVE_GDBM_NDBM_H], [1],
[Define if you have the <gdbm/ndbm.h> header file.])],
[AS_UNSET([ac_cv_header_gdbm_ndbm_h])
AC_CHECK_HEADER([gdbm-ndbm.h])
AS_IF([test x"$ac_cv_header_gdbm_ndbm_h" != xno],
[AC_DEFINE([HAVE_GDBM_NDBM_H_DASH], [1],
[Define if you have the <gdbm-ndbm.h> header file.])])])
If you know a better way to do that, I would be interested in hearing it.
Thanks beforehand,
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Julien ÉLIE
2013-12-12 21:42:26 UTC
Permalink
Hi Eric,
Post by Eric Blake
Post by Julien ÉLIE
I have a question about how to deal with looking for two different headers that
lead to the same HAVE_FILENAME variable.
For instance: how to properly search for gdbm/ndbm.h and gdbm-ndbm.h?
Ugh, there's no clean way to do that with the standard macros. Who
named these header files, and can they be convinced to improve their
naming in the future?
Well, for instance libgdbm-dev in Debian provides
/usr/include/gdbm-ndbm.h whereas gdbm-devel in Red Hat provides
/usr/include/gdbm/ndbm.h...
Maybe other distributions are using other names. (I have not checked.)
Post by Eric Blake
Post by Julien ÉLIE
AC_CHECK_HEADER([gdbm/ndbm.h])
Unfortunately, AC_CHECK_HEADER short-circuits if the cache is already
populated. And since the collision is not just on the HAVE_GDBM_NDBM_H
preprocessor name, but ALSO on the $ac_cv_header_gdbm_ndbm_h shell
variable, you are liable to get wrong behavior on secondary runs when
caching is enabled ('./configure -C'). To properly distinguish between
the two names, you'll have to completely ignore the pre-set cache names,
and instead wrap the check inside a cache name that you control.
Oh, that's a pretty good point. Thanks for hinting at it.

Isn't calling AS_UNSET([ac_cv_header_gdbm_ndbm_h]) enough before the two
AC_CHECK_HEADER calls?
I do not understand well what you mean by wrapping the check inside a
cache name that I control.

Do I also have to unset HAVE_GDBM_NDBM_H and HAVE_GDBM_NDBM_H_DASH?
(Are they also cached values when set with AC_DEFINE?)

If all these removals are not enough, what more should I do?
Post by Eric Blake
Post by Julien ÉLIE
AS_IF([test x"$ac_cv_header_gdbm_ndbm_h" != xno],
[AC_DEFINE([HAVE_GDBM_NDBM_H], [1],
[Define if you have the <gdbm/ndbm.h> header file.])],
[AS_UNSET([ac_cv_header_gdbm_ndbm_h])
AC_CHECK_HEADER([gdbm-ndbm.h])
AS_IF([test x"$ac_cv_header_gdbm_ndbm_h" != xno],
[AC_DEFINE([HAVE_GDBM_NDBM_H_DASH], [1],
[Define if you have the <gdbm-ndbm.h> header file.])])])
--
Julien ÉLIE

« – Nous ne connaissons pas leur langue, donc, sous aucun prétexte
il ne faut parler aux Goths !
– Mais on peut leur taper dessus ? » (Astérix)
Loading...