-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
67 lines (54 loc) · 1.85 KB
/
Makefile
File metadata and controls
67 lines (54 loc) · 1.85 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
# Compiler/Assembler/Linker flags
GPPPARAMS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore
ASPARAMS = --32
LDPARAMS = -melf_i386
# Directories
SRC_DIR = src
BIN_DIR = bin
# Recursively find all source files
ASM_SOURCES := $(shell find $(SRC_DIR) -name '*.s')
CPP_SOURCES := $(shell find $(SRC_DIR) -name '*.cpp')
# Generate object file paths (flatten all sources into bin/)
OBJECTS := $(patsubst $(SRC_DIR)/%.s, $(BIN_DIR)/%.o, $(ASM_SOURCES)) \
$(patsubst $(SRC_DIR)/%.cpp, $(BIN_DIR)/%.o, $(CPP_SOURCES))
# Preserve subdirectory structure under bin/
$(BIN_DIR)/%.o: $(SRC_DIR)/%.s
@mkdir -p $(dir $@)
as $(ASPARAMS) -o $@ $<
$(BIN_DIR)/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(dir $@)
g++ $(GPPPARAMS) -o $@ -I includes -c $<
# Building without running
all: kernel.iso
# Link kernel binary
kernel.bin: linker.ld $(OBJECTS)
ld $(LDPARAMS) -T $< -o $@ $(OBJECTS)
# Install to /boot
install: kernel.bin
sudo cp $< /boot/kernel.bin
# Build bootable ISO
kernel.iso: kernel.bin
mkdir -p iso/boot/grub
cp $< iso/boot
@echo 'set timeout=0' >> iso/boot/grub/grub.cfg
@echo 'set default=0' >> iso/boot/grub/grub.cfg
@echo 'menuentry "Orange OS" {' >> iso/boot/grub/grub.cfg
@echo ' multiboot /boot/kernel.bin' >> iso/boot/grub/grub.cfg
@echo ' boot' >> iso/boot/grub/grub.cfg
@echo '}' >> iso/boot/grub/grub.cfg
grub-mkrescue --output=$@ iso
rm -rf iso
# Run in VirtualBox
run: kernel.iso
@if lsmod | grep -q "^kvm"; then \
bash src/toggle_kvm_for_vbox.sh; \
fi
(killall VirtualBoxVM && sleep 1) || true
VirtualBoxVM --startvm "Orange OS" &
# Ensure bin/ exists before building
$(BIN_DIR):
mkdir -p $(BIN_DIR)
clean:
rm -rf kernel.bin kernel.iso
rm -rf $(BIN_DIR)
.PHONY: clean install run all