#
# Makefile  -  main makefile for bootrom
#
# Copyright (C) 1996-1998 Gero Kuhlmann   <gero@gkminix.han.de>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  any later version.
#
#  This program 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
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#


include make.config
include make.defs


# The headers directory has to come first!
SUBDIRS	= headers utils loader kernel
TARGETS	= headers utils-$(DEV86) loader-$(DEV86) kernel-$(DEV86)


#
# Rules to generate targets
#
.PHONY:	all distrib headers
.PHONY:	kernel-i86 kernel-no86 loader-i86 loader-no86 utils-i86 utils-no86

all distrib:	$(TARGETS)


headers:
	@echo making all in $@
	@(cd $@ && $(MAKE) all) || exit 1


kernel-i86:
	@echo making all in $@
	@(cd $(@:-i86=); \
	  $(MAKE) clean; \
	  $(MAKE) P86="-DP86" all || exit 1; \
	  $(MAKE) clean; \
	  $(MAKE) MINIMAL="-DMINIMAL" all || exit 1; \
	  $(MAKE) clean; \
	  $(MAKE) all || exit 1)

kernel-no86:
	@echo nothing to make in $@


loader-i86:
	@echo making all in $@
	@(cd $(@:-i86=); \
	  $(MAKE) clean; \
	  $(MAKE) P86="-DP86" all || exit 1; \
	  $(MAKE) clean; \
	  $(MAKE) all || exit 1)

loader-no86:
	@echo nothing to make in $@


utils-i86:
	@echo making all in $@
	@(cd $(@:-i86=) && $(MAKE) all) || exit 1

utils-no86:
	@echo nothing to make in $@


#
# Maintenance rules
#
.PHONY:	dep install clean realclean distclean
.PHONY:	clean-recursive realclean-recursive distclean-recursive

dep:
	@for subdir in $(SUBDIRS); do \
	  echo making $@ in $$subdir; \
	  (cd $$subdir && $(MAKE) $@) || exit 1; \
	done


install:
	$(INSTALL) -o bin -g bin -d $(libdir)
	$(INSTALL) -o bin -g bin -d $(libdir)/binaries
	$(INSTALL) -o bin -g bin -d $(libdir)/netdrvr
	@(cd utils && $(MAKE) install) || exit 1
	@for i in ./binaries/*; do \
	  $(INSTALL) -m 644 -o bin -g bin $$i $(libdir)/binaries; \
	done
	@for i in ./netdrvr/*.com; do \
	  $(INSTALL) -m 644 -o bin -g bin $$i $(libdir)/netdrvr; \
	done


clean:	clean-recursive


realclean: 	realclean-recursive
	rm -f make.defs
	rm -f binaries/*

distclean:	distclean-recursive
	rm -f make.defs


clean-recursive realclean-recursive distclean-recursive:
	@for subdir in $(SUBDIRS); do \
	  target=`echo $@ | sed 's/-recursive//'`; \
	  echo making $$target in $$subdir; \
	  (cd $$subdir && $(MAKE) $$target) || exit 1; \
	done

