<commit_before># Copyright (C) 2008, The Perl Foundation.
# $Id$

=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

package auto::gettext;

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{Seeing if your configuration includes gettext};
    $data{result}      = q{};
    return \%data;
}

sub runstep {
    my ( $self, $conf ) = @_;

    my ( $verbose, $without ) = $conf->options->get(
        qw|
            verbose
            without-gettext
        |
    );

    if ($without) {
        $conf->data->set( has_gettext => 0 );
        $self->set_result('no');
        return 1;
    }

    my $cc        = $conf->data->get('cc');
    my $libs      = $conf->data->get('libs');
    my $linkflags = $conf->data->get('linkflags');
    my $ccflags   = $conf->data->get('ccflags');

    my $osname = $conf->data->get_p5('OSNAME');

    # On OS X check the presence of the gettext header in the standard
    # Fink location.
    $self->_handle_darwin_for_fink($conf, $osname, 'libintl.h');

    $conf->cc_gen('config/auto/gettext/gettext.in');
    if ( $osname =~ /mswin32/i ) {
        if ( $cc =~ /^gcc/i ) {
            eval { $conf->cc_build( '', '-lintl' ); };
        }
        else {
            eval { $conf->cc_build( '', 'intl.lib' ); };
        }
    }
    else {
        # don't need to link with libintl if we have GNU libc
        my $linklibs = defined $conf->data->get('glibc') ? '' : '-lintl';
        eval { $conf->cc_build( '', $linklibs ); };
    }
    my $has_gettext;
    if ( !$@ ) {
        my $test = $conf->cc_run();
        $has_gettext = $self->_evaluate_cc_run($test, $verbose);
    }
    if ($has_gettext) {
        _handle_gettext($conf, $verbose);
    }
    else {
        # The Parrot::Configure settings might have changed while class ran
        $self->_recheck_settings($conf, $libs, $ccflags, $linkflags, $verbose);
    }
    $conf->data->set( HAS_GETTEXT => $has_gettext );

    return 1;
}

sub _evaluate_cc_run {
    my $self = shift;
    my ($test, $verbose) = @_;
    my $has_gettext = 0;
    if ( $test eq "Hello, world!\n" ) {
        $has_gettext = 1;
        print " (yes) " if $verbose;
        $self->set_result('yes');
    }
    return $has_gettext;
}

sub _handle_gettext {
    my ($conf, $verbose) = @_;
    $conf->data->add( ' ', ccflags => "-DHAS_GETTEXT" );
    $verbose and print "\n  ccflags: ", $conf->data->get("ccflags"), "\n";
    return 1;
}

1;

# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4:
<commit_msg>[gettext] - fix build on MinGW32 - more consistent with gmp.pm and others<commit_after># Copyright (C) 2008, The Perl Foundation.
# $Id$

=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

package auto::gettext;

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{Seeing if your configuration includes gettext};
    $data{result}      = q{};
    return \%data;
}

sub runstep {
    my ( $self, $conf ) = @_;

    my ( $verbose, $without ) = $conf->options->get(
        qw|
            verbose
            without-gettext
        |
    );

    if ($without) {
        $conf->data->set( has_gettext => 0 );
        $self->set_result('no');
        return 1;
    }

    my $cc        = $conf->data->get('cc');
    my $libs      = $conf->data->get('libs');
    my $linkflags = $conf->data->get('linkflags');
    my $ccflags   = $conf->data->get('ccflags');

    my $osname = $conf->data->get_p5('OSNAME');

    _handle_mswin32($conf, $osname, $cc);

    # On OS X check the presence of the gettext header in the standard
    # Fink location.
    $self->_handle_darwin_for_fink($conf, $osname, 'libintl.h');

    $conf->cc_gen('config/auto/gettext/gettext.in');
    eval { $conf->cc_build(); };
    my $has_gettext;
    if ( !$@ ) {
        my $test = $conf->cc_run();
        $has_gettext = $self->_evaluate_cc_run($test, $verbose);
    }
    if ($has_gettext) {
        _handle_gettext($conf, $verbose);
    }
    else {
        # The Parrot::Configure settings might have changed while class ran
        $self->_recheck_settings($conf, $libs, $ccflags, $linkflags, $verbose);
    }
    $conf->data->set( HAS_GETTEXT => $has_gettext );

    return 1;
}

sub _handle_mswin32 {
    my ($conf, $osname, $cc) = @_;
    if ( $osname =~ /mswin32/i ) {
        if ( $cc =~ /^gcc/i ) {
            $conf->data->add( ' ', libs => '-lintl' );
        }
        else {
            $conf->data->add( ' ', libs => 'intl.lib' );
        }
    }
    else {
        # don't need to link with libintl if we have GNU libc
        my $linklibs = defined $conf->data->get('glibc') ? '' : '-lintl';
        $conf->data->add( ' ', libs => $linklibs );
    }
    return 1;
}

sub _evaluate_cc_run {
    my $self = shift;
    my ($test, $verbose) = @_;
    my $has_gettext = 0;
    if ( $test eq "Hello, world!\n" ) {
        $has_gettext = 1;
        print " (yes) " if $verbose;
        $self->set_result('yes');
    }
    return $has_gettext;
}

sub _handle_gettext {
    my ($conf, $verbose) = @_;
    $conf->data->add( ' ', ccflags => "-DHAS_GETTEXT" );
    $verbose and print "\n  ccflags: ", $conf->data->get("ccflags"), "\n";
    return 1;
}

1;

# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4:

{'fraction_non_alphanumeric': 0.1634676903390915, 'fraction_numerical': 0.007837492002559182, 'mean_word_length': 2.5148960089938166, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 82, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6680953', 'n_tokens_mistral': 2273, 'n_tokens_neox': 2167, 'n_words': 547}