forked from mrgian/felix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
93 lines (82 loc) · 3.24 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
UNAME := $(shell uname)
#MacOS tools
ifeq ($(UNAME), Darwin)
SFDISK := $(shell brew --prefix util-linux)/sbin/sfdisk
MKFS := $(shell brew --prefix dosfstools)/sbin/mkfs.fat
MCOPY := $(shell brew --prefix mtools)/bin/mcopy
OBJCOPY := $(shell brew --prefix binutils)/bin/objcopy
endif
ifeq ($(UNAME), Linux)
SFDISK := /sbin/sfdisk
MKFS := mkfs.fat
MCOPY := mcopy
OBJCOPY := objcopy
endif
.PHONY: all
all: get-deps build objcopy image
@echo "Felix has been successfully built!"
.PHONY: get-deps
get-deps:
ifeq ($(UNAME), Darwin)
@echo "Downloading MacOS build tools..."
@brew list util-linux > /dev/null || brew install util-linux
@brew list e2fsprogs > /dev/null || brew install e2fsprogs
@brew list mtools > /dev/null || brew install mtools
@brew list binutils > /dev/null || brew install binutils
@brew list dosfstools > /dev/null || brew install dosfstools
endif
ifeq ($(UNAME), Linux)
@echo "Downloading Linux build tools..."
# TODO: Download linux build tools
endif
.PHONY: build
build:
@echo "Building Felix..."
@cargo build --target=x86_16-felix.json --package=felix-boot
@cargo build --target=x86_16-felix.json --package=felix-bootloader
@cargo build --target=x86_32-felix.json --package=felix-kernel
@cargo build --target=x86_32-felix.json --package=hello
@cargo build --target=x86_32-felix.json --package=atest
@cargo build --target=x86_32-felix.json --package=btest
@cargo build --target=x86_32-felix.json --package=ctest
.PHONY: objcopy
objcopy:
@echo "Copying Felix..."
@mkdir -p build
@$(OBJCOPY) -I elf32-i386 -O binary target/x86_16-felix/debug/felix-boot build/boot.bin
@$(OBJCOPY) -I elf32-i386 -O binary target/x86_16-felix/debug/felix-bootloader build/bootloader.bin
@$(OBJCOPY) -I elf32-i386 -O binary target/x86_32-felix/debug/felix-kernel build/kernel.bin
@$(OBJCOPY) -I elf32-i386 -O binary target/x86_32-felix/debug/hello build/hello.bin
@$(OBJCOPY) -I elf32-i386 -O binary target/x86_32-felix/debug/atest build/atest.bin
@$(OBJCOPY) -I elf32-i386 -O binary target/x86_32-felix/debug/btest build/btest.bin
@$(OBJCOPY) -I elf32-i386 -O binary target/x86_32-felix/debug/ctest build/ctest.bin
.PHONY: image
image:
@dd if=/dev/zero of=build/disk.img bs=67108864 count=1
@$(SFDISK) build/disk.img < disk.layout
@dd if=build/boot.bin of=build/disk.img conv=notrunc
@dd if=build/disk.img of=build/partition.img bs=512 skip=36864
@$(MKFS) -F 16 build/partition.img
@$(MCOPY) -i build/partition.img pacciani "::pacciani"
@$(MCOPY) -i build/partition.img lorem "::lorem"
@$(MCOPY) -i build/partition.img build/hello.bin "::hello"
@$(MCOPY) -i build/partition.img build/atest.bin "::atest"
@$(MCOPY) -i build/partition.img build/btest.bin "::btest"
@$(MCOPY) -i build/partition.img build/ctest.bin "::ctest"
@dd if=build/partition.img of=build/disk.img bs=512 seek=36864 conv=notrunc
@rm -rf build/partition.img
@dd if=build/bootloader.bin of=build/disk.img bs=512 seek=2048 conv=notrunc
@dd if=build/kernel.bin of=build/disk.img bs=512 seek=4096 conv=notrunc
.PHONY: clean
clean:
@echo "Cleaning Felix..."
@cargo clean
@rm -rf build
.PHONY: run
run: all
@echo "Running Felix..."
@qemu-system-i386 -drive file=build/disk.img,index=0,media=disk,format=raw,if=ide
.PHONY: debug
debug: all
@echo "Debugging Felix..."
@bochs -q -f bochs.conf