Thank you very much for your comments.
sortie wrote:
That approach is fine.
Note that having recursive make is often a bad pattern, there's an online article on this, having a single makefile with all the dependency edges lets Make work much better.
However, please note that the root build system of an operating system *is distinct* from the build system of the main components. It has all sorts of logic that doesn't belong at any lower level. The points against recursive make doesn't quite apply here. In my meaty skeleton wiki article, I actually write the root build system in shell scripts to make the distinction visible.
I suppose it is OK to have libc and the kernel and all the user-space programs and libraries in the same dependency graph, but I doubt how much this scales in practice. Using things like -MD and such seems to work well in each component in my OS. I don't have all the answers here though, I am switching to my own make implementation soon that has a feature set better adjusted to my needs and scale. The recursive make design really doesn't play well with the strengths of make.
I think make is fundamentally a good design. I don't like tools generating makefiles or trying to abstract them away. The standard unix command line tools for stuff like compiling already provide suitable abstractions. I think make can be a good deal better with some smaller improvement without throwing away the language or design (or compatibility with many existing makefiles) (just some implementation may need to go away).You may disagree with these premises, in which case good for you.
I have based my hobby os organization in meaty skeleton wiki article (are you meaty skeleton wiki article author? If so, thank you because it help me a lot). The only thing I am doing is to build it from Makefile tool.
In my original post I copy/paste a Makefile main excerpt. The complete Makefile is:
Code:
PROJECTS=libc kernel
# CURDIR is set when makefile starts and its value is the current directory.
SYSROOT?="$(CURDIR)/sysroot"
ARCH="i686-elf"
CC=$(ARCH)-gcc
LD=$(ARCH)-ld
AR=$(ARCH)-ar
.PHONY: projects
projects: sysroot-dir
for dir in $(PROJECTS); do \
CC=$(CC) LD=$(LD) AR=$(AR) DESTDIR=$(SYSROOT) PREFIX="/usr" $(MAKE) -C $$dir; \
done
sysroot-dir: | $(SYSROOT)
$(SYSROOT):
mkdir -p $(SYSROOT)
.PHONY: clean
clean:
rm -f myos.iso
for dir in $(PROJECTS); do \
$(MAKE) -C $$dir clean; \
done