3 use File
::Temp qw
'tempdir';
14 my ($cpu, $ar, $as, $nm, $objcopy);
15 GetOptions
('exclude=s'=>\
@exclude, 'static!'=>\
$static, 'v!'=>\
$inverse,
16 'cpu=s'=>\
$cpu, 'ar=s'=>\
$ar, 'as=s'=>\
$as,'nm=s'=>\
$nm, 'objcopy=s'=>\
$objcopy);
18 $_ = File
::Spec
->rel2abs($_) for @ARGV;
22 # FIXME? Do other (non-32 bit) arches on Windows still use symbol prefixes?
24 (my $iname = basename
$lib) =~ s/\.a$//o;
25 $iname = $sym_prefix . $iname . '_dll_iname';
27 open my $nm_fd, '-|', $nm, '-Apg', '--defined-only', @ARGV, $libdll or
28 die "$0: execution of $nm for object files failed - $!\n";
34 my $exclude_regex = @exclude ?
join('|', @exclude) : '\\UnLiKeLy//';
35 $exclude_regex = qr/$exclude_regex/;
39 if (/ I _?(.*)_dll_iname/o) {
42 my ($file, $member, $symbol) = m
%^([^:]*):([^:]*(?
=:))?
.* T
(.*)%o;
43 next if !defined($symbol) || $symbol =~ $exclude_regex;
44 if ($file ne $libdll) {
45 $match_syms{$symbol} = 1;
46 } elsif ($match_syms{$symbol} ?
!$inverse : $inverse) {
47 $extract{$member} = 1;
54 %extract or die "$0: couldn't find symbols for $lib\n";
56 my $dir = tempdir
(CLEANUP
=> 1);
59 # print join(' ', '+', $ar, 'x', sort keys %extract), "\n";
60 my $res = system $ar, 'x', $libdll, sort keys %extract;
61 die "$0: $ar extraction exited with non-zero status\n" if $res;
64 # Add a dummy .idata object for libtool so that it will think
65 # this library is an import library.
66 my $iname_o = 'd000000.o';
67 $extract{$iname_o} = 1;
68 open my $as_fd, '|-', $as, '-R', '-o', $iname_o, "-";
72 $iname: .asciz "$dllname.dll"
74 close $as_fd or exit 1;
75 system $objcopy, '-j', '.idata$7', $iname_o;
77 # Enable deterministic archives for reproducible builds.
79 $opts .= 'D' if ($ENV{'SOURCE_DATE_EPOCH'} != '');
81 $res = system $ar, $opts, $lib, sort keys %extract;
83 die "$0: ar creation of $lib exited with non-zero status\n" if $res;
87 chdir '/tmp'; # Allow $dir directory removal on Windows