Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 2ef74fe29e
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 109 lines (95 sloc) 2.115 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
#
# perl prepare.pl kame <osname>
# $KAME: prepare.pl,v 1.15 2005/10/13 02:45:17 t-momose Exp $
#

$debug = 1;
$test = 0;

die if (scalar(@ARGV) != 2);

$src = $ARGV[0];
$dst = $ARGV[1];

die "$src not found" if (! -d $src);
die "$dst not found" if (! -d $dst);

&dig($src, "../$src", $dst);

sub dig {
local($curdir, $src, $dst) = @_;
local(@all);
local(%exclude);
local(%linkdir);
local(%conflict);
local(%rename);

print "start: $curdir, $src, $dst\n";

opendir(DIR, $curdir);
@all = readdir(DIR);
closedir(DIR);

if (-f "$dst/.prepare") {
%exclude = ();
%linkdir = ();
%conflict = ();
%rename = ();
open(IN, "< $dst/.prepare");
while (<IN>) {
s/\s*\n$//;
s/^\s*//;
s/\#.*//;
if (/^exclude\s+(\S+)$/) {
$exclude{$1}++;
}
if (/^linkdir\s+(\S+)$/) {
$linkdir{$1}++;
}
if (/^conflict\s+(\S+)$/) {
$conflict{$1}++;
}
if (/^rename\s+(\S+)\s+(\S+)$/) {
$rename{$1} = $2;
}
}
close(IN);
print "exclude in $dst: " . join(' ', keys %exclude) . "\n"
if ($debug);
}
foreach $i (@all) {
next if ($i eq '.');
next if ($i eq '..');
next if ($i eq 'CVS');
next if ($i =~ /\.orig$/);
next if ($i =~ /\.rej$/);
next if ($i =~ /^\.\#/); # cvs temporary

if ($exclude{$i}) {
print "exclude $dst/$i\n" if $debug;
next;
}

if ($rename{$i}) {
$j = $rename{$i};
for ($pos = 0; ($pos = index($j, "/", $pos)) != -1; $pos++) {
$src = "../" . $src;
}
} else {
$j = $i;
}

if (-d "$curdir/$i" && !$linkdir{$i}) {
&dig("$curdir/$i", "../$src/$i", "$dst/$j");
} else {
if (! -d "$dst") {
print "mkdir -p $dst\n" if $debug;
system "mkdir -p $dst" if (!$test);
}

if (-f "$dst/$j" && ! -l "$dst/$j") {
print "conflict: $dst/$j";
if (defined $conflict{$j}) {
print " (expected)\n";
} else {
print " (UNEXPECTED!)\n";
exit 1;
}
} else {
if (-l "$dst/$j") {
print "unlink $dst/$j (symlink)\n" if $debug;
unlink "$dst/$j" if (!$test);
}
print "ln -s $src/$i $dst/$j\n" if $debug;
symlink("$src/$i", "$dst/$j") if (!$test);
}
}
}
}
Something went wrong with that request. Please try again.