# This Makefile builds 15-410 Project 1
#

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

#
# List object files that will be linked into the kernel binary
# here.
#
OBJS = console.o \


#
# List here source and header files that will be included
# in the document created by a 'make print'
#
SRCS = kernel.c console.c

HDRS =

all: afs

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

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

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

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

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

# build the kernel in afs, retrieving libraries from afs space.
afs:
	./update.pl afs
	$(MAKE) kernel-install

# build the kernel away from afs, retrieving libraries from the web
web:
	./update.pl web
	$(MAKE) kernel-install

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

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

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

deepclean:
	rm -f *.o *.d *.gdb kernel kernel.log ints.log
	cd lib; $(MAKE) clean

clean:
	rm -f *.o *.d *.gdb kernel kernel.log ints.log