-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
69 lines (53 loc) · 1.59 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
SRC=src
KERNELDIR=$(SRC)/kernel
INCLUDEDIR=$(SRC)/include
LIBDIR=$(SRC)/lib
CFLAGS=-std=gnu99 -ffreestanding -O2 -Wall -Wextra
LDFLAGS=-ffreestanding -O2 -nostdlib -lgcc
GRUB=grub-mkrescue
ifeq ($(ARCH), i386)
ARCHDIR=$(SRC)/arch/i386
AS=cross/bin/i686-elf-as
CC=cross/bin/i686-elf-gcc
LD=cross/bin/i686-elf-ld
EMU=qemu-system-i386 # if PVH notes error then try flag -machine type=pc-i440fx-3.1
endif
ifeq ($(ARCH), x86_64)
ARCHDIR=$(SRC)/arch/x86_64
AS=cross/bin/x86_64-elf-as
CC=cross/bin/x86_64-elf-gcc
LD=cross/bin/x86_64-elf-ld
EMU=qemu-system-x86_64 # -nographic -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 # added flag -machine q35 to fix Error loading uncompressed kernel without PVH ELF Note
endif
#QEMUOPTS = -machine virt -bios none -m 128M -smp 8 -nographic
#QEMUOPTS += -drive file=fs.img,if=none,format=raw,id=x0
#QEMUOPTS += -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
include $(KERNELDIR)/make.config
include $(ARCHDIR)/make.config
include $(LIBDIR)/make.config
OBJS=$(KERNEL_ARCH_OBJS)\
$(KERNEL_OBJS) \
$(LIB_OBJS) \
all: build-iso
run-debug:
$(EMU) -cdrom myos.iso -s -S &# -monitor stdio
gdb myos.bin
run:
$(EMU) -cdrom myos.iso
.PHONY: build-iso clean
build-iso: myos.bin
cp $^ isodir/boot/myos.bin
cp grub.cfg isodir/boot/grub/grub.cfg
$(GRUB) -o myos.iso isodir
myos.bin: $(OBJS)
$(CC) -o $@ -T $(ARCHDIR)/linker.ld $(LDFLAGS) $(OBJS)
%.o: %.c
$(CC) -c $^ $(CFLAGS) -o $@ -isystem $(INCLUDEDIR) -D CONFIG_$(ARCH)
%.o: %.S
$(CC) -c $^ -o $@ -isystem $(INCLUDEDIR)
%.o: %.s
$(AS) -c $^ -o $@
clean:
rm $(SRC)/*/*.o
rm $(SRC)/*/*/*.o
rm *.bin