in need of some scripting foo

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Anthony

in need of some scripting foo

Post 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
vlavilla

Re:in need of some scripting foo

Post 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
AR

Re:in need of some scripting foo

Post 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")
Anthony

Re:in need of some scripting foo

Post 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.
AxelDominatoR

Re:in need of some scripting foo

Post by AxelDominatoR »

Maybe you could attach your makefile...
GLneo

Re:in need of some scripting foo

Post 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

Anthony

Re:in need of some scripting foo

Post 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.
Kim

Re:in need of some scripting foo

Post 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
Post Reply