-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
63 lines (41 loc) · 1.56 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
# This is a variable containing all of the c sources.
# This will remain empty until the future
CXX_SOURCES = $(wildcard kernel/*.c kernel/**/*.c kernel/**/**/*.c)
# We also do the same for c headers
CXX_HEADERS = $(wildcard kernel/*.h kernel/**/*.h kernel/**/**/*.h)
# And we do the same for assembly files
ASM_SOURCES = $(wildcard kernel/x86/**/*.asm kernel/bootstrap/**/*.asm kernel/bootstrap/*.asm)
# Now lets create another variable containing all of our object files
OBJECTS = ${CXX_SOURCES:.c=.o} # One for c
ASMOBJECTS = ${ASM_SOURCES:.asm=.o} # One for ASM
# Now lets create a variable for all of the flags to be passed to out
# c compiler
CXX_FLAGS = -g -ffreestanding -Wall -Wextra -fno-exceptions -I ./
CXX32_FLAGS = -g -ffreestanding -Wall -Wextra -fno-exceptions -I ./
# Here we declare variables containing the command to access
# Our compiler and linker
CXX = x86_64-elf-gcc
LD = x86_64-elf-ld
CXX32 = i386-elf-gcc
# A target to build the grub image
grub: kernel.elf
mv kernel.elf image/boot/kernel.elf
grub-mkrescue -o image.iso image/
# A target to build the kernel.elf file
kernel.elf: kernel/asm/boot.o ${ASMOBJECTS} ${OBJECTS}
${LD} -o $@ -Tlink.ld $^
# Runs the kernel
run: grub
bochs -f bochsrc.txt -q
# And here we define some rules for resolving wildcard object files
# These will go at the bottom of the file
# First for c files
%.o: %.c ${CXX_HEADERS}
${CXX} ${CXX_FLAGS} -c $< -o $@
# Now for assembly files
%.o: %.asm
nasm $< -f elf64 -o $@
# Clean
clean:
rm -rf kernel.elf image/boot/kernel.elf image.iso
find . -type f -name '*.o' -delete