summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorGravatar Thiago Macieira <thiago@macieira.org>2013-10-08 17:47:25 -0700
committerGravatar Thiago Macieira <thiago@macieira.org>2013-10-08 23:29:43 -0700
commit2fedb100ca84a94868e33f871e77b6379c3748c9 (patch)
treef6fa3dd9c18cfb0e815e73400c0d4664132c3103 /scripts
parent57994fa7a19ece18ffbecfabd69216190f62e425 (diff)
downloadsubsurface-2fedb100ca84a94868e33f871e77b6379c3748c9.tar.gz
Add a tool to scan for dependencies on Windows
Similar to ldd on Linux. Signed-off-by: Thiago Macieira <thiago@macieira.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/win-ldd.pl69
1 files changed, 69 insertions, 0 deletions
diff --git a/scripts/win-ldd.pl b/scripts/win-ldd.pl
new file mode 100644
index 000000000..8af449a7b
--- /dev/null
+++ b/scripts/win-ldd.pl
@@ -0,0 +1,69 @@
+#!perl
+use strict;
+my %deploy;
+my $objdump = $ENV{objdump} ? $ENV{objdump} : "i686-w64-mingw32-objdump";
+my @searchdirs;
+
+sub addDependenciesFor($) {
+ open OBJDUMP, "-|", $objdump, "-p", $_[0] or die;
+ while (<OBJDUMP>) {
+ last if /^The Import Tables/;
+ }
+ while (<OBJDUMP>) {
+ next unless /DLL Name: (.*)/;
+ $deploy{$1} = 0 unless defined($deploy{$1});
+ last if /^\w/;
+ }
+ close OBJDUMP;
+}
+
+sub findMissingDependencies {
+ for my $name (keys %deploy) {
+ next if $deploy{$name};
+ my $path;
+ for my $dir (@searchdirs) {
+ my $fpath = "$dir/$name";
+ my $lcfpath = "$dir/" . lc($name);
+ if (-e $fpath) {
+ $path = $fpath;
+ } elsif (-e $lcfpath) {
+ $path = $lcfpath;
+ } else {
+ next;
+ }
+ addDependenciesFor($path);
+ last;
+ }
+
+ $path = "/missing/file" unless $path;
+ $deploy{$name} = $path;
+ }
+}
+
+for (@ARGV) {
+ s/^-L//;
+ next if /^-/;
+ if (-d $_) {
+ push @searchdirs, $_;
+ } elsif (-f $_) {
+ $deploy{$_} = $_;
+ addDependenciesFor($_);
+ }
+}
+
+while (1) {
+ findMissingDependencies();
+
+ my $i = 0;
+ while (my ($name, $path) = each(%deploy)) {
+ next if $path;
+ ++$i;
+ last;
+ }
+ last if $i == 0;
+}
+
+for (sort values %deploy) {
+ next if $_ eq "/missing/file";
+ print "$_\n";
+}