On 07/02/2012 07:20 PM, Bruno Haible wrote:
> Hi Eric,
> 

> How can we fix this?
> 
> I'm thinking about two macros AC_DEFUN_ONCE_IFNEEDED, AC_REQUIRE_IFNEEDED

Again, avoiding the AC_ namespace unless Autoconf 2.80 adds this methods
might be wise, we'd be safer with the names gl_DEFUN_ONCE_IFNEEDED and
gl_REQUIRE_IFNEEDED.

> that will operate like AC_DEFUN_ONCE and AC_REQUIRE except that they will
> ensure that the body is executed only when actually needed.
> 

> AC_DEFUN_ONCE_IFNEEDED would use shell functions, roughly like this:
> 
> AC_DEFUN_ONCE_IFNEEDED([FOO], [
>   AC_REQUIRE([DEPENDENCY1])
>   AC_REQUIRE_IFNEEDED([DEPENDENCY2])
>   BODY-CODE
> ])
> 
> =>
> 
> AC_DEFUN([FOO],
> [
>   AC_REQUIRE([FOO_BODY])
>   foo_func
> ])
> AC_DEFUN([FOO_BODY], [
>   AC_REQUIRE([DEPENDENCY1])
>   AC_REQUIRE([DEPENDENCY2])
>   foo_var=false
>   foo_func ()
>   {
>     if ! $foo_var; then
>       dependency2_func
>       BODY-CODE
>       foo_var=true
>     fi
>   }
> ])
> 
> Eric, is it possible to write such macros? It is complicated, sure. But
> is there something that makes the idea unimplementable?

Yes, I think such an implementation should be possible.  Doing it using
only the constructs available in autoconf 2.59 will be a bit
interesting, but I can certainly help out.

It might even be shorter to do:

AC_DEFUN([FOO_BODY], [
  AC_REQUIRE([DEPENDENCY1])
  AC_REQUIRE([DEPENDENCY2])
  foo_func ()
  {
    foo_func() { :; }
    dependency2_func
    BODY-CODE
  }
])

to use self-redefining shell functions instead of having to use both a
shell function and a witness variable.

-- 
Eric Blake   ebl...@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to