Skip to content

Instantly share code, notes, and snippets.

Created Dec 2, 2013
What would you like to do?
Lddcollect is a small tool which packs up and installs binaries, libraries and related files no a linux (possibly unix) machine.
use strict;
use warnings;
my $cmd = $ARGV[0];
if (scalar(@ARGV) < 2 or ($cmd ne "c" and $cmd ne "i" and $cmd ne "r")) {
print "Usage: lddcollect [cir] [binary/tgz/dir] [extra]\n\n";
print "Lddcollect is a small tool which packs up and installs binaries, libraries and related files.\n";
print "The tool was created to pack up cross compiled software in a small package and unpack and install it on the target machine.\n";
print "The target machine being so small memory/disk wise and slow normal distro's or packaging does not apply.\n";
print "\nArguments: c for creating and archive, i for installing an archive, r for running (in place) an archive.\n";
print "At least the binary or the location to run or install needs to be provided, and if there is more, like data files etc, they can be provided on the rest of the commandline.\n";
print "\nLicenced under the GPL. Created by T. Luyben 2000.\n";
my $tmpdir = "/tmp/binpack";
my %found = ();
sub findLibs {
my ($bin) = @_;
my @libs = `ldd $bin`;
foreach(@libs) {
if (my ($want, $have) = /(.*?)=>(.*)/) {
$want =~ s/^\s+|\s+$//g ;
if ($have =~ /(.*)\s+\(0x.*\)/) {
$have = $1;
$have =~ s/^\s+|\s+$//g ;
if ($have =~ /not found/) {
print "Cannot find $want, please resolve this before continuing!\n";
if (!$found{$have}) {
print "Found required lib: $have, copying to $tmpdir/libs\n";
print `cp $have $tmpdir/libs`;
# recurse
$found{$have} = 1;
# creating an archive
if ($cmd eq "c") {
`rm -fR $tmpdir 2>&1; mkdir $tmpdir; mkdir $tmpdir/libs`;
my $file = $ARGV[1];
if (not -e $file) {
print "File $file does not exist!\n";
`cp $file $tmpdir/runme`;
# now we resolve all libs; ze fun part!
my @libs = ();
# pack it up!
my $tgz = "$file.tgz";
if ($file =~ /^.*\/(.*)$/) {
$tgz = "$1.tgz";
my $pwd = `pwd`;
print `cd $tmpdir; tar czf $pwd/$tgz .`;
} elsif ($cmd eq "r") {
my $dir = $ARGV[1];
if (not -d $dir) {
print "Directory $dir to run in does not exist!\n";
print `cd $dir; LD_LIBRARY_PATH=./libs; ./runme`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment