Subject: Re: bug#21106: AC_SUBST([FOO_LIB], ['libfoo.la']) breaks dependency checker

From: Stanislav Brabec <[email-masked]>
Date: Thu, 23 Jul 2015 15:54:47 +0200

Gavin Smith wrote:
> On 21 July 2015 at 21:17, Stanislav Brabec <[email-masked]> wrote:
>> Is there any better way how to do such things than use
>>
>> if USE_BUILTIN_LIBFOO
>> myprogram_LDADD = libfoo.la
>> else
>> myprogram_LDADD = -lfoo
>> endif
>>
>> everywhere I need to link with libfoo?
> 
> It seems similar to the questions of conditional sources, which is
> covered in the Automake manual. It suggests two approaches, one with
> Automake conditionals, which you imply you don't like;

I just wanted to avoid it because Makefile.am with hundreds of
conditionals is less readable. But if it is the recommended way,
I'll use it.

> the other
> similar to the approach you've been trying with a *.la file in the
> place of a *.o file, with the exception that the Automake manual uses
> an EXTRA_myprogram_SOURCES variable.

This does not work. It just compiles all sources of the libfoo.la, but
the linking the library itself is run in parallel with linking of
myprogram. Parallel build ends with the same error as before.

But this works:
EXTRA_myprogram_SOURCES = libfoo.la
BUILT_SOURCES = libfoo.la

> I don't know if adding "EXTRA_myprogram_SOURCES = libfoo.c" (or
> "EXTRA_myprogram_SOURCES = $(libfoo_la_SOURCES)") is the right
> solution?
> 
Even in a form mentioned above, it is not allowed:

configure.ac:10: error: 'FOO_LIB' includes configure substitution '@FOO_LIB@'
configure.ac:10: and is referred to from 'EXTRA_myprogram_SOURCES';
configure.ac:10: configure substitutions are not allowed in _SOURCES variables

But following works: Move the if/else from configure.ac to Makefile.am:

if BUILTIN_FOO
FOOLIB = libfoo.la
else
FOOLIB = -lfoo
endif

myprogram_LDADD = $(FOO_LIB)

Now automatic dependency checker is able to expand libfoo.la and properly link
libfoo.la before myprogram, and the conditional is used just once instead of
hundred times.

I propose to improve AC_SUBST documentation. See attached patch.

-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                         e-mail: [email-masked]
Lihovarská 1060/12                            tel: +49 911 7405384547
190 00 Praha 9                                 fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76
>From abc71e35fb0fe44cb5ec8e8d31030833310b62be Mon Sep 17 00:00:00 2001
From: Stanislav Brabec <[email-masked]>
Date: Thu, 23 Jul 2015 15:43:30 +0200
Subject: [PATCH] Document that AC_SUBST can break dependencies

If configure.ac contains
AC_SUBST([FOO_LIB], ['libfoo.la'])
and Makefile am contains
myprogram_LDADD = $(FOO_LIB)
the dependency checker is not capable to detect such dependency, and
parallel build could be broken.
Document this behavior, reported in bug #21106.

Signed-off-by: Stanislav Brabec <[email-masked]>
---
 doc/automake.texi | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/doc/automake.texi b/doc/automake.texi
index ecfbbc8..efd8d74 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -3076,6 +3076,11 @@ this way, e.g., @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and
 @code{$(X_CFLAGS)} and @code{$(X_LIBS)} in any @file{Makefile.am}
 if @code{AC_PATH_XTRA} is called.
 
+The substituted value should not contain names of any generated files,
+as dependency checker is not able to evaluate them. If you need such
+assignment, use @code{AM_CONDITIONAL} and assign a proper value in
+@file{Makefile.am}.
+
 @item AM_CONDITIONAL
 This introduces an Automake conditional (@pxref{Conditionals}).
 
-- 
2.4.5