#
# This Makefile builds the 15-410 Project 2
#
# DO NOT MODIFY THIS FILE
# 

CC = gcc
LD = ld
DOC = doxygen
MAKE = make
PRINT = enscript
UPDATE = ./update.pl
AFS_DIR = /afs/cs.cmu.edu/academic/class/15410-f03/Web/update
CFLAGS = -nostdinc -fno-strict-aliasing -fno-builtin -Wall -Werror
INCLUDES = -I./inc -I./lib/inc
LDFLAGS = -static -Ttext 100000
LIBS = ./lib

export MTOOLSRC=$(shell pwd)/mtools.conf

include config.mk

.PHONY: update query_update html_doc print clean kernel-install bootfd user_apps.c

all: query_update kernel-install $(MTOOLSRC)

update:
	./update.pl $(UPDATE_METHOD)

query_update:
	./update.pl $(UPDATE_METHOD) query

user_apps.c:
	cd user; $(MAKE)

%.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

kernel-install bootfd: Makefile kernel $(MTOOLSRC)
	gzip -c kernel > kernel.gz
	mcopy -o kernel.gz K:/boot/kernel
	rm kernel.gz

$(MTOOLSRC):
	echo "drive K: file=\"$(PWD)/bootfd.img\" " > $@

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

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

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