## Copyright (C) 1993,1994 by the author(s).
# 
# This software is published in the hope that it will be useful, but
# WITHOUT ANY WARRANTY for any part of this software to work correctly
# or as described in the manuals. See the ShapeTools Public License
# for details.
#
# Permission is granted to use, copy, modify, or distribute any part of
# this software but only under the conditions described in the ShapeTools 
# Public License. A copy of this license is supposed to have been given
# to you along with ShapeTools in a file named LICENSE. Among other
# things, this copyright notice and the Public License must be
# preserved on all copies.

#
# shape_CM environment -- stdtargets
#
# Authors: Andreas Lampen (Andreas.Lampen@cs.tu-berlin.de)
#          Axel Mahler (Axel.Mahler@cs.tu-berlin.de)
#
# $Header: stdtargets[6.0] Fri Jun 25 17:01:31 1993 andy@cs.tu-berlin.de frozen $
#

rms: help

info: help

help:
	@echo shapeTools Release Managemet System; \
	echo Usage: ; \
	echo "  shape [all]   [VERSIONS=<selection_rule>] [variants] [macro settings]"; \
	echo "  make  [all]   [<macro settings>]"; \
	echo "  shape clean"; \
	echo "  make  clean"; \
	echo "  shape cleancache"; \
	echo "  shape depend  [VERSIONS=<selection_rule>] [variants]"; \
	echo "  shape extractrelease [RELEASENAME=<relId>] [(PARTIAL)RELEASEBASE=<path>]"; \
	echo "  shape install [VERSIONS=<rule>] [INSTALLBASE=<path>] [variants] [macros]"; \
	echo "  make  install [INSTALLBASE=<path>] [<macro settings>]"; \
	echo "  shape patch   OLDRELEASE=<relId> NEWRELEASE=<relId> [PATCHFILE=<filename>]"; \
	echo "  shape plprerelease"; \
	echo "  shape plrelease"; \
	echo "  shape prerelease"; \
	echo "  shape release"; \
	echo "  shape shar    [VERSIONS=<selection_rule>] [ARCHIVE=<filename>]"; \
	echo "  shape tar     [VERSIONS=<selection_rule>] [ARCHIVE=<filename>]"; \

cleancache: cclean

cclean:
	@echo "Cleaning derived object cache"; \
	atfsrepair -C -q

lint: $(VERSIONS) +$(HOSTSYSTEM) $(SOURCES) $(HEADERS) $(VERSIONFILE)
	@echo "Linting..."; \
	lint $(CFLAGS) $(SOURCES) $(VERSIONFILE) $(LINTLIBS)

lintlibrary: $(VERSIONS) +$(HOSTSYSTEM) $(SOURCES) $(HEADERS) $(VERSIONFILE)
	@echo "Making lint library."; \
	lint -C$(NODENAME) $(CFLAGS) $(SOURCES) $(VERSIONFILE)

depend: $(VERSIONS) +$(HOSTSYSTEM) +$(COMPILER) +$(QUALITY)\
	$(SOURCES) $(VERSIONFILE) $(AUXSOURCES) $(HEADERS) $(AUXHEADERS)
	@-echo "Generating Dependencies file."; \
	if [ "$(HOSTSYSTEM)" ]; \
	then \
	  _hostsystem=$(HOSTSYSTEM); \
	else \
	  _hostsystem=_xXxXxX_; \
	fi; \
	if [ "$(BASE)" ]; \
	then \
	  _basepath=$(BASE); \
	else \
	  _basepath=_xXxXxX_; \
	fi; \
	cc $(CFLAGS) -M $(SOURCES) $(VERSIONFILE) $(AUXSOURCES) \
	| grep -v "/usr/include" \
	| sort | uniq | \
	sed -e "s:$$_basepath:$$(BASE):" -e "s:$$_hostsystem:$$(HOSTSYSTEM):" \
	> Dependencies

ARCHIVE=$(NODENAME)

tar: $(VERSIONS) $(COMPONENTS) $(VERSIONFILE)
	@-if [ -z "$(ARCHIVE)" ]; \
	then \
	  echo "Empty output filename."; exit 1; \
	fi; \
	if [ "$(ARCHIVE)" = "-" ]; \
	  then \
	    tar cf - $(COMPONENTS) $(VERSIONFILE); \
	  else \
	    echo "Making tar archive $(ARCHIVE).tar." ; \
	    tar cf $(ARCHIVE).tar $(COMPONENTS) $(VERSIONFILE); \
	fi

shar: $(VERSIONS) $(COMPONENTS) $(VERSIONFILE)
	@-if [ -z "$(ARCHIVE)" ]; \
	then \
	  echo "Empty output filename."; exit 1; \
	fi; \
	if [ "$(ARCHIVE)" = "-" ]; \
	  then \
	    shar $(COMPONENTS) $(VERSIONFILE); \
	  else \
	    echo "Making shell archive $(ARCHIVE).shar."; \
	    shar $(COMPONENTS) $(VERSIONFILE) > $(ARCHIVE).shar; \
	fi

VDIFF=vdiff
DEFAULT_PFILE=$(OLDRELEASE)+2+$(NEWRELEASE)

patch: _start_patch _patchsub _patchere _done_patch

_start_patch:
	@_subsystems="$(SUBSYSTEMS)"; \
	if [ -z "$(OLDRELEASE)" -o -z "$(NEWRELEASE)" ]; \
	then \
	  echo Usage: shape patch OLDRELEASE='<name1>' NEWRELEASE='<name2>' '[PATCHFILE=<filename>]'; \
	  exit 1; \
	fi; \
	echo Generating patch to update $(OLDRELEASE) to $(NEWRELEASE).; \
	if [ -z "$(PATCHFILE)" ]; \
	then \
	  pfname=`pwd`/$(DEFAULT_PFILE).pat; \
	else \
	  pfname=$(PATCHFILE); \
	fi; \
	echo The patchfile will be $$pfname .; \
	rm -f $$pfname; \
	exit 0

_done_patch:
	@echo Patchgeneration done.; echo

_patchsub:
	@_subsystems="$(SUBSYSTEMS)"; \
	if [ -n "$(SUBSYSTEMS)" ]; \
	then \
	  echo ...visiting subsystems: $(SUBSYSTEMS); \
	else \
	  exit 0; \
	fi; \
	exitcode=0; \
	if [ -z "$(PATCHFILE)" ]; \
	then \
	  pfname=`pwd`/$(DEFAULT_PFILE).pat; \
	else \
	  pfname=$(PATCHFILE); \
	fi; \
	for i in $$_subsystems; \
	do \
	  (cd $$i; $(MAKE) OLDRELEASE=$(OLDRELEASE) NEWRELEASE=$(NEWRELEASE) \
	      PATCHFILE=$$pfname CH_FILES=$$ch_files _patchsub _patchere); \
	  if [ $$? -ne 0 ]; then exitcode=1; fi; \
	done; \
	exit $$exitcode

_patchere:
	@_components="$(COMPONENTS)"; \
	if [ -n "$(COMPONENTS)" ]; \
	then \
	  echo ...comparing $(NODEPATH) components.; \
	else \
	  exit 0; \
	fi; \
	if [ -z "$(PATCHFILE)" ]; \
	then \
	  pfname=`pwd`/$(DEFAULT_PFILE).pat; \
	else \
	  pfname=$(PATCHFILE); \
	fi; \
	if [ -n "$(NODEPATH)" ]; \
	then \
	  path_prefix=$(NODEPATH)/; \
	else \
	  path_prefix=; \
	fi; \
	for i in $$_components; \
	do \
	  $(VDIFF) -P -c -base $(NODEPATH) $$i[$(OLDRELEASE)] \
	   $$i[$(NEWRELEASE)] >> $$pfname; \
	done

unit_test: unit_test +test $(TARGET) $(TESTFILES) $(TESTDRIVER)
	@-if ./$(TESTDRIVER); \
	then \
	  echo `date`: $(TARGET) passed the regression test suite; \
	else \
	  echo `date`: $(TARGET) failed the testsuite.; \
	fi

integration_test:
	@-testmods=`vl -last -attr af_state=proposed $(SOURCES)`; \
	rm -f protocol 2>&1 > /dev/null; \
	echo PROTOCOL for integration test of $(TARGET). > protocol; \
	echo `date` >> protocol; \
	(echo; echo) >> protocol; \
	if [ -n "$${testmods}" ]; \
	then \
	  echo Modules proposed for approval: $$testmods >> protocol; \
	else \
	  echo `date`: No modules proposed for testing >> protocol; \
	  exit 0; \
	fi; \
	for i in $$testmods; \
	do \
	  vadm -setuda test_switch=on $$i 2>&1 > /dev/null; \
	  echo `date`: beginning test of $$i. >> protocol; \
	  echo `date`: beginning test of $$i.; \
	  shape -V test i_test TESTMOD=$$i TPROT=protocol; \
	  echo >> protocol; \
	done; \
	echo `date`: Integration test for $(TARGET) completed. >> protocol

i_test: _run_i_test
	@echo `date`: $(TESTMOD) passed the integration test suite >> $(TPROT);
	@publ $(TESTMOD) 2>&1 > /dev/null;
	@echo `date`: $(TESTMOD) was approved for publication. >> $(TPROT)

_build_i_test: integration_test $(TARGET)
	@vadm -unsetuda test_switch $(TESTMOD) 2>&1 > /dev/null

_run_i_test: _build_i_test $(TESTFILES) $(TESTDRIVER)
	if ./$(TESTDRIVER); \
	then : ; \
	else \
	  echo `date`: $(TESTMOD) failed the integration test. >> $(TPROT); \
	  vadm -setuda test_status=fail $(TESTMOD) 2>&1 > /dev/null; \
	  vadm -unpromte $(TESTMOD) 2>&1 > /dev/null; \
	  echo `date`: $(TESTMOD) not approved for publication. >> $(TPROT); \
	fi
