Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

automake: modify implicity make rule to include extra flags

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?

like image 437
deuberger Avatar asked Jun 21 '26 13:06

deuberger


1 Answers

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
like image 73
Jack Kelly Avatar answered Jun 24 '26 13:06

Jack Kelly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!