Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
66 lines (47 loc) · 1.91 KB
/
Copy pathMakefile
File metadata and controls
66 lines (47 loc) · 1.91 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
SHELL := /usr/bin/env bash
OUT := out
IMG_SIZE_MB := 16
KERNEL_SECTORS := 80
APP_DIRS := $(sort $(patsubst %/,%,$(dir $(wildcard src/apps/*/Makefile))))
APP_NAMES := $(notdir $(APP_DIRS))
APP_PACKAGES := $(addprefix $(OUT)/apps/,$(addsuffix .app,$(APP_NAMES)))
.PHONY: all apps kernel clean run finish
all: $(OUT)/disk.img finish
apps: $(APP_PACKAGES)
kernel: $(OUT)/kernel.bin
$(OUT):
mkdir -p $(OUT)
$(OUT)/apps: | $(OUT)
mkdir -p $(OUT)/apps
$(OUT)/kernel:
mkdir -p $(OUT)/kernel
$(OUT)/apps/%.app: | $(OUT)/apps
$(MAKE) -C src/apps/$* OUT_DIR=../../../$(OUT)/apps APP_LINKER=../linker.ld
$(OUT)/boot.bin: boot.asm | $(OUT)
nasm -f bin boot.asm -o $@
$(OUT)/kernel/kernel_entry.o: kernel_entry.asm | $(OUT)/kernel
nasm -f elf32 kernel_entry.asm -o $@
$(OUT)/kernel/isr_stubs.o: isr_stubs.asm | $(OUT)/kernel
nasm -f elf32 isr_stubs.asm -o $@
$(OUT)/kernel.elf: $(OUT)/kernel/kernel_entry.o $(OUT)/kernel/isr_stubs.o
$(MAKE) -C src/kernel
$(OUT)/kernel.bin: $(OUT)/kernel.elf
objcopy -O binary $< $@
@KERNEL_SIZE=$$(wc -c < $@); \
BUDGET=$$(( $(KERNEL_SECTORS) * 512 )); \
if [ "$$KERNEL_SIZE" -gt "$$BUDGET" ]; then \
echo ""; \
echo "WARNING: kernel.bin is $$KERNEL_SIZE bytes, but boot.asm only loads $$BUDGET bytes ($(KERNEL_SECTORS) sectors)."; \
echo " Bump 'mov dh, $(KERNEL_SECTORS)' in boot.asm to cover $$(( (KERNEL_SIZE + 511) / 512 )) sectors."; \
fi
$(OUT)/mkkfs2: tools/mkkfs2.c | $(OUT)
gcc -std=c99 -O2 $< -o $@
$(OUT)/disk.img: $(OUT)/boot.bin $(OUT)/kernel.bin $(OUT)/mkkfs2 $(APP_PACKAGES)
truncate -s "$(IMG_SIZE_MB)M" $@
dd if=$(OUT)/boot.bin of=$@ conv=notrunc status=none
dd if=$(OUT)/kernel.bin of=$@ bs=512 seek=1 conv=notrunc status=none
$(OUT)/mkkfs2 $@ $(APP_PACKAGES)
finish:
@printf -- "-----\nqemu-system-i386 -drive format=raw,file=$(OUT)/disk.img,if=ide,index=0,media=disk\n-----\n"
clean:
rm -rf $(OUT)