This repository has been archived by the owner on Aug 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
77 lines (56 loc) · 2.37 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
SRCDIR = ./src
BUILDDIR = ./build
# --------------------------------------------------------------------------- #
CC = gcc
AS = nasm
LD = ld
OBJCOPY = objcopy
CFLAGS = -std=gnu99 -nostdlib -m32 -ffreestanding -fno-pie -fno-builtin -fno-stack-protector -I./src/include -g -O2 -Wall -Wextra
LFLAGS = -m elf_i386
ASFLAGS = -g -f elf32 -I./src/include/assembly
QEMU_OPTIONS = -soundhw pcspk -m 4096
# --------------------------------------------------------------------------- #
COBJS = $(shell find $(SRCDIR) -name '*.c')
OBJS = $(patsubst $(SRCDIR)/%.c,$(BUILDDIR)/%.o,$(COBJS))
#SOBJS = $(shell find $(SRCDIR) -name '*.S')
#OBJS += $(patsubst $(SRCDIR)/%.S,$(BUILDDIR)/%.S.o,$(SOBJS))
# --------------------------------------------------------------------------- #
.PHONY: all dirs build clean qemu qemu-serial dbg
all: build
dirs:
@mkdir -p $(BUILDDIR)
@ cd $(SRCDIR) \
&& dirs=$$(find -type d) \
&& cd ../$(BUILDDIR) \
&& mkdir -p $$dirs
build: $(BUILDDIR)/kernel/kernel
clean:
@rm -rf $(BUILDDIR)
qemu: $(BUILDDIR)/kernel/kernel
@qemu-system-i386 $(QEMU_OPTIONS) -serial stdio -kernel $<
qemu-serial: $(BUILDDIR)/kernel/kernel
@qemu-system-i386 $(QEMU_OPTIONS) -display none -serial stdio -kernel $<
dbg: $(BUILDDIR)/kernel/kernel $(BUILDDIR)/kernel/kernel.dbg
@qemu-system-i386 $(QEMU_OPTIONS) -serial stdio -kernel $< -s -S &
@sleep 1
@gdb -x ./qemu.dbg
# --------------------------------------------------------------------------- #
$(BUILDDIR)/kernel/kernel: dirs $(BUILDDIR)/kernel/kernel.elf
@echo -e " [$(OBJCOPY)]\tkernel"
@$(OBJCOPY) --strip-unneeded $(BUILDDIR)/kernel/kernel.elf $@
$(BUILDDIR)/kernel/kernel.dbg: $(BUILDDIR)/kernel/kernel.elf
@echo -e " [$(OBJCOPY)]\tkernel.dbg"
@$(OBJCOPY) --only-keep-debug $< $@
$(BUILDDIR)/kernel/kernel.elf: $(OBJS)
@echo -e " [$(AS)]\tboot.S.o"
@$(AS) $(ASFLAGS) -o $(BUILDDIR)/kernel/boot.S.o $(SRCDIR)/kernel/boot.S
@echo -e " [$(LD)]\tkernel.elf"
@$(LD) $(LFLAGS) -T $(SRCDIR)/kernel/linker.ld -o $(BUILDDIR)/kernel/kernel.elf $(OBJS) $(BUILDDIR)/kernel/boot.S.o
# --------------------------------------------------------------------------- #
#$(BUILDDIR)/%.S.o: $(SRCDIR)/%.S
# @echo -e " [$(AS)]\t$(notdir $@)"
# @$(AS) -f elf32 $(ASFLAGS) -o $@ $<
$(BUILDDIR)/%.o: $(SRCDIR)/%.c
@echo -e " [$(CC)]\t$(notdir $@)"
@$(CC) $(CFLAGS) -o $@ -c $<
# --------------------------------------------------------------------------- #