1OBJS = \ 2 bio.o\ 3 console.o\ 4 exec.o\ 5 file.o\ 6 fs.o\ 7 ide.o\ 8 ioapic.o\ 9 kalloc.o\ 10 kbd.o\ 11 lapic.o\ 12 log.o\ 13 main.o\ 14 mp.o\ 15 picirq.o\ 16 pipe.o\ 17 proc.o\ 18 sleeplock.o\ 19 spinlock.o\ 20 string.o\ 21 swtch.o\ 22 syscall.o\ 23 sysfile.o\ 24 sysproc.o\ 25 trapasm.o\ 26 trap.o\ 27 uart.o\ 28 vectors.o\ 29 vm.o\ 30 31# Cross-compiling (e.g., on Mac OS X) 32# TOOLPREFIX = i386-jos-elf 33 34# Using native tools (e.g., on X86 Linux) 35#TOOLPREFIX = 36 37# Try to infer the correct TOOLPREFIX if not set 38ifndef TOOLPREFIX 39TOOLPREFIX := $(shell if i386-jos-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/dev/null 2>&1; \ 40 then echo 'i386-jos-elf-'; \ 41 elif objdump -i 2>&1 | grep 'elf32-i386' >/dev/null 2>&1; \ 42 then echo ''; \ 43 else echo "***" 1>&2; \ 44 echo "*** Error: Couldn't find an i386-*-elf version of GCC/binutils." 1>&2; \ 45 echo "*** Is the directory with i386-jos-elf-gcc in your PATH?" 1>&2; \ 46 echo "*** If your i386-*-elf toolchain is installed with a command" 1>&2; \ 47 echo "*** prefix other than 'i386-jos-elf-', set your TOOLPREFIX" 1>&2; \ 48 echo "*** environment variable to that prefix and run 'make' again." 1>&2; \ 49 echo "*** To turn off this error, run 'gmake TOOLPREFIX= ...'." 1>&2; \ 50 echo "***" 1>&2; exit 1; fi) 51endif 52 53# If the makefile can't find QEMU, specify its path here 54# QEMU = qemu-system-i386 55 56# Try to infer the correct QEMU 57ifndef QEMU 58QEMU = $(shell if which qemu > /dev/null; \ 59 then echo qemu; exit; \ 60 elif which qemu-system-i386 > /dev/null; \ 61 then echo qemu-system-i386; exit; \ 62 elif which qemu-system-x86_64 > /dev/null; \ 63 then echo qemu-system-x86_64; exit; \ 64 else \ 65 qemu=/Applications/Q.app/Contents/MacOS/i386-softmmu.app/Contents/MacOS/i386-softmmu; \ 66 if test -x $$qemu; then echo $$qemu; exit; fi; fi; \ 67 echo "***" 1>&2; \ 68 echo "*** Error: Couldn't find a working QEMU executable." 1>&2; \ 69 echo "*** Is the directory containing the qemu binary in your PATH" 1>&2; \ 70 echo "*** or have you tried setting the QEMU variable in Makefile?" 1>&2; \ 71 echo "***" 1>&2; exit 1) 72endif 73 74CC = $(TOOLPREFIX)gcc 75AS = $(TOOLPREFIX)gas 76LD = $(TOOLPREFIX)ld 77OBJCOPY = $(TOOLPREFIX)objcopy 78OBJDUMP = $(TOOLPREFIX)objdump 79CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer 80CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) 81ASFLAGS = -m32 -gdwarf-2 -Wa,-divide 82# FreeBSD ld wants ``elf_i386_fbsd'' 83LDFLAGS += -m $(shell $(LD) -V | grep elf_i386 2>/dev/null | head -n 1) 84 85xv6.img: bootblock kernel fs.img 86 dd if=/dev/zero of=xv6.img count=10000 87 dd if=bootblock of=xv6.img conv=notrunc 88 dd if=kernel of=xv6.img seek=1 conv=notrunc 89 90xv6memfs.img: bootblock kernelmemfs 91 dd if=/dev/zero of=xv6memfs.img count=10000 92 dd if=bootblock of=xv6memfs.img conv=notrunc 93 dd if=kernelmemfs of=xv6memfs.img seek=1 conv=notrunc 94 95bootblock: bootasm.S bootmain.c 96 $(CC) $(CFLAGS) -fno-pic -O -nostdinc -I. -c bootmain.c 97 $(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c bootasm.S 98 $(LD) $(LDFLAGS) -N -e start -Ttext 0x7C00 -o bootblock.o bootasm.o bootmain.o 99 $(OBJDUMP) -S bootblock.o > bootblock.asm 100 $(OBJCOPY) -S -O binary -j .text bootblock.o bootblock 101 ./sign.pl bootblock 102 103entryother: entryother.S 104 $(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c entryother.S 105 $(LD) $(LDFLAGS) -N -e start -Ttext 0x7000 -o bootblockother.o entryother.o 106 $(OBJCOPY) -S -O binary -j .text bootblockother.o entryother 107 $(OBJDUMP) -S bootblockother.o > entryother.asm 108 109initcode: initcode.S 110 $(CC) $(CFLAGS) -nostdinc -I. -c initcode.S 111 $(LD) $(LDFLAGS) -N -e start -Ttext 0 -o initcode.out initcode.o 112 $(OBJCOPY) -S -O binary initcode.out initcode 113 $(OBJDUMP) -S initcode.o > initcode.asm 114 115kernel: $(OBJS) entry.o entryother initcode kernel.ld 116 $(LD) $(LDFLAGS) -T kernel.ld -o kernel entry.o $(OBJS) -b binary initcode entryother 117 $(OBJDUMP) -S kernel > kernel.asm 118 $(OBJDUMP) -t kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernel.sym 119 120# kernelmemfs is a copy of kernel that maintains the 121# disk image in memory instead of writing to a disk. 122# This is not so useful for testing persistent storage or 123# exploring disk buffering implementations, but it is 124# great for testing the kernel on real hardware without 125# needing a scratch disk. 126MEMFSOBJS = $(filter-out ide.o,$(OBJS)) memide.o 127kernelmemfs: $(MEMFSOBJS) entry.o entryother initcode kernel.ld fs.img 128 $(LD) $(LDFLAGS) -T kernel.ld -o kernelmemfs entry.o $(MEMFSOBJS) -b binary initcode entryother fs.img 129 $(OBJDUMP) -S kernelmemfs > kernelmemfs.asm 130 $(OBJDUMP) -t kernelmemfs | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernelmemfs.sym 131 132tags: $(OBJS) entryother.S _init 133 etags *.S *.c 134 135vectors.S: vectors.pl 136 perl vectors.pl > vectors.S 137 138ULIB = ulib.o usys.o printf.o umalloc.o 139 140_%: %.o $(ULIB) 141 $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $@ $^ 142 $(OBJDUMP) -S $@ > $*.asm 143 $(OBJDUMP) -t $@ | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $*.sym 144 145_forktest: forktest.o $(ULIB) 146 # forktest has less library code linked in - needs to be small 147 # in order to be able to max out the proc table. 148 $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o _forktest forktest.o ulib.o usys.o 149 $(OBJDUMP) -S _forktest > forktest.asm 150 151mkfs: mkfs.c fs.h 152 gcc -Werror -Wall -o mkfs mkfs.c 153 154# Prevent deletion of intermediate files, e.g. cat.o, after first build, so 155# that disk image changes after first build are persistent until clean. More 156# details: 157# http://www.gnu.org/software/make/manual/html_node/Chained-Rules.html 158.PRECIOUS: %.o 159 160UPROGS=\ 161 _cat\ 162 _echo\ 163 _forktest\ 164 _grep\ 165 _init\ 166 _kill\ 167 _ln\ 168 _ls\ 169 _mkdir\ 170 _rm\ 171 _sh\ 172 _stressfs\ 173 _usertests\ 174 _wc\ 175 _zombie\ 176 177fs.img: mkfs README $(UPROGS) 178 ./mkfs fs.img README $(UPROGS) 179 180-include *.d 181 182clean: 183 rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \ 184 *.o *.d *.asm *.sym vectors.S bootblock entryother \ 185 initcode initcode.out kernel xv6.img fs.img kernelmemfs mkfs \ 186 .gdbinit \ 187 $(UPROGS) 188 189# make a printout 190FILES = $(shell grep -v '^\#' runoff.list) 191PRINT = runoff.list runoff.spec README toc.hdr toc.ftr $(FILES) 192 193xv6.pdf: $(PRINT) 194 ./runoff 195 ls -l xv6.pdf 196 197print: xv6.pdf 198 199# run in emulators 200 201bochs : fs.img xv6.img 202 if [ ! -e .bochsrc ]; then ln -s dot-bochsrc .bochsrc; fi 203 bochs -q 204 205# try to generate a unique GDB port 206GDBPORT = $(shell expr `id -u` % 5000 + 25000) 207# QEMU's gdb stub command line changed in 0.11 208QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \ 209 then echo "-gdb tcp::$(GDBPORT)"; \ 210 else echo "-s -p $(GDBPORT)"; fi) 211ifndef CPUS 212CPUS := 2 213endif 214QEMUOPTS = -drive file=fs.img,index=1,media=disk,format=raw -drive file=xv6.img,index=0,media=disk,format=raw -smp $(CPUS) -m 512 $(QEMUEXTRA) 215 216qemu: fs.img xv6.img 217 $(QEMU) -serial mon:stdio $(QEMUOPTS) 218 219qemu-memfs: xv6memfs.img 220 $(QEMU) -drive file=xv6memfs.img,index=0,media=disk,format=raw -smp $(CPUS) -m 256 221 222qemu-nox: fs.img xv6.img 223 $(QEMU) -nographic $(QEMUOPTS) 224 225.gdbinit: .gdbinit.tmpl 226 sed "s/localhost:1234/localhost:$(GDBPORT)/" < $^ > $@ 227 228qemu-gdb: fs.img xv6.img .gdbinit 229 @echo "*** Now run 'gdb'." 1>&2 230 $(QEMU) -serial mon:stdio $(QEMUOPTS) -S $(QEMUGDB) 231 232qemu-nox-gdb: fs.img xv6.img .gdbinit 233 @echo "*** Now run 'gdb'." 1>&2 234 $(QEMU) -nographic $(QEMUOPTS) -S $(QEMUGDB) 235 236# CUT HERE 237# prepare dist for students 238# after running make dist, probably want to 239# rename it to rev0 or rev1 or so on and then 240# check in that version. 241 242EXTRA=\ 243 mkfs.c ulib.c user.h cat.c echo.c forktest.c grep.c kill.c\ 244 ln.c ls.c mkdir.c rm.c stressfs.c usertests.c wc.c zombie.c\ 245 printf.c umalloc.c\ 246 README dot-bochsrc *.pl toc.* runoff runoff1 runoff.list\ 247 .gdbinit.tmpl gdbutil\ 248 249dist: 250 rm -rf dist 251 mkdir dist 252 for i in $(FILES); \ 253 do \ 254 grep -v PAGEBREAK $$i >dist/$$i; \ 255 done 256 sed '/CUT HERE/,$$d' Makefile >dist/Makefile 257 echo >dist/runoff.spec 258 cp $(EXTRA) dist 259 260dist-test: 261 rm -rf dist 262 make dist 263 rm -rf dist-test 264 mkdir dist-test 265 cp dist/* dist-test 266 cd dist-test; $(MAKE) print 267 cd dist-test; $(MAKE) bochs || true 268 cd dist-test; $(MAKE) qemu 269 270# update this rule (change rev#) when it is time to 271# make a new revision. 272tar: 273 rm -rf /tmp/xv6 274 mkdir -p /tmp/xv6 275 cp dist/* dist/.gdbinit.tmpl /tmp/xv6 276 (cd /tmp; tar cf - xv6) | gzip >xv6-rev10.tar.gz # the next one will be 10 (9/17) 277 278.PHONY: dist-test dist 279