File Coverage

File:config/inter/make.pm
Coverage:70.8%

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

config/inter/make.pm - make utility

=head1 DESCRIPTION

Determines whether C<make> is installed and if it's actually GNU C<make>.

=cut
12
13package inter::make;
14
15
3
3
3
use strict;
16
3
3
3
use warnings;
17
18
3
3
3
use base qw(Parrot::Configure::Step);
19
20
3
3
3
use Parrot::Configure::Utils qw( :inter capture_output check_progs );
21
22sub _init {
23
4
    my $self = shift;
24
4
    my %data;
25
4
    $data{description} = q{Is make installed};
26
4
    $data{result} = q{};
27
4
    return \%data;
28}
29
30sub runstep {
31
3
    my ( $self, $conf ) = @_;
32
3
    my $util = 'make';
33
3
    my $prompt = "Do you have a make utility like 'gmake' or 'make'?";
34
35
3
    my $verbose = $conf->options->get('verbose');
36
37    # undef means we don't have GNU make... default to not having it
38
3
    $conf->data->set( gmake_version => undef );
39
40
3
    my $candidates;
41
3
    if ( $^O eq 'cygwin') {
42        # On Cygwin prefer make over nmake.
43
0
        $candidates = ['gmake', 'make'];
44    }
45    elsif ($conf->option_or_data('cc') =~ /cl(\.exe)?$/i) {
46        # Windows, Visual C++, prefer nmake
47        # This test should use something more stable than the compiler
48        # executable name. 'msvcversion' might be good, but is determined
49        # after this check.
50
0
        $candidates = [ 'nmake', 'mingw32-make', 'gmake', 'make' ];
51    }
52    else {
53        # Default
54
3
        $candidates = ['gmake', 'mingw32-make', 'nmake', 'make'];
55    }
56
57
3
    my $prog;
58
59    # check the candidates for a 'make' program in this order:
60    # environment ; option ; probe ; ask ; default
61    # first pick wins.
62
3
    $prog ||= $ENV{ uc($util) };
63
3
    $prog ||= $conf->options->get($util);
64
3
    $prog ||= check_progs( $candidates, $verbose );
65
3
    if ( !$prog ) {
66
0
        $prog = ( $conf->options->get('ask') )
67            ? prompt( $prompt, $prog ? $prog : $conf->data->get($util) )
68            : $conf->data->get($util);
69    }
70
71    # never override the user. If a non-existent program is specified then
72    # the user is responsible for the consequences.
73
3
    if ( defined $prog ) {
74
3
        $conf->data->set( $util => $prog );
75
3
        $self->set_result('yes');
76    }
77    else {
78
0
        $prog = check_progs( $candidates, $verbose );
79
80
0
        unless ($prog) {
81
82            # fall back to default
83
0
            $self->set_result('no');
84
0
            return 1;
85        }
86    }
87
88
3
    my ( $stdout, $stderr, $ret ) = capture_output( $prog, '--version' );
89
90    # don't override the user even if the program they provided appears to be
91    # broken
92
3
    if ( $ret == -1 and !$conf->options->get('ask') ) {
93        # fall back to default
94
0
        $self->set_result('no');
95
0
        return 1;
96    }
97
98    # if '--version' returns a string assume that this is gmake.
99
3
    if ( $stdout =~ /GNU \s+ Make \s+ (\d+) \. (\d+)/x ) {
100
3
        $conf->data->set( gmake_version => "$1.$2" );
101    }
102
103
3
    $conf->data->set( $util => $prog );
104
3
    $self->set_result('yes');
105
106    # setup make_C
107
3
    _set_make_c($conf, $prog);
108
109
3
    return 1;
110}
111
112sub _set_make_c {
113
5
    my ($conf, $prog) = @_;
114
5
    if ( $conf->data->get('gmake_version') ) {
115
4
        $conf->data->set( make_c => "+$prog -C" );
116    }
117    else {
118        # The default value is fine.
119    }
120}
121
1221;
123
124# Local Variables:
125# mode: cperl
126# cperl-indent-level: 4
127# fill-column: 100
128# End:
129# vim: expandtab shiftwidth=4: