# Compiler and flags ASM = i686-elf-as CPP = i686-elf-g++ LD = i686-elf-gcc CFLAGS = -ffreestanding -O2 -Wall -Wextra -fno-exceptions -fno-rtti LDFLAGS = -T linker.ld -ffreestanding -O2 -nostdlib -lgcc # Directories SRC_DIR = src BUILD_DIR = build # Source files SRC_FILES := $(wildcard $(SRC_DIR)/*.cpp) $(wildcard $(SRC_DIR)/*/*.cpp) ASM_FILES := $(wildcard $(SRC_DIR)/*.s) $(wildcard $(SRC_DIR)/*/*.s) # Object files OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(SRC_FILES)) OBJ_FILES += $(patsubst $(SRC_DIR)/%.s,$(BUILD_DIR)/%.o,$(ASM_FILES)) # Output binary OUTPUT = myos.bin # Build target all: $(BUILD_DIR) $(OUTPUT) # Create the build directory if it doesn't exist $(BUILD_DIR): mkdir -p $(BUILD_DIR) # Compile C++ source files $(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp $(CPP) -c $< -o $@ $(CFLAGS) # Assemble assembly source files $(BUILD_DIR)/%.o: $(SRC_DIR)/%.s $(ASM) $< -o $@ # Link the object files to create the final binary $(OUTPUT): $(OBJ_FILES) $(LD) $(LDFLAGS) -o $@ $^ # Run QEMU after a successful build run: all qemu-system-i386 -kernel $(OUTPUT) # Clean build files clean: rm -rf $(BUILD_DIR) $(OUTPUT) .PHONY: all run clean