forked from xamidev/pepperOS
Move the PHONY tags to make them clearer to read. Fix the clean rule so it deletes the build directory.
68 lines
2.3 KiB
Makefile
68 lines
2.3 KiB
Makefile
|
|
BUILDDIR := build
|
|
ELFFILE := pepperk
|
|
SRC := src
|
|
SOURCES := $(shell find src -name '*.c')
|
|
OBJFILES := $(patsubst $(SRC)/%.c, $(BUILDDIR)/%.o, $(SOURCES))
|
|
|
|
CC := x86_64-elf-gcc
|
|
CC_FLAGS=-Wall -Wextra -std=gnu99 -nostdlib -ffreestanding -fno-stack-protector -fno-omit-frame-pointer -fno-stack-check -fno-PIC -ffunction-sections -fdata-sections -mcmodel=kernel
|
|
CC_PROBLEMATIC_FLAGS=-Wno-unused-parameter -Wno-unused-variable
|
|
|
|
LD := x86_64-elf-ld
|
|
|
|
$(ELFFILE): $(BUILDDIR) $(OBJFILES)
|
|
nasm -f elf64 src/idt/idt.S -o $(BUILDDIR)/idt_stub.o
|
|
$(LD) -o $(ELFFILE) -T linker.ld $(OBJFILES) $(BUILDDIR)/idt_stub.o
|
|
nm -n $(ELFFILE) | awk '$$2 ~ /[TtDdBbRr]/ {print $$1, $$3}' > symbols.map
|
|
python3 symbols.py
|
|
nasm -f elf64 symbols.S -o $(BUILDDIR)/symbols.o
|
|
$(LD) -o $(ELFFILE) -T linker.ld $(OBJFILES) $(BUILDDIR)/idt_stub.o
|
|
|
|
$(BUILDDIR):
|
|
@mkdir -p $(BUILDDIR)
|
|
|
|
$(BUILDDIR)/%.o: $(SRC)/%.c
|
|
mkdir -p $(dir $@)
|
|
$(CC) -g -c -Isrc $< $(CC_PROBLEMATIC_FLAGS) $(CC_FLAGS) -o $@
|
|
|
|
limine/limine:
|
|
rm -rf limine
|
|
git clone https://github.com/limine-bootloader/limine.git --branch=v9.x-binary --depth=1
|
|
$(MAKE) -C limine
|
|
|
|
build-iso: limine/limine build
|
|
rm -rf iso_root
|
|
mkdir -p iso_root/boot
|
|
cp -v $(ELFFILE) iso_root/boot
|
|
mkdir -p iso_root/boot/limine
|
|
cp -v limine.conf iso_root/boot/limine
|
|
mkdir -p iso_root/EFI/BOOT
|
|
cp -v limine/limine-bios.sys limine/limine-bios-cd.bin limine/limine-uefi-cd.bin iso_root/boot/limine/
|
|
cp -v limine/BOOTX64.EFI iso_root/EFI/BOOT/
|
|
cp -v limine/BOOTIA32.EFI iso_root/EFI/BOOT/
|
|
xorriso -as mkisofs -R -r -J -b boot/limine/limine-bios-cd.bin \
|
|
-no-emul-boot -boot-load-size 4 -boot-info-table -hfsplus \
|
|
-apm-block-size 2048 --efi-boot boot/limine/limine-uefi-cd.bin \
|
|
-efi-boot-part --efi-boot-image --protective-msdos-label \
|
|
iso_root -o pepper.iso
|
|
./limine/limine bios-install pepper.iso
|
|
|
|
.PHONY: debug
|
|
debug:
|
|
/usr/bin/qemu-system-x86_64 -drive file=pepper.iso -s -S -d int -D qemu.log -no-reboot -no-shutdown &
|
|
gdb $(ELFFILE) --command=debug.gdb
|
|
|
|
.PHONY: debug2
|
|
debug2:
|
|
/usr/bin/qemu-system-x86_64 -drive file=pepper.iso -s -S -d int -no-reboot -no-shutdown &
|
|
pwndbg $(ELFFILE) --command=debug.gdb
|
|
|
|
.PHONY: run
|
|
run: build-iso
|
|
/usr/bin/qemu-system-x86_64 -cdrom pepper.iso -serial stdio
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
rm -rf $(BUILDDIR) symbols.map symbols.S $(ELFFILE) iso_root pepper.iso limine
|