So, I got this Makefile from a git repository and it compiles the source code that came with this correctly. The project is for an Operating System from scratch. This Makefile is for a 64-bit OS tutorial. I'm currently learning about 32-bit operating systems and I don't want to jump into the long mode for now. My project compiles correctly with this makefile but it never loads the kernel into memory. I think I should change the CCFLAGS = -ggdb -c -ffreestanding -target x86_64-none-elf
to some other flags. How do I go about this. I already tried install i386-elf-gcc
using brew but it's giving me a lot of errors. Any help would be appreciated. Thanks :)
CC = clang
GDB = gdb
LD = ld.lld
ASM = nasm
INC = -Iinc/
SRC = $(shell find . -type f -name "*.c")
ASM_SRC = $(shell find . -type f -name "*.asm")
# CRITICAL: assembly must be linked first
OBJ = ${ASM_SRC:.asm=.o} ${SRC:.c=.o}
CCFLAGS = -ggdb -c -ffreestanding -target x86_64-none-elf
LDFLAGS = -Ttext 0x8200
LDFLAGS_BIN = ${LDFLAGS} --oformat binary
LDFLAGS_ELF = ${LDFLAGS} --oformat binary --entry main
ASFLAGS = -f elf64
all: kernel kernel.elf
kernel: ${OBJ}
@${LD} -o $@ ${LDFLAGS_BIN} $^
kernel.elf: ${OBJ}
@${LD} -o $@ ${LDFLAGS_ELF} $^
%.o: %.c
@${CC} ${CCFLAGS} ${INC} -o $@ $^
%.o: %.asm
@${ASM} $< ${ASFLAGS} -o $@
clean:
@rm -f kernel kernel.elf *.o **/*.o