-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
100 lines (82 loc) · 2.43 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# x64OS Makefile, some parts copied from https://wiki.osdev.org/Limine_Bare_Bones
# Its edited to be more readable.
# Internal C flags that should not be changed by the user.
USER=$(shell whoami)
HOST=$(shell hostnamectl hostname)
override CFLAGS += \
-Wall \
-Wextra \
-ffreestanding \
-fno-stack-protector \
-fno-stack-check \
-fno-lto \
-fPIE \
-m64 \
-march=x86-64 \
-mno-mmx \
-mno-sse2 \
-mno-red-zone -c \
-I include -g \
-D__BUILD_USER=\"$(USER)\" -D__BUILD_HOST=\"$(HOST)\"
# Internal C preprocessor flags that should not be changed by the user.
override CPPFLAGS := \
$(CFLAGS) \
-MMD \
-MP \
-fpermissive -fno-threadsafe-statics -fno-use-cxa-atexit -fno-rtti -fno-exceptions -fno-use-cxa-atexit
# Internal linker flags that should not be changed by the user.
override LDFLAGS += \
-m elf_x86_64 \
-nostdlib \
-static \
--no-dynamic-linker \
-pie \
-z text \
-z max-page-size=0x1000 \
-T linker.ld --export-dynamic -g
# Internal nasm flags that should not be changed by the user.
override NASMFLAGS += -f elf64 -g
C++ = g++
all: build
OBJ =
INCLUDES =
-include targets/*.mk
override COMP_OBJ := $(OBJ)
override HEADER_DEPS := $(OBJ:.o=.d)
build: image.iso
%.o: %.c
@echo " [ CC] $@"
@$(CC) $(CFLAGS) -o $@ $< $(INCLUDES)
%.o: %.cpp
@echo " [ CPP] $@"
@$(C++) $(CPPFLAGS) -o $@ $< $(INCLUDES)
%.o: %.S
@echo " [ AS] $@"
@$(CC) $(CFLAGS) -o $@ $< $(INCLUDES)
%.o: %.asm
@echo " [NASM] $@"
@nasm $(NASMFLAGS) -o $@ $<
bin/kernel.elf: $(OBJ)
@mkdir -p bin
@echo " [ LD] bin/kernel.elf"
@ld $(LDFLAGS) -o bin/kernel.elf -g $(COMP_OBJ)
image.iso: bin/kernel.elf build_usermode
@cp bin/kernel.elf iso_root
@xorriso -as mkisofs -b limine-bios-cd.bin \
-no-emul-boot -boot-load-size 4 -boot-info-table \
--efi-boot limine-uefi-cd.bin \
-efi-boot-part --efi-boot-image --protective-msdos-label \
iso_root -o image.iso -volid "x64OS Bootable"
.PHONY: image.iso bin/kernel.elf
run: image.iso
@qemu-system-x86_64 -cdrom image.iso -serial stdio $(KVM)
rung: image.iso
@qemu-system-x86_64 -cdrom image.iso -serial stdio -s -S $(KVM) -m 256m
run_uefi: image.iso
@qemu-system-x86_64 -cdrom image.iso -serial stdio -smp cores=2 $(KVM) -bios /usr/share/ovmf/x64/OVMF.fd
build_usermode:
@cd user/init && make pack && cd ../..
clean:
@rm $(COMP_OBJ) bin/kernel.elf $(HEADER_DEPS) -f
bochs: image.iso
@bochs -q -f bochs.cfg