On 02/26/2014 07:16 PM, Fredrik Tolf wrote: > Dear list, > > I'm trying to write a program that can use custom stdio streams on both > Linux/glibc and FreeBSD, and to that end, I'm trying to modify to > autoconf script to properly detect these and turn on the necessary > compiler flags to support them. > > On glibc, I need to define `_GNU_SOURCE' in order to gain access to > fopencookie() and cookie_io_functions_t. Autoconf neatly supports > turning this on with `AC_USE_SYSTEM_EXTENSIONS(_GNU_SOURCE)', but I > can't quite seem to figure out how to only do this when necessary.
That's not how AC_USE_SYSTEM_EXTENSIONS works. The macro does not take arguments. It is an all-or-none switch - if you use it, you use it early on, to tell the configure script to enable ALL extensions on ALL platforms at once (_GNU_SOURCE on Linux is one of these, but it also enables extensions on other platforms). > Currently, I'm trying to do it like this: > > HAS_FOPENCOOKIE=yes > AC_CHECK_FUNC(fopencookie, [AC_USE_SYSTEM_EXTENSIONS(_GNU_SOURCE)], > [HAS_FOPENCOOKIE=no]) > AC_CHECK_MEMBER([cookie_io_functions_t.read], [], [HAS_FOPENCOOKIE=no]) Rather, this should be: AC_USE_SYSTEM_EXTENSIONS() AC_CHECK_FUNC([fopencookie], [HAS_FOPENCOOKIE=yes], [HAS_FOPENCOOKIE=no]) AC_CHECK_MEMBER([cookie_io_functions_t.read], [], [HAS_FOPENCOOKIE=no]) > > This /works/, per se, but autoconf complains loudly when I try to > generate the configure script, several times, that `AC_COMPILE_IFELSE > was called before AC_USE_SYSTEM_EXTENSIONS'. Apparently, it thinks it is > really bad practice to actually do any tests before turning on system > extensions. Yes, it really is bad practice to mix compilation tests before turning extensions with compilation tests done afterwards. Turning on extensions is such a drastic change to the compilation environment that you want ALL your tests to run under the same environment. Either you plan on using extensions, and should enable them unconditionally up front, or you do not need extensions, and should not use the macro. > > What should I do about this? Just ignore the warnings? Do the necessary > AC_DEFINE manually instead? (This seems ugly, since I'd need to define > an `AH_TEMPLATE` as well and all that.) Just turn on all extensions that > I may or may not use, unconditionally at the top of the file? Something > completely different? Unconditionally call AC_USE_SYSTEM_EXTENSIONS() (note: no arguments) at the top of the file (well, after the AC_INIT, but before any compilation tests). -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Autoconf mailing list Autoconf@gnu.org https://lists.gnu.org/mailman/listinfo/autoconf