#
# 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


all:	$(SUBDIRS)


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


kernel:	dummy
ifndef NO_BOOTROM
	@echo making all in $@
	@(cd $@; \
	  $(MAKE) clean; \
	  $(MAKE) P86="-DP86" all || exit 1; \
	  $(MAKE) clean; \
	  $(MAKE) MINIMAL="-DMINIMAL" all || exit 1; \
	  $(MAKE) clean; \
	  $(MAKE) all || exit 1)
else
	@echo nothing to make in $@
endif


loader:	dummy
ifndef NO_BOOTROM
	@echo making all in $@
	@(cd $@; \
	  $(MAKE) clean; \
	  $(MAKE) P86="-DP86" all || exit 1; \
	  $(MAKE) clean; \
	  $(MAKE) all || exit 1)
else
	@echo nothing to make in $@
endif


utils:	dummy
ifndef NO_BOOTROM
	@echo making all in $@
	@(cd $@ && $(MAKE) all) || exit 1
else
	@echo nothing to make in $@
endif


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)/pktdrvr
	@(cd utils && $(MAKE) install) || exit 1
	@for i in ./binaries/*; do \
	  echo $(INSTALL) -m 644 -o bin -g bin $$i $(libdir)/binaries; \
	  $(INSTALL) -m 644 -o bin -g bin $$i $(libdir)/binaries; \
	done
	@for i in ./pktdrvr/*.com; do \
	  echo $(INSTALL) -m 644 -o bin -g bin $$i $(libdir)/pktdrvr; \
	  $(INSTALL) -m 644 -o bin -g bin $$i $(libdir)/pktdrvr; \
	done


dummy:


.PHONY:	clean realclean distclean
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

