Skip to content
Snippets Groups Projects
Makefile 4.06 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\
	vectors.o\
rtm's avatar
rtm committed

# Cross-compiling (e.g., on Mac OS X)
rtm's avatar
rtm committed
#TOOLPREFIX = i386-jos-elf-

# Using native tools (e.g., on X86 Linux)
rtm's avatar
rtm committed
TOOLPREFIX = 
rsc's avatar
rsc committed
AS = $(TOOLPREFIX)gas
LD = $(TOOLPREFIX)ld
OBJCOPY = $(TOOLPREFIX)objcopy
OBJDUMP = $(TOOLPREFIX)objdump
CFLAGS = -fno-builtin -O2 -Wall -MD -ggdb -m32
rsc's avatar
rsc committed
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
# 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) -O -nostdinc -I. -c bootmain.c
	$(CC) $(CFLAGS) -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 bootblock.o bootblock
	./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 $(CFLAGS) -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\
	_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

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

rsc's avatar
rsc committed
qemu: fs.img xv6.img
rsc's avatar
rsc committed
	qemu -parallel stdio -hdb fs.img xv6.img

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 usertests.c wc.c zombie.c\
	printf.c umalloc.c \
	README dot-bochsrc *.pl toc.* runoff runoff1 runoff.list\

rsc's avatar
rsc committed
dist:
rsc's avatar
rsc committed
	rm -rf dist
	mkdir dist
rsc's avatar
rsc committed
	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/* /tmp/xv6
rsc's avatar
rsc committed
	(cd /tmp; tar cf - xv6) | gzip >xv6-rev2.tar.gz
rsc's avatar
rsc committed