Skip to content

Commit

Permalink
Change copy-dlls to be mingw-only and work with cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
jberkenbilt committed Mar 18, 2022
1 parent dad8a3e commit 4a896f1
Showing 1 changed file with 12 additions and 30 deletions.
42 changes: 12 additions & 30 deletions copy_dlls
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env perl

require 5.008;
BEGIN { $^W = 1; }
use warnings;
use strict;
use File::Basename;
use File::Path qw(make_path);

my $whoami = basename($0);

usage() unless @ARGV == 4;
my ($file, $destdir, $objdump, $windows_wordsize) = @ARGV;
usage() unless @ARGV == 3;
my ($file, $libqpdf, $destdir) = @ARGV;
my $filedir = dirname($file);

my $sep = ($^O eq 'MSWin32' ? ';' : ':');
Expand All @@ -20,28 +20,6 @@ foreach my $var (qw(LIB))
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 @to_find = get_dlls($file);
Expand All @@ -53,13 +31,16 @@ while (@to_find)
{
my $dll = shift(@to_find);
my $found = 0;
foreach my $dir (@path)
foreach my $dir ($libqpdf, @path)
{
if ((-f "$dir/$dll") && is_format("$dir/$dll", $format))
{
if (! exists $final{$dll})
{
$final{$dll} = "$dir/$dll";
if ($dir ne $libqpdf)
{
$final{$dll} = "$dir/$dll";
}
push(@to_find, get_dlls("$dir/$dll"));
}
$found = 1;
Expand All @@ -77,6 +58,7 @@ if (@notfound)
join(', ', @notfound), "\n";
}

make_path($destdir);
foreach my $dll (sort keys (%final))
{
my $f = $final{$dll};
Expand All @@ -90,7 +72,7 @@ sub get_dlls
{
my @result = ();
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>)
{
if (m/^\s+DLL Name:\s+(.+\.dll)/i)
Expand Down Expand Up @@ -141,5 +123,5 @@ sub is_format

sub usage
{
die "Usage: $whoami {exe|dll} destdir\n";
die "Usage: $whoami {exe|dll} libqpdf-dir destdir\n";
}

0 comments on commit 4a896f1

Please sign in to comment.