##########################################################################
#   Copyright (C) International Business Machines  Corp., 2003
#
#   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
#   (at your option) 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
#
#  FILE   : Makefile
#
#  PURPOSE: This makefile facilitates the compiling and linking of the
#           entire SLES9 EAL4 test suite.
#
#  HISTORY:
#    11/03 originated by Dustin Kirkland (k1rkland@us.ibm.com)
#    08/04 updated by Dustin Kirkland (k1rkland@us.ibm.com)
#
##########################################################################

SUB_DIRS        = misc_test \
		  laus_test \
		  LTP
LOG		= run.log
LOG_SEPARATOR   = "======================================="
ROLLUP_MAIL     = rollup.mail
VERBOSE_MAIL    = verbose.mail
TIMESTAMP       = `date +%Y-%m-%d_%H:%M:%S`

all:: subdirs

clean:: subdirs cleanup

run:: cleanup verifydeps
	# run in subdirs, but don't stop if one of them fails,
	# proceed with the remaining tests in case of error.
	-for DIR in $(SUB_DIRS); do make -C $$DIR run; done
	make report

report:: systeminfo 
	date > $(LOG)
	uname -a >> $(LOG)
	echo "" >> $(LOG)
	echo "" >> $(LOG)
	for log in `find */ -name run.log`; do echo $(LOG_SEPARATOR) >> $(LOG); echo $$log >> $(LOG); cat $$log >> $(LOG); echo "" >> $(LOG); echo $(LOG_SEPARATOR) >> $(LOG); done
	-tar zcvf logs.tar.gz `find . | grep run.log`
	cat run.log > $(ROLLUP_MAIL)
	find */ -name run.log | xargs -i cat {} >> $(ROLLUP_MAIL)
	cp -f $(ROLLUP_MAIL) $(VERBOSE_MAIL)
	echo "********************" >> $(VERBOSE_MAIL)
	echo "** VERBOSE OUTPUT **" >> $(VERBOSE_MAIL)
	echo "********************" >> $(VERBOSE_MAIL)
	echo "" >> $(VERBOSE_MAIL)
	for log in `find . | grep "\.run\.log"`; do echo $(LOG_SEPARATOR) >> $(VERBOSE_MAIL); echo [[[$$log]]] >> $(VERBOSE_MAIL); cat $$log >> $(VERBOSE_MAIL); echo "" >> $(VERBOSE_MAIL); echo $(LOG_SEPARATOR) >> $(VERBOSE_MAIL); done
	if [ `echo $(MAILTO)` ]; then cat $(ROLLUP_MAIL) | mail -s "$(TIMESTAMP) `uname -m` `hostname -f` rollup" $(MAILTO); fi
	if [ `echo $(MAILTO)` ]; then cat $(VERBOSE_MAIL) | mail -s "$(TIMESTAMP) `uname -m` `hostname -f` verbose" $(MAILTO); fi



include ./rules.mk

