This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
74 lines (60 loc) · 1.56 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
#!Makefile
C_SOURCES = $(shell find . -name "*.c")
C_OBJECTS = $(patsubst %.c, %.o, $(C_SOURCES))
S_SOURCES = $(shell find . -name "*.s")
S_OBJECTS = $(patsubst %.s, %.o, $(S_SOURCES))
CC = gcc
LD = ld
ASM = nasm
C_FLAGS = -c -Wall -m32 -ggdb -gstabs+ -nostdinc -fno-builtin -fno-stack-protector -I include
LD_FLAGS = -T scripts/kernel.ld -m elf_i386 -nostdlib
ASM_FLAGS = -f elf -g -F stabs
all: $(S_OBJECTS) $(C_OBJECTS) link update_image
@echo Success!
%.o: %.c
@echo Complie C Codes $< ...
$(CC) $(C_FLAGS) $< -o $@
%.o: %.s
@echo Complie ASM Codes $< ...
$(ASM) $(ASM_FLAGS) $<
link:
@echo Link Kernel Files...
$(LD) $(LD_FLAGS) $(S_OBJECTS) $(C_OBJECTS) -o MortyOSKernel
.PHONY:clean
clean:
$(RM) $(S_OBJECTS) $(C_OBJECTS) MortyOSKernel
.PHONY:update_image
update_image:
sudo kpartx -a v_disk.img
sudo sleep 1
sudo mount /dev/mapper/loop0p1 /mnt/kernel
sudo cp MortyOSKernel /mnt/kernel/boot
sudo cp scripts/grub.cfg /mnt/kernel/boot/grub
sudo cp initrd /mnt/kernel/boot
sleep 1
sudo umount /mnt/kernel
sudo sleep 1
sudo kpartx -d v_disk.img
.PHONY:create_image
create_image:
scripts/./create_img.sh
.PHONY:mount_image
mount_image:
sudo kpartx -a v_disk.img
sudo sleep 1
sudo mount /dev/mapper/loop0p1 /mnt/kernel
.PHONY:umount_image
umount_image:
sudo umount /mnt/kernel
sudo sleep 1
sudo kpartx -d v_disk.img
.PHONY:qemu
qemu:
#qemu -fda floppy.img -boot a -m 512
qemu -hda v_disk.img -boot a -m 512
.PHONY:debug
debug:
#qemu -S -s -fda floppy.img -m 512 -boot a &
qemu -S -s -hda v_disk.img -m 512 -boot a &
sleep 1
gdb -x scripts/gdbinit