Discussion:
AM_CFLAGS and %reldir%
Thomas Martitz
2017-05-05 06:59:42 UTC
Permalink
Hello,


when transitioning a project to non-recursive Automake, using %reldir%,
you lose the ability to define per-directory AM_{CPP,C,CXX,LD}FLAGS.

With recursive Automake, you can simply set AM_CFLAGS in each
Makefile.am. Attempting the same in a non-recursive setup would modify
the single, global AM_CFLAGS, which may not be desirable.

The only solution seems to be to heavily expand the fragments:

AM_CFLAGS = -g

bin_PROGRAMS = foo bar baz

becomes

bin_PROGRAMS += %D%/foo %D%/bar %D%/baz

%C_foo_CFLAGS = -g

%C_bar_CFLAGS = -g

%C_baz_CFLAGS = -g

(repeat for AM_CPPFLAGS, AM_CXXFLAGS, AM_LDFLAGS).

This gets unwieldy in cases of many programs and libraries. As a side
effect, Automake will emit explicit rules, making the Makefile even
larger, though that's not much of a problem I think and is probably not
avoidable.

Is there any other solution available? I have tried to define
directory-level AM_CFLAGS, like

AM_%C%_CFLAGS = -g

(applying to all targets that start with %C% after expanding) but they
are not used.


If there are no other solutions, would the above idea considered if
someone posted a patch?

Best regards.
Mathieu Lirzin
2017-05-14 12:35:15 UTC
Permalink
Hello,
Post by Thomas Martitz
when transitioning a project to non-recursive Automake, using
%reldir%, you lose the ability to define per-directory
AM_{CPP,C,CXX,LD}FLAGS.
With recursive Automake, you can simply set AM_CFLAGS in each
Makefile.am. Attempting the same in a non-recursive setup would modify
the single, global AM_CFLAGS, which may not be desirable.
AM_CFLAGS = -g
bin_PROGRAMS = foo bar baz
becomes
bin_PROGRAMS += %D%/foo %D%/bar %D%/baz
%C_foo_CFLAGS = -g
%C_bar_CFLAGS = -g
%C_baz_CFLAGS = -g
(repeat for AM_CPPFLAGS, AM_CXXFLAGS, AM_LDFLAGS).
This gets unwieldy in cases of many programs and libraries. As a side
effect, Automake will emit explicit rules, making the Makefile even
larger, though that's not much of a problem I think and is probably
not avoidable.
Is there any other solution available? I have tried to define
directory-level AM_CFLAGS, like
AM_%C%_CFLAGS = -g
(applying to all targets that start with %C% after expanding) but they
are not used.
If there are no other solutions, would the above idea considered if
someone posted a patch?
I think I understand what you mean, however the issue has nothing to do
with %reldir% which is just a convenience for not typing the current
directory of the makefile fragment.

The issue is that you can have only one default AM_*FLAGS per Makefile
and when using a non-recursive Makefile (even with included fragments)
everything is put in a unique Makefile. When you have a lot of programs
(for example in a test suite), having to define foo_*FLAGS for each
program can indeed be cumbersome.

I like the idea of allowing per directory default flags, I don't see any
issue with such feature.

Regarding the syntax, what about dropping the "AM" in front of
AM_directory_*FLAGS like what is done for per programs _*FLAGS? IIUC,
it will be impossible to have conflicts between program and directory
flags variables.

Thanks.
--
Mathieu Lirzin
GPG: F2A3 8D7E EB2B 6640 5761 070D 0ADE E100 9460 4D37
Thomas Martitz
2017-05-15 14:59:59 UTC
Permalink
Post by Thomas Martitz
Hello,
Post by Thomas Martitz
If there are no other solutions, would the above idea considered if
someone posted a patch?
I think I understand what you mean, however the issue has nothing to do
with %reldir% which is just a convenience for not typing the current
directory of the makefile fragment.
(unrelated, but %reldir% also enables including a fragment from more
that one place, it's more that just convinience)
Post by Thomas Martitz
The issue is that you can have only one default AM_*FLAGS per Makefile
and when using a non-recursive Makefile (even with included fragments)
everything is put in a unique Makefile. When you have a lot of programs
(for example in a test suite), having to define foo_*FLAGS for each
program can indeed be cumbersome.
I like the idea of allowing per directory default flags, I don't see any
issue with such feature.
Regarding the syntax, what about dropping the "AM" in front of
AM_directory_*FLAGS like what is done for per programs _*FLAGS? IIUC,
it will be impossible to have conflicts between program and directory
flags variables.
I think this is problematic if the fragment is included within the same
directory, i.e. %C% expands empty (and eats the following remaining _).

Hence I suggested AM_%C%_FLAGS so it would automatically become
AM_CFLAGS, although a AM_%C%_CFLAGS = $(AM_CFLAGS) could also be
troublesome.

Also, I'm not planning to work on this at the moment, I'm too busy with
other stuff at the moment. But it's good to know that the idea is
generally sound.

Best regards.

Loading...