3 # mklink.pl -- a faster substitute for mklink.sh.
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
21 my @from_path = split(/\//, $from);
24 my @pwd_path = split(/\//, $pwd);
27 foreach my $dirname (@from_path) {
29 # In this loop, @to_path always is a relative path from
30 # @pwd_path (interpreted is an absolute path) to the original pwd.
32 # At the end, @from_path (as a relative path from the original pwd)
33 # designates the same directory as the absolute path @pwd_path,
34 # which means that @to_path then is a path from there to the original pwd.
36 next if ($dirname eq "" || $dirname eq ".");
38 if ($dirname eq "..") {
39 @to_path = (pop(@pwd_path), @to_path);
41 @to_path = ("..", @to_path);
42 push(@pwd_path, $dirname);
46 my $to = join('/', @to_path);
48 foreach my $file (@files) {
49 # print "ln -s $to/$file $from/$file\n";
50 symlink("$to/$file", "$from/$file");
51 print $file . " => $from/$file\n";