Hi Eric, I wrote: > But I have two issues with AC_DEFUN_ONCE. > ... > More generally, this would lead to the coding convention that all macros > gl_FUNC_FOO for a single function foo() would be an AC_DEFUN_ONCE.
My second issue with AC_DEFUN_ONCE is that this coding convention would defeat parts of the benefits of conditional dependencies. Namely, if 'foo' is a module that is conditionally included (depending on the system), then so far we have been able to eliminate both the autoconf test (gl_FUNC_FOO invocation) and the code (foo.o compilation unit) on systems where the module is not used. But if gl_FUNC_FOO is defined through AC_DEFUN_ONCE, its body is expanded unconditionally, before gl_INIT, therefore it is executed on all systems. How can we fix this? I'm thinking about two macros AC_DEFUN_ONCE_IFNEEDED, AC_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 works like this: AC_DEFUN_ONCE([FOO], [ AC_REQUIRE([DEPENDENCY1]) AC_REQUIRE([DEPENDENCY2]) BODY-CODE ]) => AC_DEFUN([FOO], [ AC_REQUIRE([FOO_BODY]) ]) AC_DEFUN([FOO_BODY], [ AC_REQUIRE([DEPENDENCY1]) AC_REQUIRE([DEPENDENCY2]) BODY-CODE ]) 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? Bruno