-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
69 lines (51 loc) · 1.32 KB
/
Makefile
File metadata and controls
69 lines (51 loc) · 1.32 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
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
define sizeof
stat -L -c %s $(1)
endef
endif
ifeq ($(UNAME), Darwin)
define sizeof
stat -L -f %z $(1)
endef
endif
AS := nasm
AS_FLAGS := -i boot
BOOT_SRC_DIR := boot
BUILD_DIR = build
TOOLS_DIR = tools
BOOT_LOG_FILE = $(BUILD_DIR)/log.txt
define putsize
echo $(@) >> $(BOOT_LOG_FILE)
$(call sizeof, $(1)) >> $(BOOT_LOG_FILE)
echo '' >> $(BOOT_LOG_FILE)
endef
all: NOS.img
NOS.img: build_dir tools $(BUILD_DIR)/boot.bin
./tools/fatcreate.exe -l "NOS Boot" -b $(BUILD_DIR)/boot.bin -o NOS.img
build_dir:
mkdir -p $(BUILD_DIR)
tools: $(TOOLS_DIR)/fatcreate.exe
$(TOOLS_DIR)/fatcreate.exe:
gcc tools/fatcreate.c -o tools/fatcreate.exe
$(BUILD_DIR)/boot.bin: $(BUILD_DIR)/stage1.bin $(BUILD_DIR)/stage2.bin \
$(BUILD_DIR)/stage3.bin
cat $^ > $@
$(BUILD_DIR)/stage1.bin:
$(AS) $(AS_FLAGS) -f bin $(BOOT_SRC_DIR)/stage1.asm -o $@
$(call putsize, $@)
$(BUILD_DIR)/stage2.bin:
$(AS) $(AS_FLAGS) -f bin $(BOOT_SRC_DIR)/stage2.asm -o $@
$(call putsize, $@)
$(BUILD_DIR)/stage3.bin: $(BUILD_DIR)/stage3.o
x86_64-elf-ld -o $@ -T boot/stage3.ld $^ --oformat binary
$(call putsize, $@)
$(BUILD_DIR)/stage3.o: boot/stage3.c
x86_64-elf-gcc -ffreestanding -c $< -o $@
run: NOS.img
make clean
make
qemu-system-x86_64 -hda $<
clean:
rm -rf $(BUILD_DIR)
rm -f *.bin *.img *.o