-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMakefile
More file actions
169 lines (136 loc) · 4.87 KB
/
Makefile
File metadata and controls
169 lines (136 loc) · 4.87 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# =====================================================
#
# Makefile
# Uinxed-Kernel compile script
#
# 2024/6/23 By Rainy101112
# Based on Apache 2.0 open source license.
# Copyright © 2020 ViudiraTech, based on the Apache 2.0 license.
#
# =====================================================
ifneq ($(wildcard .config),)
include .config
else ifneq ($(wildcard .config-default),)
include .config-default
else
$(error No configuration file (.config or .config-default) found)
endif
ifeq ($(VERBOSE), 1)
Q=
else
Q=@
endif
ifeq ($(CONFIG_KERNEL_LOG), y)
C_CONFIG += -DKERNEL_LOG=1
else
C_CONFIG += -DKERNEL_LOG=0
endif
ifeq ($(CONFIG_TTF_CONSOLE), y)
C_CONFIG += -DTTF_CONSOLE=1
else
C_CONFIG += -DTTF_CONSOLE=0
endif
ifneq ($(CONFIG_CONSOLE_FONT_SIZE),)
C_CONFIG += -DCONSOLE_FONT_SIZE=$(CONFIG_CONSOLE_FONT_SIZE)
endif
ifneq ($(CONFIG_MAX_CPU_COUNT),)
C_CONFIG += -DMAX_CPU_COUNT=$(CONFIG_MAX_CPU_COUNT)
endif
ifeq ($(CONFIG_CPU_FEATURE_FPU), y)
C_CONFIG += -DCPU_FEATURE_FPU=1
else
C_CONFIG += -DCPU_FEATURE_FPU=0 -mno-mmx -mno-80387
endif
ifeq ($(CONFIG_CPU_FEATURE_SSE), y)
C_CONFIG += -DCPU_FEATURE_SSE=1
else
C_CONFIG += -DCPU_FEATURE_SSE=0 -mno-sse -mno-sse2
endif
ifeq ($(CONFIG_CPU_FEATURE_AVX), y)
C_CONFIG += -DCPU_FEATURE_AVX=1
else
C_CONFIG += -DCPU_FEATURE_AVX=0 -mno-avx -mno-avx2
endif
ifneq ($(CONFIG_TTY_DEFAULT_DEV),)
C_CONFIG += -DTTY_DEFAULT_DEV=\"$(CONFIG_TTY_DEFAULT_DEV)\"
endif
ifneq ($(CONFIG_TTY_BUF_SIZE),)
C_CONFIG += -DTTY_BUF_SIZE=$(CONFIG_TTY_BUF_SIZE)
endif
ifneq ($(CONFIG_SERIAL_BAUD_RATE),)
C_CONFIG += -DSERIAL_BAUD_RATE=$(CONFIG_SERIAL_BAUD_RATE)
endif
ifneq ($(CONFIG_SERIAL_DATA_BITS),)
C_CONFIG += -DSERIAL_DATA_BITS=$(CONFIG_SERIAL_DATA_BITS)
endif
ifneq ($(CONFIG_SERIAL_STOP_BITS),)
C_CONFIG += -DSERIAL_STOP_BITS=$(CONFIG_SERIAL_STOP_BITS)
endif
C_SOURCES := $(shell find * -name "*.c")
C_HEADERS := $(shell find * -name "*.h")
OBJS := $(C_SOURCES:%.c=%.o)
DEPS := $(OBJS:%.o=%.d)
LIBS := $(wildcard libs/lib*.a)
PWD := $(shell pwd)
QEMU := qemu-system-x86_64
QEMU_FLAGS := -machine q35 -bios assets/ovmf-code.fd
# If you want to get more details of `dump_stack`, you need to replace `-O3` with `-O0` or '-Os'.
# `-fno-optimize-sibling-calls` is for `dump_stack` to work properly.
C_FLAGS := -Wall -Wextra -O3 -g3 -m64 -fpie -ffreestanding -fno-optimize-sibling-calls -fno-stack-protector -fno-omit-frame-pointer -mstackrealign -mno-red-zone -I include -MMD
LD_FLAGS := -nostdlib -pie -T assets/linker.ld -m elf_x86_64
all: Uinxed-x64.iso
%.o: %.c
$(Q)printf " CC $@\n"
$(Q)$(CC) $(C_FLAGS) $(C_CONFIG) -c -o $@ $<
%.fmt: %
$(Q)printf " FORMAT $<\n"
$(Q)clang-format -i $<
%.tidy: %
$(Q)printf " TIDY $<\n"
$(Q)clang-tidy $< -- $(C_FLAGS)
info:
$(Q)printf "Uinxed-Kernel Compile Script.\n"
$(Q)printf "Copyright 2020 ViudiraTech, based on the Apache 2.0 license.\n"
$(Q)printf "Based on Apache 2.0 open source license.\n\n"
UxImage: $(OBJS) $(LIBS)
$(Q)printf " LD $@\n"
$(Q)$(LD) $(LD_FLAGS) -o $@ $^
Uinxed-x64.iso: info UxImage
$(Q)printf " XORRISO $@\n\n"
$(Q)cp -a assets/Limine iso
$(Q)cp $(word 2,$^) iso/EFI/Boot
$(Q)xorriso -as mkisofs -R -r -J -b Limine/limine-bios-cd.bin -no-emul-boot -boot-load-size 4 -boot-info-table \
-hfsplus -apm-block-size 2048 -efi-boot-part --efi-boot-image --protective-msdos-label \
--efi-boot Limine/limine-uefi-cd.bin -o $@ iso
$(Q)$(RM) -rf iso
$(Q)printf "Kernel: $(word 2,$^) is ready.\n"
$(Q)printf "Image: $@ is ready.\n"
$(Q)printf "Compilation complete.\n"
.PHONY: help run clean format check gen.clangd menuconfig
help: info
$(Q)printf "Uinxed-Kernel Makefile Usage:\n"
$(Q)printf " make all - Build the entire project.\n"
$(Q)printf " make run - Run the Uinxed-x64.iso in QEMU.\n"
$(Q)printf " make clean - Clean all generated files.\n"
$(Q)printf " make format - Format all source files using clang-format.\n"
$(Q)printf " make check - Run static code checks using clang-tidy.\n"
$(Q)printf " make gen.clangd - Generate .clangd configuration file.\n"
$(Q)printf " make menuconfig - Run menuconfig to configure the kernel.\n"
$(Q)printf " make help - Display this help message.\n"
run: info Uinxed-x64.iso
$(QEMU) $(QEMU_FLAGS) -cdrom $(word 2,$^)
clean: info
$(Q)$(RM) $(OBJS) $(DEPS) UxImage Uinxed-x64.iso
$(Q)printf "Clean completed.\n"
format: info $(C_SOURCES:%=%.fmt) $(C_HEADERS:%=%.fmt)
$(Q)printf "\nCode Format complete.\n"
check: info $(C_SOURCES:%=%.tidy) $(C_HEADERS:%=%.tidy)
$(Q)printf "\nCode Checks complete.\n"
gen.clangd: info
$(Q)$(RM) -f .clangd
$(Q)echo "# Generated by Makefile" >> .clangd
$(Q)sed "s/\$${workspaceFolder}/$(subst /,\/,${PWD})/g" .clangd_template >> .clangd
$(Q)printf ".clangd configuration generated.\n"
menuconfig: info
$(Q)kconfig-mconf Kconfig
-include $(DEPS)