Skip to content

Instantly share code, notes, and snippets.

@ashgti
Created May 18, 2010 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashgti/405722 to your computer and use it in GitHub Desktop.
Save ashgti/405722 to your computer and use it in GitHub Desktop.
# Copyright (C) 2010, Parrot Foundation.
# $Id$
=head1 NAME
config/auto/libffi.pm - find libffi
=head1 DESCRIPTION
Discovers libffi, if it exists.
=cut
package auto::libffi;
use strict;
use warnings;
use base qw(Parrot::Configure::Step);
use Parrot::Configure::Utils ':auto';
sub _init {
my $self = shift;
my %data;
$data{description} = q{Is libffi installed};
$data{result} = q{};
return \%data;
}
sub runstep {
my ( $self, $conf ) = @_;
my $test = $self->_probe_for_libffi($conf);
$self->_evaluate_libffi($conf, $test);
return 1;
}
sub _probe_for_libffi {
my ( $self, $conf ) = @_;
my %libffi;
my $extra_libs = $self->_select_lib( {
default => '-lffi',
} );
$conf->cc_gen("config/auto/libffi/test_c.in");
eval { $conf->cc_build( q{}, $extra_libs ) };
if ( !$@ ) {
%libffi = eval $conf->cc_run() or die "Can't run the test program: $!";
}
$conf->cc_clean();
return \%libffi;
}
sub _evaluate_libffi {
my ( $self, $conf, $test ) = @_;
if ( defined $test->{libffi} ) {
$self->set_result("yes");
$conf->data->set( libffi => $test->{libffi} );
}
else {
$self->set_result("no");
$conf->data->set( libffi => undef );
}
return 1;
}
1;
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment