# $Id: cvs.postamble,v 2.2 94/05/15 23:14:34 nwc Exp $
#                               cvs.postamble
# Art Isbell
# isbell@cats.ucsc.edu
#
# NeXTSTEP 3.0's ProjectBuilder and InterfaceBuilder do not work well with CVS
# (Concurrent Versions System).  Occasionally, InterfaceBuilder complains that
# it cannot save certain directories (e.g., nib's and rtfd's) containing a CVS
# administrative directory; saving a second time will force a successful save.
# But a successful save causes these CVS directories to be lost resulting in
# CVS complaining that it cannot check in these directories during a subsequent
# CVS commit.  All CVS administrative directories are copied into the product
# when the "app", "debug", or "profile" targets are made.  Although the
# existence of these directories appears to cause no problems, it serves no
# purpose and increases the product size.  cvs.postamble attempts to correct
# these problems.
#
# In addition, once a CVS working directory has been created, all CVS commands
# can be run from ProjectBuilder using the "cvs" target.
#
# One approach to using cvs.postamble is to install it in a well-known
# directory (e.g., /LocalDeveloper/Makefiles) defined as LOCALMAKEDIR in
# Makefile.preamble:
#
# LOCALMAKEDIR = /LocalDeveloper/Makefiles
#
# and include it in Makefile.postamble (separate "include" statements from
# surrounding statements by at least one blank line):
#
# include $(LOCALMAKEDIR)/cvs.postamble
#
# Defined in cvs.postamble:
#   CVSDIR - name of CVS administrative directories.

CVSDIR = CVS

#       Example:
#           To use cvs.postamble with versions of CVS that use a administrative
#           directory name different from "CVS" (e.g., "CVS.adm"), change the
#           above statement to:
#               CVSDIR = CVS.adm
#   CVSARCHIVE - archive file in the CVS working directory in which all CVS
#       administrative directories will be stored during project modification.

CVSARCHIVE = CVS.tar

#       Example:
#           To change CVSARCHIVE to be "foo.tar", change the above statement
#           to:
#               CVSARCHIVE = foo.tar
#   CVSROOT - full path to CVS repository root directory.  This will be used
#       to set the CVSROOT environment variable from the Bourne (not C) shell
#       in which the cvs command is executed, so any '$' must be escaped with
#       another '$'.

CVSROOT = $$HOME/Development/CVS

#       Example:
#           To change CVSROOT to /usr/cvsroot, change the above statement to:
#               CVSROOT = /usr/cvsroot
#   CVS - full path of the cvs executable.

CVS = /usr/local/bin/cvs

#
# Inputs from "make" macro definition arguments (defaults set in
# cvs.postamble):
#   SEARCHDIRS - white space delimited list of one or more directories relative
#       to the CVS working directory to which to limit the scope of the current
#       target.  This minimizes the time to make the target after a CVS
#       checkout or before a CVS commit of a specific subdirectory of a CVS
#       working directory.  No directory in SEARCHDIRS should be a subdirectory
#       of any other directory in SEARCHDIRS.  Bourne shell wildcard characters
#       can be used.

SEARCHDIRS = .

#       Example:
#           To make the ARCHIVE_CVS_DIRS target on an unlocalized nib, foo.nib,
#           and a localized Help directory, German.lproj/Help, include a macro
#           definition as a "make" argument, either from a shell command line:
#               % make ckout SEARCHDIRS="foo.nib German.lproj/Help"
#           or as an entry in the "Args" FormCell in ProjectBuilder's Builder
#           View:
#               ckout SEARCHDIRS="foo.nib German.lproj/Help"
#   PRODUCTS - white space delimited list of one or more product directories
#       from which all CVS directories are to be deleted.

PRODUCTS = debug app profile

#       Example:
#           To remove CVS directories from foo.debug and foo.app, but not
#           foo.profile, include a macro definition as a "make" argument,
#           either from a shell command line:
#               % make rm PRODUCTS="debug app"
#           or as an entry in the "Args" FormCell in ProjectBuilder's Builder
#           View:
#               rm PRODUCTS="debug app"
#
# Targets: (Customize target names, if desired.)

ARCHIVE_CVS_DIRS = ckout cvs_dirs_out cvs_archive

#       Archives all CVS directories (excluding NAME.app, NAME.debug,
#       NAME.profile, and backup directories (~)) rooted in SEARCHDIRS
#       (default = .) into CVSARCHIVE.  THIS TARGET MUST BE MADE AFTER A CVS
#       CHECKOUT AND BEFORE AN IB SAVE TO AVOID LOSS OF CVS DIRECTORIES!!
#       Example:
#           To copy French.lproj/foo.nib's CVS directory to CVSARCHIVE
#           immediately after checking it out from the CVS repository, include
#           a macro definition as a "make" argument, either from a shell
#           command line:
#               % make ckout SEARCHDIRS=French.lproj/foo.nib
#           or as an entry in the "Args" FormCell in ProjectBuilder's Builder
#           View:
#               ckout SEARCHDIRS=French.lproj/foo.nib

RESTORE_CVS_DIRS = ckin cvs_dirs_in cvs_restore

#       Restores all CVS directories rooted in SEARCHDIRS (default = .) from
#       CVSARCHIVE.  THIS TARGET MUST BE MADE AFTER THE LAST IB SAVE AND BEFORE
#       CVS COMMIT TO AVOID AN UNSUCCESSFUL COMMIT!!
#       Example:
#           To prepare English.lproj/Help/Index.rtfd for a CVS commit after its
#           modification in InterfaceBuilder, include a macro definition as a
#           "make" argument, either from a shell command line:
#               % make ckin SEARCHDIRS=English.lproj/Help/Index.rtfd
#           or as an entry in the "Args" FormCell in ProjectBuilder's Builder
#           View:
#               ckin SEARCHDIRS=English.lproj/Help/Index.rtfd

REMOVE_CVS_DIRS = rm cvs_dirs_rm

#       Removes CVS directories from PRODUCTS in the CVS working directory.
#       Making this target is not necessary and should be done only when
#       desiring to rid an uninstalled product of its CVS directories.  See
#       example in "PRODUCTS" above.
#   cvs
#       Runs any CVS command specified by the value of the ARGS variable.
#       However, any command requiring user input in an editor (e.g., cvs
#       checkin) should not be run because of lack of terminal support in
#       ProjectBuilder Builder View's ScrollView.
#       Example:
#           To run "cvs -d $HOME/cvsroot checkout -r tag foomod/barfile":
#               cvs ARGS="-d $HOME/cvsroot checkout -r tag foomod/barfile"
#   help
#       Adds help for CVS-specific targets.
#   before_install
#       Removes CVS directories before the app is installed as the "install"
#       target is being made.  Should not be explicitly made.
#
# Revision 1.1  1992/12/09  03:12:32  nwc
# Helps cvs deal with NS3.0 nibs
#
# Revision 1.6  1992/10/15  18:52:23  art
# Added "find" options to prevent cvs from searching through various app
# wrappers when either archiving or restoring CVS directories.
#
# Revision 1.5  1992/09/01  04:43:56  art
# Replaced tabs (except those at beginning of target rule lines) with 4
# spaces and rewrapped lines so that file is more readable using Edit's
# default 8-column tab width.
#
# Revision 1.4  1992/08/31  17:57:15  art
# Made target names easy to change to local preferences.  Added cvs-specific
# help.
#
# Revision 1.3  1992/08/27  20:32:15  art
# Fixed bug that prevented the restoration of missing CVS directories in the
# cvsci target.  Added code to skip backup directories when cvsci is being
# made.
#
# Revision 1.2  1992/08/27  04:42:50  art
# Changed archiving of CVS administration directories to a tar archive so
# that CVS doesn't try to descend into archive directory during cvs update.
# Added a target that permits the running of CVS commands from ProjectBuilder.
#
# Revision 1.1.1.1  1992/08/10  01:42:32  art
# Initial release
#

# Variables
FIND = /usr/bin/find
XARGS = /usr/bin/xargs
SED = /bin/sed
GNUTAR = /usr/bin/gnutar

# Targets
$(ARCHIVE_CVS_DIRS):
	@for searchdir in $(SEARCHDIRS) ; do \
	    for dir in `$(FIND) $$searchdir -type d \( \( -name '*~' -o \
	        -name "$(NAME).debug" -o -name "$(NAME).app" -o \
	        -name "$(NAME).profile" -o -name '*obj' \) -prune \) -o \
	        \( -name "$(CVSDIR)" -prune -print \) | \
	        $(SED) 's/^\.\/\(.*\)$$/\1/'` ; do \
	        $(ECHO) Checking $$dir ; \
	        $(GNUTAR) uf $(CVSARCHIVE) $$dir; \
	    done ; \
	done

$(RESTORE_CVS_DIRS):
	@if [ ! -f "$(CVSARCHIVE)" ] ; then \
	    $(ECHO) Cannot proceed without CVS archive ; \
	    exit ; \
	fi ; \
	for searchdir in $(SEARCHDIRS) ; do \
	    for dir in `$(FIND) $$searchdir -type d \( \
	        \( \( -name "$(CVSDIR)" -o -name '*~' -o \
	        -name "$(NAME).debug" -o -name "$(NAME).app" -o \
	        -name "$(NAME).profile" -o -name '*obj' \) -prune \) -o \
	        -print \) | $(SED) 's/^\.\/\(.*\)$$/\1/'` ; do \
	        $(ECHO) Checking $$dir ; \
	        if [ ! -d $$dir/$(CVSDIR) ] ; then \
	            if [ $$dir = . ] ; then \
	                tardir=$(CVSDIR) ; \
	            else \
	                tardir=$$dir/$(CVSDIR) ; \
	            fi ; \
	            $(GNUTAR) xf $(CVSARCHIVE) $$tardir >/dev/null 2>&1 ; \
	        fi ; \
	    done ; \
	done

$(REMOVE_CVS_DIRS):
	@for product in $(PRODUCTS) ; do \
	    product=$(NAME).$$product ; \
	    if [ -d "$$product" ] ; then \
	        $(ECHO) "Removing $(CVSDIR) directories from $$product" ; \
	        $(FIND) $$product -name "$(CVSDIR)" -prune -print | \
	            $(XARGS) $(RM) -rf ; \
	    fi ; \
	done

cvs:
	@if [ -z "$(ARGS)" ] ; then \
	    $(ECHO) Usage: cvs ARGS=\"[cvs_options] cvs_command [command_options] [command_args]\" ; \
	else \
	    CVSROOT=$(CVSROOT) $(CVS) $(ARGS) ; \
	fi

before_install::
	@set $(REMOVE_CVS_DIRS) ; \
	$(MAKE) "PRODUCTS = app" $$1
