Files
novaos/Makefile

83 lines
2.5 KiB
Makefile

#TODO: add a rule to setup the cross compiler
# or maybe add it to a bash script instead? im not sure
CC = i686-elf-gcc
DEBUG_FLAGS = -D__TESTING__ -g
CFLAGS = -m32 -ffreestanding -Wall -Wextra -Werror -Wpedantic --sysroot=$(PWD)/sysroot -isystem=/usr/include -Iinclude -MD $(DEBUG_FLAGS)
AS = nasm
ASFLAGS = -f elf
LD = i686-elf-ld
LDFLAGS = -T $(shell find . -name "link.ld") -melf_i386 --sysroot=$(PWD)/sysroot -nostdlib -lk -lgcc
AR = i686-elf-ar
TERM_EXEC = kitty --hold sh -c
c_kern_objects := $(patsubst %.c,%.o,$(shell find kernel/ -name "*.c"))
asm_kern_objects := $(patsubst %.s,%.o,$(shell find kernel/ -name "*.s"))
free_objs = $(patsubst %.c,%.o, $(shell find libc/ -path "libc/arch" -prune -o -type f | grep "\.c"))
hosted_objs = $(patsubst, %.c,%.o,$(shell find libc/arch/ -name "*.c"))
libc_objs = $(free_objs) $(hosted_objs)
libk_objs = $(free_objs)
# binaries = libk.a libc.a # Not ready for libc yet
binaries = libk.a
.PHONY: clean all run install-headers install-libs env
all: kernel.elf
env: install-headers install-libs # TODO: change this to a file specific target, so it doesnt recompile everytime, and so we can move as a prereq on kernel.elf
util/./gen-clangd.sh
kernel.elf: install-headers install-libs env $(c_kern_objects) $(asm_kern_objects)
$(CC) $(CFLAGS) -T $(shell find . -name "link.ld") -o $@ $(c_kern_objects) $(asm_kern_objects) -nostdlib -lk -lgcc
os.iso: kernel.elf
mkdir -p iso/boot/grub
cp $< iso/boot/kernel.elf
cp util/grub.cfg iso/boot/grub/grub.cfg
grub-mkrescue -o $@ iso
run: os.iso
$(TERM_EXEC) "gdb kernel.elf -x util/gdbcmds" &
qemu-system-i386 -s -cdrom os.iso
bochs: os.iso
bochs -f util/bochsrc.txt -q
#TODO: when i inevitably do add libc, this is going to fail because they have the same name as the libk objects
#TODO: so we'll need to do a batch rename on one of the two object files,
libc.a: CFLAGS:=$(CFLAGS) -D__is_libc # Target rule to define __is_libc
libc.a: $(libc_objs)
$(AR) rcs $@ $(libc_objs)
libk.a: CFLAGS:=$(CFLAGS) -D__is_libk # Target rule to define __is_libk
libk.a: $(libk_objs)
$(AR) rcs $@ $(libk_objs)
install-headers:
mkdir -p sysroot/usr/include
cp -r --preserve=timestamps kernel/include/. sysroot/usr/include/.
cp -r --preserve=timestamps libc/include/. sysroot/usr/include/.
install-libs: $(binaries)
mkdir -p sysroot/usr/lib
cp -r --preserve=timestamps $(binaries) sysroot/usr/lib/.
clean:
-rm -rf iso/ sysroot/
-rm $(shell find . -name "*.o")
-rm $(shell find . -name "*.d")
-rm *.iso *.elf *.a com1.out bochslog.txt
-rm .clangd