This repository was archived by the owner on Jan 11, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
100 lines (76 loc) · 2.66 KB
/
Makefile
File metadata and controls
100 lines (76 loc) · 2.66 KB
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
CC=gcc
CXX = g++
NASM=nasm
LD=ld
INCLUDE= -Ikernel/include
GFLAGS=
CCFLAGS=-m32 -std=c11 -O2 -g -Wall -Wextra -Wpedantic -Wstrict-aliasing $(INCLUDE)
CCFLAGS+=-Wno-pointer-arith -Wno-unused-parameter
CCFLAGS+=-nostdlib -nostdinc -ffreestanding -fno-pie -fno-stack-protector
CCFLAGS+=-fno-builtin-function -fno-builtin
CXXFLAGS = -m32 -std=c++17 -fno-exceptions -fno-rtti -ffreestanding -nostdlib -Wall -Wextra -O2 -fno-pie $(INCLUDE)
NASMFLAGS=-f elf32
LDFLAGS=-m elf_i386 -g
BOOTSECT_SRCS=\
kernel/boot/boot.S
BOOTSECT_OBJS=$(BOOTSECT_SRCS:.S=.o)
START_SRCS=\
kernel/boot/start.S
START_OBJS=$(START_SRCS:.S=.o)
ASM_SRCS=\
#all asm sources
ASM_OBJS=$(ASM_SRCS:.S=.o)
# find all C source files
KERNEL_C_SRCS=$(wildcard kernel/*.c kernel/mem/*.c kernel/ui/system/*.c kernel/drivers/*.c kernel/ui/*.c user/home/*.c kernel/core/*.c)
# find all C++ source files
KERNEL_CPP_SRCS=$(wildcard kernel/*.cpp kernel/ui/system/*.cpp kernel/drivers/*.cpp kernel/ui/*.cpp kernel/mem/*.cpp kernel/core/*.cpp)
# convert C source files to .o
KERNEL_C_OBJS=$(KERNEL_C_SRCS:.c=.o)
# convert C++ source files to .o
KERNEL_CPP_OBJS=$(KERNEL_CPP_SRCS:.cpp=.o)
# all kernel objects combined
KERNEL_OBJS=$(KERNEL_C_OBJS) $(KERNEL_CPP_OBJS) $(START_OBJS) $(ASM_OBJS)
# output files
BOOTSECT=bootsect.bin
KERNEL=kernel.bin
ISO=auroraos.iso
all: dirs bootsect kernel iso
dirs:
mkdir -p bin
clean:
rm -rf bin
find kernel -name "*.o" -type f -delete
rm -f ./*.iso
rm -f ./**/*.elf
rm -f ./**/*.bin
rm -f ./*.img
rm -f ./*.log
# rule to assemble GNU asm files (.S)
%.o: %.S
$(CC) -o $@ -c $< $(GFLAGS) $(CCFLAGS)
# rule to assemble NASM files (.asm)
%.o: %.asm
$(NASM) $(NASMFLAGS) -o $@ $<
# rule to compile C files
%.o: %.c
$(CC) -o $@ -c $< $(GFLAGS) $(CCFLAGS)
# rule to compile C++ files
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
# rule to build bootsector
bootsect: $(BOOTSECT_OBJS)
$(LD) -o ./bin/$(BOOTSECT) $^ -Ttext 0x7C00 --oformat=binary -N -m elf_i386
# rule to build kernel
kernel: $(KERNEL_OBJS)
$(LD) -o ./bin/$(KERNEL) $^ $(LDFLAGS) -Tlinker.ld -m elf_i386
# rule to create bootable ISO (using mkisofs)
iso: dirs bootsect kernel
mkisofs -o $(ISO) -b $(BOOTSECT) -c boot.catalog -no-emul-boot -boot-load-size 4 -boot-info-table bin/
run: clean dirs bootsect kernel img
qemu-system-i386 --drive format=raw,file=auroraos.img -serial stdio -no-reboot -d guest_errors,int,pcall,unimp,out_asm -D debug.log
img: dirs bootsect kernel
dd if=/dev/zero of=auroraos.img bs=512 count=2880
dd if=./bin/$(BOOTSECT) of=auroraos.img conv=notrunc bs=512 seek=0 count=1
dd if=./bin/$(KERNEL) of=auroraos.img conv=notrunc bs=512 seek=1 count=2048
# special targets
.PHONY: all dirs clean bootsect kernel iso img