# 
# Copyright (c) 1996 The University of Utah and
# the Computer Systems Laboratory at the University of Utah (CSL).
# All rights reserved.
#
# Permission to use, copy, modify and distribute this software is hereby
# granted provided that (1) source code retains these copyright, permission,
# and disclaimer notices, and (2) redistributions including binaries
# reproduce the notices in supporting documentation, and (3) all advertising
# materials mentioning features or use of this software display the following
# acknowledgement: ``This product includes software developed by the
# Computer Systems Laboratory at the University of Utah.''
#
# THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
# IS" CONDITION.  THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
# ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
#
# CSL requests users of this software to return to csl-dist@cs.utah.edu any
# improvements that they make and grant CSL redistribution rights.
#

ifndef _boot_bsd_makerules_
_boot_bsd_makerules_ = yes

TARGETS = bsdboot.o mkbsdimage
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/bsd $(OSKIT_SRCDIR)/boot 

# 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

# Make sure crt0 comes first.
OBJFILES := crt0.o $(filter-out crt0.o,$(OBJFILES))

# 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 = -lexec -lkern -lmc -llmm
DEPENDLIBS = $(filter %.a, $(foreach DIR,$(LIBDIRS),$(wildcard $(DIR)/*)))

bsdboot.o: $(OBJFILES) $(DEPENDLIBS)
	$(LD) -o $@ -r $(LDFLAGS) $(OSKIT_LDFLAGS) $(OBJFILES) $(LIBS)

.PHONY: mkbsdimage
mkbsdimage:
	chmod +x $@

# How to install it.  The rule to make $(INSTALL_BINDIR/mkbsdimage
# comes from the generic rule file
install: $(INSTALL_LIBDIR)/boot/bsdboot.o $(INSTALL_BINDIR)/mkbsdimage

$(INSTALL_LIBDIR)/boot/%: %
	-mkdir -p $(@D)
	$(INSTALL) $< $@

endif
