mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
90 lines
2.6 KiB
Makefile
90 lines
2.6 KiB
Makefile
# Variables
|
|
CC := i686-elf-gcc
|
|
LD := i686-elf-ld
|
|
AS := nasm
|
|
|
|
CCFLAGS := -g -std=c17 -ffreestanding -fno-builtin -fno-stack-protector -fno-pie \
|
|
-Os -nostdinc -mgeneral-regs-only -m32 -march=i386 -Wall
|
|
LDFLAGS := -z notext -melf_i386 -nostdlib
|
|
ASFLAGS :=
|
|
|
|
include make.config
|
|
|
|
SRC := ./src
|
|
BIN := ./bin
|
|
LIBK_INC := ./include
|
|
LIBC_INC := ./include/libc
|
|
LIBC_DIR := ./libc
|
|
LIBK_DIR := ./libk
|
|
|
|
C_FILES := calc edit
|
|
FONTS := testfont term16n
|
|
|
|
BOOTLOADER := $(BIN)/stage1.bin $(BIN)/stage2.bin $(BIN)/stage3.bin
|
|
KERNEL := $(BIN)/kernel.bin
|
|
LIBC := $(BIN)/libc.o
|
|
# TODO: LIBK := $(BIN)/libk.o
|
|
ISO := kern.iso
|
|
|
|
.PHONY: os clean run
|
|
|
|
# Main compilation target
|
|
os: $(ISO)
|
|
$(ISO): $(BIN) $(BOOTLOADER) $(KERNEL) $(C_FILES) $(FONTS)
|
|
cc ./makedisk.c -o ./makedisk
|
|
./makedisk # TODO: List of files
|
|
@echo "\nDone!\n"
|
|
|
|
$(BIN):
|
|
[ -d $(BIN) ] || mkdir $(BIN)
|
|
rm -rf $(BIN)/*
|
|
|
|
# Bootloader: This target is responsible for creating stage?.bin (1,2,3)
|
|
$(BOOTLOADER): $(SRC)/stage1.asm $(SRC)/stage2.asm $(SRC)/stage3.c $(LIBC)
|
|
@echo "Assembling $(SRC)/stage1.asm..."
|
|
$(AS) -fbin -o $(BIN)/stage1.bin $(SRC)/stage1.asm $(ASFLAGS)
|
|
@echo "Assembling $(SRC)/stage2.asm..."
|
|
$(AS) -fbin -o $(BIN)/stage2.bin $(SRC)/stage2.asm $(ASFLAGS)
|
|
@echo "Compiling $(SRC)/stage3.c..."
|
|
$(CC) $(CCFLAGS) -I$(LIBK_INC) -I$(LIBC_INC) -o $(BIN)/stage3.o -c $(SRC)/stage3.c
|
|
$(LD) $(LDFLAGS) -T$(SRC)/stage3.ld --oformat binary -o $(BIN)/stage3.bin $(BIN)/stage3.o $(LIBC)
|
|
rm $(BIN)/stage3.o
|
|
|
|
# Kernel: This target is responsible for creating kernel.bin
|
|
$(KERNEL): $(SRC)/kernel.c $(LIBC) #TODO: $(LIBK)
|
|
@echo "Compiling $(SRC)/kernel.c..."
|
|
$(CC) $(CCFLAGS) -I$(LIBK_INC) -I$(LIBC_INC) -o $(BIN)/kernel.o -c $(SRC)/kernel.c
|
|
$(LD) $(LDFLAGS) -T$(SRC)/kernel.ld --oformat binary -o $(BIN)/kernel.bin $(BIN)/kernel.o $(LIBC) #TODO: LIBK
|
|
rm $(BIN)/kernel.o
|
|
|
|
# This target compiles *.c (except kernel.c)
|
|
$(C_FILES): $(LIBC)
|
|
@echo "Compiling $(SRC)/$@.c..."
|
|
$(CC) $(CCFLAGS) -I$(LIBC_INC) -o $(BIN)/$@.o -c $(SRC)/$@.c
|
|
$(LD) $(LDFLAGS) -T$(SRC)/$@.ld --oformat binary -o $(BIN)/$@.bin $(BIN)/$@.o $(LIBC)
|
|
rm $(BIN)/$@.o
|
|
|
|
$(LIBC): $(LIBC_DIR)/**.c
|
|
@echo "Compiling $(LIBC)..."
|
|
mkdir -p $(BIN)/libc
|
|
for f in libc/*.c; do $(CC) $(CCFLAGS) -I$(LIBC_INC) -o $(BIN)/$$f.o -c $$f; done
|
|
$(LD) $(LDFLAGS) -r -o $(LIBC) $(BIN)/libc/**.o
|
|
|
|
# This target retrieves all fonts inside src/fonts
|
|
$(FONTS):
|
|
cp $(SRC)/fonts/$@.fnt $(BIN)/$@.fnt
|
|
|
|
# Run QEMU
|
|
run:
|
|
qemu-system-x86_64\
|
|
-drive format=raw,file=$(ISO),index=0,media=disk\
|
|
-m 256M -accel tcg -monitor stdio\
|
|
-rtc base=localtime,clock=host,driftfix=slew\
|
|
-audiodev coreaudio,id=audio0 -machine pcspk-audiodev=audio0
|
|
|
|
# Clean all build files
|
|
clean:
|
|
rm -rf $(BIN)
|
|
rm -f makedisk
|
|
|