-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
47 lines (40 loc) · 1.13 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
# Define variables
NASM = nasm
NASM_FLAGS = -f bin
NASM_DEBUG_FLAGS = -g -f elf64
QEMU = qemu-system-x86_64
GDB = gdb
BOOTSECTOR = birdos.bin
ASM_SOURCE = birdos.asm
IMG = boot.img
# Phony targets
.PHONY: all build run debug clean
# Default target
all: build
# Build target
build:
@echo -e "[1/2] $(NASM) $(NASM_FLAGS) -o $(BOOTSECTOR) $(ASM_SOURCE)"
$(NASM) $(NASM_FLAGS) -o $(BOOTSECTOR) $(ASM_SOURCE)
debug_build:
$(NASM) $(NASM_FLAGS) -o $(BOOTSECTOR) $(ASM_SOURCE)
# Run target
run: build
@echo -e "[2/2] $(QEMU) -drive format=raw,file=$(BOOTSECTOR) &"
$(QEMU) -drive format=raw,file=$(BOOTSECTOR)
# Debug target
debug: debug_build
@echo -e "Creating temporary image file $(IMG)"
dd if=/dev/zero of=$(IMG) bs=512 count=1
dd if=$(BOOTSECTOR) of=$(IMG) conv=notrunc
@echo -e "Starting $(QEMU) for debugging"
$(QEMU) -drive format=raw,file=$(IMG) -s -S &
QEMU_PID=$!
@echo -e "Starting $(GDB) and connecting to $(QEMU)"
sleep 1
$(GDB) -ex "target remote localhost:1234" -ex "symbol-file $(BOOTSECTOR)"
kill $$QEMU_PID
@echo -e "Cleaning up temporary image file $(IMG)"
rm $(IMG)
# Clean target
clean:
rm -f $(BOOTSECTOR) $(IMG)