Skip to content
Snippets Groups Projects
Makefile 4.71 KiB
Newer Older
rsc's avatar
rsc committed
OBJS = \
rsc's avatar
rsc committed
	bio.o\
rsc's avatar
rsc committed
	console.o\
rsc's avatar
rsc committed
	exec.o\
rsc's avatar
rsc committed
	file.o\
rsc's avatar
rsc committed
	fs.o\
rsc's avatar
rsc committed
	ide.o\
rsc's avatar
rsc committed
	ioapic.o\
rsc's avatar
rsc committed
	kalloc.o\
rsc's avatar
rsc committed
	kbd.o\
rsc's avatar
rsc committed
	lapic.o\
	main.o\
	mp.o\
	picirq.o\
	pipe.o\
	proc.o\
	spinlock.o\
	string.o\
rsc's avatar
rsc committed
	swtch.o\
rsc's avatar
rsc committed
	syscall.o\
rsc's avatar
rsc committed
	sysfile.o\
	sysproc.o\
rsc's avatar
rsc committed
	timer.o\
rsc's avatar
rsc committed
	trapasm.o\
	trap.o\
rsc's avatar
 
rsc committed
	uart.o\
rsc's avatar
rsc committed
	vectors.o\
rtm's avatar
rtm committed

# Cross-compiling (e.g., on Mac OS X)
TOOLPREFIX = i386-jos-elf-

# Using native tools (e.g., on X86 Linux)
rsc's avatar
rsc committed
AS = $(TOOLPREFIX)gas
LD = $(TOOLPREFIX)ld
OBJCOPY = $(TOOLPREFIX)objcopy
OBJDUMP = $(TOOLPREFIX)objdump
CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror
rsc's avatar
rsc committed
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
ASFLAGS = -m32 -gdwarf-2
# FreeBSD ld wants ``elf_i386_fbsd''
LDFLAGS += -m $(shell $(LD) -V | grep elf_i386 2>/dev/null)
rtm's avatar
rtm committed

rsc's avatar
rsc committed
xv6.img: bootblock kernel fs.img
rtm's avatar
rtm committed
	dd if=/dev/zero of=xv6.img count=10000
	dd if=bootblock of=xv6.img conv=notrunc
	dd if=kernel of=xv6.img seek=1 conv=notrunc

rsc's avatar
rsc committed
bootblock: bootasm.S bootmain.c
	$(CC) $(CFLAGS) -fno-pic -O -nostdinc -I. -c bootmain.c
	$(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c bootasm.S
	$(LD) $(LDFLAGS) -N -e start -Ttext 0x7C00 -o bootblock.o bootasm.o bootmain.o
rtm's avatar
rtm committed
	$(OBJDUMP) -S bootblock.o > bootblock.asm
	$(OBJCOPY) -S -O binary -j .text bootblock.o bootblock
rtm's avatar
rtm committed
	./sign.pl bootblock

rsc's avatar
rsc committed
bootother: bootother.S
	$(CC) $(CFLAGS) -nostdinc -I. -c bootother.S
	$(LD) $(LDFLAGS) -N -e start -Ttext 0x7000 -o bootother.out bootother.o
	$(OBJCOPY) -S -O binary bootother.out bootother
	$(OBJDUMP) -S bootother.o > bootother.asm
rsc's avatar
rsc committed

initcode: initcode.S
	$(CC) $(CFLAGS) -nostdinc -I. -c initcode.S
	$(LD) $(LDFLAGS) -N -e start -Ttext 0 -o initcode.out initcode.o
rsc's avatar
 
rsc committed
	$(OBJCOPY) -S -O binary initcode.out initcode
	$(OBJDUMP) -S initcode.o > initcode.asm
rsc's avatar
rsc committed

kernel: $(OBJS) bootother initcode
	$(LD) $(LDFLAGS) -Ttext 0x100000 -e main -o kernel $(OBJS) -b binary initcode bootother
rtm's avatar
rtm committed
	$(OBJDUMP) -S kernel > kernel.asm
rsc's avatar
rsc committed
	$(OBJDUMP) -t kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernel.sym
rtm's avatar
rtm committed

rsc's avatar
rsc committed
tags: $(OBJS) bootother.S _init
kaashoek's avatar
kaashoek committed
	etags *.S *.c

rsc's avatar
rsc committed
vectors.S: vectors.pl
rtm's avatar
rtm committed
	perl vectors.pl > vectors.S

kaashoek's avatar
kaashoek committed
ULIB = ulib.o usys.o printf.o umalloc.o
rsc's avatar
rsc committed
_%: %.o $(ULIB)
	$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $@ $^
rsc's avatar
rsc committed
	$(OBJDUMP) -S $@ > $*.asm
rsc's avatar
rsc committed
	$(OBJDUMP) -t $@ | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $*.sym
rsc's avatar
rsc committed

rsc's avatar
rsc committed
_forktest: forktest.o $(ULIB)
	# forktest has less library code linked in - needs to be small
	# in order to be able to max out the proc table.
	$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o _forktest forktest.o ulib.o usys.o
rsc's avatar
rsc committed
	$(OBJDUMP) -S _forktest > forktest.asm

rsc's avatar
rsc committed
mkfs: mkfs.c fs.h
	gcc -Wall -o mkfs mkfs.c
rsc's avatar
rsc committed

UPROGS=\
	_cat\
rsc's avatar
rsc committed
	_echo\
rsc's avatar
rsc committed
	_forktest\
rsc's avatar
rsc committed
	_grep\
rsc's avatar
rsc committed
	_init\
	_kill\
	_ln\
	_ls\
	_mkdir\
	_rm\
	_sh\
rsc's avatar
rsc committed
	_usertests\
	_wc\
	_zombie\

fs.img: mkfs README $(UPROGS)
rsc's avatar
rsc committed
	./mkfs fs.img README $(UPROGS)
rtm's avatar
rtm committed

rtm's avatar
rtm committed
-include *.d

rsc's avatar
rsc committed
clean: 
rsc's avatar
rsc committed
	rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \
rsc's avatar
rsc committed
	*.o *.d *.asm *.sym vectors.S parport.out \
rsc's avatar
rsc committed
	bootblock kernel xv6.img fs.img mkfs \
	$(UPROGS)
rsc's avatar
rsc committed

# make a printout
rsc's avatar
rsc committed
FILES = $(shell grep -v '^\#' runoff.list)
PRINT = runoff.list $(FILES)
rsc's avatar
rsc committed

rsc's avatar
rsc committed
xv6.pdf: $(PRINT)
rsc's avatar
rsc committed
	./runoff
	ls -l xv6.pdf
rsc's avatar
rsc committed

rsc's avatar
rsc committed
print: xv6.pdf
rsc's avatar
rsc committed

# run in emulators

bochs : fs.img xv6.img
	if [ ! -e .bochsrc ]; then ln -s dot-bochsrc .bochsrc; fi
	bochs -q

# try to generate a unique GDB port
GDBPORT = $(shell expr `id -u` % 5000 + 25000)
QEMUOPTS = -smp 2 -hdb fs.img xv6.img

rsc's avatar
rsc committed
qemu: fs.img xv6.img
	qemu -serial mon:stdio $(QEMUOPTS)
rsc's avatar
rsc committed

qemu-nox: fs.img xv6.img
	qemu -nographic $(QEMUOPTS)

.gdbinit: .gdbinit.tmpl
	sed "s/localhost:1234/localhost:$(GDBPORT)/" < $^ > $@

qemu-gdb: fs.img xv6.img .gdbinit
	@echo "*** Now run 'gdb'." 1>&2
	qemu -serial mon:stdio $(QEMUOPTS) -s -S -p $(GDBPORT)
rsc's avatar
 
rsc committed

qemu-gdb-nox: fs.img xv6.img .gdbinit
	@echo "*** Now run 'gdb'." 1>&2
	qemu -nographic $(QEMUOPTS) -s -S -p $(GDBPORT)

rsc's avatar
rsc committed
# CUT HERE
# prepare dist for students
# after running make dist, probably want to
# rename it to rev0 or rev1 or so on and then
# check in that version.
rsc's avatar
rsc committed

EXTRA=\
	mkfs.c ulib.c user.h cat.c echo.c forktest.c grep.c kill.c\
	ln.c ls.c mkdir.c rm.c stressfs.c usertests.c wc.c zombie.c\
	printf.c umalloc.c\
rsc's avatar
rsc committed
	README dot-bochsrc *.pl toc.* runoff runoff1 runoff.list\
	.gdbinit.tmpl gdbutil\
rsc's avatar
rsc committed

rsc's avatar
rsc committed
dist:
rsc's avatar
rsc committed
	rm -rf dist
	mkdir dist
	for i in $(FILES); \
rsc's avatar
rsc committed
	do \
		grep -v PAGEBREAK $$i >dist/$$i; \
	done
	sed '/CUT HERE/,$$d' Makefile >dist/Makefile
rsc's avatar
rsc committed
	echo >dist/runoff.spec
	cp $(EXTRA) dist
rsc's avatar
rsc committed

rsc's avatar
rsc committed
dist-test:
rsc's avatar
rsc committed
	rm -rf dist
	make dist
rsc's avatar
rsc committed
	rm -rf dist-test
	mkdir dist-test
	cp dist/* dist-test
	cd dist-test; ../m print
	cd dist-test; ../m bochs || true
	cd dist-test; ../m qemu

rsc's avatar
rsc committed
# update this rule (change rev1) when it is time to
rsc's avatar
rsc committed
# make a new revision.
rsc's avatar
rsc committed
tar:
rsc's avatar
rsc committed
	rm -rf /tmp/xv6
	mkdir -p /tmp/xv6
	cp dist/* dist/.gdbinit.tmpl /tmp/xv6
Silas Boyd-Wickizer's avatar
Silas Boyd-Wickizer committed
	(cd /tmp; tar cf - xv6) | gzip >xv6-rev3.tar.gz