Best way of doing Make library dependencies

Programming, for all ages and all languages.
Post Reply
nexos
Member
Member
Posts: 1071
Joined: Tue Feb 18, 2020 3:29 pm
Freenode IRC: nexos

Best way of doing Make library dependencies

Post by nexos »

Hello,
I have been working on the build system of my operating system (for 2 months :roll: ). I am using non recursive GNU Make to build it. One question I have is what is the best way of making an executable depend on a library? At the moment, I'm doing it like this:

Code: Select all

$(BOOTEFI_OUTPUTNAME): $(BOOTEFI_OBJFILES) $(LIBK_OUTPUTNAME) Makefile
LIBK_OUTPUTNAME contains the name of the libk archive. One problem I perceived is the infinitesimally small chance that libk is still building when the executable is finished. Then, it will see an out of date libk (which is really in the process of being built), and then it will re-invoke the recipe. This would probably cause race conditions and other evils.

So, my question is: How can I make the executable wait for libk to come in date, instead of invoking the recipe itself? Is that even possible?
Thanks,
nexos

P.S. The full repo is in my signature
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
nullplan
Member
Member
Posts: 1643
Joined: Wed Aug 30, 2017 8:24 am

Re: Best way of doing Make library dependencies

Post by nullplan »

If the makefile is non-recursive, then the make instance building the kernel is also the instance building the libk, and will not start the build process until libk is remade.
Carpe diem!
nexos
Member
Member
Posts: 1071
Joined: Tue Feb 18, 2020 3:29 pm
Freenode IRC: nexos

Re: Best way of doing Make library dependencies

Post by nexos »

nullplan wrote:If the makefile is non-recursive, then the make instance building the kernel is also the instance building the libk, and will not start the build process until libk is remade.
I wondered that! Thanks!

Edit - on parallel make, are targets built in parallel? If so, then the above scenario might could still happen
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
nullplan
Member
Member
Posts: 1643
Joined: Wed Aug 30, 2017 8:24 am

Re: Best way of doing Make library dependencies

Post by nullplan »

The whole deal with make is that it manages dependencies. That is the reason you write a Makefile instead of just a build script. On parallel make, it will only run independent builds in parallel. For the same reason, it can also not start to build your kernel while the object files are still in progress, but it can build the object files in parallel.
Carpe diem!
Post Reply