-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
77 lines (61 loc) · 1.86 KB
/
makefile
File metadata and controls
77 lines (61 loc) · 1.86 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
# Makefile for Copium OS - Multi-Component Kernel
# Cross-compiler prefix
CC=i686-elf-gcc
AS=i686-elf-as
# Directories
SRC_DIR=src
BUILD_DIR=build
ISO_DIR=$(BUILD_DIR)/isodir
INCLUDE_DIR=include
# Source files
BOOT_SRC=$(SRC_DIR)/boot.s
KERNEL_SOURCES=$(wildcard $(SRC_DIR)/kernel/*.c) \
$(wildcard $(SRC_DIR)/debug/*.c) \
$(wildcard $(SRC_DIR)/env/*.c) \
$(wildcard $(SRC_DIR)/mcu/*.c) \
$(wildcard $(SRC_DIR)/events/*.c) \
$(wildcard $(SRC_DIR)/visual/*.c)
LINKER_SCRIPT=linker.ld
GRUB_CFG=grub.cfg
# Output files
BOOT_OBJ=$(BUILD_DIR)/boot.o
KERNEL_OBJS=$(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(KERNEL_SOURCES))
KERNEL_BIN=$(BUILD_DIR)/myos.bin
ISO_FILE=$(BUILD_DIR)/myos.iso
# Compiler flags
CFLAGS=-c -std=gnu99 -ffreestanding -O2 -Wall -Wextra -I$(INCLUDE_DIR)
LDFLAGS=-ffreestanding -O2 -nostdlib -lgcc
all: $(ISO_FILE)
# Create build directories
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
mkdir -p $(BUILD_DIR)/kernel
mkdir -p $(BUILD_DIR)/debug
mkdir -p $(BUILD_DIR)/env
mkdir -p $(BUILD_DIR)/mcu
mkdir -p $(BUILD_DIR)/events
mkdir -p $(BUILD_DIR)/visual
# Assemble bootloader
$(BOOT_OBJ): $(BOOT_SRC) | $(BUILD_DIR)
$(AS) $< -o $@
# Compile kernel sources
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
$(CC) $(CFLAGS) $< -o $@
# Link kernel and bootloader
$(KERNEL_BIN): $(BOOT_OBJ) $(KERNEL_OBJS) $(LINKER_SCRIPT)
$(CC) -T $(LINKER_SCRIPT) -o $@ $(BOOT_OBJ) $(KERNEL_OBJS) $(LDFLAGS)
# Create ISO image
$(ISO_FILE): $(KERNEL_BIN) $(GRUB_CFG)
mkdir -p $(ISO_DIR)/boot/grub
cp $(KERNEL_BIN) $(ISO_DIR)/boot/
cp $(GRUB_CFG) $(ISO_DIR)/boot/grub/
grub-mkrescue -o $(ISO_FILE) $(ISO_DIR)
# Run in QEMU
run: $(ISO_FILE)
qemu-system-i386 -cdrom $(ISO_FILE)
# Clean everything
clean:
rm -rf $(BUILD_DIR)
# Docker build (same as all, but explicit)
docker-build: all
.PHONY: all clean run docker-build