#
# Copyright (c) 1996-1999 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 = netboot
CLEAN_FILES += $(TARGETS)
# 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)/boot/net
MOSTLY_SRCDIRS = $(OSKIT_SRCDIR)/boot
OBJFILES += getline.o

# 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.
LIBS = -loskit_bootp \
	-loskit_linux_dev -loskit_dev -loskit_exec -loskit_kern \
	-loskit_memdebug -loskit_c -loskit_lmm
DEPENDLIBS = $(filter %.a, $(foreach DIR,$(LIBDIRS),$(wildcard $(DIR)/*)))

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

version.c: $(filter-out version.o,$(DEPS))
	echo >$@ "char version[] = \"NetBoot metakernel v2.5\";"
	echo >>$@ "char build_info[] = \"Built `date +%d-%b-%Y` by `id -nu`@`hostname | sed 's/\..*//'`:`pwd`\nwith options: $(OSKIT_OPTIONS)\";"
CLEAN_FILES += 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.
netboot: $(DEPS)
	$(LD) -o $@ -Ttext 100000 $(LDFLAGS) $(OSKIT_LDFLAGS) \
		$(OBJDIR)/lib/multiboot.o \
		$(OBJFILES) $(LIBS) \
		$(OBJDIR)/lib/crtn.o
	cp $@ $@.debug
	$(STRIP) $@
CLEAN_FILES += netboot.debug

# How to install it.
install: netboot
	-mkdir -p $(INSTALL_LIBDIR)/boot
	$(INSTALL) netboot $(INSTALL_LIBDIR)/boot/netboot.mb
	$(INSTALL) netboot.debug $(INSTALL_LIBDIR)/boot/netboot.mb.debug

endif
