Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 226 lines (185 sloc) 6.237 kb
e1a4735 Patrick R. Michaud Initial files for regex implementations.
pmichaud authored
1 #! perl
2 # Copyright (C) 2009 The Perl Foundation
3
4 use 5.008;
5 use strict;
6 use warnings;
7 use Getopt::Long;
8 use Cwd;
fdbe423 Moritz Lenz switch Configure.pl and gen_parrot.pl to git
moritz authored
9 use lib "build/lib";
10 use Rakudo::CompareRevisions qw(compare_parrot_revs);
e1a4735 Patrick R. Michaud Initial files for regex implementations.
pmichaud authored
11
12 MAIN: {
13 my %options;
14 GetOptions(\%options, 'help!', 'parrot-config=s',
15 'gen-parrot!', 'gen-parrot-prefix=s', 'gen-parrot-option=s@');
16
17 # Print help if it's requested
18 if ($options{'help'}) {
19 print_help();
20 exit(0);
21 }
22
23 # Determine the revision of Parrot we require
24 open my $REQ, "build/PARROT_REVISION"
25 || die "cannot open build/PARROT_REVISION\n";
26 my ($reqsvn, $reqpar) = split(' ', <$REQ>);
27 close $REQ;
28
29 # Update/generate parrot build if needed
30 if ($options{'gen-parrot'}) {
31 my @opts = @{ $options{'gen-parrot-option'} || [] };
32 my $prefix = $options{'gen-parrot-prefix'} || cwd()."/parrot_install";
33 # parrot's Configure.pl mishandles win32 backslashes in --prefix
34 $prefix =~ s{\\}{/}g;
35 my @command = ($^X, "build/gen_parrot.pl", "--prefix=$prefix", ($^O !~ /win32/i ? "--optimize" : ()), @opts);
36
37 print "Generating Parrot ...\n";
38 print "@command\n\n";
39 system @command;
40 }
41
42 # Get a list of parrot-configs to invoke.
43 my @parrot_config_exe = qw(
44 parrot_install/bin/parrot_config
45 ../../parrot_config
46 parrot_config
47 );
48 if (exists $options{'gen-parrot-prefix'}) {
49 unshift @parrot_config_exe,
50 $options{'gen-parrot-prefix'} . '/bin/parrot_config';
51 }
52
53 if ($options{'parrot-config'} && $options{'parrot-config'} ne '1') {
54 @parrot_config_exe = ($options{'parrot-config'});
55 }
56
57 # Get configuration information from parrot_config
58 my %config = read_parrot_config(@parrot_config_exe);
59
60 my $parrot_errors = '';
0b3c754 Patrick R. Michaud Remove trailing spaces from a lot of files, to make Parrot happier.
pmichaud authored
61 if (!%config) {
62 $parrot_errors .= "Unable to locate parrot_config\n";
e1a4735 Patrick R. Michaud Initial files for regex implementations.
pmichaud authored
63 }
c4c31a1 Moritz Lenz [configure] fix two thinkos
moritz authored
64 elsif (compare_parrot_revs($reqsvn, $config{'git_describe'}) > 0 &&
fdbe423 Moritz Lenz switch Configure.pl and gen_parrot.pl to git
moritz authored
65
e1a4735 Patrick R. Michaud Initial files for regex implementations.
pmichaud authored
66 ($reqpar eq '' || version_int($reqpar) > version_int($config{'VERSION'}))) {
fdbe423 Moritz Lenz switch Configure.pl and gen_parrot.pl to git
moritz authored
67 $parrot_errors .= "Parrot revision $reqsvn required (currently $config{'git_describe'})\n";
e1a4735 Patrick R. Michaud Initial files for regex implementations.
pmichaud authored
68 }
69
70 if ($parrot_errors) {
71 die <<"END";
72 ===SORRY!===
73 $parrot_errors
fdbe423 Moritz Lenz switch Configure.pl and gen_parrot.pl to git
moritz authored
74 To automatically checkout (git) and build a copy of parrot $reqsvn,
e1a4735 Patrick R. Michaud Initial files for regex implementations.
pmichaud authored
75 try re-running Configure.pl with the '--gen-parrot' option.
76 Or, use the '--parrot-config' option to explicitly specify
77 the location of parrot_config to be used to build NQP.
78
79 END
80 }
81
82 # Verify the Parrot installation is sufficient for building NQP
83 verify_parrot(%config);
84
85 # Create the Makefile using the information we just got
86 create_makefile(%config);
87 my $make = $config{'make'};
88
89 {
90 no warnings;
91 print "Cleaning up ...\n";
0b3c754 Patrick R. Michaud Remove trailing spaces from a lot of files, to make Parrot happier.
pmichaud authored
92 if (open my $CLEAN, '-|', "$make clean") {
e1a4735 Patrick R. Michaud Initial files for regex implementations.
pmichaud authored
93 my @slurp = <$CLEAN>;
0b3c754 Patrick R. Michaud Remove trailing spaces from a lot of files, to make Parrot happier.
pmichaud authored
94 close $CLEAN;
e1a4735 Patrick R. Michaud Initial files for regex implementations.
pmichaud authored
95 }
96 }
97
98 print <<"END";
99
100 You can now use '$make' to build NQP.
d9b4687 Patrick R. Michaud Remove bogus note about Perl 6 spectests (Coke++).
pmichaud authored
101 After that, you can use '$make test' to run some local tests.
e1a4735 Patrick R. Michaud Initial files for regex implementations.
pmichaud authored
102
103 END
104 exit 0;
105
106 }
107
108
109 sub read_parrot_config {
110 my @parrot_config_exe = @_;
111 my %config = ();
112 for my $exe (@parrot_config_exe) {
113 no warnings;
114 if (open my $PARROT_CONFIG, '-|', "$exe --dump") {
115 print "\nReading configuration information from $exe ...\n";
116 while (<$PARROT_CONFIG>) {
117 if (/(\w+) => '(.*)'/) { $config{$1} = $2 }
118 }
119 close $PARROT_CONFIG or die $!;
120 last if %config;
121 }
122 }
123 return %config;
124 }
125
126
127 sub verify_parrot {
128 print "Verifying Parrot installation...\n";
129 my %config = @_;
130 my $PARROT_VERSION = $config{'versiondir'};
131 my $PARROT_LIB_DIR = $config{'libdir'}.$PARROT_VERSION;
132 my $PARROT_SRC_DIR = $config{'srcdir'}.$PARROT_VERSION;
133 my $PARROT_INCLUDE_DIR = $config{'includedir'}.$PARROT_VERSION;
134 my $PARROT_TOOLS_DIR = "$PARROT_LIB_DIR/tools";
135 my @required_files = (
136 "$PARROT_LIB_DIR/library/PGE/Perl6Grammar.pbc",
137 "$PARROT_LIB_DIR/library/PCT/HLLCompiler.pbc",
138 "$PARROT_TOOLS_DIR/build/ops2c.pl",
139 "$PARROT_TOOLS_DIR/build/pmc2c.pl",
140 "$PARROT_SRC_DIR",
141 "$PARROT_SRC_DIR/pmc",
142 "$PARROT_INCLUDE_DIR",
143 "$PARROT_INCLUDE_DIR/pmc",
144 );
145 my @missing;
146 for my $reqfile (@required_files) {
147 push @missing, " $reqfile" unless -e $reqfile;
148 }
149 if (@missing) {
150 my $missing = join("\n", @missing);
151 die <<"END";
152
153 ===SORRY!===
154 I'm missing some needed files from the Parrot installation:
155 $missing
156 (Perhaps you need to use Parrot's "make install-dev" or
157 install the "parrot-devel" package for your system?)
158
159 END
160 }
161 }
162
163 # Generate a Makefile from a configuration
164 sub create_makefile {
165 my %config = @_;
166
167 my $maketext = slurp( 'build/Makefile.in' );
168
169 $config{'win32_libparrot_copy'} = $^O eq 'MSWin32' ? 'copy $(PARROT_BIN_DIR)\libparrot.dll .' : '';
170 $maketext =~ s/@(\w+)@/$config{$1}/g;
171 if ($^O eq 'MSWin32') {
172 $maketext =~ s{/}{\\}g;
173 $maketext =~ s{\\\*}{\\\\*}g;
174 $maketext =~ s{http:\S+}{ do {my $t = $&; $t =~ s'\\'/'g; $t} }eg;
175 }
176
177 my $outfile = 'Makefile';
178 print "\nCreating $outfile ...\n";
179 open(my $MAKEOUT, '>', $outfile) ||
180 die "Unable to write $outfile\n";
181 print {$MAKEOUT} $maketext;
182 close $MAKEOUT or die $!;
183
184 return;
185 }
186
187 sub slurp {
188 my $filename = shift;
189
190 open my $fh, '<', $filename or die "Unable to read $filename\n";
191 local $/ = undef;
192 my $maketext = <$fh>;
193 close $fh or die $!;
194
195 return $maketext;
196 }
197
198 sub version_int {
199 sprintf('%d%03d%03d', split(/\./, $_[0]))
200 }
201
202
203 # Print some help text.
204 sub print_help {
205 print <<'END';
206 Configure.pl - NQP Configure
207
208 General Options:
209 --help Show this text
210 --gen-parrot Download and build a copy of Parrot to use
211 --gen-parrot-option='--option=value'
212 Set parrot config option when using --gen-parrot
213 --parrot-config=(config)
214 Use configuration information from config
215 END
216
217 return;
218 }
219
220 # Local Variables:
221 # mode: cperl
222 # cperl-indent-level: 4
223 # fill-column: 100
224 # End:
225 # vim: expandtab shiftwidth=4:
Something went wrong with that request. Please try again.