summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2012-07-10 16:41:02 +0000
committerMarc Espie <espie@cvs.openbsd.org>2012-07-10 16:41:02 +0000
commitf593257db8ce46cc010d2354b98ccf5790d294bc (patch)
treee393b64be4dcddaf84fb492da22ae6976a97503b
parentdc9bd4218a829331d3ce7723cb61c14e4717b55b (diff)
ouch, Rresolved and libsearchdirs no longer live in main, so make them
part of $gp as they should be... Oh, and create an actual linker object for later.
-rw-r--r--usr.bin/libtool/LT/LaFile.pm11
-rw-r--r--usr.bin/libtool/LT/Linker.pm10
-rw-r--r--usr.bin/libtool/LT/Mode/Link.pm42
-rw-r--r--usr.bin/libtool/LT/Parser.pm17
-rw-r--r--usr.bin/libtool/LT/Program.pm13
5 files changed, 59 insertions, 34 deletions
diff --git a/usr.bin/libtool/LT/LaFile.pm b/usr.bin/libtool/LT/LaFile.pm
index 2255def2e8d..5cc7d6905f7 100644
--- a/usr.bin/libtool/LT/LaFile.pm
+++ b/usr.bin/libtool/LT/LaFile.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: LaFile.pm,v 1.11 2012/07/10 15:53:26 espie Exp $
+# $OpenBSD: LaFile.pm,v 1.12 2012/07/10 16:41:00 espie Exp $
# Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org>
# Copyright (c) 2012 Marc Espie <espie@openbsd.org>
@@ -152,7 +152,7 @@ sub find
sub link
{
require LT::Linker;
- return LT::Linker::LaFile->link(@_);
+ return LT::Linker::LaFile->new->link(@_);
}
sub install
@@ -214,7 +214,7 @@ use File::Basename;
sub link
{
- my ($class, $self, $ltprog, $ltconfig, $la, $fname, $odir, $shared,
+ my ($linker, $self, $ltprog, $ltconfig, $la, $fname, $odir, $shared,
$objs, $dirs, $libs, $deplibs, $libdirs, $parser, $gp) = @_;
tsay {"creating link command for library (linked ",
@@ -240,8 +240,7 @@ sub link
my $orderedlibs = [];
my $staticlibs = [];
$parser->{args} = $args;
- $args = $parser->parse_linkargs2(\@LT::Linker::Rresolved,
- \@LT::Linker::libsearchdirs, $orderedlibs, $staticlibs, $dirs,
+ $args = $parser->parse_linkargs2($gp, $orderedlibs, $staticlibs, $dirs,
$libs);
tsay {"staticlibs = \n", join("\n", @$staticlibs)};
tsay {"orderedlibs = @$orderedlibs"};
@@ -315,7 +314,7 @@ sub link
tsay {"libfiles:\n",
join("\n", map { $_->{fullpath}//'UNDEF' } @libobjects) };
- $class->create_symlinks($symlinkdir, $libs);
+ $linker->create_symlinks($symlinkdir, $libs);
my $prev_was_archive = 0;
my $libcounter = 0;
foreach my $k (@$finalorderedlibs) {
diff --git a/usr.bin/libtool/LT/Linker.pm b/usr.bin/libtool/LT/Linker.pm
index 43b1dc17d35..16ff6748ffb 100644
--- a/usr.bin/libtool/LT/Linker.pm
+++ b/usr.bin/libtool/LT/Linker.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: Linker.pm,v 1.2 2012/07/10 15:53:26 espie Exp $
+# $OpenBSD: Linker.pm,v 1.3 2012/07/10 16:41:00 espie Exp $
# Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org>
# Copyright (c) 2012 Marc Espie <espie@openbsd.org>
@@ -25,8 +25,12 @@ use LT::Util;
use File::Basename;
use Cwd qw(abs_path);
-# XXX ?
-our (@Rresolved, @libsearchdirs);
+sub new
+{
+ my $class = shift;
+ bless {}, $class;
+}
+
sub create_symlinks
{
my ($self, $dir, $libs) = @_;
diff --git a/usr.bin/libtool/LT/Mode/Link.pm b/usr.bin/libtool/LT/Mode/Link.pm
index f2712bd31a0..15590ad156f 100644
--- a/usr.bin/libtool/LT/Mode/Link.pm
+++ b/usr.bin/libtool/LT/Mode/Link.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Link.pm,v 1.7 2012/07/10 13:32:10 espie Exp $
+# $OpenBSD: Link.pm,v 1.8 2012/07/10 16:41:01 espie Exp $
#
# Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org>
# Copyright (c) 2012 Marc Espie <espie@openbsd.org>
@@ -19,6 +19,35 @@ use strict;
use warnings;
use feature qw(say);
+# let's add the libsearchdirs and -R options there
+package LT::Options;
+
+sub add_libsearchdir
+{
+ my $self = shift;
+ push(@{$self->{libsearchdir}}, @_);
+}
+
+sub libsearchdirs
+{
+ my $self = shift;
+ return @{$self->{libsearchdir}};
+}
+
+# -R options originating from .la resolution
+sub add_R
+{
+ my $self = shift;
+ push(@{$self->{Rresolved}}, @_);
+}
+
+sub Rresolved
+{
+ my $self = shift;
+ $self->{Rresolved} //= [];
+ return @{$self->{Rresolved}};
+}
+
package LT::Mode::Link;
our @ISA = qw(LT::Mode);
@@ -44,7 +73,6 @@ EOH
my $shared = 0;
my $static = 1;
-my @libsearchdirs;
sub run
{
@@ -52,7 +80,6 @@ sub run
my $noshared = $ltconfig->noshared;
my $cmd;
- my @Rresolved; # -R options originating from .la resolution
my $libdirs = []; # list of libdirs
my $libs = {}; # libraries
my $dirs = {}; # paths to find libraries
@@ -94,10 +121,9 @@ sub run
my @RPopts = $gp->rpath; # -rpath options
my @Ropts = $gp->R; # -R options on the command line
- @libsearchdirs = get_search_dirs();
# add the .libs dir as well in case people try to link directly
# with the real library instead of the .la library
- push @libsearchdirs, './.libs';
+ $gp->add_libsearchdir(get_search_dirs(), './.libs');
if (!$gp->o) {
shortdie "No output file given.\n";
@@ -149,7 +175,7 @@ sub run
push(@{$parser->{args}}, "-Wl,-E");
}
- $parser->parse_linkargs1($deplibs, \@Rresolved, \@libsearchdirs,
+ $parser->parse_linkargs1($deplibs, $gp,
$dirs, $libs, $parser->{args}, 0);
$parser->{args} = $parser->{result};
tsay {"end parse_linkargs1"};
@@ -166,7 +192,7 @@ sub run
}
}
my $RPdirs = [];
- @$RPdirs = (@Ropts, @RPopts, @Rresolved);
+ @$RPdirs = (@Ropts, @RPopts, $gp->Rresolved);
$program->{RPdirs} = $RPdirs;
$program->link($ltprog, $ltconfig, $dirs, $libs, $deplibs, $libdirs, $parser, $gp);
@@ -201,7 +227,7 @@ sub run
}
$shared = 0 if $noshared;
- $parser->parse_linkargs1($deplibs, \@Rresolved, \@libsearchdirs,
+ $parser->parse_linkargs1($deplibs, $gp,
$dirs, $libs, $parser->{args}, 0);
$parser->{args} = $parser->{result};
tsay {"end parse_linkargs1"};
diff --git a/usr.bin/libtool/LT/Parser.pm b/usr.bin/libtool/LT/Parser.pm
index 4dffc6817b7..6e566492d48 100644
--- a/usr.bin/libtool/LT/Parser.pm
+++ b/usr.bin/libtool/LT/Parser.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: Parser.pm,v 1.3 2012/07/06 11:30:41 espie Exp $
+# $OpenBSD: Parser.pm,v 1.4 2012/07/10 16:41:00 espie Exp $
# Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org>
# Copyright (c) 2012 Marc Espie <espie@openbsd.org>
@@ -109,8 +109,7 @@ sub resolve_la
sub parse_linkargs1
{
state $seen_pthread = 0;
- my ($self, $deplibs, $Rresolved, $libsearchdirs,
- $dirs, $libs, $args, $level) = @_;
+ my ($self, $deplibs, $gp, $dirs, $libs, $args, $level) = @_;
tsay {"parse_linkargs1, level: $level"};
tsay {" args: @$args"};
my $result = $self->{result};
@@ -140,7 +139,7 @@ sub parse_linkargs1
} elsif ($a =~ m/^-R(.*)/) {
# -R options originating from .la resolution
# those from @ARGV are in @Ropts
- push @$Rresolved, $1;
+ $gp->add_R($1);
} elsif ($a =~ m/^-l(\S+)/) {
my @largs = ();
my $key = $1;
@@ -157,7 +156,7 @@ sub parse_linkargs1
push @$result, $lafile;
next;
} else {
- $libs->{$key}->find($dirs, 1, 0, 'notyet', $libsearchdirs);
+ $libs->{$key}->find($dirs, 1, 0, 'notyet', [$gp->libsearchdirs]);
my @deps = $libs->{$key}->inspect;
foreach my $d (@deps) {
my $k = basename $d;
@@ -171,8 +170,7 @@ sub parse_linkargs1
push @$deplibs, $a;
push(@$result, $a);
my $dummy = []; # no need to add deplibs recursively
- $self->parse_linkargs1($dummy, $Rresolved,
- $libsearchdirs, $dirs, $libs,
+ $self->parse_linkargs1($dummy, $gp, $dirs, $libs,
\@largs, $level+1) if @largs;
} elsif ($a =~ m/(\S+\/)*(\S+)\.a$/) {
(my $key = $2) =~ s/^lib//;
@@ -229,8 +227,7 @@ sub parse_linkargs1
sub parse_linkargs2
{
state $seen_pthread = 0;
- my ($self, $Rresolved, $libsearchdirs, $orderedlibs, $staticlibs,
- $dirs, $libs) = @_;
+ my ($self, $gp, $orderedlibs, $staticlibs, $dirs, $libs) = @_;
tsay {"parse_linkargs2"};
tsay {" args: @{$self->{args}}"};
$self->{result} = [];
@@ -253,7 +250,7 @@ sub parse_linkargs2
} elsif ($a =~ m/^-R(.*)/) {
# -R options originating from .la resolution
# those from @ARGV are in @Ropts
- push @$Rresolved, $1;
+ $gp->add_R($1);
} elsif ($a =~ m/^-l(.*)/) {
my @largs = ();
my $key = $1;
diff --git a/usr.bin/libtool/LT/Program.pm b/usr.bin/libtool/LT/Program.pm
index baf91d79d06..aca1ab413c5 100644
--- a/usr.bin/libtool/LT/Program.pm
+++ b/usr.bin/libtool/LT/Program.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: Program.pm,v 1.9 2012/07/10 15:53:26 espie Exp $
+# $OpenBSD: Program.pm,v 1.10 2012/07/10 16:41:00 espie Exp $
# Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org>
# Copyright (c) 2012 Marc Espie <espie@openbsd.org>
@@ -81,7 +81,7 @@ sub install
sub link
{
require LT::Linker;
- return LT::Linker::Program->link(@_);
+ return LT::Linker::Program->new->link(@_);
}
package LT::Linker::Program;
@@ -93,7 +93,7 @@ use File::Basename;
sub link
{
- my ($class, $self, $ltprog, $ltconfig, $dirs, $libs, $deplibs,
+ my ($linker, $self, $ltprog, $ltconfig, $dirs, $libs, $deplibs,
$libdirs, $parser, $gp) = @_;
tsay {"linking program (", ($gp->static ? "not " : ""),
@@ -117,8 +117,7 @@ sub link
my $staticlibs = [];
$parser->{args} = $args;
$parser->{seen_la_shared} = 0;
- $args = $parser->parse_linkargs2(\@LT::Linker::Rresolved,
- \@LT::Linker::libsearchdirs, $orderedlibs, $staticlibs, $dirs,
+ $args = $parser->parse_linkargs2($gp, $orderedlibs, $staticlibs, $dirs,
$libs);
tsay {"staticlibs = \n", join("\n", @$staticlibs)};
tsay {"orderedlibs = @$orderedlibs"};
@@ -148,7 +147,7 @@ sub link
# add libdirs to rpath if they are not in standard lib path
for my $l (@$libdirs) {
my $found = 0;
- for my $d (@LT::Linker::libsearchdirs) {
+ for my $d ($gp->libsearchdirs) {
if ($l eq $d) { $found = 1; last; }
}
if (!$found) { push @$RPdirs, $l; }
@@ -172,7 +171,7 @@ sub link
tsay {"libs:\n", join("\n", keys %$libs)};
tsay {"libfiles:\n", join("\n", map { $_->{fullpath} } @libobjects)};
- $class->create_symlinks($symlinkdir, $libs);
+ $linker->create_symlinks($symlinkdir, $libs);
foreach my $k (@$finalorderedlibs) {
my $a = $libs->{$k}->{fullpath} || die "Link error: $k not found in \$libs\n";
if ($a =~ m/\.a$/) {