shadeos/Makefile

67 lines
2.0 KiB
Makefile
Raw Normal View History

2022-05-14 01:33:49 +00:00
ASM := nasm
CC := x86_64-elf-gcc
2022-05-14 01:33:49 +00:00
CCFLAGS :=
LD := x86_64-elf-ld
2022-05-14 01:33:49 +00:00
LDFLAGS :=
INCLUDE := include/
2022-05-13 03:08:46 +00:00
2022-05-14 01:33:49 +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-13 03:08:46 +00:00
2022-05-14 01:33:49 +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-13 03:08:46 +00:00
2022-05-14 01:33:49 +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-13 03:08:46 +00:00
2022-05-14 01:33:49 +00:00
shade_bin_ldfile = src/linker.ld
2022-05-13 03:08:46 +00:00
2022-05-14 01:33:49 +00:00
default: run
2022-05-13 03:08:46 +00:00
bin/shade.iso: bin/shade.bin
2022-05-14 01:33:49 +00:00
cp bin/shade.bin src/iso/boot/shade.bin
grub-mkrescue src/iso/ -o $@
rm src/iso/boot/shade.bin
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-13 03:08:46 +00:00
2022-05-14 01:33:49 +00:00
# Generics
# Source file types: C ASM
# C
2022-05-13 03:08:46 +00:00
obj/%.o: src/%.c
mkdir -p "$(@D)"
2022-05-14 01:33:49 +00:00
$(CC) $(CCFLAGS) -I $(INCLUDE) -ffreestanding -c $< -o $@
2022-05-13 03:08:46 +00:00
2022-05-14 01:33:49 +00:00
# ASM
2022-05-13 03:08:46 +00:00
obj/%.o: src/%.asm
mkdir -p "$(@D)"
2022-05-14 01:33:49 +00:00
$(ASM) -felf64 $< -o $@
2022-05-13 03:08:46 +00:00
2022-05-14 01:33:49 +00:00
# Other
2022-05-13 03:08:46 +00:00
run: clean bin/shade.iso
2022-05-14 01:33:49 +00:00
qemu-system-x86_64 -drive file=bin/shade.iso,index=0,media=disk,format=raw
2022-05-13 03:08:46 +00:00
clean:
2022-05-14 01:33:49 +00:00
rm -rf bin/*
rm -rf obj/*