Skip to content

Commit

Permalink
Simplify build process so external libcld is not required.
Browse files Browse the repository at this point in the history
Instead of libcld just link the .o files from cld-src into the perl XSLoaded module directly

This makes it much easier to use when perl lives in non-standard location (i.e. local::lib or similar)
  • Loading branch information
ashb committed Jun 14, 2013
1 parent 4ccd179 commit b153f04
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 109 deletions.
22 changes: 0 additions & 22 deletions Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,4 @@ my $builder = MyBuilder->new
);


## HACK HACK HACK HACK
my $libdir = $builder->install_destination("bin");
if ($^O =~ /mswin32/i) {
$libdir = $ENV{WINDIR} || 'c:\\WINDOWS\\'; ## HACK HACK HACK
} else {
if ($Config{archname} =~ /^x86_64/) {
$libdir =~ s/\bbin\b/lib64/;
if (!-d $libdir) {
my $test = $libdir;
$test =~ s/lib64/lib/;
$libdir = $test if -d $test;
}
} else {
$libdir =~ s/\bbin\b/lib/;
}
}
$builder->notes('libdir' => $libdir);
$builder->notes('lib_path' => $libdir);

$builder->add_build_element('usrlib');
$builder->install_path( 'usrlib' => $libdir );

$builder->create_build_script;
93 changes: 6 additions & 87 deletions inc/MyBuilder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,6 @@ my @SOURCES = map { "cld-src/$_" }
use ExtUtils::ParseXS;
use ExtUtils::Mkbootstrap;



sub ACTION_install {
my $self = shift;

my $usrlib = $self->install_path( 'usrlib' );

if ($^O =~ /cygwin/i) { # cygwin uses windows lib searching (PATH instead of LD_LIBRARY_PATH)
$self->install_path( 'usrlib' => '/usr/local/bin' );
}
elsif (defined $self->{properties}{install_base}) {
$usrlib = catdir($self->{properties}{install_base} => 'lib');
$self->install_path( 'usrlib' => $usrlib );
}
$self->SUPER::ACTION_install;
if ($^O =~ /linux/ && $ENV{USER} eq 'root') {
my $linux = Config::AutoConf->check_prog("ldconfig");
system $linux if (-x $linux);
}
if ($^O =~ /(?:linux|bsd|sun|sol|dragonfly|hpux|irix|darwin)/
&&
$usrlib !~ m!^/usr(/local)?/lib/?$!)
{
warn "\n** WARNING **\n"
. "It seems you are installing in a non standard path.\n"
. "You might need to add $usrlib to your library search path.\n";
}
}

sub ACTION_code {
my $self = shift;

Expand All @@ -76,7 +47,6 @@ sub ACTION_code {
$self->notes(LDFLAGS => '-L.');

$self->dispatch("create_objects");
$self->dispatch("create_library");
$self->dispatch("compile_xscode");

$self->SUPER::ACTION_code;
Expand Down Expand Up @@ -127,10 +97,14 @@ sub ACTION_compile_xscode {
utime( (time) x 2, $bs_file ); # touch
}

my $extra_linker_flags = "-Lcld-src -lcld -lstdc++";
my $extra_linker_flags = "-lstdc++";
$extra_linker_flags .= " -lgcc_s" if $^O eq 'netbsd';

my $objects = [ $ofile ];
my $objects = [
$ofile,
@{ $self->rscan_dir('cld-src', qr/\.o$/) },
];

# .o => .(a|bundle)
my $lib_file = catfile( $archdir, "CLD.$Config{dlext}" );
if ( !$self->up_to_date( [ @$objects ], $lib_file ) ) {
Expand Down Expand Up @@ -163,59 +137,4 @@ sub ACTION_create_objects {
}
}

sub ACTION_create_library {
my $self = shift;
my $cbuilder = $self->cbuilder;

my $libbuilder = $self->notes('libbuilder');
my $LIBEXT = $libbuilder->{libext};

my $o_files = $self->rscan_dir('cld-src', qr/\.o$/);


my $libpath = $self->notes('libdir');
$libpath = catfile($libpath, "libcld$LIBEXT");
my $libfile = catfile("cld-src","libcld$LIBEXT");

my $extralinkerflags = "";
$extralinkerflags.=" -install_name $libpath" if $^O =~ /darwin/;

if (!$self->up_to_date($o_files, $libfile)) {
$libbuilder->link(module_name => 'libcld',
extra_linker_flags => $extralinkerflags,
'C++' => 1,
objects => $o_files,
lib_file => $libfile,
);
}

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_test {
my $self = shift;

if ($^O =~ /mswin32/i) {
$ENV{PATH} = catdir($self->blib,"usrlib").";$ENV{PATH}";
}
elsif ($^O =~ /darwin/i) {
$ENV{DYLD_LIBRARY_PATH} = catdir($self->blib,"usrlib");
}
elsif ($^O =~ /(?:linux|bsd|sun|sol|dragonfly|hpux|irix)/i) {
my $oldlibpath = $ENV{LD_LIBRARY_PATH} || '/lib:/usr/lib';
$ENV{LD_LIBRARY_PATH} = catdir($self->blib,"usrlib").":$oldlibpath";
}
elsif ($^O =~ /aix/i) {
my $oldlibpath = $ENV{LIBPATH} || '/lib:/usr/lib';
$ENV{LIBPATH} = catdir($self->blib,"usrlib").":$oldlibpath";
}
$self->SUPER::ACTION_test
}


1;
3 changes: 3 additions & 0 deletions lib/Lingua/Identify/CLD.pm
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ Chrome team for making the code available.
Jean Véronis for pushing me to do this.
SocialFlow L<http://www.socialflow.com> for simplifiying the
build/install process.
=head1 LICENSE AND COPYRIGHT
Copyright 2011 Alberto Simoes.
Expand Down

0 comments on commit b153f04

Please sign in to comment.