Build File Help Ubuntu (Linux)

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.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Build File Help Ubuntu (Linux)

Post by Love4Boobies »

You need to have tab characters not spaces where you need to execute shell instructions (such as rm).
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Build File Help Ubuntu (Linux)

Post by JohnnyTheDon »

Way to take a good makefile and destory it...

Code: Select all

[img]gcc[/img]
Get rid of the img tags. Why are they there?

Code: Select all

kernel.bin
That is supposed to be the directory where you want to output your file. Make sure it ends with a / (ie bin/). If you want it to ouput the file in the same directory as the makefile, leave it blank.

Code: Select all

WalkerOS
Make this kernel.bin (or whatever you want the filename for your output to be).

You need to make a linker script. The one from bare bones will suffice. Call it linkerscript.ld.

I really recommend giving up on making an OS right now. Like others have said, you lack sufficient experience. Try programming some regular user mode programs. We don't need another person who copies tutorials and then asks how to write a function in C.
User avatar
GeniusCobyWalker
Member
Member
Posts: 65
Joined: Mon Jan 12, 2009 4:17 pm

Re: Build File Help Ubuntu (Linux)

Post by GeniusCobyWalker »

Fixed everything both of y'all said,
Same Error :(

!!!!!!!!!
Look at main post! Updated makefile and Error
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Build File Help Ubuntu (Linux)

Post by Firestryke31 »

I am confused as to what these are for:

Code: Select all

$(CSOURCES) :
$(ASMSOURCES) :
$(CHEADERS) :
What happens if you remove them?

Also, try looking around line 24, to see if something's missing. Unfortunately I don't know if it counts empty lines or not, so try looking at both. Hint: With newlines it's at the 'rm' statement in clean, and without it's the statements coded above.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Build File Help Ubuntu (Linux)

Post by JamesM »

You lie. You didn't fix everything we said, because if you did, it would work.

I know this, because I just copy-pasted from your post into a new file, changed the spaces to tabs where they should be, and ran it.

Code: Select all

[18:54:02] ~/tmp $ make
ld -T linkerscript.ld --strip-all -nostdlib -nodefaultlibs -o bin/kernel.bin
ld: cannot open linker script file linkerscript.ld: No such file or directory
make: *** [bin/kernel.bin] Error 1
[18:54:03] ~/tmp
There should be one tab character before the "rm", before the "$(LD)", "$(CC)" and "$(ASM)" on lines 24, 26, 28 and 30.

Make sure your editor isn't set up to convert tabs to spaces (most unset this functionality when they see a Makefile, but you decided not to captialise your filename correctly, so they may not have picked it up.)
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Build File Help Ubuntu (Linux)

Post by JohnnyTheDon »

Firestryke31 wrote:I am confused as to what these are for:

Code: Select all

$(CSOURCES) :
$(ASMSOURCES) :
$(CHEADERS) :
What happens if you remove them?
I had some problems with my makefiles not checking timestamps. I added these and it fixed it. I'm not sure if the makefile docs say they're required, but they worked for me.
User avatar
stephenj
Member
Member
Posts: 140
Joined: Wed Jul 23, 2008 1:37 am
Location: Canada

Re: Build File Help Ubuntu (Linux)

Post by stephenj »

You know the annoying Z80 processor, and trust me, this isn't remotely as difficult to learn.

I've read this tutorial and it explains the mistakes you've made this far. Now don't skim it, read it carefully.

Also, your makefile is pretty complex at the moment. I advise you temporarily rename it, and write a simpler, more fragile version for the sake of learning. Build it piecemeal, not all at once. Your goal, for the moment, shouldn't be to build a kernel, but learning how to use make.

I've written a base, to get you started.

Code: Select all

ASM = nasm
ASMFLAGS = -f elf32

.PHONY : all clean

all: loader.o

clean:
<TAB ONCE>rm -f *.o

loader.o: loader.s
<TAB ONCE>$(ASM) $(ASMFLAGS) -o loader.o loader.s
Good luck.
User avatar
GeniusCobyWalker
Member
Member
Posts: 65
Joined: Mon Jan 12, 2009 4:17 pm

Re: Build File Help Ubuntu (Linux)

Post by GeniusCobyWalker »

I figured out what the commands meant.
So I just wrote a basic Makefile that
Assembles,Compiles, Links,Makes a Floppy, Erases O/Bin files and Runs my OS.

I'll write a more advanced one as I need it.

Makefile:
all: kernel.c
rm -f *.o
nasm -f elf -o loader.o loader.s
gcc -o kernel.o -c kernel.c -nostdlib -nostartfiles -nodefaultlibs -m32
ld -T linker.ld -o kernel.bin loader.o kernel.o -m elf_i386
cat stage1 stage2 pad kernel.bin > floppy.img
rm -f *.o
rm -f *.bin
bochs
Full Knowledge in:
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
User avatar
stephenj
Member
Member
Posts: 140
Joined: Wed Jul 23, 2008 1:37 am
Location: Canada

Re: Build File Help Ubuntu (Linux)

Post by stephenj »

The "all" label should have all the files it requires after it (not just kernel.c).

"rm -f *.o *.bin" is also legal. You should put it under a label named "clean" at the very least (it can be called by all).

That is a REALLY pointless makefile though. You're never going to need something more complex. But both you and your computer are going to have to do extra work that could easily be automated. Your loss though.
User avatar
GeniusCobyWalker
Member
Member
Posts: 65
Joined: Mon Jan 12, 2009 4:17 pm

Re: Build File Help Ubuntu (Linux)

Post by GeniusCobyWalker »

Finished Makefile
all: Source/kernel.c
rm -f *.o
nasm -f elf -o loader.o Source/loader.s
gcc -o kernel.o -c Source/kernel.c -nostdlib -nostartfiles -nodefaultlibs -m32
ld -T linker.ld -o Kernel/Kernel.bin loader.o kernel.o -m elf_i386
cat stage1 stage2 pad Kernel/Kernel.bin > Floppy/Floppy.img
rm -f *.o
bochs
Full Knowledge in:
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Build File Help Ubuntu (Linux)

Post by JohnnyTheDon »

What are stage1 and stage2?
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Build File Help Ubuntu (Linux)

Post by neon »

What are stage1 and stage2?
Probably based off of GRUBs naming conventions of its bootloader. ie; Stage1 is the boot strap program / MBR and Stage 2 is the "second stage loader" or "OS loader" that actually loads the OS kernel.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Build File Help Ubuntu (Linux)

Post by JohnnyTheDon »

neon wrote:
What are stage1 and stage2?
Probably based off of GRUBs naming conventions of its bootloader. ie; Stage1 is the boot strap program / MBR and Stage 2 is the "second stage loader" or "OS loader" that actually loads the OS kernel.
I know that, I meant what are they for his OS? The makefile isn't creating them.
User avatar
GeniusCobyWalker
Member
Member
Posts: 65
Joined: Mon Jan 12, 2009 4:17 pm

Re: Build File Help Ubuntu (Linux)

Post by GeniusCobyWalker »

Should I be making them?

If I did, would that omit the "Kernel 200+18" and "Boot" required by GRUB?
Full Knowledge in:
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Build File Help Ubuntu (Linux)

Post by JohnnyTheDon »

Oh, okay stage1 and stage2 are from grub. That make sense then.
Post Reply