version 1.22, 2012/07/08 09:36:31 |
version 1.23, 2012/07/08 10:42:25 |
|
|
use strict; |
use strict; |
use warnings; |
use warnings; |
use feature qw(say switch state); |
use feature qw(say switch state); |
use Cwd qw(getcwd abs_path); |
use Cwd qw(getcwd); |
use File::Basename; |
|
use File::Glob ':glob'; |
use File::Glob ':glob'; |
use File::Path; |
use File::Path; |
|
|
use LT::Trace; |
use LT::Trace; |
use LT::Exec; |
use LT::Exec; |
use LT::Util; |
use LT::Util; |
|
use LT::Getopt; |
|
|
$SIG{__DIE__} = sub { |
$SIG{__DIE__} = sub { |
require Carp; |
require Carp; |
|
|
} |
} |
|
|
package LT::Mode; |
package LT::Mode; |
|
use LT::Util; |
|
|
sub new |
sub new |
{ |
{ |
|
|
if (defined $mode_maker->{$mode}) { |
if (defined $mode_maker->{$mode}) { |
return $mode_maker->{$mode}->new($origin); |
return $mode_maker->{$mode}->new($origin); |
} else { |
} else { |
# XXX invokved from getopt, can't die yet. |
shortdie "Mode=$mode not implemented yet.\n"; |
say STDERR "Mode=$mode not implemented yet.\n"; |
|
exit 1; |
|
} |
} |
} |
} |
|
|
|
|
|
|
package LT::Options; |
package LT::Options; |
use Getopt::Long; |
use Getopt::Long; |
|
use LT::Util; |
|
our @ISA = qw(LT::Getopt); |
|
|
my @valid_modes = qw(compile clean execute finish install link uninstall); |
my @valid_modes = qw(compile clean execute finish install link uninstall); |
|
|
|
|
{ |
{ |
my ($self, $value) = @_; |
my ($self, $value) = @_; |
if ($value =~ m/[^\-\w,\/]/) { |
if ($value =~ m/[^\-\w,\/]/) { |
# XXX stupid Getopt pre-empts die ! |
shortdie "invalid tag name: $value"; |
say STDERR "invalid tag name: $value"; |
|
exit 1; |
exit 1; |
} |
} |
if (grep {$value eq $_} @known_tags) { |
if (grep {$value eq $_} @known_tags) { |
|
|
package main; |
package main; |
|
|
use subs qw( |
use subs qw( |
create_symlinks |
|
help |
help |
notyet |
|
); |
); |
|
|
my $ltconfig = LT::OSConfig->new; |
my $ltconfig = LT::OSConfig->new; |
|
|
} |
} |
|
|
my $gp = LT::Options->new; |
my $gp = LT::Options->new; |
$gp->getoptions('config' => \&config, |
$gp->handle_options('-config' => \&config, |
'debug' => sub { |
'-debug|x' => sub { |
LT::Trace->set($_[1]); |
LT::Trace->set(1); |
LT::Exec->verbose_run; |
LT::Exec->verbose_run; |
}, |
}, |
'dry-run|n' => sub { LT::Exec->dry_run; }, |
'-dry-run|-dryrun|n' => sub { LT::Exec->dry_run; }, |
'features' => sub { |
'-features' => sub { |
my $v = `uname -r`; |
my $v = `uname -r`; |
chomp $v; |
chomp $v; |
say "host: $ltconfig->{gnu_arch}-unknown-openbsd$v"; |
say "host: $ltconfig->{gnu_arch}-unknown-openbsd$v"; |
|
|
say "enable static libraries"; |
say "enable static libraries"; |
exit 0; |
exit 0; |
}, |
}, |
'finish' => sub { $mode = LT::Mode::Finish->new('--finish'); }, |
'-finish' => sub { $mode = LT::Mode::Finish->new('--finish'); }, |
'help' => \&help, # does not return |
'-help|?|h' => \&help, # does not return |
'mode=s{1}' => sub { |
'-mode=' => sub { |
$mode = LT::Mode->factory($_[1], "--mode=$_[1]"); |
$mode = LT::Mode->factory($_[2], "--mode=$_[2]"); |
}, |
}, |
'quiet' => sub { $verbose = 0; }, |
'-quiet|-silent|-no-verbose' => sub { $verbose = 0; }, |
'silent' => sub { $verbose = 0; }, |
'-verbose|-no-silent|-no-quiet|v' => sub {$verbose = 1;}, |
'tag=s{1}' => sub { $gp->add_tag($_[1]); }, |
'-tag=' => sub { $gp->add_tag($_[2]); }, |
'version' => sub { |
'-version' => sub { |
say "libtool (not (GNU libtool)) $version" ; |
say "libtool (not (GNU libtool)) $version" ; |
exit 0; |
exit 0; |
}, |
}, |
|
|
exit 0; |
exit 0; |
} |
} |
|
|
sub notyet |
|
{ |
|
die "Option not implemented yet.\n"; |
|
} |
|
|
|
sub config |
sub config |
{ |
{ |
$ltconfig->dump; |
$ltconfig->dump; |
exit 0; |
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; |
|
} |
} |
|
|