reimplmenets the previous iteration with a brand new custom build system
This commit is contained in:
63
Makefile
Normal file
63
Makefile
Normal file
@ -0,0 +1,63 @@
|
||||
CC = i686-elf-gcc
|
||||
CFLAGS = -m32 -ffreestanding -Wall -Wextra -Werror -Wpedantic --sysroot=$(PWD)/sysroot -isystem=/usr/include -Iinclude -MD
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
all: kernel.elf
|
||||
|
||||
kernel.elf: install-headers install-libs $(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 $(shell find . -name "kernel.elf") iso/boot/kernel.elf
|
||||
cp util/grub.cfg iso/boot/grub/grub.cfg
|
||||
grub-mkrescue -o $@ iso
|
||||
|
||||
run: os.iso
|
||||
bochs -f util/bochsrc.txt -q
|
||||
|
||||
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
|
Reference in New Issue
Block a user