#------------------------------------------------------------------------------
# $Id: Makefile,v 1.12 2002/02/22 19:33:37 jfboud Exp $
#

include Mk/mk-$(target).mk

pre-checks:
	@if [ -z "$(target)" ]; then \
	    echo ; \
	    echo "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"; \
	    echo "You must supply the target type!"; \
	    echo "make all target=target-type"; \
	    echo ; \
	    echo "where target-type is one of the following:"; \
	    echo "   freebsd4     for freebsd 4 up to 4.3"; \
	    echo "   freebsd44    for freebsd 4.4 and up."; \
	    echo "   netbsd       for netbsd 1.5 and up."; \
	    echo "   openbsd      for openbsd 2.7 and up."; \
	    echo "   solaris8     for solaris 8 and up."; \
	    echo "   linux        for linux. (Red Hat 7 tested, others may work but not tested)"; \
	    echo "   WindowsNT-2K for windows NT and 2000 based systems."; \
	    echo "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"; \
	    echo ; \
	    exit 1;\
	fi
	@if [ ! -f Mk/mk-$(target).mk ]; then \
	    echo "incomplete target setup for $(target) - no Mk/mk-$(target).mk"; \
	fi
	@if [ ! -f template/$(target).sh ]; then \
	    echo "incomplete target setup for $(target) - no template/$(target).sh"; \
	fi

all: pre-checks
	@for dir in ${subdirs}; do \
	  (cd $$dir && $(MAKE) all) \
	  || case "$(MFLAGS)" in *k*) fail=yes;; *) exit 1;; esac; \
	done && test -z "$$fail"

install: all
	@if [ -z "$(installdir)" ]; then \
	    echo ; \
	    echo "You must specify the install directory"; \
	    echo "ex.: make install target=os-type installdir=/usr/local/tsp"; \
	    echo ; \
	    exit 1;\
	fi
	@INSTALL=cp
	mkdir -p $(installdir)
	@for dir in ${subdirs}; do \
	  (cd $$dir && $(MAKE) install) \
	  || case "$(MFLAGS)" in *k*) fail=yes;; *) exit 1;; esac; \
	done && test -z "$$fail"
clean: pre-checks
	/bin/rm -f *~
	@for dir in ${subdirs}; do \
	  (cd $$dir && $(MAKE) clean) \
	  || case "$(MFLAGS)" in *k*) fail=yes;; *) exit 1;; esac; \
	done && test -z "$$fail"

distclean: clean
	/bin/rm -f Makefile config.h config.status config.cache config.log
	@for dir in ${subdirs}; do \
	  (cd $$dir && $(MAKE) distclean) \
	  || case "$(MFLAGS)" in *k*) fail=yes;; *) exit 1;; esac; \
	done && test -z "$$fail"
