Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
94 lines (74 loc) · 2.88 KB
/
Copy pathMakefile
File metadata and controls
94 lines (74 loc) · 2.88 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
TARGET := x86_64-unknown-none-elf
CC := clang
LD := ld.lld
HOST_CC ?= cc
BUILD := build
KERNEL := $(BUILD)/aster-kernel.elf
ISO := $(BUILD)/aster-kernel.iso
NET_TEST := $(BUILD)/tests/net_parser_test
CFLAGS := --target=$(TARGET) -std=c11 -O2 -g \
-ffreestanding -fno-builtin -fno-stack-protector -fno-pic -fno-pie \
-fno-strict-aliasing -fno-asynchronous-unwind-tables -fno-unwind-tables \
-mno-red-zone -mcmodel=kernel -Wall -Wextra -Wpedantic -Werror \
-Iinclude
ASFLAGS := --target=$(TARGET) -g -c
LDFLAGS := -nostdlib -static --fatal-warnings --no-undefined \
-z max-page-size=0x1000 -T linker.ld
HOST_CFLAGS := -std=c11 -O2 -Wall -Wextra -Wpedantic -Werror -Iinclude
C_SOURCES := $(wildcard kernel/*.c arch/x86_64/*.c)
ASM_SOURCES := $(wildcard arch/x86_64/*.S)
OBJECTS := $(patsubst %.c,$(BUILD)/%.o,$(C_SOURCES)) \
$(patsubst %.S,$(BUILD)/%.o,$(ASM_SOURCES))
QEMU ?= qemu-system-x86_64
QEMU_MEMORY ?= 256M
.PHONY: all kernel iso run run-gui run-headless run-direct clean check smoke tools
all: kernel
kernel: $(KERNEL)
$(KERNEL): $(OBJECTS) linker.ld
@mkdir -p $(@D)
$(LD) $(LDFLAGS) -o $@ $(OBJECTS)
$(BUILD)/%.o: %.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD)/%.o: %.S
@mkdir -p $(@D)
$(CC) $(ASFLAGS) $< -o $@
$(NET_TEST): tests/net_parser_test.c kernel/net.c
@mkdir -p $(@D)
$(HOST_CC) $(HOST_CFLAGS) $< -o $@
check: $(KERNEL) $(NET_TEST)
@$(NET_TEST)
@python3 scripts/check_kernel.py $(KERNEL)
@python3 scripts/check_repo.py
iso: $(KERNEL)
@command -v grub-mkrescue >/dev/null || { echo "Missing grub-mkrescue"; exit 1; }
@command -v xorriso >/dev/null || { echo "Missing xorriso"; exit 1; }
rm -rf $(BUILD)/isodir
mkdir -p $(BUILD)/isodir/boot/grub
cp $(KERNEL) $(BUILD)/isodir/boot/aster-kernel.elf
cp grub/grub.cfg $(BUILD)/isodir/boot/grub/grub.cfg
grub-mkrescue -o $(ISO) $(BUILD)/isodir
smoke: iso
QEMU="$(QEMU)" QEMU_MEMORY="$(QEMU_MEMORY)" \
python3 scripts/smoke_qemu.py "$(ISO)"
# Auto-detect GTK, SDL, or Cocoa. If none exists, keep the kernel usable
# by falling back to its colored serial console instead of aborting.
run: iso
QEMU="$(QEMU)" QEMU_MEMORY="$(QEMU_MEMORY)" sh ./scripts/run_qemu.sh auto "$(ISO)"
# Require a real graphical window and print exact installation help if absent.
run-gui: iso
QEMU="$(QEMU)" QEMU_MEMORY="$(QEMU_MEMORY)" sh ./scripts/run_qemu.sh gui "$(ISO)"
# Useful over SSH or when no graphical QEMU display module is installed.
run-headless: iso
QEMU="$(QEMU)" QEMU_MEMORY="$(QEMU_MEMORY)" sh ./scripts/run_qemu.sh headless "$(ISO)"
run-direct: $(KERNEL)
$(QEMU) -kernel $(KERNEL) -m $(QEMU_MEMORY) \
-serial stdio -display none \
-netdev user,id=net0,ipv6=off \
-device rtl8139,netdev=net0,mac=52:54:00:12:34:56 \
-no-reboot -no-shutdown
clean:
rm -rf $(BUILD)
# Arch Linux / CachyOS host dependencies.
tools:
@echo "sudo pacman -S --needed base-devel clang lld qemu-system-x86 qemu-ui-gtk grub xorriso mtools"