-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
241 lines (186 loc) · 6.57 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
# Makefile for dwjos
#
# Required tool chain:
# GCC
# sys-fs/dosfstools # not needed anymore??
# sys-fs/mtools # for building the boot floppy.
# app-cdr/cdrtools # for mkisofs, for making the boot cd.
#
# You can edit these settings.
#
OUT_DIR:= ./output
TMP_DIR:= ./tmp
#
# It is best to leave these alone:
#
GAS:=as
MKDOSFS:=/usr/sbin/mkdosfs
GRUB_SRC_DIR:=/boot/grub
# #osdev, "froggey"'s c flags:
# -nostdinc -Iinclude -ffreestanding -Wall -Wextra -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wstrict-prototypes -O2 -march=pentium4 -mtune=pentium4 -g -std=gnu99
CFLAGS:=
KERNEL_CFLAGS:=-DBUILDING_KERNEL -Werror -Wall -std=c99 -O0 -m32 -I ./ -I ./kernel/ -nostdinc \
-fno-strength-reduce -finline-functions -fno-builtin -fleading-underscore -ffreestanding \
-Wno-unused-but-set-variable -Wno-unused-variable
## -fstrength-reduce -finline-functions -fno-builtin -fleading-underscore -ffreestanding
HOST_CFLAGS:=-Wall -Wno-pointer-to-int-cast -m32 -O2 -I ./
ASFLAGS:= --32
# Place all compiler intermediates here:
#OBJ_DIR:= $(TMP_DIR)/obj
OBJ_DIR:= .
#
# Aliases for the targets:
#
GRUB_CDROM:= $(OUT_DIR)/grub_cd.iso
GRUB_FLOPPY:= $(OUT_DIR)/grub_fd0.img
FLOPPY:= $(OUT_DIR)/floppy.img
DEBUG:= $(OUT_DIR)/debug.img
DEBUGGER:= $(OUT_DIR)/core-debugger
GRUB_MENU:= $(TMP_DIR)/grub_menu_fd0.lst
GRUB_MENU_CD:= $(TMP_DIR)/grub_menu_cd.cd
BOOT.0.fat12:= $(TMP_DIR)/boot.0.fat12
LOADER.COM:= $(TMP_DIR)/loader.com
DEBUG.0:= $(TMP_DIR)/debug.0
KERNEL.MAP:= $(TMP_DIR)/kernel.map
KERNEL.ELF:= $(TMP_DIR)/kernel.elf
TEST_MOD:= $(TMP_DIR)/test_mod.bin
ISO_DIR:= $(TMP_DIR)/iso
MAP_TEMP:= $(TMP_DIR)/makemap.inc
MAKE_MAP_TOOL:= $(TMP_DIR)/makemap
KERNEL.VAST:= $(TMP_DIR)/kernel.vst
INITRD:= $(TMP_DIR)/initrd.tar
#
# Aliases for misc sources, tools.
#
ELF_LINK_SCRIPT:= kernel/kernel/kernel-elf.lds
#
# File system objects that we build.
#
# Disk Images
IMAGES:= $(GRUB_FLOPPY) $(GRUB_CDROM)
# Binaries
TARGETS:= $(TEST_MOD) $(MAP_TEMP) $(KERNEL.ELF) $(KERNEL.VAST) $(INITRD)
# Tools
TOOLS:= $(MAKE_MAP_TOOL) $(DEBUGGER)
#
# Guts of the Makefile.
#
.PHONY: all clean dirs
all: dirs $(TOOLS) $(TARGETS) $(IMAGES)
x16: $(BOOT.0.fat12) $(LOADER.COM) $(DEBUG.0)
clean:
rm -f $(TARGETS) $(IMAGES) $(TOOLS)
find . -name "*.[oa]" | xargs rm -f
find . -name "gmon.out" | xargs rm -f
find . -name "*.lst" | xargs rm -f
rm -rf $(TMP_DIR) ./output
dirs:
@mkdir -p $(OUT_DIR)
@mkdir -p $(TMP_DIR)
@mkdir -p $(ISO_DIR)
@mkdir -p $(OBJ_DIR)/kernel
#
# Build rules for various targets.
#
$(GRUB_MENU): boot/grub-fd0.conf
rm -f $@
# echo -e "title\tdwjos\n\troot\t(fd0)\n\tkernel\t/kernel.bin\n\n" > $@
cp boot/grub-fd0.conf $@
$(GRUB_FLOPPY): $(GRUB_MENU) $(TARGETS) $(INITRD)
rm -f $@
bzcat < boot/grub.img.bz2 > $@
mcopy -i $@ -o -t $(GRUB_MENU) ::boot/grub/menu.lst
mcopy -i $@ -o -b $(KERNEL.ELF) ::kernel.elf
mcopy -i $@ -o -b $(TEST_MOD) ::test_mod.bin
mcopy -i $@ -o -b $(KERNEL.VAST) ::kernel.vst
mcopy -i $@ -o -b $(INITRD) ::initrd.tar
@echo -e "\n\tBootable floppy image ready: $(GRUB_FLOPPY)\n"
$(GRUB_MENU_CD): $(GRUB_MENU)
rm -f $@
sed -e "s/fd0/cd/g" < $< > $@
$(GRUB_CDROM): $(GRUB_MENU_CD) $(TARGETS) $(INITRD)
rm -f $@
mkdir -p $(ISO_DIR)/boot/grub
cp $(GRUB_SRC_DIR)/stage2_eltorito $(ISO_DIR)/boot/grub
cp $(GRUB_MENU_CD) $(ISO_DIR)/boot/grub/menu.lst
cp $(KERNEL.ELF) $(ISO_DIR)
cp $(TEST_MOD) $(ISO_DIR)
cp $(KERNEL.VAST) $(ISO_DIR)
cp $(INITRD) $(ISO_DIR)
mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o $@ $(ISO_DIR)
@echo -e "\n\tBootable iso image ready: $(GRUB_CDROM)\n"
$(FLOPPY): $(BOOT.0.fat12)
rm -f $@
dd if=/dev/zero of=$@ bs=512 count=2880 &> /dev/null
$(MKDOSFS) -F 12 -n dwjosboot $@
dd if=$(BOOT.0.fat12) of=$@ bs=1 skip=62 seek=62 count=448 conv=notrunc &> /dev/null
$(DEBUG): $(DEBUG.0)
rm -f $@
dd if=/dev/zero of=$@ bs=512 count=2880 &> /dev/null
$(MKDOSFS) -F 12 -n dwjosboot $@
dd if=$(DEBUG.0) of=$@ bs=1 skip=62 seek=62 count=448 conv=notrunc &> /dev/null
mcopy -t -i $@ boot/dumpbios.S ::dumpbios.S
$(BOOT.0.fat12): boot/fat12.o
$(LD) -m elf_i386 -Ttext 0x0 -s --oformat binary -o $@ $<
$(DEBUG.0): boot/dumpbios.o
$(LD) -m elf_i386 -Ttext 0x0 -s --oformat binary -o $@ $<
$(LOADER.COM): loader/start.o loader/init.o loader/panic.o loader/print.o \
loader/memmap.o
$(LD) -m elf_i386 -Ttext 0x0 -s --oformat binary -o $@ $^
# Just build a dummy initial ram disk for now.
$(INITRD): $(KERNEL.VAST)
tar vcf $(INITRD) --exclude ".svn" $(KERNEL.VAST) boot
#############################
##
KERNEL_SETUP:= start setup_con setup_vmm
KERNEL_ARCH:= breakpoint gdt i386 idt intr
KERNEL_DRVRS:= ata console keyboard pci reboot timer vgafonts vmw_gate vmwguest
KERNEL_FS:= dentry devfs mount ramfs vfs vfs_ops vnode
KERNEL_KERNEL:= debug main multiboot panic spinlock task obj_array semaphore wait
KERNEL_KTASKS:= demo hud reaper startup
KERNEL_LIB:= lib printf strerror
KERNEL_VMM:= heap pagefault vmm
KERNEL_TEST:= t-printf
KERNEL_FILES:= $(addprefix setup/,$(KERNEL_SETUP)) \
$(addprefix arch/,$(KERNEL_ARCH)) \
$(addprefix drivers/,$(KERNEL_DRVRS)) \
$(addprefix fs/,$(KERNEL_FS)) \
$(addprefix kernel/,$(KERNEL_KERNEL)) \
$(addprefix ktasks/,$(KERNEL_KTASKS)) \
$(addprefix lib/,$(KERNEL_LIB)) \
$(addprefix vmm/,$(KERNEL_VMM)) \
$(addprefix test/,$(KERNEL_TEST)) \
KERNEL_FILES2:= $(addprefix $(OBJ_DIR)/kernel/,$(KERNEL_FILES))
KERNEL_OBJ:= $(KERNEL_FILES2:=.o)
$(KERNEL.ELF): $(KERNEL_OBJ)
$(LD) -m elf_i386 -T $(ELF_LINK_SCRIPT) --cref -Map $(KERNEL.MAP) -o $@ $^
$(MAKE_MAP_TOOL): tools/makemap.c $(MAP_TEMP) $(KERNEL.MAP)
$(CC) $(HOST_CFLAGS) -o $@ tools/makemap.c
$(MAP_TEMP): $(KERNEL.MAP) $(KERNEL.ELF)
perl -w scripts/proc_map.pl < $(KERNEL.MAP) > $(MAP_TEMP)
$(KERNEL.VAST): $(TMP_TEMP) $(MAKE_MAP_TOOL) $(KERNEL.MAP) $(KERNEL.ELF)
$(MAKE_MAP_TOOL) > $@
$(TEST_MOD): mod/test.o
cp $< $@
.s.o:
$(AS) $(ASFLAGS) -I inc -o $@ $<
.S.o:
$(AS) $(ASFLAGS) -I inc -o $@ $<
.c.o:
$(CC) $(KERNEL_CFLAGS) -c -o $@ $<
# Dependencies.
$(KERNEL.ELF): $(ELF_LINK_SCRIPT)
$(KERNEL.MAP): $(KERNEL.ELF)
#############################################################################
#
DEBUGGER_FILES:= heap init main stack
DEBUGGER_PATHS:= $(addprefix tools/core-debugger/,$(DEBUGGER_FILES))
DEBUGGER_SRC:= $(DEBUGGER_PATHS:=.c)
DEBUGGER_OBJ:= $(DEBUGGER_PATHS:=.o)
$(DEBUGGER_SRC): tools/core-debugger/core-debugger.h
$(DEBUGGER): $(DEBUGGER_OBJ) | $(KERNEL.MAP) $(MAP_TEMP)
$(CC) $(HOST_CFLAGS) -o $@ $(DEBUGGER_OBJ)
tools/core-debugger/%.o : tools/core-debugger/%.c
$(CC) $(HOST_CFLAGS) -c -o $@ $<
cppcheck:
cppcheck --quiet --enable=all --inconclusive --std=posix ./ 2>&1 | sort