Change copy-dlls to be mingw-only and work with cmake

This commit is contained in:
Jay Berkenbilt 2022-03-09 16:58:29 -05:00 committed by Jay Berkenbilt
parent dad8a3e6ea
commit 4a896f1798
1 changed files with 12 additions and 30 deletions

View File

@ -1,14 +1,14 @@
#!/usr/bin/env perl #!/usr/bin/env perl
require 5.008; require 5.008;
BEGIN { $^W = 1; } use warnings;
use strict; use strict;
use File::Basename; use File::Basename;
use File::Path qw(make_path);
my $whoami = basename($0); my $whoami = basename($0);
usage() unless @ARGV == 4; usage() unless @ARGV == 3;
my ($file, $destdir, $objdump, $windows_wordsize) = @ARGV; my ($file, $libqpdf, $destdir) = @ARGV;
my $filedir = dirname($file); my $filedir = dirname($file);
my $sep = ($^O eq 'MSWin32' ? ';' : ':'); my $sep = ($^O eq 'MSWin32' ? ';' : ':');
@ -20,28 +20,6 @@ foreach my $var (qw(LIB))
push(@path, split($sep, $ENV{$var})); push(@path, split($sep, $ENV{$var}));
} }
} }
my $redist_suffix = (($windows_wordsize eq '64') ? "x64" : "x86");
if (exists $ENV{'VCINSTALLDIR'})
{
my $redist = $ENV{'VCINSTALLDIR'} . "/Redist/$redist_suffix";
if (opendir(D, $redist))
{
my @entries = readdir(D);
closedir(D);
foreach my $e (@entries)
{
if ($e =~ m/\.CRT$/i)
{
unshift(@path, "$redist/$e");
}
}
}
}
if (exists $ENV{'UniversalCRTSdkDir'})
{
my $redist = $ENV{'UniversalCRTSdkDir'} . "/Redist/ucrt/DLLs/$redist_suffix";
unshift(@path, $redist);
}
my $format = undef; my $format = undef;
my @to_find = get_dlls($file); my @to_find = get_dlls($file);
@ -53,13 +31,16 @@ while (@to_find)
{ {
my $dll = shift(@to_find); my $dll = shift(@to_find);
my $found = 0; my $found = 0;
foreach my $dir (@path) foreach my $dir ($libqpdf, @path)
{ {
if ((-f "$dir/$dll") && is_format("$dir/$dll", $format)) if ((-f "$dir/$dll") && is_format("$dir/$dll", $format))
{ {
if (! exists $final{$dll}) if (! exists $final{$dll})
{ {
$final{$dll} = "$dir/$dll"; if ($dir ne $libqpdf)
{
$final{$dll} = "$dir/$dll";
}
push(@to_find, get_dlls("$dir/$dll")); push(@to_find, get_dlls("$dir/$dll"));
} }
$found = 1; $found = 1;
@ -77,6 +58,7 @@ if (@notfound)
join(', ', @notfound), "\n"; join(', ', @notfound), "\n";
} }
make_path($destdir);
foreach my $dll (sort keys (%final)) foreach my $dll (sort keys (%final))
{ {
my $f = $final{$dll}; my $f = $final{$dll};
@ -90,7 +72,7 @@ sub get_dlls
{ {
my @result = (); my @result = ();
my $exe = shift; my $exe = shift;
open(O, "$objdump -p \"$exe\"|") or die "$whoami: can't run objdump\n"; open(O, "objdump -p \"$exe\"|") or die "$whoami: can't run objdump\n";
while (<O>) while (<O>)
{ {
if (m/^\s+DLL Name:\s+(.+\.dll)/i) if (m/^\s+DLL Name:\s+(.+\.dll)/i)
@ -141,5 +123,5 @@ sub is_format
sub usage sub usage
{ {
die "Usage: $whoami {exe|dll} destdir\n"; die "Usage: $whoami {exe|dll} libqpdf-dir destdir\n";
} }