-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
251 lines (213 loc) · 6.75 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
OBJS = \
bio.o\
console.o\
exec.o\
file.o\
fs.o\
ide.o\
ioapic.o\
kalloc.o\
kbd.o\
lapic.o\
log.o\
main.o\
mp.o\
mux.o\
picirq.o\
pipe.o\
proc.o\
spinlock.o\
string.o\
swtch.o\
syscall.o\
sysfile.o\
sysproc.o\
timer.o\
trapasm.o\
trap.o\
uart.o\
vectors.o\
vm.o\
users.o\
syschroot.o\
bitbucket.o\
devsysctl.o\
kfields.o\
disk.o\
# Cross-compiling (e.g., on Mac OS X)
# TOOLPREFIX = i386-jos-elf
# Using native tools (e.g., on X86 Linux)
#TOOLPREFIX = /usr/local/bin/
# If the makefile can't find QEMU, specify its path here
QEMU = qemu-system-i386
FSFILE=newfs.img
ARCH=i386
XV6DIR = $(shell pwd)
MKFSCC = /usr/bin/clang
CC = $(TOOLPREFIX)gcc
AS = $(TOOLPREFIX)as
LD = $(TOOLPREFIX)ld
OBJCOPY = $(TOOLPREFIX)objcopy
OBJDUMP = $(TOOLPREFIX)objdump
#CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer
CFLAGS = -march=$(ARCH) -fno-pic -static -fno-builtin -fno-strict-aliasing -fvar-tracking -Wno-unused-variable -fplan9-extensions
CFLAGS += -fvar-tracking-assignments -O0 -g -Wall -MD -gdwarf-2 -m32 -Werror -fno-omit-frame-pointer
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
CFLAGS += -std=gnu99 -I./
ASFLAGS = -march=$(ARCH) -m32 -gdwarf-2 -Wa,-divide
# FreeBSD ld wants ``elf_i386_fbsd'' no it doesn't.
#LDFLAGS += -m $(shell $(LD) -V | grep elf_i386 2>/dev/null)
# backport from stable
LDFLAGS += -m elf_i386
# xv6.img: bootblock kernel.elf fs.img
# dd if=/dev/zero of=xv6.img count=10000
# dd if=bootblock of=xv6.img conv=notrunc
# dd if=kernel.elf of=xv6.img seek=1 conv=notrunc
bootblock: oldboot/bootasm.S oldboot/bootmain.c
$(CC) $(CFLAGS) -fno-pic -O -nostdinc -I. -c oldboot/bootmain.c
$(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c oldboot/bootasm.S
$(LD) $(LDFLAGS) -N -e start -Ttext 0x7C00 -o bootblock.o bootasm.o bootmain.o
$(OBJDUMP) -S bootblock.o > bootblock.asm
$(OBJCOPY) -S -O binary -j .text bootblock.o bootblock
./Tools/sign.pl bootblock
vsdmbr: newboot/mbrasm.S newboot/mbrmain.c
$(CC) $(CFLAGS) -fno-pic -O -nostdinc -I. -c newboot/mbrmain.c
$(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c newboot/mbrasm.S
$(LD) $(LDFLAGS) -N -e start -Ttext 0x7C00 -o vsdmbr.o mbrasm.o mbrmain.o
$(OBJDUMP) -S vsdmbr.o > vsdmbr.asm
$(OBJCOPY) -S -O binary -j .text vsdmbr.o vsdmbr
./Tools/sign.pl vsdmbr
bootelf: newboot/bootelf.c newboot/bootentry.S newboot/smalloc.c
$(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c newboot/bootentry.S
$(CC) $(CFLAGS) -fno-pic -O -nostdinc -I. -c newboot/bootelf.c
$(LD) $(LDFLAGS) -N -e bootelf_entry -Ttext 0x9000 -Tdata 0x8000 -o bootelf.o_ bootentry.o bootelf.o
$(OBJDUMP) -S bootelf.o_ > bootelf.asm
$(OBJCOPY) -S -O binary bootelf.o_ bootelf
bootbin: newboot/bootbin.c newboot/bootentry.S newboot/smalloc.c
$(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c newboot/bootentry.S
$(CC) $(CFLAGS) -fno-pic -O -nostdinc -I. -c newboot/bootbin.c
$(CC) $(CFLAGS) -fno-pic -O -nostdinc -I. -c newboot/smalloc.c
$(LD) $(LDFLAGS) -N -e bootelf_entry -Ttext 0x9000 -o bootbin.o_ bootentry.o bootbin.o smalloc.o
$(OBJDUMP) -S bootbin.o_ > bootbin.asm
$(OBJCOPY) -S -O binary -j .text bootbin.o_ bootbin
entryother: entryother.S
$(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c entryother.S
$(LD) $(LDFLAGS) -N -e start -Ttext 0x7000 -o bootblockother.o entryother.o
$(OBJCOPY) -S -O binary -j .text bootblockother.o entryother
$(OBJDUMP) -S bootblockother.o > entryother.asm
initcode: initcode.S
$(CC) $(CFLAGS) -nostdinc -I. -c initcode.S
$(LD) $(LDFLAGS) -N -e start -Ttext 0 -o initcode.out initcode.o
$(OBJCOPY) -S -O binary initcode.out initcode
$(OBJDUMP) -S initcode.o > initcode.asm
initkern: initkern.S
$(CC) $(CFLAGS) -nostdinc -I. -c initkern.S
$(LD) $(LDFLAGS) -N -e start -Ttext 0 -o initkern.out initkern.o
$(OBJCOPY) -S -O binary initkern.out initkern
$(OBJDUMP) -S initkern.o > initkern.asm
kernel.elf: $(OBJS) entry.o entryother initcode initkern kernel.ld
$(LD) $(LDFLAGS) -T kernel.ld -o kernel.elf entry.o $(OBJS) -b binary initcode initkern entryother
$(OBJDUMP) -t kernel.elf | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernel.sym
$(OBJCOPY) --only-keep-debug kernel.elf kernel.dsyms
kernel.bin: kernel.elf
$(OBJCOPY) -S -O binary -j .text kernel.elf kernel.bin
tags:
etags *.S *.c
vectors.o: vectors.S
$(CC) $(CFLAGS) -nostdinc -I. -c vectors.S
sysall: fs.img
all: sysall
qemu: sysall
sh ./Tools/qemu
qemu-gdb: sysall
sh ./Tools/qemu-gdb
qemu-nb: sysall
sh ./Tools/qemu-nb
qemu-nb-gdb: sysall
sh ./Tools/qemu-nb-gdb
bochs: sysall
bochs -q -f xv6-vsd.cfg
ULIB = ulib.o usys.o printf.o umalloc.o user_string.o ulocks.o uthread.o \
sprintf.o message.o args.o formatting.o
libc.a: $(ULIB)
ar -rc libc.a $(ULIB)
_%: %.o libc.a
$(LD) $(LDFLAGS) -N -e _start -Ttext 0 -o $@ $*.o libc.a
$(OBJDUMP) -t $@ | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $*.sym
$(OBJCOPY) --only-keep-debug $@ $*.dsyms
# $(OBJDUMP) -S $@ > $*.asm
# forktest is just a normal program now
#_forktest: forktest.o libc.a
# $(LD) $(LDFLAGS) -N -e _start -Ttext 0 -o _forktest forktest.o libc.a
# $(OBJDUMP) -S _forktest > forktest.asm
mkfs:
$(MKFSCC) -Werror -Wall -o mkfs Tools/mkfs_new.c
mkfs_vsd:
$(MKFSCC) -Werror -Wall -o mkfs_vsd Tools/mkfs_vsd.c
mkproto: Tools/mkproto.c
$(MKFSCC) -O0 -g -Werror -Wall -o mkproto Tools/mkproto.c
# Prevent deletion of intermediate files, e.g. cat.o, after first build, so
# that disk image changes after first build are persistent until clean. More
# details:
# http://www.gnu.org/software/make/manual/html_node/Chained-Rules.html
.PRECIOUS: %.o
UPROGS=\
_cat\
_echo\
_forktest\
_grep\
_init\
_kill\
_ln\
_ls\
_mkdir\
_rm\
_sh\
_stressfs\
_wc\
_zombie\
_login\
_chroot\
_cp\
_uname\
_errtest\
_devd\
_sleep\
_disallow\
_reboot\
_halt\
_sysctl\
_usertests\
_rfperms\
_tforktest\
_clonetest\
_deepthreads\
_recvtest\
_sendtest\
_printer\
_sprintftest\
_msgtest\
_malloctest\
_clonemalloc\
_argstest\
_chperms\
oldfs.img: mkfs_vsd $(UPROGS) kernel.elf kernel.bin bootelf bootbin vsdmbr
./mkfs_vsd oldfs.img VSDSYS $(UPROGS) kernel.elf kernel.bin bootelf bootbin @passwd @devices @rc @motd
dd if=vsdmbr of=fs.img conv=notrunc
newfs.img: mkproto $(UPROGS) kernel.elf kernel.bin bootelf bootbin vsdmbr
./mkproto -f Tools/rootfs_proto -o newfs.img
dd if=vsdmbr of=newfs.img conv=notrunc
fs.img: $(FSFILE)
cp $(FSFILE) fs.img
fs.qcow: fs.img
qemu-img convert -O qcow2 fs.img fs.qcow
-include *.d
clean:
rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \
*.o *.d *.asm *.sym *.dsyms bootblock entryother \
initcode initcode.out kernel.bin kernel.elf xv6.img \
fs.img kernelmemfs mkfs .gdbinit libc.a vsdmbr bootelf \
*.o_ bootbin initkern initkern.out fs.qcow $(UPROGS) \
mkfs_vsd mkproto newfs.img oldfs.img
fsclean:
rm -f mkfs_vsd mkproto mkfs fs.img newfs.img oldfs.img