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