File: otool.pl

package info (click to toggle)
libpar-packer-perl 1.064-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,388 kB
  • sloc: perl: 12,774; ansic: 1,474; makefile: 30; sh: 5
file content (38 lines) | stat: -rw-r--r-- 851 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!perl

use strict;
use warnings;
use File::Basename;

sub is_system_lib { shift =~ m{^/usr/lib|^/System/Library/} };

sub find_files_to_embed
{
    my ($par, $libperl) = @_;

    my $dlls = otool($par); 

    # weed out system libs (but exclude the shared perl lib)
    foreach my $name (keys %$dlls)
    {
        my $path = $dlls->{$name};
        delete $dlls->{$name} if is_system_lib($path) && basename($path) !~ /perl/;
    }

    return $dlls;
}

# NOTE: "otool -L" is NOT recursive, i.e. it's the equivalent
# of "objdump -ax" or "readelf -d" on Linux, but NOT "ldd".
# So perhaps a recursive method like the one for objdump below is in order.
sub otool
{
    my ($file) = @_;

    my $out = qx(otool -L $file);
    die qq["otool -L $file" failed\n] unless $? == 0;

    return { map { basename($_) => $_ } $out =~ /^ \s+ (\S+) /gmx };
}

1;