forked from Raku/nqp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Configure.pl
executable file
·349 lines (310 loc) · 12 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#!/usr/bin/env perl
# Copyright (C) 2009 The Perl Foundation
use 5.008;
use strict;
use warnings;
use Text::ParseWords;
use Getopt::Long;
use Cwd qw/abs_path cwd/;
use File::Spec;
use lib "tools/lib";
use NQP::Configure qw(cmp_rev gen_moar
fill_template_file fill_template_text
probe_node
slurp system_or_die verify_install sorry);
my @known_backends = qw/moar jvm js/;
my %known_backends = map { $_, 1; } @known_backends;
my %prefixes = ( moar => 'm', jvm => 'j', js => 'js' );
MAIN: {
if (-r "config.default") {
unshift @ARGV, shellwords(slurp('config.default'));
}
my $slash = $^O eq 'MSWin32' ? '\\' : '/';
my %config = (perl => $^X);
$config{'nqp_config_status'} = join(' ', map { "\"$_\""} @ARGV);
my $exe = $NQP::Configure::exe;
my %options;
GetOptions(\%options, 'help!', 'prefix=s', 'libdir=s',
'sysroot=s', 'sdkroot=s',
'backends=s',
'no-clean',
'with-moar=s', 'gen-moar:s', 'moar-option=s@',
'with-asm=s', 'with-asm-tree=s', 'with-jline=s', 'with-jna=s',
'make-install!', 'makefile-timing!',
'git-protocol=s', 'ignore-errors',
'link',
'git-depth=s', 'git-reference=s',);
# Print help if it's requested
if ($options{'help'}) {
print_help();
exit(0);
}
if ($options{'ignore-errors'}) {
print "===WARNING!===\nErrors are being ignored.\nIn the case of any errors the script may behave unexpectedly.\n";
}
if ($options{'with-asm'}) {
if ($options{'with-asm'} ne '-') {
$config{'asm'} = $options{'with-asm'};
}
} else {
$config{'asm'} = "3rdparty/asm/asm-4.1.jar";
}
if ($options{'with-asm-tree'}) {
if ($options{'with-asm-tree'} ne '-') {
$config{'asmtree'} = $options{'with-asm-tree'};
}
} else {
$config{'asmtree'} = "3rdparty/asm/asm-tree-4.1.jar";
}
if ($options{'with-jline'}) {
if ($options{'with-jline'} ne '-') {
$config{'jline'} = $options{'with-jline'};
}
} else {
$config{'jline'} = "3rdparty/jline/jline-1.0.jar";
}
if ($options{'with-jna'}) {
if ($options{'with-jna'} ne '-') {
$config{'jna'} = $options{'with-jna'};
}
} else {
$config{'jna'} = "3rdparty/jna/jna.jar";
}
if ($^O eq 'MSWin32') {
$config{'asmfile'} = $config{'asm'};
$config{'asmfile'} =~ s/.*\\//;
$config{'jlinefile'} = $config{'jline'};
$config{'jlinefile'} =~ s/.*\\//;
} else {
$config{'asmfile'} = $config{'asm'};
$config{'asmfile'} =~ s/.*\///;
$config{'jlinefile'} = $config{'jline'};
$config{'jlinefile'} =~ s/.*\///;
}
fill_template_file(
'tools/build/install-jvm-runner.pl.in',
'tools/build/install-jvm-runner.pl',
%config,
);
my $default_backend;
my @backends;
my %backends;
if ($options{backends}) {
$options{backends} = join ',', @known_backends if lc($options{backends}) eq 'all';
for my $be (split /,/, $options{backends}) {
$be = lc $be;
unless ($known_backends{$be}) {
die "Unknown backend: '$be'; Known backends: " .
join(', ', sort keys %known_backends) . "\n";
}
$default_backend ||= $be;
push @backends, $be unless $backends{$be};
$backends{$be} = 1;
}
}
if (defined $options{'gen-moar'}) {
push @backends, 'moar' unless $backends{moar};
$backends{moar} = 1;
$default_backend ||= 'moar';
}
unless (%backends) {
# TODO: come up with more sensible defaults
$backends{moar} = 1;
push @backends, 'moar';
$default_backend = 'moar';
}
if ($backends{js} and !$backends{moar}) {
sorry($options{'ignore-errors'}, "When building the js backend you must also build moar\nPlease build with --backends=moar,js\n");
}
# XXX mkpath instead?
mkdir($options{'prefix'}) if $options{'prefix'} && $^O =~ /Win32/ && !-d $options{'prefix'};
my $prefix = $options{'prefix'}
? abs_path($options{'prefix'})
: ($options{sysroot}
? '/usr'
: File::Spec->catdir(cwd, 'install'));
$config{prefix} = $prefix;
$config{nqplibdir} = $options{libdir} ? "$options{libdir}/nqp" : '$(NQP_LANG_DIR)/lib';
$config{sysroot} = $options{sysroot};
$config{sdkroot} = $options{sdkroot};
# Save options in config.status
unlink('config.status');
if (open(my $CONFIG_STATUS, '>', 'config.status')) {
print $CONFIG_STATUS
"$^X Configure.pl $config{'nqp_config_status'} \$*\n";
close($CONFIG_STATUS);
}
$config{'makefile-timing'} = $options{'makefile-timing'};
$config{'stagestats'} = '--stagestats' if $options{'makefile-timing'};
$config{'shell'} = $^O eq 'MSWin32' ? 'cmd' : 'sh';
$config{'bat'} = $^O eq 'MSWin32' ? '.bat' : '';
$config{'cpsep'} = $^O eq 'MSWin32' ? ';' : ':';
$config{'slash'} = $slash;
open my $MAKEFILE, '>', 'Makefile'
or die "Cannot open 'Makefile' for writing: $!";
my @prefixes = map { $prefixes{$_} } @backends;
print $MAKEFILE "\n# Makefile code generated by Configure.pl:\n";
my $launcher = $prefixes{$default_backend} . '-runner-default';
print $MAKEFILE "all: ", join(' ', map("$_-all", @prefixes), $launcher), "\n";
print $MAKEFILE "install: ", join(' ', map("$_-install", @prefixes), $launcher . '-install'), "\n";
for my $t (qw/clean test qregex-test/) {
print $MAKEFILE "$t: ", join(' ', map "$_-$t", @prefixes), "\n";
}
fill_template_file(
'tools/build/Makefile-common.in',
$MAKEFILE,
%config,
);
if ($backends{moar}) {
my @errors;
my ($moar_want) = split(' ', slurp('tools/build/MOAR_REVISION'));
my ($moar_path, @moar_errors) = gen_moar($moar_want, %config, %options);
if (!$moar_path) {
push @errors,
"No suitable MoarVM (moar executable) found using the --prefix\n" .
"(You can get a MoarVM built automatically with --gen-moar.)";
unshift @errors, @moar_errors if @moar_errors;
}
sorry($options{'ignore-errors'}, @errors) if @errors;
# If we ignore errors, normally we'd print out the @moar_errors elsewhere
# so make sure to print them out now. Don't print unless errors are ignored
print join("\n", '', @moar_errors, "\n") if @moar_errors and $options{'ignore-errors'};
$config{'make'} = `$moar_path --libpath="src/vm/moar/stage0" "src/vm/moar/stage0/nqp.moarvm" -e "print(nqp::backendconfig()<make>)"`
|| 'make';
$config{moar} = $moar_path;
$config{moar_prefix} = File::Spec->catpath((File::Spec->splitpath($moar_path))[0, 1], File::Spec->updir);
fill_template_file(
'tools/build/Makefile-Moar.in',
$MAKEFILE,
%config,
);
}
if ($backends{js}) {
system_or_die($config{moar}, '--libpath=src/vm/moar/stage0', 'src/vm/moar/stage0/nqp.moarvm', 'tools/build/gen-js-makefile.nqp', 'gen/js/Makefile-JS.in');
$config{'make'} = $^O eq 'MSWin32' ? 'nmake' : 'make';
$config{link} = $options{link};
my $node = probe_node();
if ($node eq 'nodejs') {
sorry($options{'ignore-errors'}, 'You have a broken node.js. Please install node.js as node instead of nodejs.')
}
elsif (!$node) {
sorry($options{'ignore-errors'}, "You don't have node.js. Please install node.js.");
}
fill_template_file(
'gen/js/Makefile-JS.in',
$MAKEFILE,
%config,
);
}
if ($backends{jvm}) {
my @errors;
my $got;
if (!@errors) {
my @jvm_info = `java -showversion 2>&1`;
my $jvm_found = 0;
my $jvm_ok = 0;
for (@jvm_info) {
print "got: $_";
if (/(?:java|jdk) version "(\d+)(?:\.(\d+))?/) {
$jvm_found = 1;
if ($1 > 1 || $1 == 1 && $2 >= 8) {
$jvm_ok = 1;
}
$got = $_;
last;
}
}
if (!$jvm_found) {
push @errors,
"No JVM (java executable) in path; cannot continue";
}
elsif (!$jvm_ok) {
push @errors,
"Need at least JVM 1.8 (got $got)";
}
}
sorry($options{'ignore-errors'}, @errors) if @errors;
print "Using $got\n";
$config{'make'} = $^O eq 'MSWin32' ? 'nmake' : 'make';
$config{'runner'} = $^O eq 'MSWin32' ? 'nqp.bat' : 'nqp';
fill_template_file(
'tools/build/Makefile-JVM.in',
$MAKEFILE,
%config,
);
}
my $ext = '';
if ($^O eq 'MSWin32') {
$ext = '.bat';
}
print $MAKEFILE qq[t/*/*.t: all\n\tprove -r -v --exec ./nqp$ext \$\@\n];
close $MAKEFILE
or die "Error while writing to 'Makefile': $!";
my $make = fill_template_text('@make@', %config);
unless ($options{'no-clean'}) {
no warnings;
print "Cleaning up ...\n";
if (open my $CLEAN, '-|', "$make clean") {
my @slurp = <$CLEAN>;
close($CLEAN);
}
}
if ($options{'make-install'}) {
system_or_die($make);
system_or_die($make, 'install');
print "\nNQP has been built and installed.\n";
}
else {
print "You can now use '$make' to build NQP.\n";
print "After that, '$make test' will run some tests and\n";
print "'$make install' will install NQP.\n";
}
exit 0;
}
# Print some help text.
sub print_help {
my $backends = join ',',keys %known_backends;
print <<"END";
Configure.pl - NQP Configure
General Options:
--help Show this text
--prefix=dir Install files in dir
--sdkroot=dir When given, use for searching build tools here, e.g.
nqp, java etc.
--sysroot=dir When given, use for searching runtime components here
--backends=list Backends to use: $backends
--gen-moar Download, build, and install a copy of MoarVM to use before writing the Makefile
--moar-option='--option=value'
Options to pass to MoarVM configuration for --gen-moar
--with-moar='/path/to/moar'
Provide path to already installed moar binary
--with-asm='/path/to/jar'
--with-asm-tree='/path/to/jar'
--with-jline='/path/to/jar'
--with-jna='/path/to/jar'
Provide paths to already installed jars
--git-protocol={ssh,https,git}
Protocol to use for git clone. Default: https
--make-install Immediately run `MAKE install` after configuring
--git-depth=<number>
Use the --git-depth option for git clone with parameter number
--git-reference=<path>
Use --git-reference option to identify local path where git repositories are stored
For example: --git-reference=/home/user/repo/for_perl6
Folders 'nqp', 'MoarVM' with corresponding git repos should be in for_perl6 folder
--ignore-errors
Can ignore errors such as what version MoarVM or the JVM is. May not work for other
errors currently.
Please note that the --gen-moar option is there for convenience only and will
actually immediately - at Configure time - compile and install moar. Moar will
live under the path given to --prefix, unless other targeting options are used.
Configure.pl also reads options from 'config.default' in the current directory.
END
return;
}
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: