help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Recursive make and linking


From: Gerhard Fiedler
Subject: Re: Recursive make and linking
Date: Wed, 21 Oct 2009 19:58:48 -0200
User-agent: 40tude_Dialog/2.0.15.1

On 2009-10-21 14:25:58, Sam Ravnborg wrote:

> On Wed, Oct 21, 2009 at 11:46:32AM -0200, Gerhard Fiedler wrote:
>> 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.

Got it, and it seems to work (need to do some more testing to be sure).

The strange thing is that I had something like this in the makefile 
already:

  foo/.../libfoo.a: foo
  bar/.../libbar.a: bar

After I replaced it with your suggestion

  foo/.../libfoo.a bar/.../libbar.a: foo bar

it now seems to work.

Can somebody explain to me the difference between the two, please?

Thanks,
Gerhard





reply via email to

[Prev in Thread] Current Thread [Next in Thread]