这是一个基于Ubuntu和GCC的操作系统编译Makefile
可以用来生成二进制程序和APP,以及Image镜像文件。
详细的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
|
ifndef GCCPREFIX
GCCPREFIX :=
endif
ifndef ARCH
ARCH := x86
endif
ifndef DEBUG
DEBUG := 1
endif
TARGET := target
AS := nasm
CC := $(GCCPREFIX)gcc
LD := $(GCCPREFIX)ld
OBJCOPY := $(GCCPREFIX)objcopy
ifeq ($(ARCH), x86_64)
QEMU := qemu-system-i386
CFLAGS += -Wall -Wno-format -Wno-unused -fno-pic
CFLAGS += -gstabs -std=gnu99 -static -m64 -fno-stack-protector
CFLAGS += -I ./sys/include -I ./libc/include
CFLAGS += -ffunction-sections -nostdlib -nostdinc -fno-builtin -ffreestanding
QEMU_FLAGS += -no-reboot -d in_asm -m size=128
else
QEMU := qemu-system-i386
CFLAGS += -Wall -Wno-format -Wno-unused -fno-pic
CFLAGS += -gstabs -std=gnu99 -static -m32 -fno-stack-protector
CFLAGS += -I ./sys/include -I ./libc/include
CFLAGS += -ffunction-sections -nostdlib -nostdinc -fno-builtin -ffreestanding
QEMU_FLAGS += -no-reboot -d in_asm -m size=128
endif
# C Library Objects
CLIB_OBJS := \
libc/stdio/stdio.bin \
libc/string/strcmp.bin \
libc/string/strncmp.bin \
libc/stdlib/rand.bin \
libc/graphics/arc.bin \
libc/graphics/ATT_driver.bin \
libc/graphics/bar3d.bin \
libc/graphics/bar.bin \
libc/graphics/CGA_driver.bin \
libc/graphics/circle.bin \
libc/graphics/cleardevice.bin \
libc/graphics/clearviewport.bin \
libc/graphics/closegraph.bin \
libc/graphics/detectgraph.bin \
libc/graphics/drawpoly.bin \
libc/graphics/EGAVGA_driver.bin \
libc/graphics/ellipse.bin \
libc/graphics/fillellipse.bin \
libc/graphics/fillpoly.bin \
libc/graphics/floodfill.bin \
libc/graphics/getarccoords.bin \
libc/graphics/getaspectratio.bin \
libc/graphics/getbkcolor.bin \
libc/graphics/getcanvas.bin \
libc/graphics/getcolor.bin \
libc/graphics/getdefaultpalette.bin \
libc/graphics/getdrivername.bin \
libc/graphics/getfillpattern.bin \
libc/graphics/getfillsettings.bin \
libc/graphics/getgraphmode.bin \
libc/graphics/getimage.bin \
libc/graphics/getlinesettings.bin \
libc/graphics/getmaxcolor.bin \
libc/graphics/getmaxmode.bin \
libc/graphics/getmaxx.bin \
libc/graphics/getmaxy.bin \
libc/graphics/getmodename.bin \
libc/graphics/getmoderange.bin \
libc/graphics/getpalette.bin \
libc/graphics/getpalettesize.bin \
libc/graphics/getpixel.bin \
libc/graphics/gettextsettings.bin \
libc/graphics/getviewsettings.bin \
libc/graphics/getx.bin \
libc/graphics/gety.bin \
libc/graphics/gothic_font.bin \
libc/graphics/graphdefaults.bin \
libc/graphics/grapherrormsg.bin \
libc/graphics/_graphfreemem.bin \
libc/graphics/_graphgetmem.bin \
libc/graphics/graphresult.bin \
libc/graphics/Herc_driver.bin \
libc/graphics/IBM8514_driver.bin \
libc/graphics/imagesize.bin \
libc/graphics/initgraph.bin \
libc/graphics/installuserdriver.bin \
libc/graphics/installuserfont.bin \
libc/graphics/line.bin \
libc/graphics/linerel.bin \
libc/graphics/lineto.bin \
libc/graphics/moverel.bin \
libc/graphics/moveto.bin \
libc/graphics/outtext.bin \
libc/graphics/outtextxy.bin \
libc/graphics/PC3270_driver.bin \
libc/graphics/pieslice.bin \
libc/graphics/putimage.bin \
libc/graphics/putpixel.bin \
libc/graphics/rectangle.bin \
libc/graphics/registerbgidriver.bin \
libc/graphics/registerbgifont.bin \
libc/graphics/restorecrtmode.bin \
libc/graphics/sansserif_font.bin \
libc/graphics/sector.bin \
libc/graphics/setactivepage.bin \
libc/graphics/setallpalette.bin \
libc/graphics/setaspectratio.bin \
libc/graphics/setbkcolor.bin \
libc/graphics/setcanvas.bin \
libc/graphics/setcolor.bin \
libc/graphics/setfillpattern.bin \
libc/graphics/setfillstyle.bin \
libc/graphics/setgraphbufsize.bin \
libc/graphics/setgraphmode.bin \
libc/graphics/setlinestyle.bin \
libc/graphics/setpalette.bin \
libc/graphics/setrgbcolor.bin \
libc/graphics/setrgbpalette.bin \
libc/graphics/settextjustify.bin \
libc/graphics/settextstyle.bin \
libc/graphics/setusercharsize.bin \
libc/graphics/setviewport.bin \
libc/graphics/setvisualpage.bin \
libc/graphics/setwritemode.bin \
libc/graphics/small_font.bin \
libc/graphics/textheight.bin \
libc/graphics/textwidth.bin \
libc/graphics/triplex_font.bin
# Kernel Objects
KERNEL_OBJS := \
sys/arch/$(ARCH)/kernel/system.bin \
sys/arch/$(ARCH)/kernel/io.bin \
sys/arch/$(ARCH)/kernel/pm.bin \
sys/arch/$(ARCH)/kernel/desctbl.bin \
sys/arch/$(ARCH)/kernel/int.bin \
sys/arch/$(ARCH)/kernel/inthandler.bin \
sys/arch/$(ARCH)/kernel/fifo.bin \
sys/arch/$(ARCH)/kernel/memory.bin \
sys/arch/$(ARCH)/kernel/timer.bin \
sys/arch/$(ARCH)/kernel/task_asm.bin \
sys/arch/$(ARCH)/kernel/task.bin \
sys/arch/$(ARCH)/kernel/api.bin \
sys/arch/$(ARCH)/kernel/api_asm.bin \
sys/arch/$(ARCH)/kernel/app.bin \
sys/arch/$(ARCH)/kernel/elf.bin
# FileSystem Objects
FILESYSTEM_OBJS := \
sys/filesystem/fat/fat12/fat12.bin \
sys/filesystem/fat/fat32/fat32.bin
# GUI Objects
GUI_OBJS := \
sys/gui/window.bin \
sys/gui/command.bin \
sys/gui/console.bin \
sys/gui/cursor.bin \
sys/gui/screen.bin \
sys/gui/fonts.bin \
sys/gui/layer.bin
# Drivers Objects
DRIVERS_OBJS := \
sys/arch/$(ARCH)/drivers/input/keyboard/keyboard.bin \
sys/arch/$(ARCH)/drivers/input/mouse/mouse.bin \
sys/arch/$(ARCH)/drivers/video/VESA/VESA.bin \
sys/arch/$(ARCH)/drivers/video/VGA/VGA.bin \
sys/arch/$(ARCH)/drivers/audio/sound.bin \
sys/arch/$(ARCH)/drivers/network/LAN/LAN.bin \
sys/arch/$(ARCH)/drivers/storage/harddrive/harddrive.bin
# Applications
APPS := \
app/bgidemo.app
#APPS :=
SYS := system.sys
IMG := appspace.img
ifdef DEBUG
QEMU_FLAGS += -gdb tcp::1234 -S
CFLAGS += -g
endif
sys/arch/$(ARCH)/boot/load.bin:
$(AS) -f bin sys/arch/$(ARCH)/boot/load.asm -o sys/arch/$(ARCH)/boot/load.bin -l sys/arch/$(ARCH)/boot/load.lst
sys/arch/$(ARCH)/kernel/asmhead.bin:
$(AS) -f bin sys/arch/$(ARCH)/kernel/asmhead.asm -o sys/arch/$(ARCH)/kernel/asmhead.bin -l sys/arch/$(ARCH)/kernel/asmhead.lst
sys/arch/$(ARCH)/kernel/%.bin: sys/arch/$(ARCH)/kernel/%.asm
$(AS) -f elf $< -o $@ -l $(subst .asm,.lst,$<)
%.bin: %.c
$(CC) $(CFLAGS) -c $< -o $@
# Applications
sys/api/api.lib:
$(AS) -f elf sys/arch/$(ARCH)/api/api.asm -o $@
sys/arch/$(ARCH)/kernel/app.lib:
$(AS) -f elf sys/arch/$(ARCH)/kernel/app.asm -o $@
%.app: %.asm
$(AS) -f elf $< -o $@ -l $(subst .asm,.lst,$<)
app/%.o: app/%.c
$(CC) $(CFLAGS) -c $< -o $@
app/%.app: app/%.o sys/arch/$(ARCH)/kernel/app.lib
ifeq ($(ARCH), x86_64)
$(LD) -m elf_x86_64 --oformat elf32-x86-64 -shared -e main -pie $^ -o $@
else
$(LD) -m elf_i386 --oformat elf32-i386 -shared -e main -pie $^ -o $@
endif
# Kernel
sys/arch/$(ARCH)/kernel/kernel.sys: ${CLIB_OBJS} ${DRIVERS_OBJS} ${FILESYSTEM_OBJS} ${KERNEL_OBJS} ${GUI_OBJS}
ifeq ($(ARCH), x86_64)
$(LD) -m elf_x86_64 --oformat binary -o sys/arch/$(ARCH)/kernel/kernel.sys -T sys/arch/$(ARCH)/kernel/kernel.ld $^
else
$(LD) -m elf_i386 --oformat binary -o sys/arch/$(ARCH)/kernel/kernel.sys -T sys/arch/$(ARCH)/kernel/kernel.ld $^
endif
system.sys: sys/arch/$(ARCH)/kernel/asmhead.bin sys/arch/$(ARCH)/kernel/kernel.sys
cat sys/arch/$(ARCH)/kernel/asmhead.bin > system.sys
cat sys/arch/$(ARCH)/kernel/kernel.sys >> system.sys
system-image: sys/arch/$(ARCH)/boot/load.bin system.sys ${APPS}
dd if=/dev/zero of=$(IMG) bs=512 count=2880
mkfs.msdos $(IMG)
dd if=sys/arch/$(ARCH)/boot/load.bin of=$(IMG) bs=512 count=1 conv=notrunc
copyapps:
mcopy -i $(IMG) system.sys ::/
mcopy -i $(IMG) ${APPS} ::/
mcopy -i $(IMG) sys/arch/$(ARCH)/boot/load.bin ::/
mcopy -i $(IMG) sys/fonts/hzk16.fonts ::/
all: ${CLIB_OBJS} ${DRIVERS_OBJS} ${FILESYSTEM_OBJS} ${KERNEL_OBJS} ${GUI_OBJS} ${APPS} system.sys system-image copyapps
clean:
rm -rf $(IMG)
rm -rf *.bin
rm -rf *.lst
rm -rf *.obj
rm -rf *.sys
rm -rf app/*.app
rm -rf app/*.bin
rm -rf sys/arch/$(ARCH)/kernel/*.bin
rm -rf **/*.bin
rm -rf **/*.lib
rm -rf **/*.lst
rm -rf **/*.o
rm -rf **/*.sys
rm -rf **/**/*.bin
qemu: clean all
$(QEMU) -fda $(IMG) $(QEMU_FLAGS)
#run: clean all
# $(QEMU) -drive file=$(IMG),if=floppy $(QEMU_FLAGS)
|