views:

45

answers:

3

How can I add extra flag variables (like CPPFLAGS) that will apply to all makefiles? Currently, we're using CPPFLAGS, but that is supposed to be reserved as a user variable and I would like to reserve it. I'd prefer not to use AM_CPPFLAGS because I would like to reserve that for specific Makefile.amS. What I want is something like GLOBAL_CPPFLAGS that I could set in configure.ac and have it applied to everything. It would also be nice if there were a way to explicitly ignore the flag.

I think what I need to do is to write my own make rule, but how would I make that available in all subfolders without copying it into every Makefile.am?

+1  A: 

I think you answered your own question: you will have to copy the new rule into every makefile.

Steve Emmerson
False. automake supports `include`: http://www.gnu.org/software/hello/manual/automake/Include.html#Include
Jack Kelly
Jack, that effectively copies the rule, which is what his question was about.
Steve Emmerson
@Steve: I suppose it does, but the copying's not done by hand and there's a central place to update the rule or variable.
Jack Kelly
A: 

CPPFLAGS is the mechanism you probably should be using. Just concatenate the flags you want somewhere in configure.ac:

GLOBAL_CPPFLAGS="-DSOMETHING"

...

CPPFLAGS="$CPPFLAGS $GLOBAL_CPPFLAGS"

and you should be set.

ldav1s
No, it's not. `CPPFLAGS` is a user variable. http://www.gnu.org/software/hello/manual/automake/User-Variables.html#User-Variables . `AC_SUBST`-ing in common flags isn't a terrible idea, though.
Jack Kelly
+2  A: 

You're correct in not using CPPFLAGS. That's a user variable. What I'd do is something like this:

In the root of your source dir, create a file called common.am and define whatever you need in there:

## common.am
AM_CPPFLAGS = -DFOO

I know you said you didn't want to use AM_CPPFLAGS, but hear me out. In your individual subdirectories, include $(top_srcdir)/common.am and extend or override AM_CPPFLAGS as needed:

## bar/Makefile.am
include $(top_srcdir)/common.am
AM_CPPFLAGS += -DBAR

If you want to override, use = instead of +=:

## baz/Makefile.am
include $(top_srcdir)/common.am
AM_CPPFLAGS = -DBAZ
Jack Kelly
Instead of `include` you could also `AC_SUBST([AM_CPPFLAGS], ["-Whatever"])` from `configure.ac` and then simply update with `+=` in those `Makefile.am` that need it.
adl
Thanks, I did something similar to this, but opted to use my own variables (e.g. GLOBAL_CPPFLAGS) and AC_SUBST them from from configigure.ac. Then I included those flags in the equivalent AM_CPPFLAGS in all makefiles and I included AM_CPPFLAGS in target_CPPFLAGS. I think this gives maximum overall control and what's happening is very explicit.
deuberger
@deuberger: If you mean you wrote `target_CPPFLAGS = $(AM_CPPFLAGS)`, you don't have to do that as it's used as the default if not set. If you mean you wrote `target_CPPFLAGS = $(AM_CPPFLAGS) -DFOO`, I can see the point of that.
Jack Kelly
@Jack Kelly: yes I meant the latter. To be specific, anywhere that target_CPPFLAGS was set, I included $(AM_CPPFLAGS) in the definition. In cases where target_CPPFLAGS was set to nothing, I often just removed it so that AM_CPPFLAGS would be used as you said.
deuberger