HhhOS/Makefile
2021-08-23 14:05:04 +03:00

70 lines
1.9 KiB
Makefile

KERNEL := hhhos.elf
ISO := hhhos.iso
CC = x86_64-elf-gcc
NASM = nasm
# User controllable CFLAGS.
CFLAGS = -Wall -Wextra -O2 -pipe
NASMFLAGS = -felf64
# Internal link flags that should not be changed by the user.
INTERNALLDFLAGS := \
-fno-pic -fpie \
-Wl,-static,-pie,--no-dynamic-linker,-ztext \
-static-pie \
-nostdlib \
-Tlinker.ld \
-z max-page-size=0x1000
# Internal C flags that should not be changed by the user.
INTERNALCFLAGS := \
-Iinclude \
-std=gnu17 \
-ffreestanding \
-fno-stack-protector \
-fno-pic -fpie \
-mno-80387 \
-mno-mmx \
-mno-3dnow \
-mno-sse \
-mno-sse2 \
-mno-red-zone
# Use find to glob all *.c files in the directory and extract the object names.
CFILES := $(shell find ./arch -type f -name '*.c')
OBJ := $(CFILES:.c=.o)
OBJ += font.o
# Targets that do not actually build a file of the same name.
.PHONY: all clean run
run: $(ISO)
qemu-system-x86_64 -cdrom $(ISO) -m 128M -serial file:serial.log \
-drive id=disk,file=disk.img,if=none,format=raw \
-device ide-hd,drive=disk,bus=ide.0
$(ISO): $(KERNEL)
mkdir -p sysroot
cp -v $(KERNEL) limine.cfg limine/limine.sys limine/limine-cd.bin limine/limine-eltorito-efi.bin sysroot/
xorriso -as mkisofs -b limine-cd.bin -no-emul-boot -boot-load-size 4 -boot-info-table \
--efi-boot limine-eltorito-efi.bin -efi-boot-part --efi-boot-image --protective-msdos-label \
sysroot -o $(ISO)
# Default target.
all: $(KERNEL)
# Link rules for the final kernel executable.
$(KERNEL): $(OBJ)
$(CC) $(OBJ) -o $@ $(INTERNALLDFLAGS)
# Compilation rules for *.c files.
%.o: %.c
$(CC) $(CFLAGS) $(INTERNALCFLAGS) -c $< -o $@
font.o:
objcopy -O elf64-x86-64 -B i386 -I binary font.psfu font.o
# Remove object files and the final executable.
clean:
rm -rf $(KERNEL) $(OBJ) $(ISO)