Annotation of openbsd/fill_chroot/find_depends, Revision 1.1
1.1 ! andrew 1: #!/usr/bin/perl
! 2: # $RedRiver$
! 3: use strict;
! 4: use warnings;
! 5:
! 6: # find www/ -name *.so* | xargs find_depends | sort -u | xargs -I {} cp {} /home/andrew/www{}
! 7:
! 8:
! 9: #use OpenBSD::PackageInfo;
! 10: #use OpenBSD::PackingList;
! 11: #use OpenBSD::SharedLibs;
! 12: #use Data::Dumper;
! 13:
! 14: #my $dir = '/var/db/pkg';
! 15: #my $pkg = 'p5-DBD-mysql-3.0002';
! 16: #my $pkg = 'p5-DBD-mysql';
! 17:
! 18:
! 19:
! 20: #my $file = shift || '/usr/local/libdata/perl5/site_perl/i386-openbsd/auto/DBD/mysql/mysql.so';
! 21:
! 22:
! 23: die unless @ARGV;
! 24:
! 25: my %libs;
! 26: foreach my $file (@ARGV) {
! 27: my $libs = find_libs($file);
! 28: #print Dumper $libs;
! 29: foreach (keys %{ $libs }) {
! 30: $libs{ $_ } = $libs->{$_};
! 31: }
! 32: }
! 33:
! 34: foreach (keys %libs) {
! 35: print $libs{$_}, "\n";
! 36: }
! 37:
! 38: exit;
! 39:
! 40: #OpenBSD::SharedLibs::add_system_libs('/');
! 41:
! 42: #print installed_packages();
! 43: #print installed_name($pkg);
! 44: #print info_names();
! 45: #exit;
! 46:
! 47: #my $plist = OpenBSD::PackingList->from_installation($pkg) || die $!;
! 48:
! 49: #print Dumper $plist->{wantlib};
! 50:
! 51: #print Dumper $OpenBSD::SharedLibs::registered_libs;
! 52:
! 53: #foreach (@{ $plist->{wantlib} }) {
! 54: # print Dumper $_->{name}, find_library($_->{name});
! 55: #}
! 56:
! 57: #sub find_library
! 58: #{
! 59: # my $spec = shift;
! 60: # my @r;
! 61: # OpenBSD::SharedLibs::add_system_libs('/');
! 62: #
! 63: # my $lib = '/usr';
! 64: # @r = OpenBSD::SharedLibs::lookup_libspec('/usr', $spec);
! 65: # unless (@r) {
! 66: # $lib = '/usr/X11R6';
! 67: # @r = OpenBSD::SharedLibs::lookup_libspec('/usr/X11R6', $spec);
! 68: # }
! 69: # unless (@r) {
! 70: # for my $pkg (installed_packages()) {
! 71: # OpenBSD::SharedLibs::add_package_libs($pkg, 1);
! 72: # }
! 73: # $lib = '/usr/local';
! 74: # @r = OpenBSD::SharedLibs::lookup_libspec('/usr/local', $spec);
! 75: # }
! 76: # return $lib, @r;
! 77: #}
! 78:
! 79: sub find_libs
! 80: {
! 81: my $file = shift;
! 82: my $ld = shift || get_ldconfig();
! 83: my $locs = shift || {};
! 84:
! 85: print STDERR "Finding libs for '$file'\n";
! 86:
! 87: my @libs = search_file($file);
! 88: foreach (@libs) {
! 89: my ($name, $maj, $min) = $_ =~ /^([^\.]+)\.so\.(\d+)\.(\d+)$/;
! 90: my $spec = 'l' . $name . '.' . $maj . '.' . $min;
! 91:
! 92: if (exists $ld->{$spec}) {
! 93: next if exists $locs->{$spec};
! 94:
! 95: $locs->{$spec} = $ld->{$spec};
! 96:
! 97: $locs = find_libs($locs->{$spec}, $ld, $locs);
! 98:
! 99: } else {
! 100: warn "Couldn't find location for lib '$_'";
! 101: }
! 102: }
! 103:
! 104: return $locs;
! 105: }
! 106:
! 107: sub search_file
! 108: {
! 109: my $file = shift;
! 110: my @libs;
! 111:
! 112: open my $libs, '<', $file or die;
! 113: local $/ = chr(0);
! 114: while (<$libs>) {
! 115: if (m|^(/[^\w\/]+/)?lib(\S+)\.(\d+)\.(\d+)|) {
! 116: my ($path, $name, $major, $minor) = ($1, $2, $3, $4);
! 117: my $spec="$name.$major.$minor";
! 118: if (defined $path && $path ne '/usr/local/lib') {
! 119: $spec="$path/$spec";
! 120: }
! 121: push @libs, $spec;
! 122: }
! 123: }
! 124: close $libs;
! 125:
! 126: return @libs;
! 127: }
! 128:
! 129: sub get_ldconfig
! 130: {
! 131: my $ldconfig = '/sbin/ldconfig';
! 132: my (%paths, %libs);
! 133:
! 134: open my $ld, '-|', $ldconfig, '-r' or die;
! 135: while (<$ld>) {
! 136: chomp;
! 137: if (/search directories:\s+(.*)/) {
! 138: #search directories: /usr/lib:/usr/local/lib
! 139: my @p = split /:/, $1;
! 140: @paths{@p} = 1;
! 141: } elsif (/\d+:-(\S+)\s+=>\s+(\S+)/) {
! 142: #0:-ldes.9.0 => /usr/lib/libdes.so.9.0
! 143: my $lib = $1;
! 144: my $loc = $2;
! 145: #my ($name, $maj, $min) = $lib =~ /l([^\.]+)\.(\d+)\.(\d+)/;
! 146: #my $spec = 'lib' . $name . '.so.' . $maj . '.' . $min;
! 147: $libs{$lib} = $loc;
! 148: } else {
! 149: #print $_, "\n";
! 150: }
! 151: }
! 152: close $ld;
! 153:
! 154: $libs{_paths} = [ keys %paths ];
! 155: return \%libs;
! 156: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>