OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 19, 2024 12:54 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Best way of doing Make library dependencies
PostPosted: Tue Sep 14, 2021 1:50 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
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:
$(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


Top
 Profile  
 
 Post subject: Re: Best way of doing Make library dependencies
PostPosted: Tue Sep 14, 2021 1:56 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1590
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!


Top
 Profile  
 
 Post subject: Re: Best way of doing Make library dependencies
PostPosted: Tue Sep 14, 2021 2:00 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
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


Top
 Profile  
 
 Post subject: Re: Best way of doing Make library dependencies
PostPosted: Tue Sep 14, 2021 2:28 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1590
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group