OS Makefile Design - Recursive or not
- thepowersgang
- Member
- Posts: 734
- Joined: Tue Dec 25, 2007 6:03 am
- Libera.chat IRC: thePowersGang
- Location: Perth, Western Australia
- Contact:
OS Makefile Design - Recursive or not
I'm planning on rewriting my OS's build system from being based on recursive make, with each application/driver having its own makefile that includes common configuration makefiles further up the tree, into a single make call which compiles the entire OS on its own (with per-application settings/objects handled with config makefiles in each directory).
My question is, Is this a good idea? Or should I have one makefile for the kernel mode build and one for usermode? Or keep it as it is, invoking many different make processes.
The currrent system takes ~50s to recompile (`make all install`) from clean on my Atom N450 netbook, and 2s to run `make all install` on a fully remade tree, and compiles about 40 different binaries.
What does everyone else use, and how well does it suit you?
My question is, Is this a good idea? Or should I have one makefile for the kernel mode build and one for usermode? Or keep it as it is, invoking many different make processes.
The currrent system takes ~50s to recompile (`make all install`) from clean on my Atom N450 netbook, and 2s to run `make all install` on a fully remade tree, and compiles about 40 different binaries.
What does everyone else use, and how well does it suit you?
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: OS Makefile Design - Recursive or not
Your build system's structure should be similar to the one you have now, except you should include "child" makefiles instead. As for the second question, they can have multiple targets so you could get different components built for "make" (or "make all"), "make kernel", and "make foobar".
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: OS Makefile Design - Recursive or not
Makefile is what I use. Non-recursive, definitely. Doesn't make much sense to have a dependency-checking build system, but not telling it about the whole build tree, does it?
Every good solution is obvious once you've found it.
- thepowersgang
- Member
- Posts: 734
- Joined: Tue Dec 25, 2007 6:03 am
- Libera.chat IRC: thePowersGang
- Location: Perth, Western Australia
- Contact:
Re: OS Makefile Design - Recursive or not
I agree with the ideas from that article, but my issue is handling different compilation flags. Usermode applications take very different CFLAGS/LDFLAGS to kernel modules.
Can you think of a good way of compiling each module using the required settings? I just thought of using a suffix on the object file, but that may not work nicely.
EDIT: Clarifcation
My current system allows me to compile the entire OS and install it to a FAT floppy (via mtools) so has to cope with multiple different areas, not just the kernel/modules, which could be relatively easily handled with a singe make process.
Can you think of a good way of compiling each module using the required settings? I just thought of using a suffix on the object file, but that may not work nicely.
EDIT: Clarifcation
My current system allows me to compile the entire OS and install it to a FAT floppy (via mtools) so has to cope with multiple different areas, not just the kernel/modules, which could be relatively easily handled with a singe make process.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: OS Makefile Design - Recursive or not
I use nonrecursive make as well and it does exactly what it needs to do. Recursive make would get ugly with the web of (false) dependencies you generate. If I change a sourcefile in the C library I only need to recompile that file and relink the binaries, not do a full recompile of all userland code I can find.
It's not too difficult to specify per-task rules using make.
It's not too difficult to specify per-task rules using make.
Re: OS Makefile Design - Recursive or not
That's the point. It shouldn't be too difficult to specify seperate sets of compiler flags, and using one set in general rules and another in rules specific for a subdirectory.Combuster wrote:It's not too difficult to specify per-task rules using make.
The oft-abused variable name CFLAGS - which I guiltily admit using in the Makefile tutorial - is a bad practice anyway. CFLAGS is meant for user specified flags, as in:
Code: Select all
CFLAGS="-DENABLE_SPECIAL_LOGGING" make all
Every good solution is obvious once you've found it.
Re: OS Makefile Design - Recursive or not
Am I the only person who uses python scripts?
Seriously I don't know how big your OS is so I cannot tell, but if there are more than 30 file then use a recursive makefile otherwise non-recursive.
Seriously I don't know how big your OS is so I cannot tell, but if there are more than 30 file then use a recursive makefile otherwise non-recursive.
Get back to work!
Github
Github
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: OS Makefile Design - Recursive or not
You too, young padawan, must read Recursive make considered harmful before making suggestions without arguments.but if there are more than 30 file then use a recursive makefile
The downside of having CFLAGS (or whatever you want to named it) out of the makefile, is that you'd often need a construct like CFLAGS="..." make clean && make all to have it actually do what you intend to.Solar wrote: CFLAGS="-DENABLE_SPECIAL_LOGGING" make all
Re: OS Makefile Design - Recursive or not
Nonononono.... you misunderstood.Combuster wrote:The downside of having CFLAGS (or whatever you want to named it) out of the makefile, is that you'd often need a construct like CFLAGS="..." make clean && make all to have it actually do what you intend to.
Outside the Makefile:
Code: Select all
CFLAGS="-DENABLE_SPECIAL_LOGGING" make all
Code: Select all
LOCAL_CFLAGS=-Wall -Wextra -Werror -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-rtti -fno-stack-protector
%.o: %.c
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -c $< -o $@
Then again, that's only one "school" of 'make'. Others think and do and recommend different.
Every good solution is obvious once you've found it.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: OS Makefile Design - Recursive or not
Consider the following use case (or bug report if you like):
$ make all
$ ./app
ENABLE_LOGGING not set
$ CFLAGS="-DENABLE_LOGGING" make all
$ ./app
ENABLE_LOGGING not set
$ CFLAGS="-DENABLE_LOGGING" make clean && make all
$ ./app
ENABLE_LOGGING set
$ make all
$ ./app
ENABLE_LOGGING not set
$ CFLAGS="-DENABLE_LOGGING" make all
$ ./app
ENABLE_LOGGING not set
$ CFLAGS="-DENABLE_LOGGING" make clean && make all
$ ./app
ENABLE_LOGGING set
Re: OS Makefile Design - Recursive or not
Yes, sure. Overriding CFLAGS is for people who know what they're doing (i.e., run 'make clean' first). The alternative to this is poking around in the Makefile itself.
Anyway, it's a minor point.
Anyway, it's a minor point.
Every good solution is obvious once you've found it.
Re: OS Makefile Design - Recursive or not
I use non-recursive make too. However they look like puke because I haven't had the time/interest in fixing them. I've heard bad things about recursive makes but I think they make sense when your subfolders can be considered seperate projects like you said that compiling user programs is different from the kernel.
A nice guy forked and created scons scripts for me which I think about using. They seem nice.
A nice guy forked and created scons scripts for me which I think about using. They seem nice.
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/
http://github.com/Jezze/fudge/
Re: OS Makefile Design - Recursive or not
If two applications are completely seperate projects, and have no code in common other than including the same kernel's include files, there's nothing wrong with seperate Makefiles. A "recursive" Makefile is something else, it's when you have a Makefile for components of an embracing project. A Makefile per driver, for example, would be a mistake, as I figure they will (and likely should) share quite some common code.
If you find your application Makefiles to be largely identical, you can still use a common Makefile include.
If you find your application Makefiles to be largely identical, you can still use a common Makefile include.
Every good solution is obvious once you've found it.