#
# This Makefile builds the 15-410 Project 2
#

CC = gcc
LD = ld
DOC = doxygen
MAKE = make
PRINT = enscript
UPDATE = ./update.pl
AFS_DIR = /afs/andrew/scs/cs/15-412/Web/update
CFLAGS = -nostdinc -fno-strict-aliasing -fno-builtin -Wall -Werror
INCLUDES = -I./inc -I./lib/inc
LDFLAGS = -static -Ttext 100000
LIBS = ./lib

# This should be the only line you have to edit
all: afs

%.o: Makefile %.c
	$(CC) -c -o $(*F).o $(CFLAGS) $(INCLUDES) $(*F).c

kernel: Makefile ref_kernel.o user_apps.o
	$(LD) $(LDFLAGS) -L$(LIBS)/ -o kernel \
	ref_kernel.o user_apps.o
	#$(LIBS)/MultiBoot.o ref_kernel user_apps.o  \
	#-llmm -lstdio -lstdlib -lstring -lx86 -ldebug

kernel-install bootfd: Makefile kernel
	echo "drive k: file=\"$(PWD)/bootfd.img\" " > ~/.mtoolsrc
	mcopy -o kernel K:/boot/

# build the kernel in afs, retrieving libraries from afs space.
afs:
	$(UPDATE) afs
	cd user; $(MAKE)
	$(MAKE) kernel-install

# build the kernel away from afs, retrieving libraries from the web
web:
	$(UPDATE) web
	cd user; $(MAKE)
	$(MAKE) kernel-install

# build the kernel disconnected. build libraries here.
# building like this should be avoided.
#offline:
#	$(UPDATE) offline
#	cd user; $(MAKE)
#	$(MAKE) kernel-install

clean:
	rm -f *~ *.d *.gdb kernel kernel.log ints.log kernel.ps user_apps.*
	cd user; $(MAKE) clean

html_doc:
	$(DOC) $(AFS_DIR)/doxygen.config

print:
	$(PRINT) -2r -p kernel.ps $(SRCS) $(HDRS)
