Import OpenSSL-0.9.8i.
[dragonfly.git] / crypto / openssl-0.9.7d / util / mklink.pl
blob9386da7aa4c3a3f0f02e3d32583c06b0684f6e8b
1 #!/usr/local/bin/perl
3 # mklink.pl
5 # The first command line argument is a non-empty relative path
6 # specifying the "from" directory.
7 # Each other argument is a file name not containing / and
8 # names a file in the current directory.
10 # For each of these files, we create in the "from" directory a link
11 # of the same name pointing to the local file.
13 # We assume that the directory structure is a tree, i.e. that it does
14 # not contain symbolic links and that the parent of / is never referenced.
15 # Apart from this, this script should be able to handle even the most
16 # pathological cases.
18 my $from = shift;
19 my @files = @ARGV;
21 my @from_path = split(/[\\\/]/, $from);
22 my $pwd = `pwd`;
23 chop($pwd);
24 my @pwd_path = split(/[\\\/]/, $pwd);
26 my @to_path = ();
28 my $dirname;
29 foreach $dirname (@from_path) {
31 # In this loop, @to_path always is a relative path from
32 # @pwd_path (interpreted is an absolute path) to the original pwd.
34 # At the end, @from_path (as a relative path from the original pwd)
35 # designates the same directory as the absolute path @pwd_path,
36 # which means that @to_path then is a path from there to the original pwd.
38 next if ($dirname eq "" || $dirname eq ".");
40 if ($dirname eq "..") {
41 @to_path = (pop(@pwd_path), @to_path);
42 } else {
43 @to_path = ("..", @to_path);
44 push(@pwd_path, $dirname);
48 my $to = join('/', @to_path);
50 my $file;
51 $symlink_exists=eval {symlink("",""); 1};
52 foreach $file (@files) {
53 my $err = "";
54 if ($symlink_exists) {
55 symlink("$to/$file", "$from/$file") or $err = " [$!]";
56 } else {
57 unlink "$from/$file";
58 open (OLD, "<$file") or die "Can't open $file: $!";
59 open (NEW, ">$from/$file") or die "Can't open $from/$file: $!";
60 binmode(OLD);
61 binmode(NEW);
62 while (<OLD>) {
63 print NEW $_;
65 close (OLD) or die "Can't close $file: $!";
66 close (NEW) or die "Can't close $from/$file: $!";
68 print $file . " => $from/$file$err\n";