/
progs.pm
206 lines (160 loc) · 5.97 KB
/
progs.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# Copyright (C) 2001-2008, Parrot Foundation.
=head1 NAME
config/inter/progs.pm - C Compiler and Linker
=head1 DESCRIPTION
Asks the user which compiler, linker, shared library builder, C libraries,
lexical analyzer generator and parser generator to use. Also whether debugging
should be enabled.
=cut
package inter::progs;
use strict;
use warnings;
use base qw(Parrot::Configure::Step);
use Parrot::Configure::Utils ':inter', ':auto';
sub _init {
my $self = shift;
my %data;
$data{description} = q{Determine what C compiler and linker to use};
$data{result} = q{};
return \%data;
}
sub runstep {
my ( $self, $conf ) = @_;
my $ask = _prepare_for_interactivity($conf);
my $cc;
($conf, $cc) = _get_programs($conf, $ask);
my $debug = _get_debug($conf, $ask);
my $debug_validity = _is_debug_setting_valid($debug);
return unless defined $debug_validity;
$conf = _set_debug_and_warn($conf, $debug);
# Beware! Inside test_compiler(), cc_build() and cc_run() both silently
# reference the Parrot::Configure object ($conf) at its current state.
test_compiler($conf, $cc);
return 1;
}
sub _prepare_for_interactivity {
my $conf = shift;
my $ask = $conf->options->get('ask');
if ($ask) {
print <<'END';
Okay, I'm going to start by asking you a couple questions about your
compiler and linker. Default values are in square brackets; you can
hit ENTER to accept them. If you don't understand a question, the
default will usually work--they've been intuited from your Perl 5
configuration.
END
}
return $ask;
}
sub _get_programs {
my ($conf, $ask) = @_;
# Set each variable individually so that hints files can use them as
# triggers to help pick the correct defaults for later answers.
my ( $cc, $cxx, $link, $ld, $ccflags, $linkflags, $ldflags, $arflags);
my ( $libs, $lex, $yacc, $ar );
$cc = integrate( $conf->data->get('cc'), $conf->options->get('cc') );
$cc = prompt( "What C compiler do you want to use?", $cc )
if $ask;
$conf->data->set( cc => $cc );
$link = integrate( $conf->data->get('link'), $conf->options->get('link') );
$link = prompt( "How about your linker?", $link ) if $ask;
$conf->data->set( link => $link );
$ld = integrate( $conf->data->get('ld'), $conf->options->get('ld') );
$ld = prompt( "What program do you want to use to build shared libraries?", $ld ) if $ask;
$conf->data->set( ld => $ld );
$ccflags = integrate( $conf->data->get('ccflags'),
$conf->options->get('ccflags') );
# Remove some perl5-isms.
$ccflags =~ s/-D((PERL|HAVE)_\w+\s*|USE_PERLIO)//g;
$ccflags =~ s/-fno-strict-aliasing//g;
$ccflags =~ s/-fnative-struct//g;
$ccflags = prompt( "What flags should your C compiler receive?", $ccflags )
if $ask;
$conf->data->set( ccflags => $ccflags );
$conf->debug("\nccflags: $ccflags\n");
$ar = integrate( $conf->data->get('ar'), $conf->options->get('ar') );
$ar = prompt( "What archiver do you want to use to build static libraries?", $ar ) if $ask;
$conf->data->set( ar => $ar );
$arflags = integrate( $conf->data->get('arflags'), $conf->options->get('arflags') );
$arflags = prompt( "What flags should your archiver receive to create static libraries?",
$arflags) if $ask;
$conf->data->set( arflags => $arflags );
$linkflags = $conf->data->get('linkflags');
# Remove the path to the Perl library (from Win32 config).
# See TT #854.
$linkflags =~ s/-libpath:\S+//g;
$linkflags = integrate( $linkflags, $conf->options->get('linkflags') );
$linkflags = prompt( "And flags for your linker?", $linkflags ) if $ask;
$conf->data->set( linkflags => $linkflags );
$ldflags = $conf->data->get('ldflags');
# For substitution below, see comment for $linkflags above.
$ldflags =~ s/-libpath:\S+//g;
$ldflags = integrate( $ldflags, $conf->options->get('ldflags') );
$ldflags = prompt( "And your $ld flags for building shared libraries?", $ldflags )
if $ask;
$conf->data->set( ldflags => $ldflags );
$libs = $conf->data->get('libs');
$libs = join q{ },
grep { $conf->data->get('OSNAME_provisional') =~ /VMS|MSWin/ || !/^-l(c|gdbm(_compat)?|dbm|ndbm|db)$/ }
split( q{ }, $libs );
$libs = integrate( $libs, $conf->options->get('libs') );
$libs = prompt( "What libraries should your C compiler use?", $libs )
if $ask;
$conf->data->set( libs => $libs );
$cxx = integrate( $conf->data->get('cxx'), $conf->options->get('cxx') );
$cxx = prompt( "What C++ compiler do you want to use?", $cxx ) if $ask;
$conf->data->set( cxx => $cxx );
return ($conf, $cc);
}
sub _get_debug {
my ($conf, $ask) = @_;
my $debug = 'n';
$debug = 'y' if $conf->options->get('debugging');
$debug = prompt( "Do you want a debugging build of Parrot?", $debug )
if $ask;
return $debug;
}
sub _is_debug_setting_valid {
my $debug = shift;
( $debug =~ /^[yn]$/i ) ? return 1 : return;
}
sub _set_debug_and_warn {
my ($conf, $debug) = @_;
if ( $debug =~ /n/i ) {
$conf->data->set(
cc_debug => '',
link_debug => '',
ld_debug => ''
);
}
# This one isn't prompted for above. I don't know why.
my $ccwarn = integrate( $conf->data->get('ccwarn'), $conf->options->get('ccwarn') );
$conf->data->set( ccwarn => $ccwarn );
return $conf;
}
sub test_compiler {
my ($conf, $cc) = @_;
open( my $out_fh, '>', "test_$$.c" )
or die "Unable to open 'test_$$.c': $@\n";
print {$out_fh} <<END_C;
int main() {
return 0;
}
END_C
close $out_fh;
unless ( eval { $conf->cc_build(); 1 } ) {
warn "Compilation failed with '$cc'\n";
exit 1;
}
unless ( eval { $conf->cc_run(); 1 } ) {
warn $@ if $@;
exit 1;
}
}
1;
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: