-
Notifications
You must be signed in to change notification settings - Fork 2
/
Nekofile
160 lines (136 loc) Β· 3.44 KB
/
Nekofile
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
; NekoMake build script for nekosys
;
; Compiler
GCC = neko-gcc
; Compiler base config
CCBASECONF = -std=gnu++11 -Wall -Wextra -O2 -mgeneral-regs-only -mno-red-zone -fno-exceptions -fno-pie -fno-rtti
; Compiler flags for kernel
KFLAGS = -ffreestanding -nostdlib -lelf -lk
; Assembler
[asm, multi]:
nasm -f {format=bin} {input} -o {output}
; Kernel compiler
[kcc, single]:
{GCC} {input} -o {output} -T kernel.ld {KFLAGS} {CCBASECONF}
; Lib compiler
[flibcc, multi]:
{GCC} -c {input} -o {output} {CCBASECONF} {flags}
[olibcc, multi]:
{GCC} -c {input} -o {output} -fno-rtti -O3 -fno-exceptions
[libcc, multi]:
{GCC} -c {input} -o {output} -fno-rtti -fno-exceptions
; GNU ar
[ar, single]:
ar rcs {output} {input}
; Default: Compile everything
default:
% clean
% sysroot
% libk
% libc
% libelf
% libpng
% libgui
% libgfx
% bootloader
% kernel
; Reset build directory
clean:
rm -rf build/
; Build dirs
mkdir -p build/kernel
mkdir -p build/libk
mkdir -p build/libc
mkdir -p build/libelf
mkdir -p build/libpng
mkdir -p build/libgui
mkdir -p build/libgfx
; Sysroot
mkdir -p sysroot/usr/include
mkdir -p sysroot/usr/lib
rm -rf sysroot/usr/include/*
rm -rf sysroot/usr/lib/*
; Set up the sysroot
sysroot:
cp -RT kernel/include sysroot/usr/include
cp -RT libc/include sysroot/usr/include
cp -RT libelf/include sysroot/usr/include
cp -RT libpng/include sysroot/usr/include
cp -RT libgui/include sysroot/usr/include
cp -RT libneko/include sysroot/usr/include
cp -RT libgfx/include sysroot/usr/include
; Compile kernel version of libc
libk:
[flibcc]
input: libc/**.c
libc/**.cpp
flags: -ffreestanding -D__KERNEL
output: build/libk/~.o
[ar]
input: build/libk/*.o
output: sysroot/usr/lib/libk.a
; Compile regular libc
libc:
[libcc]
input: libc/**.c
libc/**.cpp
libc/**.S
output: build/libc/~.o
[ar]
input: build/libc/*.o
output: sysroot/usr/lib/libc.a
cp build/libc/crt0.o sysroot/usr/lib
libelf:
[libcc]
input: libelf/**.cpp
output: build/libelf/~.o
[ar]
input: build/libelf/*.o
output: sysroot/usr/lib/libelf.a
libpng:
[libcc]
input: libpng/**.cpp
output: build/libpng/~.o
[ar]
input: build/libpng/*.o
output: sysroot/usr/lib/libpng.a
libgui:
[libcc]
input: libgui/**.cpp
output: build/libgui/~.o
[ar]
input: build/libgui/*.o
output: sysroot/usr/lib/libgui.a
libgfx:
[olibcc]
input: libgfx/**.cpp
output: build/libgfx/~.o
[ar]
input: build/libgfx/*.o
output: sysroot/usr/lib/libgfx.a
; Compiles the bootloader
bootloader:
[asm]
input: boot/*.asm
output: build/~.bin
; Compiles the kernel
kernel:
[asm]
input: kernel/**.asm
format: elf32
output: build/kernel/~.o
[kcc]
input: build/kernel/*.o
kernel/**.cpp
output: build/koneko.bin
; Creates a bootable image
image:
cp build/koneko.bin sysroot
nkimg -s build/boot.bin -l build/loader.bin -r sysroot -o build/neko.img
; Compile, create an image, and run in QEMU
run:
% default
% qemu
qemu:
% image
qemu-system-i386 -m 512M -drive format=raw,file=build/neko.img -usb -vga std -d cpu_reset -no-reboot -serial stdio