From 2fedb100ca84a94868e33f871e77b6379c3748c9 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 8 Oct 2013 17:47:25 -0700 Subject: Add a tool to scan for dependencies on Windows Similar to ldd on Linux. Signed-off-by: Thiago Macieira --- scripts/win-ldd.pl | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 scripts/win-ldd.pl (limited to 'scripts') 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 () { + last if /^The Import Tables/; + } + while () { + 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"; +} -- cgit v1.2.3-70-g09d2 From 245e29a72e47177b3337f7046b6bb0702888e3d8 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 8 Oct 2013 21:07:43 -0700 Subject: Use the $PATH environment variable to pass extra dirs for DLLs Unix developers, look away... this is how it's done on Windows: the binary loader searches $PATH for the DLLs, so let's reuse the same variable. This simplifies the command-line a little. Signed-off-by: Thiago Macieira --- scripts/win-ldd.pl | 2 +- subsurface-install.pri | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/win-ldd.pl b/scripts/win-ldd.pl index 8af449a7b..6ca97b74a 100644 --- a/scripts/win-ldd.pl +++ b/scripts/win-ldd.pl @@ -2,7 +2,7 @@ use strict; my %deploy; my $objdump = $ENV{objdump} ? $ENV{objdump} : "i686-w64-mingw32-objdump"; -my @searchdirs; +my @searchdirs = split(/:/, $ENV{PATH}); sub addDependenciesFor($) { open OBJDUMP, "-|", $objdump, "-p", $_[0] or die; diff --git a/subsurface-install.pri b/subsurface-install.pri index 37c8e077f..c71ae0ada 100644 --- a/subsurface-install.pri +++ b/subsurface-install.pri @@ -51,8 +51,8 @@ mac { !win32-msvc* { #!equals($$QMAKE_HOST.os, "Windows"): dlls.commands += OBJDUMP=`$(CC) -dumpmachine`-objdump + dlls.commands += PATH=\$\$PATH:`$(CC) -print-search-dirs | $(SED) -nE \'/^libraries: =/{s///;s,/lib/?(:|\\\$\$),/bin\\1,g;p;q;}\'` dlls.commands += perl $$PWD/scripts/win-ldd.pl $(DESTDIR_TARGET) - dlls.commands += `$(CC) -print-search-dirs | $(SED) -n \'/^libraries: =/{s///;s/:/\\n/g;p;q;}\' | $(SED) -E \'s,/lib/?\\\$\$,/bin,\'` dlls.commands += $$LIBS dlls.commands += | while read name; do $(INSTALL_FILE) \$\$name $$PWD/$$WINDOWSSTAGING; done dlls.depends = $(DESTDIR_TARGET) -- cgit v1.2.3-70-g09d2