-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
96 lines (76 loc) · 2.04 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
94
95
96
############
# KERNEL #
############
KERNELDIR = src
include $(KERNELDIR)/make.config
##################
# ARCHITECTURE #
##################
ARCH = i686
ARCHDIR = $(KERNELDIR)/arch/$(ARCH)
include $(ARCHDIR)/make.config
###############
# TOOLCHAIN #
###############
CROSS = toolchain/i686-elf/bin/i686-elf-
CC = $(CROSS)gcc
CX = $(CROSS)g++
AS = nasm
LD = $(CROSS)ld
###########
# FILES #
###########
OBJECTS = $(ARCHDIR)/lib/crti.s.o \
$(ARCHDIR)/lib/crtbegin.o \
$(KERNEL_ARCH_OBJS) \
$(KERNEL_OBJECTS) \
$(ARCHDIR)/lib/crtend.o \
$(ARCHDIR)/lib/crtn.s.o
###########
# FLAGS #
###########
MACROS = -D__ARCH__=$(ARCH)
INCS = -I$(KERNELDIR)/ \
-Ilibs/pdclib/include \
-Ilibs/pdclib/platform/nucleOS/include \
-L./toolchain/i686-elf/lib/gcc/i686-elf/8.2.0
CFLAGS = -ggdb -O3 -nostdlib -nostartfiles -nodefaultlibs -fstack-protector \
-Wall -Wextra -Werror $(MACROS) $(INCS) -c \
-include $(ARCHDIR)/common.h
ASFLAGS = -f elf32
LDFLAGS = -T $(KERNEL_ARCH_LINKER) -nostdlib -lgcc $(INCS)
###########
# RULES #
###########
OUT = iso/boot/kernel.elf
all: $(OUT)
$(CC):
./toolchain/build_toolchain.sh
$(ARCHDIR)/lib/crtbegin.o $(ARCHDIR)/lib/crtend.o:
TOBJ=`$(CC) $(CFLAGS) $(LDFLAGS) -print-file-name=$(@F)` && cp "$$TOBJ" $@
$(OUT): $(CC) $(OBJECTS)
$(LD) $(LDFLAGS) $(OBJECTS) -o $(OUT)
os.iso: $(OUT)
xorrisofs -R \
-b boot/grub/stage2_eltorito \
-no-emul-boot \
-boot-load-size 4 \
-A os \
-input-charset utf8 \
-quiet \
-boot-info-table \
-o os.iso \
iso
run: os.iso
bochs -f bochsrc.txt -q
qemu: os.iso
qemu-system-i386 -cdrom os.iso -serial mon:stdio -m 4G -soundhw ac97,pcspk \
-enable-kvm -rtc base=localtime -gdb tcp::1234,ipv4
%.o: %.c
$(CC) $(CFLAGS) $< -o $@
%.cpp.o: %.cpp
$(CX) $(CFLAGS) $< -o $@
%.s.o: %.s
$(AS) $(ASFLAGS) $< -o $@
clean:
rm -rf $(OUT) os.iso $(OBJECTS)