-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
122 lines (92 loc) · 2.48 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
.PHONY: do run build clean rebuild
CFLAGS+=-fno-pie -nostdlib -ffreestanding -g -m32 -DDebug
LDFLAGS+=-lgcc -m elf_i386 -T link.ld
CORE=\
include/core/utils.o\
include/core/wumbo.o
DRIVERS=\
include/drivers/io.o\
include/drivers/pci.o\
include/drivers/pcspeak.o\
include/drivers/rtc.o\
include/drivers/sleep.o\
include/drivers/tty.o\
include/drivers/cpuid.o\
include/drivers/ps2.o\
include/drivers/parallelport.o\
include/drivers/serviceInterrupt.o\
include/drivers/serviceInterruptHandler.o\
include/drivers/mem.o\
include/drivers/pit.o
CLIB_STUFF_OBJS=\
include/crti.o \
include/crtbegin.o \
include/crtend.o \
include/crtn.o
OBJS=\
boot.o\
loadstuff.o\
$(CORE)\
$(DRIVERS)\
$(CLIB_STUFF_OBJS)
INTERRUPT_OBJS=\
include/drivers/idt.o\
include/drivers/irq.o
LIBC_OBJS=\
include/libc/stdio.o\
include/libc/stdlib.o\
include/libc/string.o\
$(CLIB_STUFF_OBJS)
LIBD_OBJS=\
$(DRIVERS)\
$(INTERRUPT_OBJS)
# The mystery of wumbo
# Even though it is part of libcore and is linked with the rest of the kernel,
# Other objects can't resolve symbols unless it is linked directly
LINK_OBJS=\
boot.o\
loadstuff.o\
libcore.a\
libc.a\
libd.a\
include/core/wumbo.o
include makefile.conf
.SUFFIXES:.o .c .S .asm
do: build run
redo: rebuild run
run:
cmd.exe /c qemu.bat
gdb --command=gdbcommands
build: boot.bin
rebuild: clean build
boot.o:
nasm -felf32 -o boot.o bootloader.asm
include/crtbegin.o include/crtend.o:
cp "$(CRTPATH)/crtbegin.o" include
cp "$(CRTPATH)/crtend.o" include
$(INTERRUPT_OBJS):
$(CC) -c -mgeneral-regs-only -mno-red-zone $(CFLAGS) $(basename $@).c -o $@
.asm.o:
nasm -f elf32 $< -o $@
.c.o:
$(CC) -c -Wall -Wextra $(CFLAGS) $< -o $@
.S.o:
$(AS) -c -nostdlib -march=i386 --32 $< -o $@
libcore.a: $(CORE)
$(AR) rcs $@ $(CORE)
libc.a: $(LIBC_OBJS)
$(AR) rcs $@ $(LIBC_OBJS)
libd.a: $(LIBD_OBJS)
$(AR) rcs $@ $(LIBD_OBJS)
boot.bin: $(LINK_OBJS)
# Link bootloader and C code, convert to flat binary and dump symbols
$(LD) $(LINK_OBJS) -L$(CRTPATH) $(LDFLAGS) -o boot.bin
$(LD) $(LINK_OBJS) -L$(CRTPATH) $(LDFLAGS) --oformat elf32-i386 -o symbols.elf
FAT_OFFSET=$(wc -c boot.bin | grep -o '^\S*')
@echo "Size of boot.bin before padding to fit floppy disk (in bytes): $(FAT_OFFSET)"
#mkfs.fat -D 0 -F 12 -g 2/18 -n OS6BOOT --mbr no --offset $(FAT_OFFSET) boot.bin
# Pad output to size of 1.44MB floppy
truncate -s 1474560 boot.bin
clean:
# Delete all compiled files
find . \( -name "*.o" -o -name "*.elf" -o -name "*.bin" -o -name "*.s" -o -name "*.i" -o -name "*.a" \) -exec rm {} \;