#
## Copyright (C) 1989,1990,1991,1992 by
#	Wilfried Koch, Andreas Lampen, Axel Mahler, Juergen Nickelsen,
#	Wolfgang Obst and Ulrich Pralle 
# 
# This file is part of shapeTools.
#
# 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
#
# $Header: stdtargets[1.13] Thu Feb 20 19:55:06 1992 andy@cs.tu-berlin.de accessed $
#

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

