shadeos/Makefile

85 lines
2.8 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
version = 0.1.1-alpha
stream = shade-development
git_build = $(shell git rev-parse --short HEAD)
date = $(shell date)
codename = willow
2022-05-14 01:44:14 +00:00
default: run
.FORCE:
2022-05-15 23:02:09 +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
bin/shade.bin: $(sboot_object_files) $(kernel_object_files) $(libc_object_files)
echo "#ifndef SHADE_VERSION_H" > include/shade/version.h
echo "#define SHADE_VERSION_H" >> include/shade/version.h
echo "// This file was autogenerated by the shadeOS build system. It should not be modified." >> include/shade/version.h
echo "#define SHADE_OS_KERNEL_VERSION \"$(version)\"" >> include/shade/version.h
echo "#define SHADE_OS_KERNEL \"$(stream)\"" >> include/shade/version.h
echo "#define SHADE_OS_BUILD \"$(git_build)\"" >> include/shade/version.h
echo "#define SHADE_OS_COMPILE_DATE \"$(date)\"" >> include/shade/version.h
echo "#define SHADE_OS_CODENAME \"$(codename)\"" >> include/shade/version.h
echo "#endif" >> include/shade/version.h
2022-05-14 01:44:14 +00:00
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/*