-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
48 lines (37 loc) · 1.98 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
kernel_cpp_src := $(shell find src/kernel -name *.cpp)
kernel_cpp_obj := $(patsubst src/kernel/%.cpp, build/kernel/%.o, $(kernel_cpp_src))
x86_64_asm_src := $(shell find src/x86_64 -name *.asm)
x86_64_asm_obj := $(patsubst src/x86_64/%.asm, build/x86_64/%.o, $(x86_64_asm_src))
x86_64_cpp_src := $(shell find src/x86_64 -name *.cpp)
x86_64_cpp_obj := $(patsubst src/x86_64/%.cpp, build/x86_64/%.o, $(x86_64_cpp_src))
kernel_obj := $(kernel_cpp_obj)
x86_64_obj := $(x86_64_asm_obj) $(x86_64_cpp_obj)
##################################################
# Kernel object files
##################################################
$(kernel_cpp_obj): build/kernel/%.o : src/kernel/%.cpp
mkdir -p $(dir $@) && \
x86_64-elf-g++ -c -g -I src/intf -I src/x86_64/boot/intf -ffreestanding -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -mgeneral-regs-only -Wall $(patsubst build/kernel/%.o, src/kernel/%.cpp, $@) -o $@
##################################################
# x86_64 object files
##################################################
$(x86_64_asm_obj): build/x86_64/%.o : src/x86_64/%.asm
mkdir -p $(dir $@) && \
nasm -g -F dwarf -f elf64 $(patsubst build/x86_64/%.o, src/x86_64/%.asm, $@) -o $@
$(x86_64_cpp_obj): build/x86_64/%.o : src/x86_64/%.cpp
mkdir -p $(dir $@) && \
x86_64-elf-g++ -c -g -I src/intf -I src/x86_64/boot/intf -ffreestanding -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -mgeneral-regs-only -Wall $(patsubst build/x86_64/%.o, src/x86_64/%.cpp, $@) -o $@
##################################################
# PHONY
##################################################
.PHONY: build-x86_64
build-x86_64: $(kernel_obj) $(x86_64_obj)
mkdir -p dist/x86_64 && \
x86_64-elf-ld -n -o dist/x86_64/kernel.bin -T targets/x86_64/linker.ld $(kernel_obj) $(x86_64_obj) && \
cp dist/x86_64/kernel.bin targets/x86_64/iso/boot/kernel.bin &&\
grub-mkrescue /usr/lib/grub/i386-pc -o dist/x86_64/kernel.iso targets/x86_64/iso
.PHONY: clean
clean:
rm -rf build/
rm -rf dist/
rm -f targets/x86_64/iso/boot/kernel.bin