forked from gmh5225/PaybackOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
48 lines (37 loc) · 1.2 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
include make.config
# Define variables
SRC_DIR = src
OBJ_DIR = obj
TARGET = PaybackOS.bin
# Automatically find all source files
SRCS := $(shell find $(SRC_DIR) -name '*.cpp' -o -name '*.s' -o -name '*.asm')
OBJS := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(patsubst $(SRC_DIR)/%.s,$(OBJ_DIR)/%.o,$(patsubst $(SRC_DIR)/%.asm,$(OBJ_DIR)/%.o,$(SRCS))))
# Ensure the object directory exists
$(shell mkdir -p $(OBJ_DIR))
# Define the build rules
build: $(OBJS)
$(LD) -T linker.ld -o $(TARGET) $(LDFLAGS) $(OBJS)
# Pattern rules to build .o files from .s, .asm, and .cpp files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.s
mkdir -p $(dir $@) # Create the target directory
$(AS) -o $@ $<
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.asm
mkdir -p $(dir $@) # Create the target directory
$(AS) -o $@ $<
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
mkdir -p $(dir $@) # Create the target directory
$(CXX) $(CXXFLAGS) -c $< -o $@
# Create the GRUB iso
iso: build
mkdir -p iso/boot/grub/
cp grub.cfg iso/boot/grub/
mv $(TARGET) iso/boot/
grub-mkrescue iso/ -o PaybackOS.iso
rm -rf iso
# Run the OS
run:
qemu-system-x86_64 -cdrom PaybackOS.iso
# Clean rule to remove generated files
clean:
rm -rf obj $(TARGET) iso *.iso
.PHONY: all build clean iso run