Re: Setting libXXX_la_CPPFLAGS and libXXX_la_CFLAGS erases AM_CPPFLAGS and AM_CFLAGS

2022-11-18 Thread Jan Engelhardt


On Friday 2022-11-18 22:57, Russ Allbery wrote:
>madmurphy  writes:
>
>> However, if at the same time I set also the libfoo_la_CPPFLAGS variable (no
>> matter the content), as in the following example,
>
>> AM_CPPFLAGS = \
>>   "-DLIBFOO_BUILD_MESSAGE=\"correctly defined via AM_CPPFLAGS\""
>> libfoo_la_CPPFLAGS = \
>>   "-DLIBFOO_DUMMY=\"This is just a dummy text\""
>
>> the AM_CPPFLAGS variable will be completely overwritten

It makes sense though.

It's better that pertarget_CPPFLAGS overwrites, because otherwise... there
would be no chance to dump (get rid) the AM_CPPFLAGS portion in the
command-line - short of never setting AM_CPPFLAGS at all, which is not very
economical if all you want to change is one target...



Re: Setting libXXX_la_CPPFLAGS and libXXX_la_CFLAGS erases AM_CPPFLAGS and AM_CFLAGS

2022-11-18 Thread Russ Allbery
madmurphy  writes:

> However, if at the same time I set also the libfoo_la_CPPFLAGS variable (no
> matter the content), as in the following example,

> AM_CPPFLAGS = \
>"-DLIBFOO_BUILD_MESSAGE=\"correctly defined via AM_CPPFLAGS\""

> ...

> libfoo_la_CPPFLAGS = \
>"-DLIBFOO_DUMMY=\"This is just a dummy text\""

> the AM_CPPFLAGS variable will be completely overwritten by the
> libfoo_la_CPPFLAGS variable, and invoking libfoo_func() will print

> Message from the build system: undefined

While this is often confusing, this is the documented behavior of
Automake.  See:

https://www.gnu.org/software/automake/manual/automake.html#Program-and-Library-Variables

In compilations with per-target flags, the ordinary ‘AM_’ form of the
flags variable is not automatically included in the compilation
(however, the user form of the variable is included). So for instance,
if you want the hypothetical maude compilations to also use the value
of AM_CFLAGS, you would need to write:

maude_CFLAGS = … your flags … $(AM_CFLAGS)

See Flag Variables Ordering, for more discussion about the interaction
between user variables, ‘AM_’ shadow variables, and per-target
variables.

and

https://www.gnu.org/software/automake/manual/automake.html#Flag-Variables-Ordering

-- 
Russ Allbery (ea...@eyrie.org) 



Setting libXXX_la_CPPFLAGS and libXXX_la_CFLAGS erases AM_CPPFLAGS and AM_CFLAGS

2022-11-18 Thread madmurphy
Hi,

If I create a library named libfoo containing the following code (example
attached),

#include "libfoo.h"

#ifndef LIBFOO_BUILD_MESSAGE
#define LIBFOO_BUILD_MESSAGE "undefined"
#endif


int libfoo_func() {
printf("Message from the build system: " LIBFOO_BUILD_MESSAGE "\n");
return 0;
}

and then I set the LIBFOO_BUILD_MESSAGE preprocessor macro via Makefile.am,

AM_CPPFLAGS = \
 "-DLIBFOO_BUILD_MESSAGE=\"correctly defined via AM_CPPFLAGS\""

invoking libfoo_func() from a linked program will correctly print the
following text.

Message from the build system: correctly defined via AM_CPPFLAGS

However, if at the same time I set also the libfoo_la_CPPFLAGS variable (no
matter the content), as in the following example,

AM_CPPFLAGS = \
 "-DLIBFOO_BUILD_MESSAGE=\"correctly defined via AM_CPPFLAGS\""

...

libfoo_la_CPPFLAGS = \
 "-DLIBFOO_DUMMY=\"This is just a dummy text\""

the AM_CPPFLAGS variable will be completely overwritten by the
libfoo_la_CPPFLAGS variable, and invoking libfoo_func() will print

Message from the build system: undefined

If I decide to use the *_CFLAGS class of variables instead of *_CPPFLAGS,

AM_CFLAGS = \
 -Wall \
 -Wextra \
 -g \
 "-DLIBFOO_BUILD_MESSAGE=\"correctly defined via AM_CPPFLAGS\""

...

libfoo_la_CFLAGS = \
 "-DLIBFOO_DUMMY=\"This is just a dummy text\""

the result will be the same.

Message from the build system: undefined

To restore AM_CPPFLAGS (or AM_CFLAGS) I need to mention it explicitly in
libfoo_la_CPPFLAGS.

AM_CPPFLAGS = \
 "-DLIBFOO_BUILD_MESSAGE=\"correctly defined via AM_CPPFLAGS\""

...

libfoo_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
 "-DLIBFOO_DUMMY=\"This is just a dummy text\""

In this case libfoo_func() will correctly print

Message from the build system: correctly defined via AM_CPPFLAGS

Is this a wanted behavior? Isn't the sense of AM_* variables that of being
applied to every single library in a project?

--madmurphy


libfoo-1.0.0.tar.xz
Description: application/xz