#
# Copyright (c) 1996-2001 University of Utah and the Flux Group.
# All rights reserved.
# 
# This file is part of the Flux OSKit.  The OSKit is free software, also known
# as "open source;" you can redistribute it and/or modify it under the terms
# of the GNU General Public License (GPL), version 2, as published by the Free
# Software Foundation (FSF).  To explore alternate licensing terms, contact
# the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
# 
# The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GPL for more details.  You should have
# received a copy of the GPL along with the OSKit; see the file COPYING.  If
# not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
#

ifndef _boot_net_makerules_
_boot_net_makerules_ = yes

TARGETS = netdisk
CLEAN_FILES += $(TARGETS)
OSKIT_CFLAGS += -DPTHREADS
OSKIT_CFLAGS += -DOSKIT -DINFLATE -DUTAHTESTBED
OSKIT_CFLAGS += -DDOTIMEIT
#OSKIT_CFLAGS += -DCYCLECOUNTS
#OSKIT_CFLAGS += -DFREEBSD_NET

# This must come before any includes since make runs the first rule
# found if not explicitly told not to.
all: $(TARGETS)

# Where to look for src files.
SRCDIRS += $(OSKIT_SRCDIR)/netdisk
MOSTLY_SRCDIRS = $(OSKIT_SRCDIR)/boot

INCDIRS +=	$(OSKIT_SRCDIR)/zlib/src				\
		$(OSKIT_SRCDIR)/freebsd/libc/include			\
		$(OSKIT_SRCDIR)/freebsd/3.x/src/include			\
		$(OSKIT_SRCDIR)/freebsd/3.x/src/sys			\
		$(OSKIT_SRCDIR)/freebsd/3.x/src/lib/libc/i386		\
		$(OBJDIR)/freebsd/libc/objinclude			\
		$(OSKIT_SRCDIR)/netdisk

# We need this before including the generic rules so it
# doesn't get in there twice.
OBJFILES += version.o

# Include the makefile containing the generic rules.  This must come
# here since it depends on SRCDIRS and sets OBJFILES.  Yuck, I hate
# order dependence.
include $(OSKIT_SRCDIR)/GNUmakerules

# DEPENDLIBS is kind of bogus.  It makes it so we get rebuilt if *any*
# of the LIBS are newer than us.  It doesn't cause any libraries we
# need to be built though.
SLIBS = -loskit_startup -loskit_clientos -loskit_memfs -loskit_fsnamespace \
	-loskit_udp -loskit_bootp -loskit_diskpart -loskit_zlib \
	-loskit_linux_dev \
	-loskit_realtime -loskit_dev -loskit_exec -loskit_kern -loskit_lmm \
	-loskit_freebsd_c -loskit_com

TLIBS = -loskit_startup -loskit_clientos -loskit_memfs -loskit_fsnamespace_r \
	-loskit_threads -loskit_svm -loskit_amm -loskit_freebsd_c_r \
	-loskit_udp -loskit_bootp -loskit_diskpart -loskit_zlib \
	-loskit_linux_dev \
	-loskit_realtime -loskit_dev -loskit_exec -loskit_kern -loskit_lmm \
	-loskit_freebsd_c_r -loskit_com -loskit_threads

DEPENDLIBS = $(filter %.a, $(foreach DIR,$(LIBDIRS),$(wildcard $(DIR)/*)))

DEPS = $(OBJDIR)/lib/multiboot.o $(OBJFILES) $(DEPENDLIBS) $(OBJDIR)/lib/crtn.o

ifneq "$(filter -DPTHREADS, $(OSKIT_CFLAGS))" ""
_LIBS = $(TLIBS)
else
_LIBS = $(SLIBS)
endif

version.c: $(filter-out version.o,$(DEPS))
	echo >$@ "char version[] = \"NetDisk v3.1.0\";"
	echo >>$@ "char build_info[] = \"Built `date +\"%d-%b-%Y %H:%M:%S\"` by `id -nu`@`hostname | sed 's/\..*//'`:`pwd`\";"
CLEAN_FILES += version.c

# The dependencies on version.c seem completely bogus.  I'm sure there's a 
# good reason though.
prepare:: version.c

## Debugging hint: set the -Ttext to 3MB or so so you can run GDB and
## trace through the booted kernel (which presumably loads lower than
## 3MB).  Also, you can use the GDB `symbol-file' command to load the booted
## kernel's symbols once you get inside of it.
netdisk: $(DEPS)
	$(OSKIT_QUIET_MAKE_INFORM) "Linking $@"
	$(LD) -o $@ -Ttext 100000 $(LDFLAGS) $(OSKIT_LDFLAGS) \
		$(OBJDIR)/lib/multiboot.o \
		$(OBJFILES) $(_LIBS) \
		$(OBJDIR)/lib/crtn.o
	cp $@ $@.debug
	$(STRIP) $@
CLEAN_FILES += netdisk.debug
endif
