Page 1 of 1

Help with a makefile

Posted: Mon Apr 23, 2007 7:03 pm
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

Posted: Mon Apr 23, 2007 7:25 pm
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) 

Posted: Tue Apr 24, 2007 4:46 am
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

Posted: Tue Apr 24, 2007 4:48 am
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

Posted: Wed Apr 25, 2007 6:05 am
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.