Re: How to write directly to config.h from configure?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/26/2018 10:36 AM, Jeffrey Walton wrote:
Hi Everyone,

I have a bad interaction with a project and Autotools. The project is
not an Autotools project but we are trying to [cleanly] support
Autotools. The project provides its own config.h since the mid-1990's.
We want to supply roughly the same file though Autotools.

The problem is, the project's config.h has some stuff that does not
seem to fit in the Autotools model like typedefs and declarations of
namespaces. I think the solution is to write directly to config.h but
I can't figure out how to do it. Testing code like below is lost
(i.e., it is not in the resulting config.h):

     ## Some real autoconf tests...

     cat << EOT >> config.h
       typedef unsigned char byte;
       typedef unsigned short word16;
       typedef unsigned int word32;
     EOT

     ## Back to real autoconf tests...

Is it possible to write directly to config.h? If yes, then how do I do it?

Sort of. It's possible to use AH_VERBATIM() to put almost-arbitrary text into the config.h file, with the caveat that '#undef' within that text is still a magic sequence that gets turned into a comment or #define as needed. For example, from autoconf itself:

AC_DEFUN([AC_C_BIGENDIAN],
[AH_VERBATIM([WORDS_BIGENDIAN],
[/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
   significant byte first (like Motorola and SPARC, unlike Intel). */
#if defined AC_APPLE_UNIVERSAL_BUILD
# if defined __BIG_ENDIAN__
#  define WORDS_BIGENDIAN 1
# endif
#else
# ifndef WORDS_BIGENDIAN
#  undef WORDS_BIGENDIAN
# endif
#endif])dnl
 AC_CACHE_CHECK([whether byte ordering is bigendian], [ac_cv_c_bigendian],
...

which results in a verbatim chunk of code in config.h where only one line (third from the bottom) is later rewritten by AC_DEFINE, but where the logic flow of the preprocessor doesn't care about the rewritten line on Apple universal builds.

In your case, it looks like you'd do:

AH_VERBATIM([MY_TYPEDEFS], [[
       typedef unsigned char byte;
       typedef unsigned short word16;
       typedef unsigned int word32;
]])

(where MY_TYPEDEFS is replaced by whatever name you desire, although it should be prefixed to your project to avoid collisions)

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
https://lists.gnu.org/mailman/listinfo/autoconf



[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux