# This Makefile builds 15-410 Project 1
#
# DO NOT EDIT THIS FILE

include config.mk

MAKE = make
CC = gcc
CFLAGS = -nostdinc -fno-strict-aliasing -fno-builtin -gstabs+ -Wall -Werror
LD = ld
LDFLAGS = -static -Ttext 100000
LIBS = 410kern/lib
AFS_DIR = /afs/cs.cmu.edu/academic/class/15410-s05/Web/update
INCLUDES = -Ikern/inc -I410kern/inc -I410kern/lib/inc
PRINT = enscript
DOC = doxygen


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

.PHONY: all clean progs nightdriver.o update query_update print html_doc \
	$(MTOOLSRC) kern 410kern

all: query_update bootfd.img

update:
	./update.sh $(UPDATE_METHOD)

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

kern:
	$(MAKE) -C kern -f ../410kern/Makefile

410kern:
	$(MAKE) -C 410kern -f ../410kern/Makefile

nightdriver: 410kern kern
	$(LD) -static -L$(LIBS)/ $(LDFLAGS) -o $@  \
	$(LIBS)/MultiBoot.o 410kern/common.o \
	kern/common.o \
	`if [ -f 410kern/nightdriver_game.o ]; then echo 410kern/nightdriver_game.o; fi` \
	`if [ -f kern/nightdriver_game.o ]; then echo kern/nightdriver_game.o; fi` \
	-lrand -llmm -lstdio -lstdlib -lstring -lx86 -ldebug

410test: 410kern kern
	$(LD) -static -L$(LIBS)/ $(LDFLAGS) -o $@  \
	$(LIBS)/MultiBoot.o 410kern/common.o \
	kern/common.o \
	`if [ -f 410kern/410test.o ]; then echo 410kern/410test.o; fi` \
	`if [ -f kern/410test.o ]; then echo kern/410test.o; fi` \
	-lrand -llmm -lstdio -lstdlib -lstring -lx86 -ldebug 

bootfd.img.gz:
	@echo file bootfd.img.gz missing
	@false

bootfd.img: nightdriver 410test bootfd.img.gz $(MTOOLSRC)
	gzip -cd bootfd.img.gz > bootfd.img

	gzip -c nightdriver > nightdriver.gz
	mcopy -o nightdriver.gz K:/boot/nightdriver.gz
	rm nightdriver.gz

	gzip -c 410test > 410test.gz
	mcopy -o 410test.gz K:/boot/410test.gz
	rm 410test.gz

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

clean:
	rm -fr *.o *~ *.d *.a user_apps.c bootfd.img $(MTOOLSRC) temp doc \
		nightdriver.ps nightdriver 410test
	$(MAKE) -C 410kern clean -f ../410kern/Makefile
	$(MAKE) -C kern clean -f ../410kern/Makefile

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

print:
	enscript -2r -p nightdriver.ps \
		`find ./kern/ -type f -regex  '.*\.[chS]' | sort`

