-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
60 lines (50 loc) · 1.76 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
SRCDIR = ./src
BUILDDIR = ./build
DISK = $(BUILDDIR)/disk.dmg
NASM_BUILD = nasm -w+orphan-labels -f bin
BOOTLOADER = $(SRCDIR)/bootloader.asm
TEMPFILE = $(BUILDDIR)/temp.xxxx
PROGRAMS := $(wildcard $(SRCDIR)/program/*.asm)
PROGRAMSBIN := $(PROGRAMS:$(SRCDIR)/program/%.asm=$(BUILDDIR)/program/%.bin)
$(shell mkdir -p $(BUILDDIR)/program)
.PHONY:
run: $(BUILDDIR)/bootloader.bin $(BUILDDIR)/kernel.bin
qemu-system-i386 -drive format=raw,file=$(DISK),media=disk -monitor stdio
.PHONY:
debug: $(BUILDDIR)/bootloader.bin $(BUILDDIR)/kernel.bin
qemu-system-i386 -s -S -drive format=raw,file=$(DISK),media=disk -monitor stdio
$(BUILDDIR)/program/%.bin: $(SRCDIR)/program/%.asm
$(NASM_BUILD) $< -o $@
$(BUILDDIR)/kernel.bin: $(SRCDIR)/kernel.asm $(BUILDDIR)/bootloader.bin $(PROGRAMSBIN)
$(NASM_BUILD) $< -o $(BUILDDIR)/kernel.bin
mktemp -d $(TEMPFILE)
$(eval dev = $(shell hdiutil attach -nobrowse -nomount $(DISK)))
mount -t msdos $(dev) $(TEMPFILE)
rm -rf $(TEMPFILE)/*
cp $(BUILDDIR)/kernel.bin $(TEMPFILE)/
cp $(BUILDDIR)/program/*.bin $(TEMPFILE)/
diskutil umount $(dev)
hdiutil detach $(dev)
rm -rf $(TEMPFILE)
$(BUILDDIR)/bootloader.bin: $(SRCDIR)/bootloader.asm createImg
$(NASM_BUILD) $< -o $(BUILDDIR)/bootloader.bin
dd if=$(BUILDDIR)/bootloader.bin of=$(DISK) conv=notrunc
.PHONY:
createImg:
ifeq (, $(wildcard $(DISK)))
hdiutil create -fs "MS-DOS FAT12" -size 16m -layout None $(DISK)
endif
# rm -f $(DISK)
# hdiutil create -fs "MS-DOS FAT12" -size 16m -layout None $(DISK)
# createImg:
# dd if=/dev/zero of=$(DISK) conv=sync bs=1m count=16
# $(eval dev = $(shell hdiutil attach -nobrowse -nomount $(DISK)))
# echo $(dev)
# newfs_msdos -F 12 -v disk $(dev)
# hdiutil detach $(dev)
.PHONY:
clean:
rm -rf $(BUILDDIR)/*
.PHONY:
cleanall:
rm -rf $(BUILDDIR)