automake
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Setting libXXX_la_CPPFLAGS and libXXX_la_CFLAGS erases AM_CPPFLAGS and A


From: madmurphy
Subject: Setting libXXX_la_CPPFLAGS and libXXX_la_CFLAGS erases AM_CPPFLAGS and AM_CFLAGS
Date: Fri, 18 Nov 2022 20:40:18 +0000

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

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]