File Coverage

File:config/auto/gettext.pm
Coverage:95.5%

linestmtbrancondsubcode
1# Copyright (C) 2008, Parrot Foundation.
2
3 - 16
=head1 NAME

config/auto/gettext.pm - Test for GNU native language support (gettext) library

=head1 DESCRIPTION

Determines whether the platform supports gettext. This is needed for parrot
internationalization.

From L<http://www.gnu.org/software/gettext/>:  "[T]he GNU `gettext' utilities
are a set of tools that provides a framework to help other GNU packages
produce multi-lingual messages."

=cut
17
18package auto::gettext;
19
20
2
2
2
use strict;
21
2
2
2
use warnings;
22
23
2
2
2
use base qw(Parrot::Configure::Step);
24
25
2
2
2
use Parrot::Configure::Utils ':auto';
26
27
28sub _init {
29
4
    my $self = shift;
30
4
    my %data;
31
4
    $data{description} = q{Does your configuration include gettext};
32
4
    $data{result} = q{};
33
4
    return \%data;
34}
35
36sub runstep {
37
2
    my ( $self, $conf ) = @_;
38
39
2
    my $without = $conf->options->get( qw| without-gettext | );
40
41
2
    if ($without) {
42
1
        $conf->data->set( has_gettext => 0 );
43
1
        $self->set_result('no');
44
1
        return 1;
45    }
46
47
1
    my $osname = $conf->data->get('osname');
48
49
1
    my $extra_libs = $self->_select_lib( {
50        conf => $conf,
51        osname => $osname,
52        cc => $conf->data->get('cc'),
53        win32_gcc => '-lintl',
54        win32_nongcc => 'intl.lib',
55        default => defined $conf->data->get('glibc') ? '' : '-lintl',
56    } );
57
58
1
    $conf->cc_gen('config/auto/gettext/gettext_c.in');
59
1
1
    eval { $conf->cc_build( q{}, $extra_libs ); };
60
1
    my $has_gettext = 0;
61
1
    if ( !$@ ) {
62
1
        my $test = $conf->cc_run();
63
1
        $has_gettext = $self->_evaluate_cc_run($conf, $test);
64    }
65
1
    if ($has_gettext) {
66
1
        _handle_gettext($conf, $extra_libs);
67    }
68
1
    $conf->data->set( HAS_GETTEXT => $has_gettext );
69
70
1
    return 1;
71}
72
73sub _evaluate_cc_run {
74
4
    my ($self, $conf, $test) = @_;
75
4
    my $has_gettext = 0;
76
4
    if ( $test eq "Hello, world!\n" ) {
77
3
        $has_gettext = 1;
78
3
        $conf->debug(" (yes) ");
79
3
        $self->set_result('yes');
80    }
81
4
    return $has_gettext;
82}
83
84sub _handle_gettext {
85
3
    my ($conf, $libs) = @_;
86
3
    $conf->data->add( ' ', ccflags => "-DHAS_GETTEXT" );
87
3
    $conf->data->add( ' ', libs => $libs );
88
3
    $conf->debug("\n ccflags: ", $conf->data->get("ccflags"), "\n");
89
3
    return 1;
90}
91
921;
93
94# Local Variables:
95# mode: cperl
96# cperl-indent-level: 4
97# fill-column: 100
98# End:
99# vim: expandtab shiftwidth=4: