[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Recursive make and linking
From: |
Sam Ravnborg |
Subject: |
Re: Recursive make and linking |
Date: |
Wed, 21 Oct 2009 18:25:58 +0200 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
On Wed, Oct 21, 2009 at 11:46:32AM -0200, Gerhard Fiedler wrote:
> Hello,
>
> I have a problem with the link prerequisites in a recursive make.
>
> Basically, I have a list of directories that are all phony targets and
> that each contain a makefile that builds a static library. The library
> is built into a sub-directory of that makefile directory.
>
> This all works nicely, including automatic dependency generation. Due to
> the directories being phony targets, the sub-makes are always run
> through, and that's ok for this.
>
> My problem is with the linking. The final executable needs to be linked
> when it is not there (of course) or whenever it is older than any of the
> libraries created by the phony targets.
>
> I made the library files prerequisites of the final executable, but this
> doesn't seem to do the trick.
You need to tell make that the static libraries are prerequisites
of the directories.
Something like this:
dirs := foo/ bar/
libs := $(addsuffix lib.a, $(dirs))
program: $(libs)
ld $(libs) -o $@
# This is where you tell make that the libs depend on the dirs so make
# will revisit timestamps of the libs files
$(libs): $(dirs) ;
.PHONY: $(dirs)
$(dirs):
$(MAKE) -c $@
Not tested - but I hope you get the idea.
Sam