-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
62 lines (48 loc) · 1.33 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Compiler and linker settings
CC = gcc
AS = nasm
CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector \
-nostartfiles -nodefaultlibs -c
ASFLAGS = -f elf32
LDFLAGS = -m elf_i386 -T linker.ld
# Directories
SRC_DIR = src
BUILD_DIR = build
# Find all source files
C_SRCS := $(wildcard $(SRC_DIR)/*.c)
ASM_SRCS := $(wildcard $(SRC_DIR)/*.asm)
HEADERS := $(wildcard $(SRC_DIR)/*.h)
# Generate object file names
C_OBJS := $(C_SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
ASM_OBJS := $(ASM_SRCS:$(SRC_DIR)/%.asm=$(BUILD_DIR)/%.o)
# All object files
OBJ = $(C_OBJS) $(ASM_OBJS)
# Default target
all: build/noiros.iso
# Create build directory
build:
mkdir -p build
mkdir -p iso/boot/grub
# Compile C files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $(HEADERS)
$(CC) $(CFLAGS) $< -o $@
# Compile Assembly files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.asm
$(AS) $(ASFLAGS) $< -o $@
# Link everything together
build/noiros.bin: $(OBJ)
ld $(LDFLAGS) $(OBJ) -o build/noiros.bin
# Create ISO
build/noiros.iso: build build/noiros.bin
cp build/noiros.bin iso/boot/
grub-mkrescue -o build/noiros.iso iso
# Clean build files
clean:
rm -rf build
rm -f iso/boot/noiros.bin
run: build/noiros.iso
qemu-system-i386 -cdrom build/noiros.iso -machine pc -enable-kvm -audio alsa
# Print variables for debugging
print-%:
@echo $* = $($*)
.PHONY: all clean run print-%