-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
136 lines (105 loc) · 4.3 KB
/
Makefile
File metadata and controls
136 lines (105 loc) · 4.3 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
CC := i686-elf-gcc
AS := i686-elf-as
TST_CC := gcc
WARNINGS := -Wall -Wextra -Wshadow -Wpointer-arith -Wcast-align \
-Wwrite-strings -Wmissing-prototypes -Wmissing-declarations \
-Wredundant-decls -Wnested-externs -Winline -Wno-long-long \
-Wconversion -Wstrict-prototypes
CFLAGS := -std=gnu23 $(WARNINGS) -ffreestanding -O2
LDFLAGS := -ffreestanding -O2 -nostdlib
TST_CFLAGS := -DUNITY_INCLUDE_CONFIG_H -DTEST -nostdlib -ffreestanding
TST_LDFLAGS :=
SRC := src
BUILD := build
OBJ := $(BUILD)/obj
INCLUDES := $(wildcard $(SRC)/**/include)
BIN := $(BUILD)/bin
KERNEL := $(BIN)/kernel.bin
ISO := $(BUILD)/iso
RELEASE := $(BUILD)/release/ckos.iso
TST_SRC := test
TST_BIN := $(BUILD)/test/bin
TST_OBJ := $(BUILD)/test/obj
TST_RESULT := $(BUILD)/test/results
TST_INCLUDES:= $(INCLUDES) Unity/src $(TST_SRC)
SRCS := $(wildcard $(SRC)/**/*.c) $(wildcard $(SRC)/**/*.S)
OBJS := $(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(SRCS))
OBJS := $(patsubst $(SRC)/%.S, $(OBJ)/%.o, $(OBJS))
OBJS := $(OBJS) $(OBJ)/external/font.o
DEPS := $(patsubst $(SRC)/%.c, $(OBJ)/%.d, $(SRCS))
DEPS := $(patsubst $(SRC)/%.S, $(OBJ)/%.d, $(DEPS))
TSTS := $(wildcard $(TST_SRC)/**/*.c)
TST_EXCLUDES:= $(TST_OBJ)/kernel/kernel.o $(TST_OBJ)/kernel/paging.o $(TST_OBJ)/kernel/boot.o
TST_OBJS := $(patsubst $(TST_SRC)/%.c, $(TST_OBJ)/%.o, $(TSTS)) $(TST_OBJ)/unity.o $(patsubst $(OBJ)/%.o, $(TST_OBJ)/%.o, $(OBJS))
TST_OBJS := $(filter-out $(TST_EXCLUDES), $(TST_OBJS))
TST_RESULTS := $(patsubst $(TST_SRC)/%.c, $(TST_RESULT)/%.txt, $(TSTS))
HEADERS := $(foreach incl, $(INCLUDES), $(wildcard $(incl)/*.h))
ALLFILES := $(SRCS) $(HEADERS)
PASSED := `grep -s :PASS $(TST_RESULT)/**/*.txt`
FAIL := `grep -s :FAIL $(TST_RESULT)/**/*.txt`
IGNORE := `grep -s :IGNORE $(TST_RESULT)/**/*.txt`
-include $(DEPS)
.PHONY: all clean todo static test
all: setup $(RELEASE)
debug:
@echo $(TST_INCLUDES)
setup:
@mkdir -p build/obj/kernel
@mkdir -p build/obj/libc
@mkdir -p build/obj/external
@mkdir -p build/bin
@mkdir -p build/release
@mkdir -p build/iso/boot/grub
@mkdir -p build/test/bin
@mkdir -p build/test/results/kernel
@mkdir -p build/test/results/libc
@mkdir -p build/test/obj/kernel
@mkdir -p build/test/obj/libc
@mkdir -p build/test/obj/external
clean:
-@rm -R build/*
todo:
-@for file in $(ALLFILES:Makefile=); do fgrep -H -e TODO $$file; done; true
test: setup $(TST_RESULTS)
@echo "-----------------------\nIGNORES:\n-----------------------"
@echo "$(IGNORE)"
@echo "-----------------------\nFAILURES:\n-----------------------"
@echo "$(FAIL)"
@echo "-----------------------\nPASSED:\n-----------------------"
@echo "$(PASSED)"
@echo "\nDONE"
# Create ISO
$(RELEASE): $(KERNEL) $(SRC)/kernel/grub.cfg
@cp $(KERNEL) $(ISO)/boot/kernel.bin
@cp $(SRC)/kernel/grub.cfg $(ISO)/boot/grub/grub.cfg
@grub-mkrescue -o $(RELEASE) $(ISO)
# Linker
$(KERNEL): $(OBJS)
@$(CC) -T $(SRC)/kernel/linker.ld -o $(KERNEL) $(LDFLAGS) $(OBJS) -lgcc
# Build
$(OBJ)/%.o: $(SRC)/%.c Makefile $(SRC)/kernel/linker.ld
@$(CC) $(CFLAGS) $(foreach incl, $(INCLUDES), $(addprefix -I ,$(incl))) -MMD -MP -c $< -o $@
$(OBJ)/%.o: $(SRC)/%.S Makefile $(SRC)/kernel/linker.ld
@$(AS) $< -o $@
# Build special content
$(OBJ)/external/font.o: font.psf Makefile $(SRC)/kernel/linker.ld
@objcopy -O elf32-i386 -B i386 -I binary $< $@
# Tests-----------------------------------------------------------------------------------------------------
# Test results
$(TST_RESULT)/%.txt: $(TST_BIN)/test-runner.bin
-./$< > $@ 2>&1
# Create test runner binary (Linker)
$(TST_BIN)/test-runner.bin: $(TST_OBJS)
@$(TST_CC) $(TST_LDFLAGS) -o $(TST_BIN)/test-runner.bin $(TST_OBJS)
# Create obj files from tests
$(TST_OBJ)/%.o: $(TST_SRC)/%.c Makefile $(SRC)/kernel/linker.ld
$(TST_CC) $(TST_CFLAGS) $(foreach incl, $(TST_INCLUDES), $(addprefix -I,$(incl))) -c $< -o $@
# Create obj files from src
$(TST_OBJ)/%.o: $(SRC)/%.c Makefile $(SRC)/kernel/linker.ld
$(TST_CC) $(TST_CFLAGS) $(foreach incl, $(TST_INCLUDES), $(addprefix -I,$(incl))) -c $< -o $@
# Font obj
$(TST_OBJ)/external/font.o: font.psf Makefile $(SRC)/kernel/linker.ld
@objcopy -O pe-x86-64 -B i386:x86-64 -I binary $< $@
# Unity obj
$(TST_OBJ)/unity.o: Unity/src/unity.c Makefile $(SRC)/kernel/linker.ld
$(TST_CC) $(TST_CFLAGS) $(foreach incl, $(TST_INCLUDES), $(addprefix -I,$(incl))) -c $< -o $@