File Coverage

File:config/auto/zlib.pm
Coverage:96.6%

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

config/auto/zlib.pm - Test for zlib library

=head1 DESCRIPTION

This library is linked to a dynamic PMC.

=cut
12
13package auto::zlib;
14
15
2
2
2
use strict;
16
2
2
2
use warnings;
17
18
2
2
2
use base qw(Parrot::Configure::Step);
19
20
2
2
2
use Parrot::Configure::Utils ':auto';
21
22
23sub _init {
24
4
    my $self = shift;
25
4
    my %data;
26
4
    $data{description} = q{Does your platform support zlib};
27
4
    $data{result} = q{};
28
4
    return \%data;
29}
30
31sub runstep {
32
2
    my ( $self, $conf ) = @_;
33
34
2
    my $without = $conf->options->get( qw| without-zlib | );
35
36
2
    if ($without) {
37
1
        $conf->data->set( has_zlib => 0 );
38
1
        $self->set_result('no');
39
1
        return 1;
40    }
41
42
1
    my $osname = $conf->data->get('osname');
43
44
1
    my $extra_libs = $self->_select_lib( {
45        conf => $conf,
46        osname => $osname,
47        cc => $conf->data->get('cc'),
48        win32_nongcc => 'zlib.lib',
49        default => '-lz',
50    } );
51
52
1
    $conf->cc_gen('config/auto/zlib/zlib_c.in');
53
1
1
    eval { $conf->cc_build( q{}, $extra_libs); };
54
1
    my $has_zlib = 0;
55
1
    if ( !$@ ) {
56
1
        my $test = $conf->cc_run();
57
1
        $has_zlib = $self->_evaluate_cc_run($conf, $test, $has_zlib);
58    }
59
1
    $conf->data->set( has_zlib => $has_zlib );
60
1
    $self->set_result($has_zlib ? 'yes' : 'no');
61
62
1
    return 1;
63}
64
65sub _evaluate_cc_run {
66
4
    my $self = shift;
67
4
    my ($conf, $test, $has_zlib) = @_;
68
4
    if ( $test =~ m/^(\d\.\d\.\d)/ ) {
69
3
        my $version = $1;
70
3
        $has_zlib = 1;
71
3
        $conf->debug(" (yes) ");
72
3
        $self->set_result("yes, $version");
73    }
74
4
    return $has_zlib;
75}
76
771;
78
79# Local Variables:
80# mode: cperl
81# cperl-indent-level: 4
82# fill-column: 100
83# End:
84# vim: expandtab shiftwidth=4: