Hi John,
Thanks for the fast reply (my mailtool messed up the line-feeds I guess,
sorry about that).
You were right about the wrong order in SUBDIRS = apps comps (that was a
type).
Your answers raised some new questions to me:
- non-recursive make, is that the same as just making one big make file that
will always build
everything? So I would loose the ability to build (for example) only one
application, or library?
- isn't there any other way to modify the makefile.am of an application so
that it will execute the
makefile's of it's dependend library (components)?
- making a hack so that an application will go BACK into the directories of
the dependend
components by adding SUBDIRS = ../comps/comp1 is probably not the way to
go (and can
cause infinity recursion loops).
best regards,
Michiel
--------------------------------------------------
From: "John Calcote" <john.calc...@gmail.com>
Sent: Tuesday, August 04, 2009 6:54 PM
To: "Michiel Soede" <michielso...@hotmail.com>
Cc: <automake@gnu.org>
Subject: Re: library dependencies SUBDIR problem automake
Hi Michiel,
On 8/4/2009 10:01 AM, Michiel Soede wrote:
Hi,
I have a problem with dependencies to libraries in my build structure.the
directory structure in my project is as follows (roughly):
configure.acmakefile.amapps/ makefile.am app1/
main.cc makefile.am comps/ makefile.am
comp1/ comp1.cc makefile.am
the component makefile generates a library:noinst_LIBRARIES =
libcomp1.alibcomp1a_a_SOURCES = comp1.cc
I recurse in all subdirectories, using SUBDIRS:SUBDIRS = apps comps
in the comps:SUBDIRS = comp1
same for the apps directory.
the app1 uses LDADD to link the app with main.cc
bin_PROGRAMS = app1app1_SOURCES = main.ccapp1_LDADD =
$(top_builddir)/comps/comp1/libcomp1.a
Now when I call make at the root, everything is build correctly.
But when I cd into apps/app1/ and call make, I have problems with:
- if comp1 was not made before (e.g. from the root), make will fail (no
rule to make libcomp1.a)
- if I did make the library at the root, it is not recompiled
automatically when I modify comp1.cc
.. any ideas on these problems?
The lack of proper text wrapping on your message made it a bit difficult
to see your directory structure, but I think I've sorted it out, based on
your other comments:
configure.ac
makefile.am
apps/
makefile.am
app1/
main.cc
makefile.am
comps/
makefile.am
comp1/
comp1.cc
makefile.am
According to your makefiles, app1 is dependent on comp1 (app1_LDADD =
.../libcomp1.a), but comp1 is not built as a sub-component (sub-directory)
of app1. Thus, (I believe you are saying) when you build from the project
root, everything is fine, but when you build from the app1 directory,
comp1 doesn't get built, and thus the app1 build fails. Is this correct?
A recursive build system must be designed to build component dependencies
first before building the components. Thus, one limitation of a recursive
build system is that it rather defines (or at least constrains) the
directory structure that you must use. To get comps to be built before
apps from within the app1 directory, you must build the comps directory
structure from within the app1 directory.
I recognize that applications 2-n may also use components 1-n, so you have
a problem here, and the only way around it is to use a non-recursive build
system. That is, you can place all of your build logic in the top-level
Makefile.am file using relative paths, and then the makefile dependencies
will be properly structured for you by Automake:
Makefile.am:
= = = = = = = = = = =
bin_PROGRAMS = app1 app2 app3 ...
app1_SOURCES = apps/app1/main.cc
app2_SOURCES = apps/app2/...
...
noinst_LIBRARIES = libcomp1.a libcomp2.a libcomp3.a ...
libcomp1_a_SOURCES = comps/comp1/comp1.cc
libcomp2_a_SOURCES = comps/comp2/...
...
app1_LDADD = libcomp1.a
= = = = = = = = = = =
I also noted that you had
SUBDIRS = apps comps
in your top-level Makefile.am file. This is wrong - the comps hierarchy
should be built before the apps hierarchy, or else there will still be no
libraries in the comps hierarchy for the apps to link against, unless
you've manually built the comps directory first, and then attempted to
build from root.
Regards,
John