Page 1 of 1

in need of some scripting foo

Posted: Sat May 21, 2005 7:39 pm
by Anthony
ok, so i am redoing the Makefile for my kernel, from being one giant messy cumbersome file, to one small one in each directory and traversing all the directories to compile all the files.

well, the end result is that it outputs all the .o files into the toplevel source directory. and from there i need to link everything together. i thought it would be as simple as doing:

ld -T kernel.ld -o kernel.bin *.o

but unfortunantly, that doesn't seem to work as my k_init.o apparently needs to be the first file linked. which is understandable. so now i am at the predicament of needing to automate the linking somehow so that it links all the .o files produced but making sure k_init.o is first. thanks in advance

Re:in need of some scripting foo

Posted: Sat May 21, 2005 9:49 pm
by vlavilla
what about doing

Code: Select all

ld -T kernel.ld -o kernel.bin k_init.o *.o
so it links k_init.o first and then all the other ones, but i don't know if it would cause a problem linking k_init.o more than once though

Re:in need of some scripting foo

Posted: Sat May 21, 2005 10:06 pm
by AR
I'm not sure what will happen if you link it more than once, best case is nothing, worse case is it gets linked twice and explodes because there are multiple copies of the same symbol.

The *.o should include the files in alphabetical order (at least the Windows command prompt does) so if you put a '1' at the start it will be the first object file in the list (ie. "1k_init.o")

Re:in need of some scripting foo

Posted: Sat May 21, 2005 10:20 pm
by Anthony
yeah, it doesn't want to link with two copies.

i tried something like
ld -T kernel.ld -o kernel.bin kinit.o `ls *.o | grep -v kinit.o`

but then the very first file it tries to link says that it doesn't exist? odd.

Re:in need of some scripting foo

Posted: Sun May 22, 2005 4:28 am
by AxelDominatoR
Maybe you could attach your makefile...

Re:in need of some scripting foo

Posted: Sun May 22, 2005 7:16 am
by GLneo
what i did is compile my main .o's in a diferent folder:

Code: Select all

ld -T link.ld -o kernel.bin MAIN\*.o SUB\*.o


Re:in need of some scripting foo

Posted: Sun May 22, 2005 6:03 pm
by Anthony
thanks for the suggestions. i ended up changing my linker script to be:

Code: Select all

SECTIONS 
{ 
  .text { 
    k_init.o(.text) 
    *(.text) 
    ...
and that seemed to do the trick.

Re:in need of some scripting foo

Posted: Fri May 27, 2005 6:56 am
by Kim
I wrote this small batch file, because ..\bin\ld -T kernel.ld -o ..\output\kernel\kernel.elf ..\output\obj\*. didn't work...

Code: Select all

@echo off

if %1'==build' goto build
if %1'==' goto force
if not %1'==' goto end

:force
echo Enabeling extentions...
cmd /V:ON /C "build kernel.bat" build
goto end

:build
cd .\kernel
echo Executing nasm...
..\bin\nasm -f elf stub.asm -o ..\output\obj\stub.o
..\bin\nasm -f elf _isr.asm -o ..\output\obj\_isr.o
echo Executing freepascal...
..\bin\ppc386 -Aelf -FE..\output\obj -Fi.\include -Fu.\support -n -OG3p3 -Si -Sc -Sg -Xd -Rintel -Tlinux kernel.pas
echo Executing linker...
for %%c in (..\output\obj\*.o) do set objects=!objects! %%c
..\bin\ld -T kernel.ld -o ..\output\kernel\kernel.elf%objects%
cd ..
echo Executing strip...
.\bin\strip .\output\kernel\kernel.elf
pause
goto end

:end
@echo on