Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use File::Basename;
- use File::Path qw/make_path/;
- use File::Copy;
- my $qt_plugins_root = "/c/Qt/4.7.4/plugins";
- # @todo opendir; readdir; closedir
- my %qt_plugins = (
- '--qsqlite' => $qt_plugins_root . '/sqldrivers/qsqlite4.dll',
- '--qsqlmysql' => $qt_plugins_root . '/sqldrivers/qsqlmysql4.dll',
- '--qsqlodbc' => $qt_plugins_root . '/sqldrivers/qsqlodbc4.dll',
- '--qsqlpsql' => $qt_plugins_root . '/sqldrivers/qsqlpsql4.dll',
- '--qmysql' => $qt_plugins_root . '/sqldrivers/qsqlmysql4.dll',
- '--qodbc' => $qt_plugins_root . '/sqldrivers/qsqlodbc4.dll',
- '--qpsql' => $qt_plugins_root . '/sqldrivers/qsqlpsql4.dll',
- '--qgif' => $qt_plugins_root . '/imageformats/qgif4.dll',
- '--qico' => $qt_plugins_root . '/imageformats/qico4.dll',
- '--qjpeg' => $qt_plugins_root . '/imageformats/qjpeg4.dll',
- '--qmng' => $qt_plugins_root . '/imageformats/qmng4.dll',
- '--qsvg' => $qt_plugins_root . '/imageformats/qsvg4.dll',
- '--qtiff' => $qt_plugins_root . '/imageformats/qtiff4.dll'
- );
- sub usage {
- print STDERR "Usage: " . $0 . " [-f] [-n] [-s] [-c] app.exe [foo.dll] [bar.dll] \n";
- print STDERR " -f print found dlls\n";
- print STDERR " -n print not found dlls\n";
- print STDERR " -s print system dlls\n";
- print STDERR " -c copy dependecies to 'distribution' directory\n";
- print STDERR "Include Qt plugins: \n";
- my @plugins = keys %qt_plugins;
- my @plugins1 = @plugins[0..8];
- my @plugins2 = @plugins[9..scalar(@plugins)-1];
- my @plugins3 = ('--imageformats','--qsql');
- print STDERR " " . join(',',@plugins1) . ",\n";
- print STDERR " " . join(',',@plugins2) . ",\n";
- print STDERR " " . join(',',@plugins3) . "\n";
- print STDERR "Example: " . $0 . " -c release/myapp.exe --qmysql debug/options.ini\n";
- }
- sub dlls {
- my ($path) = @_;
- #print STDERR $path . "\n";
- my %result = ();
- my @deps = split("\n",`objdump -p "$path" | grep "DLL Name:"`);
- for my $dep (@deps) {
- if ($dep =~ /DLL Name: (.*)/) {
- my $n = $1;
- my $p = `which "$n"`;
- $p =~ s/\n//;
- $result{$n} = $p;
- }
- }
- return %result;
- }
- # -f found -n not found -s system
- #ls /c/Qt/4.7.4/plugins/sqldrivers/ | grep '.*[^d]\.dll' | sed 's,4.dll,,'
- my $print_found = 0;
- my $print_notfound = 0;
- my $print_system = 0;
- my $copy_dependencies = 0;
- my @bins = ();
- my %deps = ();
- if (scalar(@ARGV)<1) {
- usage();
- exit(0);
- }
- sub plugin_bin {
- my ($bins,$arg) = @_;
- push(@$bins,$qt_plugins{$arg});
- }
- #my $include_dll = 0;
- #my $include_exe = 0;
- for my $arg (@ARGV) {
- if ($arg eq '-f') {
- $print_found = 1;
- } elsif ($arg eq '-n') {
- $print_notfound = 1;
- } elsif ($arg eq '-s') {
- $print_system = 1;
- } elsif ($arg eq '-c') {
- $copy_dependencies = 1;
- } elsif ($arg eq "-h" || $arg eq "--help") {
- usage();
- exit(0);
- } elsif ( exists $qt_plugins{$arg} ) {
- plugin_bin(\@bins,$arg);
- } elsif ($arg eq '--imageformats') {
- plugin_bin(\@bins,$_) foreach ('--qgif','--qico','--qjpeg','--qmng','--qsvg','--qtiff');
- } elsif ($arg eq '--qsql') {
- plugin_bin(\@bins,$_) foreach ('--qsqlite','--qsqlmysql','--qsqlodbc','--qsqlpsql');
- } else {
- push(@bins,$arg);
- }
- }
- #print join("\n",@bins) . "\n"; exit(0); #debug
- if ($print_found+$print_notfound+$print_system == 0) {
- $print_found = 1;
- $print_notfound = 1;
- $print_system = 1;
- }
- if (scalar(@bins)==0) {
- print STDERR "Error: pass executable[s] path[es].\n";
- usage();
- exit(-1);
- }
- for my $bin (@bins) {
- %deps = (%deps, dlls($bin));
- }
- #my @deps_ = keys(%deps);
- #print join("\n",values(%deps)) . "\n";
- my %complete = ();
- my $iscomplete = 0;
- while (!$iscomplete) {
- $iscomplete = 1;
- for my $dep (keys %deps) {
- #print STDERR "dep $dep\n";
- #print STDERR "exists\n" if exists $complete{$dep};
- #print STDERR "matches\n" if $deps{$dep} =~ /Windows.system32/;
- if (!exists $complete{$dep} && !($deps{$dep} =~ /Windows.system32/)) {
- $iscomplete = 0;
- my %deps_ = dlls($deps{$dep});
- #print STDERR "deps for " . $deps{$dep} . ":\n" . join("\n",values(%deps_)) . "\n";
- %deps = (%deps, %deps_);
- $complete{$dep} = 1;
- }
- }
- }
- my @found = sort map { $deps{$_} } grep { length($deps{$_}) > 0 && !($deps{$_} =~ /Windows.system32/) } keys %deps;
- my @notfound = sort grep { length($deps{$_}) == 0 } keys %deps;
- my @system = sort map { $deps{$_} } grep { $deps{$_} =~ /Windows.system32/ } keys %deps;
- my $print_header = 0;
- if ($print_found+$print_notfound+$print_system > 1) {
- $print_header = 1;
- }
- if ($print_found) {
- print "FOUND DLLS:\n" if $print_header;
- print join("\n",@found) . "\n" if scalar(@found)>0;
- }
- if ($print_notfound) {
- print "NOT FOUND DLLS:\n" if $print_header;
- print join("\n",@notfound) . "\n" if scalar(@notfound)>0;
- }
- if ($print_system) {
- print "SYSTEM DLLS:\n" if $print_header;
- print join("\n",@system) . "\n" if scalar(@system)>0;
- }
- my $qt_conf = 0;
- my $dest = './distribution';
- if ($copy_dependencies) {
- if ( ! -d $dest ) {
- mkdir($dest);
- }
- for my $dep (@found) {
- #print "cp $dep $dest\n";
- copy($dep,$dest);
- }
- for my $bin (@bins) {
- if (index($bin,$qt_plugins_root)>-1) {
- if ($bin =~ m,.*/(plugins/.*),) {
- my $dest_ = dirname($dest . '/' . $1);
- #print $bin . ' dest: ' . $dest_ . "\n"; #debug
- if (! -d $dest_) {
- make_path($dest_);
- }
- copy($bin,$dest_); # @todo overwrite only if newer
- $qt_conf = 1;
- }
- } else {
- #print 'cp ' . $bin . ' ' . $dest . "\n"; #debug
- copy($bin,$dest); # @todo overwrite only if newer
- }
- }
- }
- if ($qt_conf) {
- my $dest_ = $dest . '/qt.conf';
- if ( ! -f $dest_) {
- open OUTPUT,'>', $dest_;
- print OUTPUT "[Paths]\nPlugins = ./plugins\n";
- close OUTPUT;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement