Shlibs.pm 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use warnings;
  4. require 'dpkg-gettext.pl';
  5. use IO::File;
  6. use Exporter 'import';
  7. our @EXPORT_OK = qw(@librarypaths find_library);
  8. our @librarypaths = qw(/lib /usr/lib /lib32 /usr/lib32 /lib64 /usr/lib64
  9. /emul/ia32-linux/lib /emul/ia32-linux/usr/lib);
  10. # Update library paths with LD_LIBRARY_PATH
  11. if ($ENV{LD_LIBRARY_PATH}) {
  12. foreach my $path (reverse split( /:/, $ENV{LD_LIBRARY_PATH} )) {
  13. $path =~ s{/+$}{};
  14. unless (scalar grep { $_ eq $path } @librarypaths) {
  15. unshift @librarypaths, $path;
  16. }
  17. }
  18. }
  19. # Update library paths with ld.so config
  20. parse_ldso_conf("/etc/ld.so.conf") if -e "/etc/ld.so.conf";
  21. sub parse_ldso_conf {
  22. my $file = shift;
  23. my $fh = new IO::File;
  24. $fh->open("< $file")
  25. or main::syserr(sprintf(_g("couldn't open %s: %s"), $file, $!));
  26. while (<$fh>) {
  27. next if /^\s*$/;
  28. chomp;
  29. s{/+$}{};
  30. if (/^include\s+(\S.*\S)\s*$/) {
  31. foreach my $include (glob($1)) {
  32. parse_ldso_conf($include) if -e $include;
  33. }
  34. } elsif (m{^\s*/}) {
  35. s/^\s+//;
  36. my $libdir = $_;
  37. unless (scalar grep { $_ eq $libdir } @librarypaths) {
  38. push @librarypaths, $libdir;
  39. }
  40. }
  41. }
  42. $fh->close;
  43. }
  44. # find_library ($soname, \@rpath, $format, $root)
  45. sub find_library {
  46. my ($lib, $rpath, $format, $root) = @_;
  47. $root = "" if not defined($root);
  48. $root =~ s{/+$}{};
  49. my @rpath = @{$rpath};
  50. foreach my $dir (@rpath, @librarypaths) {
  51. if (-e "$root$dir/$lib") {
  52. my $libformat = Dpkg::Shlibs::Objdump::get_format("$root$dir/$lib");
  53. if ($format eq $libformat) {
  54. return "$root$dir/$lib";
  55. }
  56. }
  57. }
  58. return undef;
  59. }