Usage: makeliblinks libautodir targetdir
where libautodir is the architecture-dependent auto directory
(e.g. $Config::Config{archlib}/auto).
my ($libautodir, $targetdir) = @ARGV;
# Calculate relative path prefix from $targetdir to $libautodir
for ($up = 0; substr($to, 0, length($from)) ne $from; $up++) {
[^/]+ (?# a group of non-slashes)
/* (?# maybe with some trailing slashes)
$ (?# at the end of the path)
return (("../" x $up) . substr($to, length($from)));
my $relprefix = relprefix($libautodir, $targetdir);
my ($dlext, $lib_ext) = @Config::Config{qw(dlext lib_ext)};
if (/\.($dlext|$lib_ext)$/o) {
my $name = $File::Find::name;
if (substr($name, 0, length($libautodir) + 1) ne "$libautodir/") {
die "directory of $name doesn't match $libautodir\n";
substr($name, 0, length($libautodir) + 1) = '';
my @parts = split(m(/), $name);
if ($parts[-1] ne "$parts[-2].$ext") {
die "module name $_ doesn't match its directory $libautodir\n";
my $libpath = "$targetdir/lib" . join("__", @parts) . ".$ext";
print "$libpath -> $relprefix/$name\n";
symlink("$relprefix/$name", $libpath)
or warn "above link failed with error: $!\n";
find(\&link_if_library, $libautodir);