Help with a makefile

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
User avatar
astrocrep
Member
Member
Posts: 127
Joined: Sat Apr 21, 2007 7:21 pm

Help with a makefile

Post by astrocrep »

Makefile:

Code: Select all

CC=gcc
CFLAGS=-Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o
LD=ld
LDFLAGS=-T link.ld -o
ASM=nasm
ASMFLAGS=-f aout -o
SOURCES=start.asm main.c scrn.c gdt.c idt.c isrs.c irq.c timer.c kb.c
OBJS=start.o main.o scrn.o gdt.o idt.o isrs.o irq.o timer.o kb.o
EXECUTABLE=kernel32.sys

all: $(EXECUTABLE)

$(EXECUTABLE) : $(OBJECTS)
	$(LD) $(LDFLAGS) $(BUILDNAME) $(OBJS)
start.o : start.asm
	$(ASM) $(ASMFLAGS) start.o start.asm
main.o : main.c
	$(CC) $(CFLAGS) main.o main.c
scrn.o : scrn.c
	$(CC) $(CFLAGS) scrn.o scrn.c
gdt.o  : gdt.c
	$(CC) $(CFLAGS) gdt.o gdt.c
idt.o  : idt.c
	$(CC) $(CFLAGS) idt.o idt.c
isrs.o : isrs.c
	$(CC) $(CFLAGS) isrs.o isrs.c
irq.o  : irq.c
	$(CC) $(CFLAGS) irq.o irq.c
timer.o : timer.c
	$(CC) $(CFLAGS) timer.o timer.c
kb.o   : kb.c
	$(CC) $(CFLAGS) kb.o kb.c
If I do make all or make kernel32.sys it tells me ld fails cause it cannot find an object.

I can do make main.o and it runs fine. If all the .o's are build then it makes kernel32.sys fine...

Why doesn't it know to make the missing *.o files???

Thanks,
Rich
User avatar
B.E
Member
Member
Posts: 275
Joined: Sat Oct 21, 2006 5:29 pm
Location: Brisbane Australia
Contact:

Post by B.E »

you got some variables that arnt defined (i.e spelt incorrectly):

replace

Code: Select all

$(EXECUTABLE) : $(OBJECTS) 
with

Code: Select all

$(EXECUTABLE) : $(OBJS) 
Image
Microsoft: "let everyone run after us. We'll just INNOV~1"
User avatar
astrocrep
Member
Member
Posts: 127
Joined: Sat Apr 21, 2007 7:21 pm

Post by astrocrep »

Ok, so I fixed that and it will build all of the .o files except for the ASM one.

When I type make the first thing I see is:

Code: Select all

nasm -f aout -o start.o start.asm
but no start.o is produced.

If I manually run the code above at the prompt it build the .o fine.

But make still fails all of the place because it cannot find the references help in start.o

Code: Select all

ld -Tlink.ld -o  start.o main.o scrn.o gdt.o idt.o isrs.o irq.o timer.o kb.o
ld: warning: cannot find entry symbol start; defaulting to 0000000000100000
Followed by a slew of other errors that are trying to find a couple of other things in start.o, mainly the isr handlers.

Thanks in advance.
Rich
User avatar
astrocrep
Member
Member
Posts: 127
Joined: Sat Apr 21, 2007 7:21 pm

Post by astrocrep »

Nevermind....

Another stupid bug in my makefile...
And a change to the nasm output to elf format...

Everything works!

and it boots perfect.

Thanks all!

-Rich
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

Another hint: Use ":=" instead of "=" if you define immutable lists. Variables defined by "=" have their contents evaluated every time they're used, while ":="-defined variables do so only once.
Every good solution is obvious once you've found it.
Post Reply