Page 1 of 1

Makefile Issues [SOLVED]

Posted: Fri May 04, 2007 2:36 am
by pcmattman
I have the following makefile:

Code: Select all

# GCC (duh)
GCC:=gcc

# use ELF
LD:=ld-elf

# use NASM
ASSEMBLER:=nasmw

# assembly files
ASM=loader.asm

# assembler objects
AOBJS=loader.o

# source files
SRCS=kernel.cc console/console.cc syscore/fault.cc syscore/gdt.cc syscore/idt.cc lib/iostream.cc syscore/irq.cc syscore/mem.cc portio.cc syscore/timer.cc

# C object files
COBJS=kernel.o console.o fault.o gdt.o idt.o iostream.o irq.o mem.o portio.o timer.o

# all the objects
OBJS=loader.o kernel.o console.o fault.o gdt.o idt.o iostream.o irq.o mem.o portio.o timer.o

# what to do when make all
all: kernel.bin

# clean the build
clean:
	del *.o *.bin

# makes the kernel
kernel.bin: $(OBJS)
	$(LD) -T linker.ld -o kernel.bin $(OBJS)

# compile source
$(COBJS): $(SRCS)
	$(GCC) -I "include" -c $< -o $@ -nostdlib -fno-builtin -fno-rtti -fno-exceptions
	
# assemble files
$(AOBJS): $(ASM)
	$(ASSEMBLER) -o $@ -f elf $<
Unfortunately, it does this:

Code: Select all

gcc -I "include" -c kernel.cc -o console.o -nostdlib -fno-builtin -fno-rtti -fno-exceptions
gcc -I "include" -c kernel.cc -o fault.o -nostdlib -fno-builtin -fno-rtti -fno-exceptions
gcc -I "include" -c kernel.cc -o gdt.o -nostdlib -fno-builtin -fno-rtti -fno-exceptions
gcc -I "include" -c kernel.cc -o idt.o -nostdlib -fno-builtin -fno-rtti -fno-exceptions
gcc -I "include" -c kernel.cc -o iostream.o -nostdlib -fno-builtin -fno-rtti -fno-exceptions
Obviously, it's wrong. The problem is, I don't know how to fix it. Any ideas?

Edit: OK, problem solved. I was trying to be lazy... Now I just have to make sure I remember to add in new files...

Code: Select all

# compiler and flags
CC:=gcc
CFLAGS:=-I ./include -nostdlib -fno-builtin -fno-rtti -fno-exceptions
## DJGPP ELF-ENABLED LD ###
LD:=ld-elf
LDFLAGS:=-T linker.ld -o
# nasm and flags
ASM:=nasmw
ASMFLAGS:=-f elf -o
# source and objects, and final binary
SRCS:=loader.asm kernel.cc console/console.cc syscore/fault.cc syscore/gdt.cc syscore/idt.cc lib/iostream.cc syscore/irq.cc syscore/mem.cc portio.cc syscore/timer.cc
OBJS:=loader.o kernel.o console.o fault.o gdt.o idt.o iostream.o irq.o mem.o portio.o timer.o
FINALBIN:=kernel.bin

# clean up
clean:
	del kernel.bin loader.o kernel.o console.o fault.o gdt.o idt.o iostream.o irq.o mem.o portio.o timer.o

# buld the full kernel
all: $(FINALBIN)

# link command
$(FINALBIN) : $(OBJS)
	$(LD) $(LDFLAGS) $(FINALBIN) $(OBJS)

# loader - NASM
loader.o : loader.asm
	$(ASM) $(ASMFLAGS) loader.o loader.asm

# kernel
kernel.o : kernel.cc
	$(CC) $(CFLAGS) -c $< -o $@

# accessory functions in ./
portio.o : portio.cc
	$(CC) $(CFLAGS) -c $< -o $@

# console
console.o : console/console.cc
	$(CC) $(CFLAGS) -c $< -o $@

# system core
fault.o : syscore/fault.cc
	$(CC) $(CFLAGS) -c $< -o $@
gdt.o : syscore/gdt.cc
	$(CC) $(CFLAGS) -c $< -o $@
idt.o : syscore/idt.cc
	$(CC) $(CFLAGS) -c $< -o $@
irq.o : syscore/irq.cc
	$(CC) $(CFLAGS) -c $< -o $@
timer.o : syscore/timer.cc
	$(CC) $(CFLAGS) -c $< -o $@
mem.o : syscore/mem.cc
	$(CC) $(CFLAGS) -c $< -o $@

# libs
iostream.o : lib/iostream.cc
	$(CC) $(CFLAGS) -c $< -o $@

Re: Makefile Issues [SOLVED]

Posted: Fri May 04, 2007 10:43 am
by Candy
Try this too:

Code: Select all

%.o : syscore/%.cc
	$(CC) $(CFLAGS) -c $< -o $@
By the way, the common name for the C++ compiler is $(CXX), not $(CC). You also use $(CXXFLAGS).

Posted: Fri May 04, 2007 4:54 pm
by pcmattman
Yeah, that works... I changed it to

Code: Select all

%.o : */%.cc
To compile from any folder.

I'll change the references to $(CC).

Only problem now is the command length - Windows complains if it's too long.