Lingua-NATools
view release on metacpan or search on metacpan
inc/MyBuilder.pm view on Meta::CPAN
'server.o' => ['server.c'],
'adddic.o' => ['adddic.c'],
'ipfp.o' => ['ipfp.c'],
'ntdump.o' => ['ntdump.c'],
'matrix.o' => ['matrix.c', 'matrix.h'],
'initmat.o' => ['initmat.c'],
'mkdict.o' => ['mkdict.c'],
'ngrams_bdb.o' => ['ngrams_bdb.c'],
'ssentence.o' => ['search_sentence.c'],
'sent_align.o' => ['sent_align.c'],
'words2id.o' => ['words2id.c'],
'pre.o' => ['pre.c'],
);
sub _CC_ {
my ($builder, %ops) = @_;
my ($stdout, $stderr, $result) = capture { eval { $builder->compile(%ops); } };
if (!$result) {
print STDERR $stderr;
print STDOUT $stdout;
} else {
no warnings;
print LOG $stdout;
}
}
sub _LD_ {
my ($builder, %ops) = @_;
my ($stdout, $stderr, $result) = capture { eval { $builder->link_executable(%ops) } };
if (!$result) {
print STDERR $stderr;
print STDOUT $stdout;
} else {
no warnings;
print LOG $stdout;
}
}
sub _LOG_ {
print LOG @_,"\n";
print @_,"\n";
}
sub ACTION_pre_install {
my $self = shift;
# Fix the path to the library in case the user specified it during install
if (defined $self->{properties}{install_base}) {
my $usrlib = catdir($self->{properties}{install_base} => 'lib');
$self->install_path( 'usrlib' => $usrlib );
warn "libnatools will install on $usrlib. Be sure to add it to your LIBRARY_PATH\n"
}
## XXX
# if ($^O ne "MSWin32") {
# # Create and prepare for installation the .pc file if not under windows.
# _interpolate('jspell.pc.in' => 'jspell.pc',
# VERSION => $self->notes('version'),
# EXECPREFIX => $self->install_destination('bin'),
# LIBDIR => $self->install_destination('usrlib'));
# $self->copy_if_modified( from => "jspell.pc",
# to_dir => catdir('blib','pcfile'),
# flatten => 1 );
# $self->copy_if_modified( from => catfile('src','jslib.h'),
# to_dir => catdir('blib','incdir'),
# flatten => 1);
# }
}
sub ACTION_fakeinstall {
my $self = shift;
$self->dispatch("pre_install");
$self->SUPER::ACTION_fakeinstall;
}
sub ACTION_install {
my $self = shift;
$self->dispatch("pre_install");
$self->SUPER::ACTION_install;
# Run ldconfig if root
if ($^O =~ /linux/ && $ENV{USER} eq 'root') {
my $ldconfig = Config::AutoConf->check_prog("ldconfig");
my $libdir = $self->notes('libdir');
my $found = 0;
# 1. check if libdir is available
my $lines = `$ldconfig -v`;
for my $line (split /\n/, $lines) {
$found++ if $line =~ /^$libdir:/;
}
if (!$found && open X, ">>", '/etc/ld.so.conf') {
print X "$libdir\n";
close X;
}
system $ldconfig if -x $ldconfig;
}
}
sub ACTION_code {
my $self = shift;
open LOG, ">", "build.log" or die "Can't write on build.log";
for my $path (
catdir("blib","bindoc"),
# catdir("blib","pcfile"),
# catdir("blib","incdir"),
# catdir("blib","script"),
catdir("blib","bin")
) {
mkpath $path unless -d $path;
}
$self->_set_libbuilder();
my_yapp(module => 'Lingua::NATools::PatternRules',
output => 'lib/Lingua/NATools/PatternRules.pm',
input => 'lib/Lingua/NATools/PatternRules.yp');
$self->dispatch("create_manpages");
inc/MyBuilder.pm view on Meta::CPAN
# }
}
sub ACTION_create_objects {
my $self = shift;
my $libbuilder = $self->notes('libbuilder');
mkpath "_build/objects" unless -d "_build/objects";
my $cflags = $self->notes('cflags');
$cflags .= " -DMISSES_WCSDUP" unless $self->notes('have_wcsdup');
$cflags .= " -g -Wall -Werror" if $pedantic;
for my $object (keys %o_deps) {
my @deps = map { "src/$_" } @{$o_deps{$object}};
my $obj = "_build/objects/$object";
next if $self->up_to_date(\@deps, $obj);
_LOG_ " [cc] $deps[0]";
_CC_ $libbuilder => (object_file => $obj,
source => $deps[0],
include_dirs => ["src"],
extra_compiler_flags => $cflags);
}
}
sub ACTION_create_apps {
my $self = shift;
mkpath "_build/apps" unless -d "_build/apps";
my $libs = $self->notes('libs');
if ($self->notes('lddlflags_had_local_lib')
||
$self->notes('ldflags_had_local_lib'))
{
$libs = " -L/usr/local/lib $libs";
}
$libs = "-L_build/lib -lnatools $libs";
my $libbuilder = $self->notes('libbuilder');
my $EXE = $libbuilder->{exeext};
for my $app (keys %app_deps) {
my @deps = map { "_build/objects/$_" } @{$app_deps{$app}};
my $exe = "nat-$app$EXE";
my $exepath = "_build/apps/$exe";
next if $self->up_to_date(\@deps, $exepath);
_LOG_ " [ld] $exe";
_LD_ $libbuilder => (exe_file => $exepath,
objects => \@deps,
extra_linker_flags => $libs);
$self->copy_if_modified(from => $exepath, to_dir => "blib/script", flatten => 1);
}
}
sub ACTION_create_library {
my $self = shift;
my $libbuilder = $self->notes('libbuilder');
my $LIBEXT = $libbuilder->{libext};
my @objects = map { "_build/objects/$_" } keys %lib_deps;
my $libpath = $self->notes('libdir');
$libpath = catfile($libpath, "libnatools$LIBEXT");
mkpath "_build/lib" unless -d "_build/lib";
my $libfile = catfile("_build","lib","libnatools$LIBEXT");
my $extralinkerflags = $self->notes('libs');
$extralinkerflags.= " -install_name $libpath" if $^O =~ /darwin/;
if (!$self->up_to_date(\@objects, $libfile)) {
_LOG_ " [ld] building libnatools$LIBEXT";
if ($self->notes('lddlflags_had_local_lib')
||
$self->notes('ldflags_had_local_lib'))
{
$extralinkerflags = "-L/usr/local/lib $extralinkerflags";
}
my ($stdout, $stderr, $result) = capture {
eval {
$libbuilder->link(module_name => 'libnatools',
extra_linker_flags => $extralinkerflags,
objects => \@objects,
lib_file => $libfile,
);
}
};
if (!$result) {
print STDERR $stderr;
print STDOUT $stdout;
exit 1;
}
}
my $libdir = catdir($self->blib, 'usrlib');
mkpath( $libdir, 0, 0777 ) unless -d $libdir;
$self->copy_if_modified( from => $libfile,
to_dir => $libdir,
flatten => 1 );
}
sub ACTION_create_test_binaries {
my $self = shift;
my %tests = (
'words' => ['words_t.c'],
'corpus' => ['corpus_t.c'],
);
my $libbuilder = $self->notes('libbuilder');
my $cflags = $self->notes('cflags');
$cflags .= " -DMISSES_WCSDUP" unless $self->notes('have_wcsdup');
$cflags .= " -g -Wall -Werror" if $pedantic;
my $ldlibs = "";
if ($self->notes('lddlflags_had_local_lib')
||
$self->notes('ldflags_had_local_lib'))
{
$ldlibs = " -L/usr/local/lib ";
}
my $libs = join(" ",
"-L_build/lib -lnatools",
$ldlibs,
$self->notes('libs'));
my $EXE = $libbuilder->{exeext};
for my $test (keys %tests) {
my @deps = map { "t/bin/$_" } @{$tests{$test}};
my $exe = $test.$EXE;
my $object = "t/bin/$test.o";
my $exepath = "t/bin/$exe";
next if $self->up_to_date(\@deps, $exepath);
_CC_ $libbuilder => (object_file => $object,
source => $deps[0],
include_dirs => ["src"],
extra_compiler_flags => $cflags);
_LD_ $libbuilder => (exe_file => $exepath,
objects => [$object],
extra_linker_flags => $libs);
}
}
sub ACTION_test {
my $self = shift;
$self->_set_libbuilder;
$self->dispatch('create_test_binaries');
if ($^O =~ /mswin32/i) {
$ENV{PATH} = join(";",
catdir($self->blib,"script"),
( run in 1.372 second using v1.01-cache-2.11-cpan-140bd7fdf52 )