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 spinlock.o\ 19 string.o\ 20 swtch.o\ 21 syscall.o\ 22 sysfile.o\ 23 sysproc.o\ 24 timer.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 = 55 56# Try to infer the correct QEMU 57ifndef QEMU 58QEMU = $(shell if which qemu > /dev/null; \ 59 then echo qemu; exit; \ 60 else \ 61 qemu=/Applications/Q.app/Contents/MacOS/i386-softmmu.app/Contents/MacOS/i386-softmmu; \ 62 if test -x $$qemu; then echo $$qemu; exit; fi; fi; \ 63 echo "***" 1>&2; \ 64 echo "*** Error: Couldn't find a working QEMU executable." 1>&2; \ 65 echo "*** Is the directory containing the qemu binary in your PATH" 1>&2; \ 66 echo "*** or have you tried setting the QEMU variable in Makefile?" 1>&2; \ 67 echo "***" 1>&2; exit 1) 68endif 69 70CC = $(TOOLPREFIX)gcc 71AS = $(TOOLPREFIX)gas 72LD = $(TOOLPREFIX)ld 73OBJCOPY = $(TOOLPREFIX)objcopy 74OBJDUMP = $(TOOLPREFIX)objdump 75#CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer 76CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer 77CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) 78ASFLAGS = -m32 -gdwarf-2 -Wa,-divide 79# FreeBSD ld wants ``elf_i386_fbsd'' 80LDFLAGS += -m $(shell $(LD) -V | grep elf_i386 2>/dev/null) 81 82xv6.img: bootblock kernel fs.img 83 dd if=/dev/zero of=xv6.img count=10000 84 dd if=bootblock of=xv6.img conv=notrunc 85 dd if=kernel of=xv6.img seek=1 conv=notrunc 86 87xv6memfs.img: bootblock kernelmemfs 88 dd if=/dev/zero of=xv6memfs.img count=10000 89 dd if=bootblock of=xv6memfs.img conv=notrunc 90 dd if=kernelmemfs of=xv6memfs.img seek=1 conv=notrunc 91 92bootblock: bootasm.S bootmain.c 93 $(CC) $(CFLAGS) -fno-pic -O -nostdinc -I. -c bootmain.c 94 $(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c bootasm.S 95 $(LD) $(LDFLAGS) -N -e start -Ttext 0x7C00 -o bootblock.o bootasm.o bootmain.o 96 $(OBJDUMP) -S bootblock.o > bootblock.asm 97 $(OBJCOPY) -S -O binary -j .text bootblock.o bootblock 98 ./sign.pl bootblock 99 100entryother: entryother.S 101 $(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c entryother.S 102 $(LD) $(LDFLAGS) -N -e start -Ttext 0x7000 -o bootblockother.o entryother.o 103 $(OBJCOPY) -S -O binary -j .text bootblockother.o entryother 104 $(OBJDUMP) -S bootblockother.o > entryother.asm 105 106initcode: initcode.S 107 $(CC) $(CFLAGS) -nostdinc -I. -c initcode.S 108 $(LD) $(LDFLAGS) -N -e start -Ttext 0 -o initcode.out initcode.o 109 $(OBJCOPY) -S -O binary initcode.out initcode 110 $(OBJDUMP) -S initcode.o > initcode.asm 111 112kernel: $(OBJS) entry.o entryother initcode kernel.ld 113 $(LD) $(LDFLAGS) -T kernel.ld -o kernel entry.o $(OBJS) -b binary initcode entryother 114 $(OBJDUMP) -S kernel > kernel.asm 115 $(OBJDUMP) -t kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernel.sym 116 117# kernelmemfs is a copy of kernel that maintains the 118# disk image in memory instead of writing to a disk. 119# This is not so useful for testing persistent storage or 120# exploring disk buffering implementations, but it is 121# great for testing the kernel on real hardware without 122# needing a scratch disk. 123MEMFSOBJS = $(filter-out ide.o,$(OBJS)) memide.o 124kernelmemfs: $(MEMFSOBJS) entry.o entryother initcode fs.img 125 $(LD) $(LDFLAGS) -Ttext 0x100000 -e main -o kernelmemfs entry.o $(MEMFSOBJS) -b binary initcode entryother fs.img 126 $(OBJDUMP) -S kernelmemfs > kernelmemfs.asm 127 $(OBJDUMP) -t kernelmemfs | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernelmemfs.sym 128 129tags: $(OBJS) entryother.S _init 130 etags *.S *.c 131 132vectors.S: vectors.pl 133 perl vectors.pl > vectors.S 134 135ULIB = ulib.o usys.o printf.o umalloc.o 136 137_%: %.o $(ULIB) 138 $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $@ $^ 139 $(OBJDUMP) -S $@ > $*.asm 140 $(OBJDUMP) -t $@ | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $*.sym 141 142_forktest: forktest.o $(ULIB) 143 # forktest has less library code linked in - needs to be small 144 # in order to be able to max out the proc table. 145 $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o _forktest forktest.o ulib.o usys.o 146 $(OBJDUMP) -S _forktest > forktest.asm 147 148mkfs: mkfs.c fs.h 149 gcc -Werror -Wall -o mkfs mkfs.c 150 151UPROGS=\ 152 _cat\ 153 _echo\ 154 _forktest\ 155 _grep\ 156 _init\ 157 _kill\ 158 _ln\ 159 _ls\ 160 _mkdir\ 161 _rm\ 162 _sh\ 163 _stressfs\ 164 _usertests\ 165 _wc\ 166 _zombie\ 167 168fs.img: mkfs README $(UPROGS) 169 ./mkfs fs.img README $(UPROGS) 170 171-include *.d 172 173clean: 174 rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \ 175 *.o *.d *.asm *.sym vectors.S bootblock entryother \ 176 initcode initcode.out kernel xv6.img fs.img kernelmemfs mkfs \ 177 .gdbinit \ 178 $(UPROGS) 179 180# make a printout 181FILES = $(shell grep -v '^\#' runoff.list) 182PRINT = runoff.list runoff.spec README toc.hdr toc.ftr $(FILES) 183 184xv6.pdf: $(PRINT) 185 ./runoff 186 ls -l xv6.pdf 187 188print: xv6.pdf 189 190# run in emulators 191 192bochs : fs.img xv6.img 193 if [ ! -e .bochsrc ]; then ln -s dot-bochsrc .bochsrc; fi 194 bochs -q 195 196# try to generate a unique GDB port 197GDBPORT = $(shell expr `id -u` % 5000 + 25000) 198# QEMU's gdb stub command line changed in 0.11 199QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \ 200 then echo "-gdb tcp::$(GDBPORT)"; \ 201 else echo "-s -p $(GDBPORT)"; fi) 202ifndef CPUS 203CPUS := 2 204endif 205QEMUOPTS = -hdb fs.img xv6.img -smp $(CPUS) -m 512 $(QEMUEXTRA) 206 207qemu: fs.img xv6.img 208 $(QEMU) -serial mon:stdio $(QEMUOPTS) 209 210qemu-memfs: xv6memfs.img 211 $(QEMU) xv6memfs.img -smp $(CPUS) 212 213qemu-nox: fs.img xv6.img 214 $(QEMU) -nographic $(QEMUOPTS) 215 216.gdbinit: .gdbinit.tmpl 217 sed "s/localhost:1234/localhost:$(GDBPORT)/" < $^ > $@ 218 219qemu-gdb: fs.img xv6.img .gdbinit 220 @echo "*** Now run 'gdb'." 1>&2 221 $(QEMU) -serial mon:stdio $(QEMUOPTS) -S $(QEMUGDB) 222 223qemu-nox-gdb: fs.img xv6.img .gdbinit 224 @echo "*** Now run 'gdb'." 1>&2 225 $(QEMU) -nographic $(QEMUOPTS) -S $(QEMUGDB) 226 227# CUT HERE 228# prepare dist for students 229# after running make dist, probably want to 230# rename it to rev0 or rev1 or so on and then 231# check in that version. 232 233EXTRA=\ 234 mkfs.c ulib.c user.h cat.c echo.c forktest.c grep.c kill.c\ 235 ln.c ls.c mkdir.c rm.c stressfs.c usertests.c wc.c zombie.c\ 236 printf.c umalloc.c\ 237 README dot-bochsrc *.pl toc.* runoff runoff1 runoff.list\ 238 .gdbinit.tmpl gdbutil\ 239 240dist: 241 rm -rf dist 242 mkdir dist 243 for i in $(FILES); \ 244 do \ 245 grep -v PAGEBREAK $$i >dist/$$i; \ 246 done 247 sed '/CUT HERE/,$$d' Makefile >dist/Makefile 248 echo >dist/runoff.spec 249 cp $(EXTRA) dist 250 251dist-test: 252 rm -rf dist 253 make dist 254 rm -rf dist-test 255 mkdir dist-test 256 cp dist/* dist-test 257 cd dist-test; $(MAKE) print 258 cd dist-test; $(MAKE) bochs || true 259 cd dist-test; $(MAKE) qemu 260 261# update this rule (change rev#) when it is time to 262# make a new revision. 263tar: 264 rm -rf /tmp/xv6 265 mkdir -p /tmp/xv6 266 cp dist/* dist/.gdbinit.tmpl /tmp/xv6 267 (cd /tmp; tar cf - xv6) | gzip >xv6-rev5.tar.gz 268 269.PHONY: dist-test dist 270