-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
76 lines (61 loc) · 2.03 KB
/
makefile
File metadata and controls
76 lines (61 loc) · 2.03 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
# Set paths
BIN_DIR = bin
SRC_DIR = sources
# Source files
ASM_BOOTLOADER = $(SRC_DIR)/bootloader.asm
ASM_KERNEL_ENTRY = $(SRC_DIR)/kernel_entry.asm
ASM_EMULFIX = $(SRC_DIR)/emulfix.asm
C_SOURCES = $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/**/*.c) # All .c files in sources and subdirectories
HEADERS = $(wildcard $(SRC_DIR)/*.h $(SRC_DIR)/**/*.h) # All .h files in sources and subdirectories
# Object files generated from each .c source file
OBJ_FILES = $(patsubst $(SRC_DIR)/%.c, $(BIN_DIR)/%.o, $(C_SOURCES))
# Output files
BOOT_BIN = $(BIN_DIR)/boot.bin
KERNEL_ENTRY_O = $(BIN_DIR)/kernel_entry.o
FULL_KERNEL_BIN = $(BIN_DIR)/full_kernel.bin
OS_BIN = $(BIN_DIR)/OS.bin
EMULFIX_BIN = $(BIN_DIR)/zeroes.bin
# Compiler and assembler settings
CC = i386-elf-gcc
LD = i386-elf-ld
NASM = nasm
QEMU = qemu-system-x86_64
CFLAGS = -ffreestanding -m32 -no-pie -g -c
LDFLAGS = -Ttext 0x1000 --oformat binary
# Default build target
all: $(OS_BIN)
# Assemble bootloader
$(BOOT_BIN): $(ASM_BOOTLOADER)
$(NASM) $< -f bin -o $@
# Assemble kernel entry
$(KERNEL_ENTRY_O): $(ASM_KERNEL_ENTRY)
$(NASM) $< -f elf -o $@
# Compile each .c file into an object file in the bin directory
$(BIN_DIR)/%.o: $(SRC_DIR)/%.c $(HEADERS)
$(CC) $(CFLAGS) $< -o $@
# Assemble emulfix (zeroes filler)
$(EMULFIX_BIN): $(ASM_EMULFIX)
$(NASM) $< -f bin -o $@
# Link all object files to create the full kernel binary
$(FULL_KERNEL_BIN): $(KERNEL_ENTRY_O) $(OBJ_FILES)
$(LD) -o $@ $(LDFLAGS) $^
# Combine bootloader, kernel, and emulfix into the final OS binary
$(OS_BIN): $(BOOT_BIN) $(FULL_KERNEL_BIN) $(EMULFIX_BIN)
cat $^ > $@
# Run the OS in QEMU
run: $(OS_BIN)
$(QEMU) -drive format=raw,file=$(OS_BIN),index=0,if=floppy -m 128M
# Run the OS in QEMU in fullscreen
runf: $(OS_BIN)
$(QEMU) -k -full-screen -drive format=raw,file=$(OS_BIN),index=0,if=floppy -m 128M
# Clean all build artifacts
clean:
rm -rf $(BIN_DIR)/*.bin $(BIN_DIR)/*.o $(OS_BIN)
install:
sudo apt-get update
sudo apt-get install -y \
qemu-utils \
qemu-system-x86 \
qemu-system-gui \
binutils-multiarch \
nasm