-
Notifications
You must be signed in to change notification settings - Fork 2
/
GNUmakefile
115 lines (86 loc) · 2.3 KB
/
GNUmakefile
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
## SPDX-License-Identifier: Zlib
export LC_ALL=C
export LANGUAGE=C
export LANG=C
RELEASE ?= 0.0.1-dev.18
SYSNAME ?= Vex
ARCH ?= x86_64
TOOLCHAIN ?= llvm
SOURCES :=
OBJECTS :=
CLEAN0 :=
CLEAN1 :=
ALLDEP :=
PHONYS :=
build_dir := build
include config/arch.${ARCH}.mk
include config/toolchain.${TOOLCHAIN}.mk
CFLAGS += -fPIE
CFLAGS += -ffreestanding
CFLAGS += -Wall -Wextra -Werror
CFLAGS += -Wno-unused-parameter
CFLAGS += -Wno-pointer-sign
CFLAGS += -funsigned-char
CFLAGS += -O2
CPPFLAGS += -D __kernel__
CPPFLAGS += -D __KERNEL__
CPPFLAGS += -I arch/${ARCH}/include
CPPFLAGS += -I contrib/limine/include
CPPFLAGS += -I include
LDFLAGS += -nostdlib
%.c.o: %.c | ${build_dir}
${CC} ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
# ${CC} ${CFLAGS} ${CPPFLAGS} -S -o ${build_dir}/$(notdir $<).S $<
%.S.o: %.S | ${build_dir}
${CC} ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
%.s.o: %.s | ${build_dir}
${CC} ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
LDSCRIPT := ${build_dir}/link.ld
KERNEL := ${build_dir}/kernel.elf
KBOOT := ${build_dir}/kernel.boot.img
include acpi/GNUmakefile
include arch/${ARCH}/kern/GNUmakefile
include drivers/GNUmakefile
include filesys/GNUmakefile
include kern/GNUmakefile
include libk/GNUmakefile
include mm/GNUmakefile
OBJECTS += ${SOURCES:=.o}
CLEAN0 += ${OBJECTS}
CLEAN0 += ${LDSCRIPT}
CLEAN0 += ${KERNEL}
CLEAN0 += ${KBOOT}
CLEAN1 += ${build_dir}
PHONYS += all
PHONYS += force_run
PHONYS += clean distclean
PHONYS += kernel
PHONYS += bootable
ALLDEP += kernel
ALLDEP += bootable
all: ${ALLDEP}
force_run:
clean:
rm -vrf ${CLEAN0}
distclean:
rm -vrf ${CLEAN0}
rm -vrf ${CLEAN1}
kernel: ${KERNEL}
bootable: ${KBOOT}
${build_dir}:
mkdir -p ${build_dir}
${KERNEL}: ${OBJECTS} ${LDSCRIPT} ${build_dir}
${LD} ${LDFLAGS} -T ${LDSCRIPT} -pie -o $@ ${OBJECTS}
${LDSCRIPT}: config/link.${ARCH}.lds ${build_dir}
${CC} ${CPPFLAGS} -E -xc -D __ASSEMBLER__ config/link.${ARCH}.lds | grep -v "^#" > $@ || true
${KBOOT}: ${KERNEL}
dd if=/dev/zero of=$@ bs=1048576 count=32
parted $@ mklabel gpt
parted $@ mkpart ESP fat16 2048s 100%
parted $@ set 1 esp on
mkfs.fat -F16 --offset 2048 $@
mmd -i $@@@2048s ::/EFI
mmd -i $@@@2048s ::/EFI/BOOT
mcopy -i $@@@2048s boot/${ARCH}/BOOT${UEFI_ARCH}.EFI ::/EFI/BOOT/BOOT${UEFI_ARCH}.EFI
mcopy -i $@@@2048s boot/limine.cfg ::/limine.cfg
mcopy -i $@@@2048s ${KERNEL} ::/kernel.${LIMINE_ARCH}.elf