Page 2 of 2
Re: What does your Makefile look like? (or, how to build kernel)
Posted: Wed Jul 15, 2009 5:00 am
by stealther
andreaorru wrote:Aren't you linking all the library to your kernel, in that way?
Yes
At the moment it's a "hello-world" kernel so there's no way to link at runtime.
Re: What does your Makefile look like? (or, how to build kernel)
Posted: Wed Jul 15, 2009 5:05 am
by AndreaOrru
stealther wrote:andreaorru wrote:Aren't you linking all the library to your kernel, in that way?
Yes
At the moment it's a "hello-world" kernel so there's no way to link at runtime.
Is there a way to (statically) link the kernel only with the library's files which get included?
Re: What does your Makefile look like? (or, how to build kernel)
Posted: Wed Jul 15, 2009 5:18 am
by stealther
Maybe there's some linker switch which omits unreferenced object files (or even contents of object files).
Maybe ld does it automatically.
It's beyond my knowledge database.
Re: What does your Makefile look like? (or, how to build kernel)
Posted: Wed Jul 15, 2009 5:23 am
by AndreaOrru
I'll wait for Solar or someone else, then =)
Thanks anyway.
Re: What does your Makefile look like? (or, how to build kernel)
Posted: Wed Jul 15, 2009 5:56 am
by Solar
andreaorru wrote:I'll wait for Solar or someone else, then =)
That one cracked me up. Thanks for the laugh.
I know that, when linking from a linker archive (*.ar), 'ld' only takes those object files actually required to satisfy dependencies, leaving any others out of the resulting executable. Perhaps that's the feature you are looking for.
Re: What does your Makefile look like? (or, how to build kernel)
Posted: Wed Jul 15, 2009 6:06 am
by AndreaOrru
Solar wrote:I know that, when linking from a linker archive (*.ar), 'ld' only takes those object files actually required to satisfy dependencies, leaving any others out of the resulting executable. Perhaps that's the feature you are looking for.
Any other way? I'd want my Makefile to build and link only what is needed from the library. I think it would be more clean.
Re: What does your Makefile look like? (or, how to build kernel)
Posted: Wed Jul 15, 2009 6:21 am
by Solar
I don't understand, really. I understood correctly that you have a (static) function library which is linked with your kernel, and you want in the resulting binary only that part of the library which is actually used. Correct?
Well then, individually compile the translation units (*.c and *.asm files) of your library (resulting in a *.o file each), and put them in a linker archive. Link your kernel with that linker archive, and 'ld' does the selection automatically.
Code: Select all
lib.a: $(LIB_OBJFILES)
@$(AR) $(ARFLAGS) lib.a $?
kernel: lib.a $(KERN_OBJFILES)
@$(LD) $(LDFLAGS) -T linker.ld -o kernel.bin $(KERN_OBJFILES) lib.a
Re: What does your Makefile look like? (or, how to build kernel)
Posted: Wed Jul 15, 2009 6:36 am
by AndreaOrru
Ok, thank you!
Re: What does your Makefile look like? (or, how to build kernel)
Posted: Sat Jul 18, 2009 2:11 pm
by tharkun
manonthemoon wrote:
Code: Select all
loader.o: src/loader.asm
nasm -f elf $< -o $@
# a source code file. You need one of these for each file in your project
bin/main.o: src/main.cpp
$(CC) $(CFLAGS) -o $@ -c $<
bin/kio.o: src/kio.cpp
$(CC) $(CFLAGS) -o $@ -c $<
You can actually replace these lines with:
Code: Select all
%.o: %.s:
nasm -f elf $< -o $@
%.o: %.c
$(CC) $(CFLAGS) -o $@ -c $<
This creates a *.o file for every *.c and *.s file.
It' a great timesaver.
Re: What does your Makefile look like? (or, how to build kernel)
Posted: Sun Jul 19, 2009 1:36 pm
by ehenkes