File Coverage

File:config/auto/readline.pm
Coverage:79.7%

linestmtbrancondsubcode
1# Copyright (C) 2001-2011, Parrot Foundation.
2
3 - 15
=head1 NAME

config/auto/readline.pm - Probe for readline library

=head1 DESCRIPTION

Determines whether the platform supports readline.  The GNU Project describes
its version of the readline library as providing "... a set of functions for
use by applications that allow users to edit command lines as they are typed
in" (L<http://directory.fsf.org/project/readline/>).  Other readline libraries
are, however, available and usable with Parrot.

=cut
16
17package auto::readline;
18
19
3
3
3
use strict;
20
3
3
3
use warnings;
21
22
3
3
3
use base qw(Parrot::Configure::Step);
23
24
3
3
3
use Parrot::Configure::Utils ':auto';
25
26sub _init {
27
4
    my $self = shift;
28
4
    my %data;
29
4
    $data{description} = q{Does your platform support readline};
30
4
    $data{result} = q{};
31
4
    return \%data;
32}
33
34sub runstep {
35
2
    my ( $self, $conf ) = @_;
36
37
2
    my $without_opt = $conf->options->get('without-readline');
38
39
2
    if ($without_opt) {
40
1
        $conf->data->set('HAS_READLINE' => 0);
41
1
        $self->set_result('not requested');
42
1
        return 1;
43    }
44
45
1
    my $cc = $conf->data->get('cc');
46
1
    my $osname = $conf->data->get('osname');
47
48
1
    my $extra_libs = $self->_select_lib( {
49        conf => $conf,
50        osname => $osname,
51        cc => $cc,
52        win32_nongcc => 'readline.lib',
53        default => '-lreadline',
54    } );
55
56
1
    $conf->cc_gen('config/auto/readline/readline_c.in');
57
1
    my $has_readline = 0;
58
1
1
    eval { $conf->cc_build( q{}, $extra_libs ) };
59
1
    if ( !$@ ) {
60
1
        if ( $conf->cc_run() ) {
61
1
            $has_readline = $self->_evaluate_cc_run($conf);
62        }
63
1
        _handle_readline($conf, $extra_libs);
64    }
65    else {
66        # a second chance with ncurses
67
0
        $extra_libs .= ' ';
68
0
        $extra_libs .= $self->_select_lib( {
69            conf => $conf,
70            osname => $osname,
71            cc => $cc,
72            win32_nongcc => 'ncurses.lib',
73            default => '-lncurses',
74        } );
75
0
0
        eval { $conf->cc_build( q{}, $extra_libs) };
76
0
        if ( !$@ ) {
77
0
            if ( $conf->cc_run() ) {
78
0
                $has_readline = $self->_evaluate_cc_run($conf);
79            }
80
0
            _handle_readline($conf, $extra_libs);
81        }
82    }
83
1
    $conf->data->set( HAS_READLINE => $has_readline );
84
1
    $self->set_result($has_readline ? 'yes' : 'no');
85
86
1
    return 1;
87}
88
89sub _evaluate_cc_run {
90
3
    my ($self, $conf) = @_;
91
3
    my $has_readline = 1;
92
3
    $conf->debug(" (yes) ");
93
3
    $self->set_result('yes');
94
3
    return $has_readline;
95}
96
97sub _handle_readline {
98
3
    my ($conf, $libs) = @_;
99
3
    $conf->data->set( readline => 'define' );
100
3
    $conf->data->add( ' ', libs => $libs );
101
3
    return 1;
102}
103
1041;
105
106# Local Variables:
107# mode: cperl
108# cperl-indent-level: 4
109# fill-column: 100
110# End:
111# vim: expandtab shiftwidth=4: