[comp.lang.perl] VPATH support?

merlyn@iwarp.intel.com (Randal L. Schwartz) (01/16/91)

In article <1991Jan15.115821.13718@lth.se>, jh@efd (Joergen Haegg) writes:
| Would it be possible to support VPATH in the perl distribution?
| 
| I would like to have a src directory and several object directories
| on the same level, like
| 	src/ sun3/ vax/
| And run Configure as 'sh ../src/Configure' in an empty directory.
| 
| Or is this already possible?

I do this all the time, with both the Perl source and other sources
using my shadow directory maker, like so:

##################################################
#!/local/usr/bin/perl
$shr=".SHARE";
sub mkdir {
	local($d) = @_;
	print "mkdir $d\n";
	(mkdir($d,0777) || warn "'mkdir $d': $!") unless $debug;
}

sub symlink{
	local($s,$d) = @_;
	print "ln -s $s $d\n";
	(symlink($s,$d) || warn "'ln -s $s $d': $!") unless $debug;
}

$debug = 1, shift if $ARGV[0] =~ /^-d/;
$src = shift || die "Missing src parameter";
$dst = shift || die "Missing dst parameter";
shift && die "Too many parameters";
if ($src !~ /^\//) {
	chop($pwd = `/bin/pwd`);
	$src = "$pwd/$src";
}
-d $src || die "'$src': directory does not exist";
&mkdir($dst) unless -d $dst;
&symlink($src,"$dst/$shr");
open(F,"cd $src && find . -type d -print|") || die "Cannot open find ($!)";
while(<F>) {
	if ($_ ne ".\n") {
		/^\.\/((.*\/)?)(.+)\n/ || die "Cannot grok '$_'";
		($head, $tail) = ($1, $3);
		&mkdir("$dst/$head$tail") unless -d "$dst/$head$tail";
		&symlink("../$shr/$tail","$dst/$head$tail/$shr");
	} else {
		($head,$tail) = ("", ".");
	}
	for (<$dst/$head$tail/$shr/*>) {
		next if -d $_;
		s,.*/,,;
		&symlink("$shr/$_","$dst/$head$tail/$_");
	}
}
close(F);
##################################################

I call it "makeshare".  I use it by sticking the Perl distribution
into DIST, then doing the following:

$ find DIST -type f -print | xargs -t chmod a-w
$ for i in sun3 sun386 sun4 vax
> do makeshare DIST $i
> done
$ cd sun3
$ ./Configure

and so on.  Files that are common stay as symlinks back to the DIST
directory.  Files that are local to an architecture (.o's and
config.sh, for example) live in the local directory.  I've been using
it for over a year, and won't go back to any other way.

The chmod is necessary because *some* distributions (not Perl) have a
nasty habit of *writing* into stuff that comes off the tape.  Not
cool.  What happens then is you get a write error, so you go in,
rename that file (actually just renaming the symlink) to file-DIST,
then "cat file-DIST >file" so that "file" is a local copy with
file-DIST for reference to the original.

print pack("c*",unpack("c8X5cx4c3X7cx6cX3c2xcX9cx3cX4cx7c2X6c2x4c","Just anoherPlck,"))
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/