-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfigure.pl
192 lines (149 loc) · 4.61 KB
/
Configure.pl
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
#! perl
=head1 NAME
Configure.pl - a configure script for a high level language running on Parrot
=head1 SYNOPSIS
perl Configure.pl --help
perl Configure.pl
perl Configure.pl --parrot_config=<path_to_parrot>
perl Configure.pl --gen-parrot
=cut
use strict;
use warnings;
use 5.008;
# core Perl 5 modules
use File::Spec ();
# Modules from CPAN
use File::Which ();
my %valid_options = (
'help' => 'Display configuration help',
'parrot-config' => 'Use configuration given by parrot_config binary',
'gen-parrot' => 'Automatically retrieve and build Parrot',
);
# Get any options from the command line
my %options = get_command_options();
# Print help if it's requested
if ($options{'help'}) {
print_help();
exit(0);
}
# Update/generate parrot build if needed
if ($options{'gen-parrot'}) {
system("$^X build/gen_parrot.pl");
}
# Get a list of parrot-configs to invoke.
my @parrot_config_exe = (
'parrot/parrot_config',
'../../parrot_config',
'parrot_config'
);
if ($options{'parrot-config'} && $options{'parrot-config'} ne '1') {
@parrot_config_exe = ($options{'parrot-config'});
}
# Get configuration information from parrot_config
my %config = read_parrot_config(@parrot_config_exe);
unless (%config) {
die <<"END";
Unable to locate parrot_config.
To automatically checkout (svn) and build a copy of parrot,
try re-running Configure.pl with the '--gen-parrot' option.
Or, use the '--parrot-config' option to explicitly specify
the location of parrot_config.
END
}
# Create the Makefile using the information we just got
create_files(
\%config,
{ 'build/templates/Makefile.in' => 'Makefile',
'build/templates/src/pmc/Makefile.in' => 'src/pmc/Makefile',
}
);
# Done.
done($config{'make'});
# Process command line arguments into a hash.
sub get_command_options {
my %options = ();
for my $arg (@ARGV) {
if ($arg =~ /^--(\w[-\w]*)(?:=(.*))?/ && $valid_options{$1}) {
my ($key, $value) = ($1, $2);
$value = 1 unless defined $value;
$options{$key} = $value;
next;
}
die qq/Invalid option "$arg". See "perl Configure.pl --help" for valid options.\n/;
}
%options;
}
sub read_parrot_config {
my @parrot_config_exe = @_;
my %config;
for my $exe (@parrot_config_exe) {
no warnings;
if (open my $parrot_config_fh, '-|', "$exe --dump") {
print "Reading configuration information from $exe\n";
while (<$parrot_config_fh>) {
if (/(\w+) => '(.*)'/) { $config{$1} = $2 }
}
close $parrot_config_fh;
if (%config) {
my $parrot_config_exe = File::Which::which($exe) if $exe eq 'parrot_config';
$parrot_config_exe ||= File::Spec->rel2abs($exe);
$parrot_config_exe ||= File::Spec->rel2abs("$exe$config{EXE}");
$parrot_config_exe ||= $exe;
$config{parrot_config_exe} = $parrot_config_exe;
last;
}
}
}
return %config;
}
# Generate a Makefile from a configuration
sub create_files {
my ($config, $setup) = @_;
while (my ($template_fn, $target_fn) = each %{$setup}) {
my $content;
{
open my $template_fh, '<', $template_fn or
die "Unable to read $template_fn.";
$content = join('', <$template_fh>);
close $template_fn;
}
$config->{'win32_libparrot_copy'} = $^O eq 'MSWin32' ? 'copy $(BUILD_DIR)\libparrot.dll .' : '';
$content =~ s/@(\w+)@/$config->{$1}/g;
if ($^O eq 'MSWin32') {
$content =~ s{/}{\\}g;
}
print "Creating $target_fn from $template_fn.\n";
{
open(my $target_fh, '>', $target_fn)
or die "Unable to write $target_fn\n";
print $target_fh $content;
close($target_fh);
}
}
}
sub done {
my ($make) = @_;
print <<"END";
You can now use '$make' to build Pipp.
After that, you can use '$make test' to run some local tests.
See 'docs/testing.pod' for how to run the PHP 5.3 testsuite.
END
exit 0;
}
# Print some help text.
sub print_help {
print <<'END';
Configure.pl - Rakudo Configure
General Options:
--help Show this text
--gen-parrot Download and build a copy of Parrot to use
--parrot-config=(config)
Use configuration information from config
END
}
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: