sub stubify($$)
{
my $shlib = shift;
my $output = shift;
my ($pipe, $tmpf);
my $tmpname; do {
$tmpname = tmpnam();
} until sysopen($tmpf, $tmpname, O_RDWR|O_CREAT|O_EXCL, 0666);
close($tmpf);
if ($assembler_out) {
open ($pipe, ">-");
} else {
open ($pipe, "| as -o $tmpname") || die "can't start assembler: $!";
}
read_gen_symbols ($shlib, $pipe);
close ($pipe) || die "Failed to assemble to: $tmpname: $!";
system ("gcc -shared -o $output $tmpname") && die "failed to exec gcc: $!";
unlink $tmpname;
}
sub help_exit()
{
print "Usage: stubify \n";
print "Converts libraries into stubs, and bundles them and their pkg-config files\n";
print "into destdir\n";
print " -R stubbify and include all dependent pkgconfig files\n";
exit 1;
}
sub parse_pkgconfig($$)
{
my $name = shift;
my $file = shift;
my $fh;
my %hash;
my @hashes;
print "parse $file\n";
open ($fh, $file) || die "Can't open $file: $!"; while (<$fh>) {
my ($key, $value); if (/^\s*([^=]+)\s*=\s*([^=]+)\s*$/) {
$key = $1; $value = $2;
} elsif (/^\s*([^:]+)\s*:\s*([^:]+)\s*$/) {
$key = $1; $value = $2;
} elsif (/^\s*$/) {
next;
} else {
die "invalid pkgconfig line: $_\n";
}
chomp ($key); chomp ($value);
$hash{$key} = $value;
}
close ($fh); for my $key (keys (%hash)) {
print "\t'$key'\t=\t'$hash{$key}'\n";
}
$hash{_Name} = $name;
$hash{_File} = $file;
push @hashes, \%hash; if ($recursive &&
!defined $pkg_configs{$name} &&
defined $hash{Requires}) {
my @reqs = (); for my $req (split (/[ ,]/, $hash{Requires})) {
print "parse $req of $name\n";
push @reqs, get_pc_files($req);
}
$hash{_Requires} = \@reqs;
push @hashes, @reqs;
}
$pkg_configs{$name} = \%hash;
return @hashes;
}
sub get_pc_files($)
{
my $name = shift; for my $prefix (@pkg_config_paths) {
my $path = "$prefix/lib/pkgconfig/$name.pc";
return parse_pkgconfig ($name,$path) if (-f $path);
}
die "Failed to find pkg-config file for $name";
}
# primitive substitution
sub get_var($$)
{
my ($pc, $var) = @_;
my $val = $pc->{"$var"}; while ($val =~ m/^(.*)\$\{\s*(\S+)\s*\}(.*)$/) {
$val = $1 . get_var($pc, $2). $3;
}
return $val;
}
sub copy_lib($@)
{
my $lib = shift; while (my $path = shift) {
my $name = "$path/$lib";
next if (! -f $name);
# need to run ldconfig post install ... while (-l $name) {
my $dir = $name;
$dir =~ s/\/[^\/]*$//;
my $link = readlink($name); if ($link =~ m/^\//) {
$name = $link;
} else {
$name = "$dir/$link";
}
}
# ignore /lib - they use monstrous symbol versioning if ($name =~ m/^\/lib/) {
print "\tskipping system library: $lib in $name\n";
return;
}
stubify ($name, "$destdir/$name");
}
}
sub copy_and_stubify ($)
{
my $pc = shift;
`mkdir -p $destdir/usr/lib/pkgconfig`;
`mkdir -p $destdir/$pc->{libdir}` if (defined $pc->{libdir});
`mkdir -p $destdir/$pc->{includedir}` if (defined $pc->{includedir});
# copy .pc across - FIXME, may need to re-write paths
`cp -a $pc->{_File} $destdir/usr/lib/pkgconfig`;
# copy includes across
my @includes = split (/ /, get_var ($pc, "Cflags")); for my $arg (@includes) { if ($arg =~ m/^-I(.*)$/) {
my $srcdir = $1; if (! -d $srcdir || $srcdir eq '/usr/include') {
print "Warning: bogus include of '$srcdir' for pkg $pc->{_Name}\n";
} else {
`mkdir -p $destdir/$srcdir`;
`cp -a $srcdir/* $destdir/$srcdir`;
}
}
}
# stubify libraries
my @libs = split (/ /, get_var ($pc, "Libs"));
my @libpath = ( "/lib", "/usr/lib" ); for my $arg (@libs) { if ($arg =~ m/^-l(.*)$/) {
my $lib = "lib".$1.".so"; # print "lib $lib @libpath?\n";
copy_lib ($lib, @libpath);
} elsif ($arg =~ m/^-L(.*)$/) {
my $path = $1;
push (@libpath, $path) if (! grep ($path, @libpath));
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.