-
Notifications
You must be signed in to change notification settings - Fork 1
/
makefile
280 lines (187 loc) · 8.92 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# G++ Gcc make NASM grub xorriso
# Change These Compiler Values To Your Correct Values if you Are on an x64 machine Use GCC Else You need a cross compiler \n
# (e.g x86_64-elf-gcc)
# Target Architecture Supported x86_64 ARM
#dll targets
#x86_64-w64-mingw32-gcc -shared -o mydll.dll mydll.c -nostdlib -nodefaultlibs
#lib compile line
#x86_64-w64-mingw32-dlltool --input-def KernelDefs.def --output-lib louoskrnl.lib
TARGET_ARCH = x86_64
HOST_ARCH = x86_64
FIRMWARE_TARGET = BIOS
ExportTable = Config/Kernel_Config/ExportTable.xml
DriverTable = Config/System_Config/drivers.xml
FileStructureTable = Config/System_Config/FileStructure.xml
SystemFileTable = Config/System_Config/SystemFiles.xml
OSBUILDX64 := $(shell cat Config/OSIMGBUILDX64.cfg)
OSBUILDX86 := $(shell cat Config/OSIMGBUILDX86.cfg)
KernelEXPORTS := $(shell awk -F '[<>]' '/<KernelExport>/{print "-K " $$3}' $(ExportTable) | tr '\n' ' ')
WDFLDRModuleEXPORTS := $(shell awk -F '[<>]' '/<WDFLDRModuleExport>/{print "-K " $$3}' $(ExportTable) | tr '\n' ' ')
MAKEDIR := $(shell awk -F '[<>]' '/<MainDirectoryStructure>/{print " " $$3 ";"}' $(FileStructureTable) | tr '\n' ' ')
MAKEDIR64 := $(shell awk -F '[<>]' '/<MainDirectoryStructure64>/{print " " $$3 ";"}' $(FileStructureTable) | tr '\n' ' ')
CPY32 := $(shell awk -F '[<>]' '/<FILETOCPY32>/{print " " $$3 ";"}' $(SystemFileTable) | tr '\n' ' ')
CPY64 := $(shell awk -F '[<>]' '/<FILETOCPY64>/{print " " $$3 ";"}' $(SystemFileTable) | tr '\n' ' ')
Drivers32 := $(shell awk -F '[<>]' '/<DRIVERTOCPY32>/{print " " $$3 ";"}' $(DriverTable) | tr '\n' ' ')
Drivers64 := $(shell awk -F '[<>]' '/<DRIVERTOCPY64>/{print " " $$3 ";"}' $(DriverTable) | tr '\n' ' ')
EXPORT := $(KernelEXPORTS) $(WDFLDRModuleEXPORTS)
ifeq ($(HOST_ARCH),x86_64)
CC = x86_64-w64-mingw32-gcc
CP = x86_64-w64-mingw32-g++
LD = ld
endif
ifeq ($(HOST_ARCH),ARM)
CC = x86_64-w64-mingw32-gcc
CP = x86_64-w64-mingw32-g++
LD = x86_64-elf-ld
endif
ifeq ($(TARGET_ARCH),x86_64)
C_COMPILE_FLAGS = -m64
NASM_COMPILE_FLAGS = elf64
endif
ifeq ($(TARGET_ARCH),x86)
C_COMPILE_FLAGS = -m32
NASM_COMPILE_FLAGS = elf32
endif
ifeq ($(TARGET_ARCH),x86_64)
ifeq ($(FIRMWARE_TARGET),BIOS)
RELEASE_PATH = Releases/64BIOS/Annya.iso
endif
ifeq ($(FIRMWARE_TARGET),UEFI)
RELEASE_PATH = Releases/64UEFI/Annya.iso
endif
endif
ifeq ($(TARGET_ARCH),x86)
ifeq ($(FIRMWARE_TARGET),BIOS)
RELEASE_PATH = Releases/32BIOS/Annya.iso
endif
ifeq ($(FIRMWARE_TARGET),UEFI)
RELEASE_PATH = Releases/32UEFI/Annya.iso
endif
endif
ifeq ($(TARGET_ARCH),x86_64)
CFLAGS = -c -ffreestanding -Werror -I include -Wno-multichar -fno-omit-frame-pointer -O0 -mmmx -msse
CPPFLAGS = -c -ffreestanding -Wall -fno-exceptions -fno-rtti -Werror -Wno-write-strings -fno-use-cxa-atexit -I include -Wno-multichar -fno-omit-frame-pointer -O0 -mmmx -msse
endif
ifeq ($(TARGET_ARCH),x86)
CFLAGS = -c -ffreestanding -Werror -I include -Wno-multichar -mmmx -msse
CPPFLAGS = -c -ffreestanding -O2 -Wall -fno-exceptions -fno-rtti -msse -mmmx -Werror -Wno-write-strings -fno-use-cxa-atexit -I include -Wno-multichar
endif
kernel_source_files := $(shell find kernel -name *.c)
kernel_object_files := $(patsubst kernel/%.c, build/kernel/%.o, $(kernel_source_files))
x86_64_c_source_files := $(shell find init -name *.c)
x86_64_c_object_files := $(patsubst init/%.c, build/x86_64/init/%.o, $(x86_64_c_source_files))
driver_cpp_source_files := $(shell find drivers/AGP -name *.cpp)
driver_cpp_source_files += $(shell find drivers/Audio -name *.cpp)
driver_cpp_source_files += $(shell find drivers/DriverInterrupts -name *.cpp)
driver_cpp_source_files += $(shell find drivers/FileSystems -name *.cpp)
driver_cpp_source_files += $(shell find drivers/gpu -name *.cpp)
driver_cpp_source_files += $(shell find drivers/io -name *.cpp)
driver_cpp_source_files += $(shell find drivers/ISA -name *.cpp)
driver_cpp_source_files += $(shell find drivers/MotherBoards -name *.cpp)
driver_cpp_source_files += $(shell find drivers/Networking -name *.cpp)
driver_cpp_source_files += $(shell find drivers/pci_systems -name *.cpp)
driver_cpp_source_files += $(shell find drivers/PnP -name *.cpp)
driver_cpp_source_files += $(shell find drivers/processors -name *.cpp)
driver_cpp_source_files += $(shell find drivers/Serial -name *.cpp)
driver_cpp_source_files += $(shell find drivers/storage/InternalStorageDrivers -name *.cpp)
driver_cpp_source_files += $(shell find drivers/USB -name *.cpp)
driver_cpp_source_files += $(shell find drivers/virtualization -name *.cpp)
driver_cpp_object_files := $(patsubst drivers/%.cpp, build/drivers/%.o, $(driver_cpp_source_files))
x86_64_API_cpp_source_files := $(shell find API -name *.cpp)
x86_64_API_cpp_object_files := $(patsubst API/%.cpp, build/x86_64/API/%.o, $(x86_64_API_cpp_source_files))
x86_64_c_source_files := $(shell find init -name *.c)
x86_64_c_object_files := $(patsubst init/%.c, build/x86_64/init/%.o, $(x86_64_c_source_files))
x86_64_API_cpp_source_files := $(shell find API -name *.cpp)
x86_64_API_cpp_object_filee := $(patsubst API/%.cpp, build/x86_64/API/%.o, $(x86_64_API_cpp_source_files))
x86_64_API_asm_source_files := $(shell find API -name *.asm)
x86_64_API_asm_object_files := $(patsubst API/%.asm, build/x86_64/asm/API/%.o, $(x86_64_API_asm_source_files))
kernel_s_source_files := $(shell find kernel -name *.s)
kernel_s_object_files := $(patsubst kernel/%.s, build/kernel/%.o, $(kernel_s_source_files))
ifeq ($(TARGET_ARCH), x86_64)
x86_64_asm_source_files = boot/x86_64/BOOT.asm
endif
ifeq ($(TARGET_ARCH), x86)
x86_64_asm_source_files = boot/x86/BOOT.asm
endif
x86_64_asm_object_files = build/x86_64/boot/boot.o
kernel_asm_source_files := $(shell find kernel -name *.asm)
kernel_asm_object_files := $(patsubst kernel/%.asm, build/x86_64/kernelasm/%.o, $(kernel_asm_source_files))
ifeq ($(FIRMWARE_TARGET),BIOS)
x86_64_object_files := $(kernel_object_files) $(x86_64_c_object_files) $(x86_64_asm_object_files) $(driver_cpp_object_files) $(x86_64_API_asm_object_files) $(x86_64_API_cpp_object_files) $(kernel_asm_object_files) $(kernel_s_object_files)
endif
$(kernel_object_files): build/kernel/%.o : kernel/%.c
mkdir -p $(dir $@) && \
$(CC) $(C_COMPILE_FLAGS) $(CFLAGS) $(patsubst build/kernel/%.o, kernel/%.c, $@) -o $@
$(x86_64_c_object_files): build/x86_64/init/%.o : init/%.c
mkdir -p $(dir $@) && \
$(CC) $(C_COMPILE_FLAGS) $(CFLAGS) $(patsubst build/x86_64/init/%.o, init/%.c, $@) -o $@
$(driver_cpp_object_files): build/drivers/%.o : drivers/%.cpp
mkdir -p $(dir $@) && \
$(CP) $(C_COMPILE_FLAGS) $(CPPFLAGS) $(patsubst build/drivers/%.o, drivers/%.cpp, $@) -o $@ -lc
$(x86_64_API_cpp_object_files): build/x86_64/API/%.o : API/%.cpp
mkdir -p $(dir $@) && \
$(CP) $(C_COMPILE_FLAGS) $(CPPFLAGS) $(patsubst build/x86_64/API/%.o, API/%.cpp, $@) -o $@ -lc
$(x86_64_API_asm_object_files): build/x86_64/asm/API/%.o : API/%.asm
mkdir -p $(dir $@) && \
nasm -f $(NASM_COMPILE_FLAGS) $(patsubst build/x86_64/asm/API/%.o, API/%.asm, $@) -o $@
$(x86_64_asm_object_files): $(x86_64_asm_source_files)
mkdir -p $(dir $@) && \
nasm -f $(NASM_COMPILE_FLAGS) $(x86_64_asm_source_files) -o $@
$(kernel_asm_object_files): build/x86_64/kernelasm/%.o : kernel/%.asm
mkdir -p $(dir $@) && \
nasm -f $(NASM_COMPILE_FLAGS) $(patsubst build/x86_64/kernelasm/%.o, kernel/%.asm, $@) -o $@
$(kernel_s_object_files): build/kernel/%.o : kernel/%.s
mkdir -p $(dir $@) && \
$(CC) -c $(C_COMPILE_FLAGS) $(patsubst build/kernel/%.o, kernel/%.s, $@) -o $@
clean:
rm -r build
ifeq ($(TARGET_ARCH), x86_64)
lou.exe: $(x86_64_object_files)
mkdir -p dist/x86_64 && \
$(LD) -n -o dist/x86_64/LOUOSKRNL.bin -T targets/x86_64/linker.ld $(x86_64_object_files)
rm -r build
endif
ifeq ($(TARGET_ARCH), x86)
lou.exe: $(x86_64_object_files)
mkdir -p dist/x86 && \
$(LD) -melf_i386 -n -o dist/x86/LOUOSKRNL.bin -T targets/x86/linker.ld $(x86_64_object_files)
rm -r build
endif
ifeq ($(TARGET_ARCH), x86_64)
release: lou.exe
mkdir -p release/x86_64 && \
cp dist/x86_64/LOUOSKRNL.bin release/x86_64/LOUOSKRNL.exe
strip $(EXPORT) \
release/x86_64/LOUOSKRNL.exe
endif
ifeq ($(TARGET_ARCH), x86)
release: lou.exe
mkdir -p release/x86 && \
cp dist/x86/LOUOSKRNL.bin release/x86/LOUOSKRNL.exe
release/x86/LOUOSKRNL.exe
endif
annya.iso: release
rm -rf ISO
#Make The System Directories
$(MAKEDIR)
ifeq ($(TARGET_ARCH),x86_64)
#Make 64 Bit System Directories
$(MAKEDIR64)
#Copy System Files To The Appropriate Directories
$(CPY64)
$(Drivers64)
#Build The Image In One Shabang
$(OSBUILDX64)
endif
ifeq ($(TARGET_ARCH),x86)
#Copy System Files To The Appropriate Directories
$(CPY32)
#$(Drivers32)
#Build The Image In One Shabang
$(OSBUILDX86)
endif
rm -rf release
#rm -rf ISO
PublicRelease: annya.iso
cp annya.iso $(RELEASE_PATH)
rm -rf annya.iso