-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
74 lines (58 loc) · 1.7 KB
/
Makefile
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
OS := enki
ARCH := i686
FMT := elf
KERNEL_DIR := kernel
LIBC_DIR := libc
PGM_DIR := programs
BIN_DIR := bin
MNT_DIR := /mnt/$(OS)
SCRIPTS_DIR := scripts
BOOT_BIN := $(KERNEL_DIR)/bin/boot.bin
KERNEL_BIN := $(KERNEL_DIR)/bin/kernel.bin
KERNEL_OBJ := $(KERNEL_DIR)/obj/kernel_full.o
ENKI_BIN := $(BIN_DIR)/enki.bin
PGMS := shell repeat hello
KERNEL_ENTRY := 0x100000
PGM_ENTRY := 0x400000
1MB := 1048576
QEMU := qemu-system-i386
QEMU_FLAGS := -drive file=$(ENKI_BIN),format=raw
.PHONY: .FORCE
.FORCE:
all: build img mount unmount
build: clean
$(MAKE) -C $(LIBC_DIR) all
$(MAKE) -C $(KERNEL_DIR) all
$(foreach pgm, $(PGMS), $(MAKE) -C $(PGM_DIR)/$(pgm) all ; )
clean:
@rm -rf $(BIN_DIR)/*
img:
@echo "building image..."
@mkdir -p $(BIN_DIR)
dd if=$(BOOT_BIN) status=none >> $(ENKI_BIN)
dd if=$(KERNEL_BIN) status=none >> $(ENKI_BIN)
dd if=/dev/zero bs=$(1MB) count=16 status=none>> $(ENKI_BIN)
mount:
@sudo mkdir -p $(MNT_DIR)
@sudo mount -t vfat $(ENKI_BIN) $(MNT_DIR)
@$(foreach pgm, $(PGMS), sudo cp $(PGM_DIR)/$(pgm)/bin/$(pgm) $(MNT_DIR) ; )
unmount:
@sudo umount $(MNT_DIR)
qemu: all
$(QEMU) $(QEMU_FLAGS) -monitor stdio
debug_kernel: all
@gdb -ex 'set confirm off' \
-ex 'add-symbol-file $(KERNEL_OBJ) $(KERNEL_ENTRY)' \
-ex 'break kernel_main' \
-ex 'target remote | $(QEMU) $(QEMU_FLAGS) -S -gdb stdio'
debug_shell: all
@gdb -ex 'set confirm off' \
-ex 'add-symbol-file $(PGM_DIR)/shell/bin/shell $(PGM_ENTRY)' \
-ex 'break main' \
-ex 'target remote | $(QEMU) $(QEMU_FLAGS) -S -gdb stdio'
toolchain:
@echo "Building toolchain..."
@chmod +x $(SCRIPTS_DIR)/toolchain.sh
$(SCRIPTS_DIR)/toolchain.sh
line_count:
git ls-files | xargs wc -l