3 use File::Temp qw'tempdir';
14 my ($ar, $as, $nm, $objcopy);
15 GetOptions('exclude=s'=>\@exclude, 'static!'=>\$static, 'v!'=>\$inverse,
16 'ar=s'=>\$ar, 'as=s'=>\$as,'nm=s'=>\$nm, 'objcopy=s'=>\$objcopy);
18 $_ = File::Spec->rel2abs($_) for @ARGV;
22 (my $iname = basename $lib) =~ s/\.a$//o;
23 $iname = '_' . $iname . '_dll_iname';
25 open my $nm_fd, '-|', $nm, '-Apg', '--defined-only', @ARGV, $libdll or
26 die "$0: execution of $nm for object files failed - $!\n";
32 my $exclude_regex = @exclude ? join('|', @exclude) : '\\UnLiKeLy//';
33 $exclude_regex = qr/$exclude_regex/;
37 if (/ I _(.*)_dll_iname/o) {
40 my ($file, $member, $symbol) = m%^([^:]*):([^:]*(?=:))?.* T (.*)%o;
41 next if !defined($symbol) || $symbol =~ $exclude_regex;
42 if ($file ne $libdll) {
43 $match_syms{$symbol} = 1;
44 } elsif ($match_syms{$symbol} ? !$inverse : $inverse) {
45 $extract{$member} = 1;
52 %extract or die "$0: couldn't find symbols for $lib\n";
54 my $dir = tempdir(CLEANUP => 1);
57 # print join(' ', '+', $ar, 'x', sort keys %extract), "\n";
58 my $res = system $ar, 'x', $libdll, sort keys %extract;
59 die "$0: $ar extraction exited with non-zero status\n" if $res;
62 # Add a dummy .idata object for libtool so that it will think
63 # this library is an import library.
64 my $iname_o = 'd000000.o';
65 $extract{$iname_o} = 1;
66 open my $as_fd, '|-', $as, '-R', '-o', $iname_o, "-";
70 $iname: .asciz "$dllname.dll"
72 close $as_fd or exit 1;
73 system $objcopy, '-j', '.idata$7', $iname_o;
75 $res = system $ar, 'crus', $lib, sort keys %extract;
77 die "$0: ar creation of $lib exited with non-zero status\n" if $res;
81 chdir '/tmp'; # Allow $dir directory removal on Windows