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