diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2012-07-08 10:42:26 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2012-07-08 10:42:26 +0000 |
commit | 65dbabae5e7ce8992e221b17756d79049c3bed88 (patch) | |
tree | a759eb546af654ef9fc9539b76cff8b239221d77 | |
parent | 5cc866d0b4e778d2d38d8db9c41d30f75e47a78c (diff) |
a few big changes
- start using our options parser for main libtool options
- put link related stuff into their own module.
Long term, some unification should happen.
- shortdie for cases where we know libtool is not at fault.
-rw-r--r-- | usr.bin/libtool/LT/Getopt.pm | 5 | ||||
-rw-r--r-- | usr.bin/libtool/LT/LaFile.pm | 120 | ||||
-rw-r--r-- | usr.bin/libtool/LT/Linker.pm | 65 | ||||
-rw-r--r-- | usr.bin/libtool/LT/Program.pm | 48 | ||||
-rw-r--r-- | usr.bin/libtool/LT/Util.pm | 10 | ||||
-rw-r--r-- | usr.bin/libtool/Makefile | 3 | ||||
-rwxr-xr-x | usr.bin/libtool/libtool | 84 |
7 files changed, 196 insertions, 139 deletions
diff --git a/usr.bin/libtool/LT/Getopt.pm b/usr.bin/libtool/LT/Getopt.pm index 253ea9dbb76..92b8be47bae 100644 --- a/usr.bin/libtool/LT/Getopt.pm +++ b/usr.bin/libtool/LT/Getopt.pm @@ -1,4 +1,4 @@ -# $OpenBSD: Getopt.pm,v 1.2 2012/07/08 10:26:46 espie Exp $ +# $OpenBSD: Getopt.pm,v 1.3 2012/07/08 10:42:25 espie Exp $ # Copyright (c) 2012 Marc Espie <espie@openbsd.org> # @@ -152,6 +152,7 @@ sub match # seems I spend my life rewriting option handlers, not surprisingly... package LT::Getopt; +use LT::Util; # parsing an option 'all-static' will automatically add an @@ -213,7 +214,7 @@ MAINLOOP: next MAINLOOP; } } - die "Unknown option $_\n"; + shortdie "Unknown option $_\n"; } else { unshift(@main::ARGV, $_); last; diff --git a/usr.bin/libtool/LT/LaFile.pm b/usr.bin/libtool/LT/LaFile.pm index 38f77b5f3f7..fb4dd8f1e9c 100644 --- a/usr.bin/libtool/LT/LaFile.pm +++ b/usr.bin/libtool/LT/LaFile.pm @@ -1,4 +1,4 @@ -# $OpenBSD: LaFile.pm,v 1.6 2012/07/08 09:36:40 jasper Exp $ +# $OpenBSD: LaFile.pm,v 1.7 2012/07/08 10:42:25 espie Exp $ # Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org> # Copyright (c) 2012 Marc Espie <espie@openbsd.org> @@ -151,7 +151,70 @@ sub find sub link { - my ($self, $ltprog, $la, $fname, $odir, $shared, $objs, $dirs, + require LT::Linker; + return LT::Linker::LaFile->link(@_); +} + +sub install +{ + my ($class, $src, $dstdir, $instprog, $instopts, $strip) = @_; + + my $srcdir = dirname($src); + my $srcfile = basename($src); + my $dstfile = $srcfile; + + my @opts = @$instopts; + my @stripopts = ('--strip-debug'); + if ($$instprog[-1] =~ m/install([.-]sh)?$/) { + push @opts, '-m', '644'; + } + + my $lainfo = $class->parse($src); + my $sharedlib = $lainfo->{'dlname'}; + my $staticlib = $lainfo->{'old_library'}; + my $laipath = "$srcdir/$ltdir/$srcfile".'i'; + if ($staticlib) { + # do not strip static libraries, this is done below + my @realinstopts = @opts; + @realinstopts = grep { $_ ne '-s' } @realinstopts; + my $s = "$srcdir/$ltdir/$staticlib"; + my $d = "$dstdir/$staticlib"; + LT::Exec->install(@$instprog, @realinstopts, $s, $d); + LT::Exec->install('strip', @stripopts, $d) if $strip; + } + if ($sharedlib) { + my $s = "$srcdir/$ltdir/$sharedlib"; + my $d = "$dstdir/$sharedlib"; + LT::Exec->install(@$instprog, @opts, $s, $d); + } + if ($laipath) { + # do not try to strip .la files + my @realinstopts = @opts; + @realinstopts = grep { $_ ne '-s' } @realinstopts; + my $s = $laipath; + my $d = "$dstdir/$dstfile"; + LT::Exec->install(@$instprog, @realinstopts, $s, $d); + } + # for libraries with a -release in their name + my @libnames = split /\s+/, $lainfo->{'library_names'}; + foreach my $n (@libnames) { + next if $n eq $sharedlib; + unlink("$dstdir/$n"); + symlink($sharedlib, "$dstdir/$n"); + } +} + + +package LT::Linker::LaFile; +our @ISA = qw(LT::Linker); + +use LT::Util; +use LT::Trace; +use File::Basename; + +sub link +{ + my ($class, $self, $ltprog, $la, $fname, $odir, $shared, $objs, $dirs, $libs, $deplibs, $libdirs, $parser, $opts) = @_; tsay {"creating link command for library (linked ", @@ -190,7 +253,7 @@ sub link foreach my $a (@$staticlibs) { if ($a =~ m/\.a$/ && $a !~ m/_pic\.a/) { # extract objects from archive - my $libfile = basename $a; + my $libfile = basename($a); my $xdir = "$odir/$ltdir/${la}x/$libfile"; LT::Archive->extract($xdir, $a); my @kobjs = LT::Archive->get_objlist($a); @@ -251,7 +314,7 @@ sub link tsay {"libfiles:\n", join("\n", map { $_->{fullpath}//'UNDEF' } @libobjects) }; - main::create_symlinks($symlinkdir, $libs); + $class->create_symlinks($symlinkdir, $libs); my $prev_was_archive = 0; my $libcounter = 0; foreach my $k (@$finalorderedlibs) { @@ -291,53 +354,4 @@ sub link LT::Exec->link(@cmd); } -sub install -{ - my ($class, $src, $dstdir, $instprog, $instopts, $strip) = @_; - - my $srcdir = dirname($src); - my $srcfile = basename($src); - my $dstfile = $srcfile; - - my @opts = @$instopts; - my @stripopts = ('--strip-debug'); - if ($$instprog[-1] =~ m/install([.-]sh)?$/) { - push @opts, '-m', '644'; - } - - my $lainfo = $class->parse($src); - my $sharedlib = $lainfo->{'dlname'}; - my $staticlib = $lainfo->{'old_library'}; - my $laipath = "$srcdir/$ltdir/$srcfile".'i'; - if ($staticlib) { - # do not strip static libraries, this is done below - my @realinstopts = @opts; - @realinstopts = grep { $_ ne '-s' } @realinstopts; - my $s = "$srcdir/$ltdir/$staticlib"; - my $d = "$dstdir/$staticlib"; - LT::Exec->install(@$instprog, @realinstopts, $s, $d); - LT::Exec->install('strip', @stripopts, $d) if $strip; - } - if ($sharedlib) { - my $s = "$srcdir/$ltdir/$sharedlib"; - my $d = "$dstdir/$sharedlib"; - LT::Exec->install(@$instprog, @opts, $s, $d); - } - if ($laipath) { - # do not try to strip .la files - my @realinstopts = @opts; - @realinstopts = grep { $_ ne '-s' } @realinstopts; - my $s = $laipath; - my $d = "$dstdir/$dstfile"; - LT::Exec->install(@$instprog, @realinstopts, $s, $d); - } - # for libraries with a -release in their name - my @libnames = split /\s+/, $lainfo->{'library_names'}; - foreach my $n (@libnames) { - next if $n eq $sharedlib; - unlink("$dstdir/$n"); - symlink($sharedlib, "$dstdir/$n"); - } -} - 1; diff --git a/usr.bin/libtool/LT/Linker.pm b/usr.bin/libtool/LT/Linker.pm new file mode 100644 index 00000000000..0a995aa790d --- /dev/null +++ b/usr.bin/libtool/LT/Linker.pm @@ -0,0 +1,65 @@ +# $OpenBSD: Linker.pm,v 1.1 2012/07/08 10:42:25 espie Exp $ + +# Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org> +# Copyright (c) 2012 Marc Espie <espie@openbsd.org> +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +use strict; +use warnings; +use feature qw(say); + +package LT::Linker; +use LT::Trace; +use LT::Util; +use File::Basename; +use Cwd qw(abs_path); + +sub create_symlinks +{ + my ($self, $dir, $libs) = @_; + if (! -d $dir) { + mkdir($dir) or die "Cannot mkdir($dir) : $!\n"; + } + + foreach my $l (values %$libs) { + my $f = $l->{fullpath}; + next if !defined $f; + next if $f =~ m/\.a$/; + my $libnames = []; + if (defined $l->{lafile}) { + require LT::LaFile; + my $lainfo = LT::LaFile->parse($l->{lafile}); + my $librarynames = $lainfo->stringize('library_names'); + @$libnames = split /\s/, $librarynames; + $libnames = reverse_zap_duplicates_ref($libnames); + } else { + push @$libnames, basename($f); + } + foreach my $libfile (@$libnames) { + my $link = "$dir/$libfile"; + tsay {"ln -s $f $link"}; + next if -f $link; + my $p = abs_path($f); + if (!symlink($p, $link)) { + die "Cannot create symlink($p, $link): $!\n" + unless $!{EEXIST}; + } + } + } + return $dir; +} + +1; + + diff --git a/usr.bin/libtool/LT/Program.pm b/usr.bin/libtool/LT/Program.pm index c7e79e9f317..54ef8e839ed 100644 --- a/usr.bin/libtool/LT/Program.pm +++ b/usr.bin/libtool/LT/Program.pm @@ -1,4 +1,4 @@ -# $OpenBSD: Program.pm,v 1.5 2012/07/06 11:30:41 espie Exp $ +# $OpenBSD: Program.pm,v 1.6 2012/07/08 10:42:25 espie Exp $ # Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org> # Copyright (c) 2012 Marc Espie <espie@openbsd.org> @@ -38,7 +38,7 @@ sub write_wrapper my $self = shift; my $program = $self->{outfilepath}; - my $pfile = basename $program; + my $pfile = basename($program); my $realprogram = $ltdir . '/' . $pfile; open(my $pw, '>', $program) or die "Cannot write $program: $!\n"; print $pw <<EOF @@ -68,9 +68,32 @@ EOF chmod 0755, $program; } +sub install +{ + my ($class, $src, $dst, $instprog, $instopts) = @_; + + my $srcdir = dirname $src; + my $srcfile = basename $src; + my $realpath = "$srcdir/$ltdir/$srcfile"; + LT::Exec->install(@$instprog, @$instopts, $realpath, $dst); +} + +sub link +{ + require LT::Linker; + return LT::Linker::Program->link(@_); +} + +package LT::Linker::Program; +our @ISA = qw(LT::Linker); + +use LT::Trace; +use LT::Util; +use File::Basename; + sub link { - my ($self, $ltprog, $dirs, $libs, $deplibs, $libdirs, $parser, + my ($class, $self, $ltprog, $dirs, $libs, $deplibs, $libdirs, $parser, $opts) = @_; tsay {"linking program (", ($opts->{'static'}) ? "not " : "", @@ -80,8 +103,8 @@ sub link my $fpath = $self->{outfilepath}; my $RPdirs = $self->{RPdirs}; - my $odir = dirname $fpath; - my $fname = basename $fpath; + my $odir = dirname($fpath); + my $fname = basename($fpath); my @libflags; my @cmd; @@ -148,14 +171,14 @@ sub link tsay {"libs:\n", join("\n", keys %$libs)}; tsay {"libfiles:\n", join("\n", map { $_->{fullpath} } @libobjects)}; - main::create_symlinks($symlinkdir, $libs); + $class->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$/) { # don't make a -lfoo out of a static library push @libflags, $a; } else { - my $lib = basename $a; + my $lib = basename($a); if ($lib =~ m/^lib(.*)\.so(\.\d+){2}/) { $lib = $1; } else { @@ -176,15 +199,4 @@ sub link push @cmd, "-Wl,-retain-symbols-file,$symbolsfile" if ($symbolsfile); LT::Exec->link(@cmd); } - -sub install -{ - my ($class, $src, $dst, $instprog, $instopts) = @_; - - my $srcdir = dirname $src; - my $srcfile = basename $src; - my $realpath = "$srcdir/$ltdir/$srcfile"; - LT::Exec->install(@$instprog, @$instopts, $realpath, $dst); -} - 1; diff --git a/usr.bin/libtool/LT/Util.pm b/usr.bin/libtool/LT/Util.pm index 1b6c7df6986..59bb11223c4 100644 --- a/usr.bin/libtool/LT/Util.pm +++ b/usr.bin/libtool/LT/Util.pm @@ -1,4 +1,4 @@ -# $OpenBSD: Util.pm,v 1.2 2012/07/06 11:30:41 espie Exp $ +# $OpenBSD: Util.pm,v 1.3 2012/07/08 10:42:25 espie Exp $ # Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org> # Copyright (c) 2012 Marc Espie <espie@openbsd.org> @@ -21,7 +21,7 @@ package LT::Util; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(reverse_zap_duplicates_ref abs_dir $ltdir $version - @picflags $sharedflag); + @picflags $sharedflag shortdie); use File::Basename; use Cwd; @@ -51,4 +51,10 @@ sub abs_dir return dirname(Cwd::abs_path($a)); } +sub shortdie +{ + delete $SIG{__DIE__}; + die @_; +} + 1; diff --git a/usr.bin/libtool/Makefile b/usr.bin/libtool/Makefile index f4c1be144f3..f327da8758e 100644 --- a/usr.bin/libtool/Makefile +++ b/usr.bin/libtool/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.3 2012/07/08 10:12:19 espie Exp $ +# $OpenBSD: Makefile,v 1.4 2012/07/08 10:42:25 espie Exp $ .include <bsd.own.mk> @@ -12,6 +12,7 @@ PACKAGES= \ LT/LaFile.pm \ LT/LaLoFile.pm \ LT/Library.pm \ + LT/Linker.pm \ LT/LoFile.pm \ LT/Mode/Compile.pm \ LT/Mode/Install.pm \ diff --git a/usr.bin/libtool/libtool b/usr.bin/libtool/libtool index 33348b7d1bc..aa0a76e3f6f 100755 --- a/usr.bin/libtool/libtool +++ b/usr.bin/libtool/libtool @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $OpenBSD: libtool,v 1.22 2012/07/08 09:36:31 jasper Exp $ +# $OpenBSD: libtool,v 1.23 2012/07/08 10:42:25 espie Exp $ # Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org> # Copyright (c) 2012 Marc Espie <espie@openbsd.org> @@ -19,14 +19,14 @@ use strict; use warnings; use feature qw(say switch state); -use Cwd qw(getcwd abs_path); -use File::Basename; +use Cwd qw(getcwd); use File::Glob ':glob'; use File::Path; use LT::Trace; use LT::Exec; use LT::Util; +use LT::Getopt; $SIG{__DIE__} = sub { require Carp; @@ -70,6 +70,7 @@ sub dump } package LT::Mode; +use LT::Util; sub new { @@ -93,9 +94,7 @@ sub factory if (defined $mode_maker->{$mode}) { return $mode_maker->{$mode}->new($origin); } else { - # XXX invokved from getopt, can't die yet. - say STDERR "Mode=$mode not implemented yet.\n"; - exit 1; + shortdie "Mode=$mode not implemented yet.\n"; } } @@ -135,6 +134,8 @@ our @ISA = qw(LT::Mode::Empty); package LT::Options; use Getopt::Long; +use LT::Util; +our @ISA = qw(LT::Getopt); my @valid_modes = qw(compile clean execute finish install link uninstall); @@ -157,8 +158,7 @@ sub add_tag { my ($self, $value) = @_; if ($value =~ m/[^\-\w,\/]/) { - # XXX stupid Getopt pre-empts die ! - say STDERR "invalid tag name: $value"; + shortdie "invalid tag name: $value"; exit 1; } if (grep {$value eq $_} @known_tags) { @@ -228,9 +228,7 @@ sub valid_modes package main; use subs qw( - create_symlinks help - notyet ); my $ltconfig = LT::OSConfig->new; @@ -251,13 +249,13 @@ if ($mode = LT::Options->is_abreviated_mode($ARGV[0])) { } my $gp = LT::Options->new; -$gp->getoptions('config' => \&config, - 'debug' => sub { - LT::Trace->set($_[1]); +$gp->handle_options('-config' => \&config, + '-debug|x' => sub { + LT::Trace->set(1); LT::Exec->verbose_run; }, - 'dry-run|n' => sub { LT::Exec->dry_run; }, - 'features' => sub { + '-dry-run|-dryrun|n' => sub { LT::Exec->dry_run; }, + '-features' => sub { my $v = `uname -r`; chomp $v; say "host: $ltconfig->{gnu_arch}-unknown-openbsd$v"; @@ -265,15 +263,15 @@ $gp->getoptions('config' => \&config, say "enable static libraries"; exit 0; }, - 'finish' => sub { $mode = LT::Mode::Finish->new('--finish'); }, - 'help' => \&help, # does not return - 'mode=s{1}' => sub { - $mode = LT::Mode->factory($_[1], "--mode=$_[1]"); + '-finish' => sub { $mode = LT::Mode::Finish->new('--finish'); }, + '-help|?|h' => \&help, # does not return + '-mode=' => sub { + $mode = LT::Mode->factory($_[2], "--mode=$_[2]"); }, - 'quiet' => sub { $verbose = 0; }, - 'silent' => sub { $verbose = 0; }, - 'tag=s{1}' => sub { $gp->add_tag($_[1]); }, - 'version' => sub { + '-quiet|-silent|-no-verbose' => sub { $verbose = 0; }, + '-verbose|-no-silent|-no-quiet|v' => sub {$verbose = 1;}, + '-tag=' => sub { $gp->add_tag($_[2]); }, + '-version' => sub { say "libtool (not (GNU libtool)) $version" ; exit 0; }, @@ -350,49 +348,9 @@ EOF exit 0; } -sub notyet -{ - die "Option not implemented yet.\n"; -} - sub config { $ltconfig->dump; exit 0; } -sub create_symlinks -{ - my ($dir, $libs) = @_; - if (! -d $dir) { - mkdir($dir) or die "Cannot mkdir($dir) : $!\n"; - } - - foreach my $l (values %$libs) { - my $f = $l->{fullpath}; - next if !defined $f; - next if $f =~ m/\.a$/; - my $libnames = []; - if (defined $l->{lafile}) { - require LT::LaFile; - my $lainfo = LT::LaFile->parse($l->{lafile}); - my $librarynames = $lainfo->stringize('library_names'); - @$libnames = split /\s/, $librarynames; - $libnames = reverse_zap_duplicates_ref($libnames); - } else { - push @$libnames, basename($f); - } - foreach my $libfile (@$libnames) { - my $link = "$dir/$libfile"; - tsay {"ln -s $f $link"}; - next if -f $link; - my $p = abs_path($f); - if (!symlink($p, $link)) { - die "Cannot create symlink($p, $link): $!\n" - unless $!{EEXIST}; - } - } - } - return $dir; -} - |