shadeos/Makefile

67 lines
2.0 KiB
Makefile
Raw Normal View History

2022-05-14 01:44:14 +00:00
ASM := nasm
2022-05-14 01:44:14 +00:00
CC := x86_64-elf-gcc
CCFLAGS :=
2022-05-14 01:44:14 +00:00
LD := x86_64-elf-ld
LDFLAGS :=
2022-05-14 01:44:14 +00:00
INCLUDE := include/
2022-05-14 01:44:14 +00:00
# Target: kernel, type: C ASM
kernel_c_source_files = $(shell find src/kernel/ -type f -name *.c)
kernel_c_object_files = $(patsubst src/%.c,obj/%.o,$(kernel_c_source_files))
kernel_asm_source_files = $(shell find src/kernel/ -type f -name *.asm)
kernel_asm_object_files = $(patsubst src/%.asm,obj/%.o,$(kernel_asm_source_files))
kernel_source_files = $(kernel_c_source_files) $(kernel_asm_object_files)
kernel_object_files = $(kernel_c_object_files) $(kernel_asm_object_files)
2022-05-14 01:44:14 +00:00
# Target: libc, type: C ASM
libc_c_source_files = $(shell find src/libc/ -type f -name *.c)
libc_c_object_files = $(patsubst src/%.c,obj/%.o,$(libc_c_source_files))
libc_asm_source_files = $(shell find src/libc/ -type f -name *.asm)
libc_asm_object_files = $(patsubst src/%.asm,obj/%.o,$(libc_c_object_files))
libc_source_files = $(libc_c_source_files) $(libc_asm_source_files)
libc_object_files = $(libc_c_object_files) $(libc_asm_object_files)
2022-05-14 01:44:14 +00:00
# Target: sboot, type: ASM
# Override: 32-bit
sboot_asm_source_files = $(shell find src/boot/ -type f -name *.asm)
sboot_asm_object_files = $(patsubst src/%.asm,obj/%.o,$(sboot_asm_source_files))
sboot_source_files = $(sboot_asm_source_files)
sboot_object_files = $(sboot_asm_object_files)
2022-05-14 01:44:14 +00:00
shade_bin_ldfile = src/linker.ld
2022-05-14 01:44:14 +00:00
default: run
2022-05-14 01:44:14 +00:00
bin/shade.iso: bin/shade.bin
cp bin/shade.bin src/iso/boot/shade.bin
grub-mkrescue src/iso/ -o $@
rm src/iso/boot/shade.bin
2022-05-14 01:44:14 +00:00
bin/shade.bin: $(sboot_object_files) $(kernel_object_files) $(libc_object_files)
mkdir -p "$(@D)"
$(LD) $(LDFLAGS) -n -T $(shade_bin_ldfile) $^ -o $@
grub-file --is-x86-multiboot2 $@
2022-05-14 01:44:14 +00:00
# Generics
# Source file types: C ASM
2022-05-14 01:44:14 +00:00
# C
obj/%.o: src/%.c
mkdir -p "$(@D)"
2022-05-14 01:44:14 +00:00
$(CC) $(CCFLAGS) -I $(INCLUDE) -ffreestanding -c $< -o $@
2022-05-14 01:44:14 +00:00
# ASM
obj/%.o: src/%.asm
mkdir -p "$(@D)"
2022-05-14 01:44:14 +00:00
$(ASM) -felf64 $< -o $@
2022-05-14 01:44:14 +00:00
# Other
run: clean bin/shade.iso
2022-05-14 03:53:59 +00:00
qemu-system-x86_64 -drive file=bin/shade.iso,index=0,media=disk,format=raw -d int -no-reboot
clean:
2022-05-14 01:44:14 +00:00
rm -rf bin/*
rm -rf obj/*