?RCS: $Id: src.U 1 2006-08-24 12:32:52Z rmanfredi $
?RCS:
?RCS: Copyright (c) 1996, Cygnus Support
?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
?RCS: 
?RCS: You may redistribute only under the terms of the Artistic Licence,
?RCS: as specified in the README file that comes with the distribution.
?RCS: You may reuse parts of this distribution only within the terms of
?RCS: that same Artistic Licence; a copy of which may be found at the root
?RCS: of the source tree for dist 4.0.
?RCS:
?RCS: Original Author: Tom Tromey <tromey@cygnus.com>
?RCS:
?RCS: $Log: src.U,v $
?RCS: Revision 3.0.1.1  1997/02/28  16:23:54  ram
?RCS: patch61: created
?RCS:
?MAKE:src +rsrc: Options package contains
?MAKE:	-pick add $@ %<
?Y:TOP
?S:src (srcdir):
?S:	This variable holds the (possibly relative) path of the package source.
?S:	It is up to the Makefile to use this variable and set VPATH accordingly
?S:	to find the sources remotely.  Use $pkgsrc to have an absolute path.
?S:.
?S:rsrc (relsrcdir):
?S:	This variable holds a potentially relative path to the package
?S:	source.  The contents are correct for the configuration environment,
?S:	i.e. there might be an extra .. prepended to get out of the UU dir.
?S:	Configure units should use this, not the src variable.
?S:.
: Find the path to the source tree
case "$src" in
'') case "$0" in
    */*)
		src=`echo $0 | sed -e 's%/[^/][^/]*$%%'`
		;;
    *)	src='.';;
    esac;;
esac
case "$src" in
'')	src=/
	rsrc=/
	;;
/*)	rsrc="$src";;
*)	rsrc="../$src";;
esac
?X:
?X: Now check whether we have found the right source tree (i.e. the one for the
?X: package we're abount to configure). The original unit from Tom Tromey forced
?X: the user to pick a unique file from his distribution, and we were merely
?X: checking the existence of that file. I prefer to rely on Configure (which
?X: we know *is* present since this unit is part of it!) and look for the
?X: definition of the package variable, making sure it's the same as ours.
?X: If it matches, we know we found the right source tree. -- RAM, 15/03/96
?X:
if test -f $rsrc/Configure && \
	$contains "^package='$package'\$" $rsrc/Configure >/dev/null 2>&1
then
   : found it, so we are ok.
else
?X: Otherwise try "." and up to 4 parent directories...
?X: Note that we prepend a ".." to get out of the configuration environment.
	rsrc=''
	for src in . .. ../.. ../../.. ../../../..; do
		if test -f ../$src/Configure && \
			$contains "^package=$package$" ../$src/Configure >/dev/null 2>&1
		then
			rsrc=../$src
			break
		fi
	done
fi
case "$rsrc" in
'')
	cat <<EOM >&4

Sorry, I can't seem to locate the source dir for $package.  Please start
Configure with an explicit path -- i.e. /some/path/Configure.

EOM
	exit 1
	;;
?X: Don't echo anything if the sources are in . -- they should know already ;-)
?X: In that case, rsrc is ../. since we lookup from within UU
../.)	rsrc='..';;
*)
	echo " "
	echo "Sources for $package found in \"$src\"." >&4
	;;
esac

