|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Recursive make and linkingHello,
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. It seems that this dependency is checked at the beginning of the make run, and at this time, the libraries are still older than the executable. However, after the phony directory targets are all run through, possibly one or more libraries are now newer than the executable. As it is, I need to run make twice. The first time, it'll run through all the sub-makes and build whatever library needs to be built, but it won't link. The second time, it'll again run through all the sub-makes, but since their libs are all up to date, it won't build any of them -- but it will link, apparently because now make sees the updated libraries at startup and recognizes that the link target needs to be rebuilt. It seems that I need to somehow delay the prerequisite checking for the link rule until after the sub-makes have run. Is there a way to do this? I tried to make the (phony) directory targets dependent on the library files they create, but this didn't help. Thanks for any help. Gerhard _______________________________________________ Help-make mailing list Help-make@... http://lists.gnu.org/mailman/listinfo/help-make |
|
|
Re: Recursive make and linkingOn 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 _______________________________________________ Help-make mailing list Help-make@... http://lists.gnu.org/mailman/listinfo/help-make |
|
|
Re: Recursive make and linkingOn 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 _______________________________________________ Help-make mailing list Help-make@... http://lists.gnu.org/mailman/listinfo/help-make |
| Free embeddable forum powered by Nabble | Forum Help |