blob: 1270a21f6051fa6ee294b22c4b84921d44942498 (
plain)
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
|
.SILENT:
override PROMPT := printf "%s\t\t%s\n"
###############################
# CFLAGS, QEMU flags + misc
###############################
KBUILD_ARGS = ""
override PROJECT_ROOT = @PROJECT_ROOT@
override BOOT_FW = @BOOT_FW@
override ARCH = @ARCH@
override HYRA_VERSION = @PACKAGE_VERSION@
override PROMPT := printf "%s\t\t%s\n"
override KERNEL_CFLAGS = @KERNEL_CFLAGS@ $(KERNEL_DEFINES)
override KERNEL_LDFLAGS = -no-pie -nostdlib -znoexecstack -zmax-page-size=0x1000 -static -Tsys/arch/$(ARCH)/conf/link.ld
override QEMU_FLAGS = @QEMU_FLAGS@
override KERNEL_DEFINES = $(KBUILD_ARGS) -DHYRA_VERSION="\"$(HYRA_VERSION)\""\
-DHYRA_BUILDDATE="\"@HYRA_BUILDDATE@\""\
-DHYRA_ARCH="\"@ARCH@\"" $(shell cat sys/arch/$(ARCH)/conf/GENERIC | tools/kconf/kconf)
######################
# Toolchain
######################
override TOOLCHAIN = @TOOLCHAIN@
ifeq ($(TOOLCHAIN), clang)
ifeq ($(ARCH), amd64)
override CC = clang -target x86_64-none-elf -ffreestanding -nostdlib
override LD = ld.lld
else
override CC = clang -target $(ARCH)-none-elf -ffreestanding -nostdlib
override LD = ld.lld
endif
else ifeq ($(TOOLCHAIN), gcc)
ifeq ($(ARCH), amd64)
override CC = $(shell pwd)/cross/bin/x86_64-hyra-gcc
override LD = $(shell pwd)/cross/bin/x86_64-hyra-ld
else
override CC = $(shell pwd)/cross/bin/$(ARCH)-hyra-gcc
override LD = $(shell pwd)/cross/bin/$(ARCH)-hyra-ld
endif
endif
##########################
# Architecture specifics
##########################
override ALL_ARCH_CFILES = find sys/ -name "*.c" | grep "sys/arch/$(ARCH).*"
override ALL_ARCH_ASM_FILES = find sys/ -name "*.S" | grep "sys/arch/$(ARCH).*"
override QEMU = @QEMU@
##########################
# General kernel sources
##########################
override KERNEL_CFILES = $(shell find sys/ -name "*.c" | grep -v "sys/arch/*" | grep -v sys/kern/ksyms.c) $(shell $(ALL_ARCH_CFILES))
override KERNEL_ASMFILES = $(shell find sys/ -name "*.S" | grep -v "sys/arch/*") $(shell $(ALL_ARCH_ASM_FILES))
########################
# Objects & header deps
########################
override KERNEL_OBJECTS = $(KERNEL_CFILES:.c=.o)
override KERNEL_ASMOBJECTS = $(KERNEL_ASMFILES:.S=.S.o)
override KERNEL_HEADER_DEPS = $(KERNEL_CFILES:.c=.d)
########################
# Userland
########################
override SBIN_MAKEDIRS = $(shell find usr.sbin/ -type d -name "*" | awk '!/usr.sbin\/$$/')
override BIN_MAKEDIRS = $(shell find usr.bin/ -type d -name "*" | awk '!/usr.bin\/$$/')
override USRDIR = $(shell pwd)/base/usr
.PHONY: all
all: stand/boot/ libc sbin bin base/boot/hyra-kernel
rm -f sys/include/machine
.PHONY: sbin
sbin: $(SBIN_MAKEDIRS)
make -C usr.sbin/ LDSCRIPT=$(shell pwd)/usr.sbin/link.ld USRDIR=$(USRDIR)\
ROOT=$(PROJECT_ROOT)\
.PHONY: bin
bin: $(BIN_MAKEDIRS)
make -C usr.bin/ LDSCRIPT=$(shell pwd)/usr.bin/link.ld USRDIR=$(USRDIR)\
ROOT=$(PROJECT_ROOT)
.PHONY: libc
libc:
$(MAKE) -C lib/libc/ -I$(shell pwd)/builddeps \
USRDIR=$(USRDIR) ARCH=$(ARCH) ROOT=$(PROJECT_ROOT)
.PHONY: cross
cross:
bash tools/cross.sh $(ARCH)
.PHONY: run
run:
$(QEMU) $(QEMU_FLAGS)
.PHONY: clean
clean:
rm -f $(KERNEL_ASMOBJECTS) $(KERNEL_OBJECTS) $(KERNEL_HEADER_DEPS)
rm -f sys/include/machine
stand/boot/:
mkdir -p stand/boot/
cp stand/limine/$(BOOT_FW) stand/boot/
base/boot/hyra-kernel: $(KERNEL_OBJECTS) $(KERNEL_ASMOBJECTS)
$(PROMPT) " LD " $(shell pwd)/base/boot/hyra-kernel
$(LD) $(KERNEL_LDFLAGS) $(KERNEL_OBJECTS) $(KERNEL_ASMOBJECTS) -o base/boot/hyra-kernel
tools/ksyms sys/kern/ksyms.c base/boot/hyra-kernel
# === Generating symbols ===
$(CC) -c $(KERNEL_CFLAGS) $(KERNEL_DEFINES) sys/kern/ksyms.c -o sys/kern/ksyms.o
$(LD) $(KERNEL_LDFLAGS) $(KERNEL_OBJECTS) $(KERNEL_ASMOBJECTS) \
sys/kern/ksyms.o -o base/boot/hyra-kernel
sys/include/machine/:
cd sys/include/; ln -sf arch/$(ARCH) machine
-include $(KERNEL_HEADER_DEPS)
%.o: %.c sys/include/machine/
$(PROMPT) " CC " $<
$(CC) -c $(KERNEL_CFLAGS) $(KERNEL_DEFINES) $< -o $@
%.S.o: %.S
$(PROMPT) " AS " $<
$(CC) -c $< -o $@ -D__$(ARCH)__ -I sys/include/
|