-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
84 lines (65 loc) · 2.08 KB
/
Makefile
File metadata and controls
84 lines (65 loc) · 2.08 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
78
79
80
81
82
83
84
TARGET := kernel
SRC := src
INCLUDE := include
LINKER := linker
BUILD := build
RES := res
CC := i486-unknown-elf-gcc
LD := $(CC)
ASM := nasm
ASMFLAGS += -felf32
LDFLAGS += -T $(LINKER)/kernel.ld -ffreestanding -nostdlib -flto
CFLAGS += \
-g \
-O2 \
-I$(INCLUDE) \
-I$(INCLUDE)/libc \
-I$(BUILD)/gen/res \
-ffreestanding \
-nostdlib \
-std=gnu11 \
-Wall \
-Wextra \
-Wno-unused-function \
-Wno-unused-parameter \
-Wno-unused-const-variable
QEMU ?= qemu-system-x86_64
QEMU_COMMON_FLAGS += -no-reboot -cpu 486 -serial stdio -m 12M
QEMU_DEBUG_FLAGS += $(QEMU_COMMON_FLAGS) -gdb tcp::1234 -S -d int
find = $(shell find $1 -type f -name $2 -print 2> /dev/null)
FONTS = $(call find, $(RES)/fonts, "*.png")
CSRCS = $(call find, $(SRC)/, "*.c")
ASMSRCS = $(filter-out $(SRC)/libc/crti.asm $(SRC)/libc/crtn.asm,$(call find, $(SRC)/, "*.asm"))
OBJECTS = $(BUILD)/gen/res/fonts.o $(CSRCS:%=$(BUILD)/objects/%.o) $(ASMSRCS:%=$(BUILD)/objects/%.o)
all: $(BUILD)/target/$(TARGET)
$(BUILD)/target/$(TARGET): $(BUILD)/objects/src/libc/crti.asm.o $(OBJECTS) $(BUILD)/objects/src/libc/crtn.asm.o
@echo Linking $@
@mkdir -p $(BUILD)/target
@$(LD) -o $@ $(BUILD)/objects/src/libc/crti.asm.o $(OBJECTS) $(BUILD)/objects/src/libc/crtn.asm.o $(LDFLAGS)
$(BUILD)/objects/%.c.o: %.c $(BUILD)/gen/res/fonts.o
@echo Compiling $(subst $(BUILD)/,,$<)
@mkdir -p $(dir $@)
@$(CC) -MMD $(CFLAGS) -c -o $@ $<
$(BUILD)/objects/%.asm.o: %.asm
@echo Assembling $(subst $(BUILD)/,,$<)
@mkdir -p $(dir $@)
@$(ASM) -MD $@.d $(ASMFLAGS) -o $@ $<
$(BUILD)/gen/res/fonts.o: $(FONTS)
@echo Generating fonts
@mkdir -p $(dir $@)
@python3 tools/createcharmap.py \
-C $(BUILD)/gen/res/fonts.c \
-H $(BUILD)/gen/res/fonts.h \
-I fonts.h \
$(FONTS)
@$(CC) $(CFLAGS) -c -o $@ $(BUILD)/gen/res/fonts.c
$(BUILD)/gen/res/fonts.h: $(BUILD)/gen/res/fonts.o
clean:
@echo Cleaning build files
@rm -rf $(BUILD)
run: $(BUILD)/target/$(TARGET)
@$(QEMU) $(QEMU_COMMON_FLAGS) -kernel $<
run-debug: $(BUILD)/target/$(TARGET)
@$(QEMU) $(QEMU_DEBUG_FLAGS) -kernel $<
-include $(call find, $(BUILD)/, "*.d")
.PHONY: clean run run-debug