-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
262 lines (189 loc) · 8.71 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
# This work is licensed under TURNSTONE OS Public License.
# Please read and understand latest version of Licence.
HOSTOS =$(shell uname -s)
MAKE = make
ifeq ($(HOSTOS),Darwin)
CC64 = x86_64-elf-gcc
OBJCOPY = x86_64-elf-objcopy
SEDNOBAK = sed -i ''
else
CC64 = gcc
OBJCOPY = objcopy
SEDNOBAK = sed -i
endif
DOCSGEN = doxygen
DOCSFILES = $(shell find . -type f -name \*.md)
DOCSCONF = docs.doxygen
INCLUDESDIR = includes
CCXXFLAGS += -std=gnu11 -O3 -nostdlib -nostdinc -ffreestanding -fno-builtin -c -I$(INCLUDESDIR) \
-Werror -Wall -Wextra -ffunction-sections -fdata-sections \
-mno-red-zone -fstack-protector-all -fno-omit-frame-pointer \
-Wshadow -Wpointer-arith -Wcast-align \
-Wwrite-strings -Wmissing-prototypes -Wmissing-declarations \
-Wredundant-decls -Wnested-externs -Winline -Wno-long-long \
-Wstrict-prototypes \
-fPIC -fplt -mcmodel=large -fno-ident -fno-asynchronous-unwind-tables ${CCXXEXTRAFLAGS} \
-D___KERNELBUILD=1
CXXTESTFLAGS= -D___TESTMODE=1
CC64FLAGS = -m64 -march=x86-64 -D___BITS=64 -msse4.2 $(CCXXFLAGS)
CC64INTFLAGS = -m64 -march=x86-64 -mgeneral-regs-only -D___BITS=64 $(CCXXFLAGS)
OBJDIR = output
ASOBJDIR = $(OBJDIR)/asm
CCOBJDIR = $(OBJDIR)/cc
DOCSOBJDIR = $(OBJDIR)/docs
ASSRCDIR = asm
CCSRCDIR = cc
LDSRCDIR = lds
CCGENDIR = cc-gen
INCLUDESGENDIR = includes-gen
CCGENSCRIPTSDIR = scripts/gen-cc
TMPDIR = tmp
ASSETSDIR = assets
EFISRCDIR = efi
UTILSSRCDIR = utils
VBBOXDISK = /Volumes/DATA/VirtualBox\ VMs/osdev-vms/osdev/rawdisk0.raw
QEMUDISK = $(OBJDIR)/qemu-hda
TESTQEMUDISK = $(OBJDIR)/qemu-test-hda
TOSDBIMGNAME = tosdb.img
TOSDBIMG = $(OBJDIR)/$(TOSDBIMGNAME)
AS64SRCS = $(shell find $(ASSRCDIR) -type f -name \*64.S)
CC64SRCS = $(shell find $(CCSRCDIR) -type f -name \*.64.c)
CC64TESTSRCS = $(shell find $(CCSRCDIR) -type f -name \*.64.test.c)
CCXXSRCS = $(shell find $(CCSRCDIR) -type f -name \*.xx.c)
CCXXTESTSRCS = $(shell find $(CCSRCDIR) -type f -name \*.xx.test.c)
LDSRCS = $(shell find $(LDSRCDIR) -type f -name \*.ld)
UTILSSRCS = $(shell find $(UTILSSRCDIR) -type f -name \*.c)
CCGENSCRIPTS = $(shell find $(CCGENSCRIPTSDIR) -type f -name \*.sh)
GENCCSRCS = $(patsubst $(CCGENSCRIPTSDIR)/%.sh,$(CCGENDIR)/%.c,$(CCGENSCRIPTS))
ASOBJS = $(patsubst $(ASSRCDIR)/%.s,$(ASOBJDIR)/%.o,$(ASSRCS))
ASTESTOBJS = $(patsubst $(ASSRCDIR)/%.s,$(ASOBJDIR)/%.test.o,$(ASSRCS))
CC64OBJS = $(patsubst $(CCSRCDIR)/%.64.c,$(CCOBJDIR)/%.64.o,$(CC64SRCS))
CC64OBJS += $(patsubst $(CCSRCDIR)/%.xx.c,$(CCOBJDIR)/%.xx_64.o,$(CCXXSRCS))
CC64GENOBJS = $(patsubst $(CCGENSCRIPTSDIR)/%.sh,$(CCOBJDIR)/%.cc-gen.x86_64.o,$(CCGENSCRIPTS))
CC64ASMOUTS = $(patsubst $(CCSRCDIR)/%.64.c,$(CCOBJDIR)/%.64.s,$(CC64SRCS))
CC64ASMOUTS += $(patsubst $(CCSRCDIR)/%.xx.c,$(CCOBJDIR)/%.xx_64.s,$(CCXXSRCS))
CC64GENASMOUTS = $(patsubst $(CCGENSCRIPTSDIR)/%.sh,$(CCOBJDIR)/%.cc-gen.x86_64.s,$(CCGENSCRIPTS))
CC64TESTOBJS = $(patsubst $(CCSRCDIR)/%.64.test.c,$(CCOBJDIR)/%.64.test.o,$(CC64TESTSRCS))
CC64TESTOBJS += $(patsubst $(CCSRCDIR)/%.xx.test.c,$(CCOBJDIR)/%.xx_64.test.o,$(CCXXTESTSRCS))
DOCSFILES += $(CC64SRCS) $(CCXXSRCS)
DOCSFILES += $(shell find $(INCLUDESDIR) -type f -name \*.h)
DOCSFILES += $(shell find $(EFISRCDIR) -type f -name \*.c)
DOCSFILES += $(shell find $(EFISRCDIR) -type f -name \*.h)
DOCSFILES += $(shell find $(UTILSSRCDIR) -type f -name \*.c)
DOCSFILES += $(shell find $(UTILSSRCDIR) -type f -name \*.h)
#FONTSRC = https://www.zap.org.au/projects/console-fonts-distributed/psftx-debian-9.4/Lat15-Terminus24x12.psf
FONTOBJ = $(CCOBJDIR)/font.o
MOUSEOBJ = $(CCOBJDIR)/mouse_data.o
OBJS = $(ASOBJS) $(CC64OBJS) $(FONTOBJ) $(MOUSEOBJ) $(CC64ASMOUTS)
TESTOBJS= $(ASTESTOBJS) $(CC64TESTOBJS)
ifeq (,$(wildcard $(TOSDBIMG)))
LASTCCOBJS = $(CC64OBJS) $(CC64GENOBJS) $(FONTOBJ) $(MOUSEOBJ)
else
LASTCCOBJS = $(shell find $(CCOBJDIR) -type f -name \*.o -newer $(TOSDBIMG))
endif
MKDIRSDONE = .mkdirsdone
EFIDISKTOOL = $(OBJDIR)/efi_disk.bin
EFIBOOTFILE = $(OBJDIR)/BOOTX64.EFI
TOSDBIMG_BUILDER = $(OBJDIR)/generatelinkerdb.bin
PXECONFGEN = $(OBJDIR)/pxeconfgen.bin
PROGS = $(OBJDIR)/stage3.bin.pack
TESTPROGS = $(OBJDIR)/stage3.test.bin
.PHONY: all clean depend $(SUBDIRS) $(CC64GENOBJS) asm bear
.PRECIOUS:
qemu-without-analyzer:
CCXXEXTRAFLAGS= make -j $(shell nproc) -C utils
CCXXEXTRAFLAGS= make -j $(shell nproc) -C efi
CCXXEXTRAFLAGS= make -j 1 -f Makefile-np
CCXXEXTRAFLAGS= make -j $(shell nproc) -f Makefile qemu-internal
qemu:
CCXXEXTRAFLAGS=-fanalyzer make -j $(shell nproc) -C utils
CCXXEXTRAFLAGS=-fanalyzer make -j $(shell nproc) -C efi
CCXXEXTRAFLAGS=-fanalyzer make -j 1 -f Makefile-np
CCXXEXTRAFLAGS=-fanalyzer make -j $(shell nproc) -f Makefile qemu-internal
qemu-internal: $(QEMUDISK)
$(PXECONFGEN): utils/pxeconfgen.c
make -C utils ../$@
$(EFIBOOTFILE): efi/main.c
make -C efi ../$@
qemu-pxe: $(TOSDBIMG) $(PXECONFGEN) $(EFIBOOTFILE)
$(PXECONFGEN) -dbn $(TOSDBIMGNAME) -dbp $(TOSDBIMG) -o $(OBJDIR)/pxeconf.bson
qemu-test: $(TESTQEMUDISK)
virtualbox: $(VBBOXDISK)
asm:
CCXXEXTRAFLAGS=-fanalyzer make -j 1 -f Makefile-np asm
CCXXEXTRAFLAGS=-fanalyzer make -j $(shell nproc) -f Makefile asm-internal
asm-internal: $(CC64ASMOUTS)
bear:
bear --append -- make qemu
bear --append -- make -j $(shell nproc) -C tests
test: qemu-test
scripts/osx-hacks/qemu-hda-test.sh
gendirs:
mkdir -p $(CCGENDIR) $(INCLUDESGENDIR) $(ASOBJDIR) $(CCOBJDIR) $(DOCSOBJDIR) $(TMPDIR)
find $(CCSRCDIR) -type d -exec mkdir -p $(OBJDIR)/{} \;
make -C efi gendirs
make -C tests gendirs
make -C utils gendirs
$(OBJDIR)/docs: $(DOCSCONF) $(DOCSFILES)
$(DOCSGEN) $(DOCSCONF)
find output/docs/html/ -name "*.html"|sed 's-output/docs/html-https://turnstoneos.com-' > output/docs/html/sitemap.txt
touch $(OBJDIR)/docs
$(VBBOXDISK): $(MKDIRSDONE) $(CC64GENOBJS) $(TOSDBIMG)
$(EFIDISKTOOL) $(VBBOXDISK) $(EFIBOOTFILE) $(TOSDBIMG)
$(QEMUDISK): $(MKDIRSDONE) $(CC64GENOBJS) $(TOSDBIMG)
$(EFIDISKTOOL) $(QEMUDISK) $(EFIBOOTFILE) $(TOSDBIMG)
$(TESTQEMUDISK): $(TESTDISK) $(TOSDBIMG)
$(EFIDISKTOOL) $(QEMUDISK) $(EFIBOOTFILE) $(TOSDBIMG)
$(MKDIRSDONE):
mkdir -p $(CCGENDIR) $(ASOBJDIR) $(CCOBJDIR)
touch $(MKDIRSDONE)
$(TOSDBIMG): $(TOSDBIMG_BUILDER) $(CC64OBJS) $(CC64GENOBJS) $(FONTOBJ) $(MOUSEOBJ)
$(TOSDBIMG_BUILDER) -o $@ $(LASTCCOBJS)
$(CCOBJDIR)/%.64.o: $(CCSRCDIR)/%.64.c
$(CC64) $(CC64FLAGS) -o $@ $<
$(CCOBJDIR)/%.xx_64.o: $(CCSRCDIR)/%.xx.c
$(CC64) $(CC64FLAGS) -o $@ $<
$(CCOBJDIR)/%.xx_64.test.o: $(CCSRCDIR)/%.xx.test.c
$(CC64) $(CC64FLAGS) $(CXXTESTFLAGS) -o $@ $<
$(CCOBJDIR)/%.64.s: $(CCSRCDIR)/%.64.c
$(CC64) $(CC64FLAGS) -S -o $@ $<
$(CCOBJDIR)/%.xx_64.s: $(CCSRCDIR)/%.xx.c
$(CC64) $(CC64FLAGS) -S -o $@ $<
$(CCOBJDIR)/%.64.test.s: $(CCSRCDIR)/%.64.test.c
$(CC64) $(CC64FLAGS) -S $(CXXTESTFLAGS) -o $@ $<
$(ASOBJDIR)/%64.o: $(ASSRCDIR)/%64.S
$(CC64) $(CC64FLAGS) -o $@ $^
$(ASOBJDIR)/%64.test.o: $(ASSRCDIR)/%64.S
$(CC64) $(CC64FLAGS) $(CXXTESTFLAGS) -o $@ $^
$(CCOBJDIR)/cpu/interrupt.64.o: $(CCSRCDIR)/cpu/interrupt.64.c
$(CC64) $(CC64INTFLAGS) -o $@ $<
$(CCOBJDIR)/cpu/interrupt.64.s: $(CCSRCDIR)/cpu/interrupt.64.c
$(CC64) $(CC64INTFLAGS) -S -o $@ $<
$(CCOBJDIR)/%.cc-gen.x86_64.o: $(CCGENDIR)/%.c
$(CC64) $(CC64INTFLAGS) -o $@ $<
$(SUBDIRS):
$(MAKE) -j $(nproc) -C $@
$(FONTOBJ):
echo -n turnstone.kernel.hw.video > $(OBJDIR)/font.module_name.txt
$(OBJCOPY) -O elf64-x86-64 -B i386 -I binary --rename-section .data=.rodata.font --redefine-sym _binary_assets_font_psf_start=font_data_start --redefine-sym _binary_assets_font_psf_end=font_data_end --redefine-sym _binary_assets_font_psf_size=font_data_size --add-section .___module___=$(OBJDIR)/font.module_name.txt --add-symbol ___module___=.___module___:turnstone.kernel.hw.video $(ASSETSDIR)/font.psf $@
rm -f $(OBJDIR)/font.module_name.txt
$(MOUSEOBJ):
echo -n turnstone.kernel.hw.video > $(OBJDIR)/mouse.module_name.txt
$(OBJCOPY) -O elf64-x86-64 -B i386 -I binary --rename-section .data=.rodata.mouse --redefine-sym _binary_assets_mouse_tga_start=mouse_data_start --redefine-sym _binary_assets_mouse_tga_end=mouse_data_end --redefine-sym _binary_assets_mouse_tga_size=mouse_data_size --add-section .___module___=$(OBJDIR)/mouse.module_name.txt --add-symbol ___module___=.___module___:turnstone.kernel.hw.mouse $(ASSETSDIR)/mouse.tga $@
rm -f $(OBJDIR)/mouse.module_name.txt
clean:
rm -fr $(DOCSOBJDIR)/*
if [ -d $(OBJDIR) ]; then find $(OBJDIR) -type f -delete; fi
rm -f .depend*
if [ -d $(CCGENDIR) ]; then find $(CCGENDIR) -type f -delete; fi
if [ -d $(INCLUDESGENDIR) ]; then find $(INCLUDESGENDIR) -type f -delete; fi
rm -f $(MKDIRSDONE)
rm -f compile_commands.json
cleandirs:
rm -fr $(CCGENDIR) $(INCLUDESGENDIR) $(OBJDIR)
print-%: ; @echo $* = $($*)
depend: .depend64
.depend64: $(CC64SRCS) $(CCXXSRCS) $(CC64TESTSRCS)
scripts/create-cc-deps.sh "$(CC64) $(CC64FLAGS) -D___DEPEND_ANALYSIS -MM" "$^" > .depend64
$(SEDNOBAK) 's/xx.o:/xx_64.o:/g' .depend64
-include .depend64