Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.5 KiB

  1. use File::Find;
  2. use Config;
  3. if (@ARGV != 2) {
  4. warn <<"EOT";
  5. Usage: makeliblinks libautodir targetdir
  6. where libautodir is the architecture-dependent auto directory
  7. (e.g. $Config::Config{archlib}/auto).
  8. EOT
  9. exit 2;
  10. }
  11. my ($libautodir, $targetdir) = @ARGV;
  12. # Calculate relative path prefix from $targetdir to $libautodir
  13. sub relprefix {
  14. my ($to, $from) = @_;
  15. my $up;
  16. for ($up = 0; substr($to, 0, length($from)) ne $from; $up++) {
  17. $from =~ s(
  18. [^/]+ (?# a group of non-slashes)
  19. /* (?# maybe with some trailing slashes)
  20. $ (?# at the end of the path)
  21. )()x;
  22. }
  23. return (("../" x $up) . substr($to, length($from)));
  24. }
  25. my $relprefix = relprefix($libautodir, $targetdir);
  26. my ($dlext, $lib_ext) = @Config::Config{qw(dlext lib_ext)};
  27. sub link_if_library {
  28. if (/\.($dlext|$lib_ext)$/o) {
  29. my $ext = $1;
  30. my $name = $File::Find::name;
  31. if (substr($name, 0, length($libautodir) + 1) ne "$libautodir/") {
  32. die "directory of $name doesn't match $libautodir\n";
  33. }
  34. substr($name, 0, length($libautodir) + 1) = '';
  35. my @parts = split(m(/), $name);
  36. if ($parts[-1] ne "$parts[-2].$ext") {
  37. die "module name $_ doesn't match its directory $libautodir\n";
  38. }
  39. pop @parts;
  40. my $libpath = "$targetdir/lib" . join("__", @parts) . ".$ext";
  41. print "$libpath -> $relprefix/$name\n";
  42. symlink("$relprefix/$name", $libpath)
  43. or warn "above link failed with error: $!\n";
  44. }
  45. }
  46. find(\&link_if_library, $libautodir);
  47. exit 0;