#
# Makefile  -  makefile for boot rom kernel
#
# Copyright (C) 1995-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 user configuration:
#
include ../make.config


#
#  List of subdirectories
#
SUBDIRS		= arpa boot dossim lib net
ALLSUBDIRS	= init $(SUBDIRS)


#
#  List of source and object files:
#
LIBS	= libminidos.a libnet.a libromlib.a libarpa.a libboot.a
OBJS	= kernel.o main.o
SEGEND	= segend.o
TARGET	= kernel.bin


#
#  Include system dependent definitions:
#
include ../make.defs


#
#  The following macro sorts the kernel link map
#
SORT	= sort +4 +3


#
#  Target rules.
#
all:		obj/$(TARGET)


obj/$(TARGET):	objs subdirs
ifdef P86
	(cd obj; \
	  $(LD86) $(LD86FLAGS) -M -o $(TARGET) $(OBJS) $(LIBS:lib%.a=-l%) $(SEGEND) | $(SORT) >kernel86.map; \
	  cp kernel.bin $(srcdir)/binaries/kernel86.bin)
else
ifdef MINIMAL
	(cd obj; \
	  $(LD86) $(LD86FLAGS) -M -o $(TARGET) $(OBJS) $(LIBS:lib%.a=-l%) $(SEGEND) | $(SORT) >kernelm.map; \
	  cp kernel.bin $(srcdir)/binaries/kernelm.bin)
else
	(cd obj; \
	  $(LD86) $(LD86FLAGS) -M -o $(TARGET) $(OBJS) $(LIBS:lib%.a=-l%) $(SEGEND) | $(SORT) >kernel.map; \
	  cp kernel.bin $(srcdir)/binaries/kernel.bin)
endif
endif


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


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


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


install:


dummy:


.PHONY:	clean realclean distclean

clean:	clean-recursive
	rm -f obj/*

realclean distclean:	distclean-recursive
	rm -f obj/*

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

