-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
182 lines (148 loc) · 5.61 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Copyright (C) 2021-2024 Amrit Bhogal
#
# This file is part of LuaOS.
#
# LuaOS is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LuaOS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LuaOS. If not, see <http://www.gnu.org/licenses/>.
CC = clang
LD = ld.lld
LUAJIT= luajit
GDB := x86_64-elf-gdb
CFLAGS = -g -O0 -pipe -Wall -Wextra -Werror -Wno-unused -fms-extensions -Wno-microsoft
NASMFLAGS = -F dwarf -g -f elf64
CFLAGS += \
-std=gnu2x \
-ffreestanding \
-fno-stack-protector \
-fno-stack-check \
-fno-lto \
-fno-pie \
-fno-pic \
-m64 \
-march=x86-64 \
-mabi=sysv \
-mno-80387 \
-mno-mmx \
-mno-sse \
-mno-sse2 \
-mno-red-zone \
-mcmodel=kernel \
-MMD \
-target x86_64-elf \
-nostdinc \
-isystem extern/ \
-isystem extern/LuaJIT/src \
-Iinc \
-Wno-unused-command-line-argument \
-Wanon-enum-enum-conversion \
-Wassign-enum \
-Wenum-conversion \
-Wenum-enum-conversion \
-Wno-unused-function \
-Wno-unused-parameter \
-Wnull-dereference \
-Wnull-conversion \
-Wnullability-completeness \
-Wnullable-to-nonnull-conversion \
-Wno-missing-field-initializers \
-fno-omit-frame-pointer \
-Wno-deprecated-attributes \
-fms-extensions\
-fblocks
LDFLAGS += \
-nostdlib \
-static \
-m elf_x86_64 \
-z max-page-size=0x1000 \
-T res/linker.ld \
-no-pie
ASFLAGS = -f elf64
CFILES := $(shell find ./src -type f -name '*.c') extern/terminal/term.c extern/terminal/backends/framebuffer.c
ASFILES := $(shell find ./src -type f -name '*.asm')
USERLAND_FILES := $(shell find ./Userland -type f -name '*.lua')
COBJS := $(addprefix build/obj/,$(CFILES:.c=.c.o))
ASOBJS := $(addprefix build/obj/,$(ASFILES:.asm=.asm.o))
QEMUFLAGS := -smp 2 -m 2G -monitor stdio -serial file:luaos.log -vga std
QDF ?= -s
.PHONY: all
all: build/bin/luaos.iso extern/ovmf-x64
.PHONY: uefi
uefi: extern/ovmf-x64 build/bin/luaos.iso
qemu-system-x86_64 -M q35 $(QEMUFLAGS) -bios extern/ovmf-x64/OVMF.fd -cdrom build/bin/luaos.iso -boot d $(QDF)
.PHONY: bios
bios: build/bin/luaos.iso
qemu-system-x86_64 -M q35 $(QEMUFLAGS) -cdrom build/bin/luaos.iso -boot d $(QDF)
extern/LuaJIT/libluajit_luck.o:
@/usr/bin/printf "[\033[1;35mKernel - extern\033[0m] \033[32mBuilding LuaJIT\n\033[0m"
@$(MAKE) -C extern/LuaJIT CC="$(CC) -Wno-implicit-function-declaration"
extern/ovmf-x64:
@/usr/bin/printf "[\033[1;35mKernel\033[0m] \033[32mDownloading OVMF\n\033[0m"
@mkdir -p $@
cd $@ && curl -o OVMF-X64.zip https://efi.akeo.ie/OVMF/OVMF-X64.zip && 7z x OVMF-X64.zip
extern/limine/limine-deploy:
@/usr/bin/printf "[\033[1;35mKernel - extern\033[0m] \033[32mBuilding Limine\n\033[0m"
@$(MAKE) -C extern/limine
extern/LuaJIT/src/lua.h: extern/LuaJIT
user-land: build-userland.lua
@/usr/bin/printf "[\033[1;35mUserland\033[0m] \033[32mBuilding userland\n\033[0m"
@$(LUAJIT) build-userland.lua
res/limine.cfg: user-land
build/bin/luaos.iso: extern/limine extern/limine/limine-deploy build/bin/luck.elf res/limine.cfg user-land
@/usr/bin/printf "[\033[1;35mKernel\033[0m] \033[32mBuilding ISO\n\033[0m"
@mkdir -p $(dir $@)/iso
# All files in Userland/lua_modules/share/lua/5.1/ will be copied to the root of the ISO
cp -r Userland/lua_modules/share/lua/5.1/* $(dir $@)/iso
cp \
build/bin/luck.elf res/powered-by-lua.bmp res/limine.cfg \
res/font.bin extern/limine/limine-cd.bin extern/limine/limine.sys \
extern/limine/limine-cd-efi.bin\
$(dir $@)/iso
xorriso -as mkisofs\
-b limine-cd.bin\
-no-emul-boot\
-boot-load-size 4\
-boot-info-table\
--efi-boot limine-cd-efi.bin\
-efi-boot-part\
--efi-boot-image\
--protective-msdos-label\
$(dir $@)/iso -o $@
rm -rf $(dir $@)/iso
extern/limine/limine-deploy $@
@/usr/bin/printf "[\033[1;35mKernel\033[0m] \033[32mISO built at \033[33m$@\n\033[0m"
build/bin/luck.elf: $(COBJS) $(ASOBJS) extern/LuaJIT/libluajit_luck.o
@/usr/bin/printf "[\033[1;35mKernel\033[0m] \033[32mLinking \033[33m$@\n\033[0m"
@mkdir -p $(dir $@)
$(LD) $(LDFLAGS) -o $@ $^
build/obj/extern/%.c.o: extern/limine extern/terminal extern/LuaJIT
@/usr/bin/printf "[\033[1;35mKernel - extern\033[0m] \033[32mCompiling \033[33m$<\n\033[0m"
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $(shell echo "$@" | sed 's/build\/obj\///g' | sed 's/\.o//g') -o $@
build/obj/./src/%.c.o: src/%.c extern/limine extern/terminal extern/LuaJIT
@/usr/bin/printf "[\033[1;35mKernel\033[0m] \033[32mCompiling \033[33m$<\n\033[0m"
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
build/obj/%.asm.o: %.asm
@/usr/bin/printf "[\033[1;35mKernel\033[0m] \033[32mAssembling \033[33m$^\n\033[0m"
@mkdir -p $(dir $@)
nasm $(NASMFLAGS) $^ -o $@
.PHONY: clean
clean:
rm -rf build
find . -type f -name '*.o' -delete
rm -rf Userland/.luarocks
rm -rf Userland/lua_modules
rm -rf Userland/lua
rm -rf Userland/luarocks
$(MAKE) -C extern/limine clean
-include $(CFILES:%.c=build/obj/%.c.d)