Skip to content

Commit 1a09cc6

Browse files
committed
Unify Configure.pl and ConfigureMoar.pl
now "perl Configure.pl --backends=moar" creates a Makefile suitable for building nqp on Moar
1 parent 492383b commit 1a09cc6

File tree

2 files changed

+137
-208
lines changed

2 files changed

+137
-208
lines changed

Configure.pl

Lines changed: 137 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
unshift @ARGV, shellwords(slurp('config.default'));
1818
}
1919

20-
my %config;
20+
my $slash = $^O eq 'MSWin32' ? '\\' : '/';
21+
my %config = (perl => $^X);
2122
$config{'nqp_config_status'} = join(' ', map { "\"$_\""} @ARGV);
2223

2324
my $exe = $NQP::Configure::exe;
@@ -26,6 +27,7 @@
2627
GetOptions(\%options, 'help!', 'prefix=s',
2728
'with-parrot=s', 'gen-parrot:s',
2829
'make-install!', 'makefile-timing!',
30+
'backends=s',
2931
'parrot-config=s', 'parrot-option=s@');
3032

3133
# Print help if it's requested
@@ -40,9 +42,28 @@
4042
"Use --with-parrot to specify the parrot executable to use."
4143
}
4244

45+
my $default_backend;
46+
my %backends;
47+
my %known_backends = (parrot => 1, jvm => 1, moar => 1);
48+
if ($options{backends}) {
49+
for my $be (split /,/, $options{backends}) {
50+
$be = lc $be;
51+
unless ($known_backends{$be}) {
52+
die "Unknown backend: '$be'; Known backends: " .
53+
join(', ', sort keys %known_backends) . "\n";
54+
}
55+
$default_backend ||= $be;
56+
$backends{$be} = 1;
57+
}
58+
}
59+
else {
60+
# TODO: come up with more sensible defaults
61+
$backends{parrot} = 1;
62+
$default_backend = 'parrot';
63+
}
64+
4365
my $prefix = ($options{'prefix'} && abs_path($options{'prefix'})) || cwd().'/install';
44-
my $with_parrot = $options{'with-parrot'};
45-
my $gen_parrot = $options{'gen-parrot'};
66+
$config{prefix} = $prefix;
4667

4768
# Save options in config.status
4869
unlink('config.status');
@@ -51,105 +72,137 @@
5172
"$^X Configure.pl $config{'nqp_config_status'} \$*\n";
5273
close($CONFIG_STATUS);
5374
}
75+
$config{'makefile-timing'} = $options{'makefile-timing'};
76+
$config{'stagestats'} = '--stagestats' if $options{'makefile-timing'};
77+
$config{'shell'} = $^O eq 'MSWin32' ? 'cmd' : 'sh';
78+
$config{'bat'} = $^O eq 'MSWin32' ? '.bat' : '';
79+
$config{'cpsep'} = $^O eq 'MSWin32' ? ';' : ':';
80+
$config{'slash'} = $slash;
5481

55-
my ($par_want) = split(' ', slurp('tools/build/PARROT_REVISION'));
82+
if ($backends{parrot}) {
83+
my $with_parrot = $options{'with-parrot'};
84+
my $gen_parrot = $options{'gen-parrot'};
85+
my ($par_want) = split(' ', slurp('tools/build/PARROT_REVISION'));
5686

57-
if (defined $gen_parrot) {
58-
$with_parrot = gen_parrot($par_want, %options, prefix => $prefix);
59-
}
87+
if (defined $gen_parrot) {
88+
$with_parrot = gen_parrot($par_want, %options, prefix => $prefix);
89+
}
6090

61-
my @errors;
91+
my @errors;
6292

63-
my %par_config;
64-
if ($with_parrot) {
65-
%par_config = read_parrot_config($with_parrot)
66-
or push @errors, "Unable to read configuration from $with_parrot.";
67-
}
68-
else {
69-
%par_config = read_parrot_config("$prefix/bin/parrot$exe", "parrot$exe")
70-
or push @errors, "Unable to find parrot.";
71-
$with_parrot = fill_template_text('@bindir@/parrot@exe@', %par_config);
72-
}
93+
my %par_config;
94+
if ($with_parrot) {
95+
%par_config = read_parrot_config($with_parrot)
96+
or push @errors, "Unable to read configuration from $with_parrot.";
97+
}
98+
else {
99+
%par_config = read_parrot_config("$prefix/bin/parrot$exe", "parrot$exe")
100+
or push @errors, "Unable to find parrot.";
101+
$with_parrot = fill_template_text('@bindir@/parrot@exe@', %par_config);
102+
}
73103

74-
%config = (%config, %par_config);
75-
my $par_have = $config{'parrot::git_describe'} || '';
76-
if ($par_have && cmp_rev($par_have, $par_want) < 0) {
77-
push @errors, "Parrot revision $par_want required (currently $par_have).";
78-
}
104+
%config = (%config, %par_config);
105+
my $par_have = $config{'parrot::git_describe'} || '';
106+
if ($par_have && cmp_rev($par_have, $par_want) < 0) {
107+
push @errors, "Parrot revision $par_want required (currently $par_have).";
108+
}
79109

80-
if (!@errors) {
81-
push @errors, verify_install([@NQP::Configure::required_parrot_files],
82-
%config);
83-
push @errors,
84-
"(Perhaps you need to 'make install', 'make install-dev',",
85-
"or install the 'devel' package for Parrot?)"
86-
if @errors;
87-
}
110+
if (!@errors) {
111+
push @errors, verify_install([@NQP::Configure::required_parrot_files],
112+
%config);
113+
push @errors,
114+
"(Perhaps you need to 'make install', 'make install-dev',",
115+
"or install the 'devel' package for Parrot?)"
116+
if @errors;
117+
}
88118

89-
if (@errors && !defined $gen_parrot) {
90-
push @errors,
91-
"\nTo automatically clone (git) and build a copy of Parrot $par_want,",
92-
"try re-running Configure.pl with the '--gen-parrot' option.",
93-
"Or, use '--with-parrot=' to explicitly specify the Parrot",
94-
"executable to use to build NQP.";
95-
}
119+
if (@errors && !defined $gen_parrot) {
120+
push @errors,
121+
"\nTo automatically clone (git) and build a copy of Parrot $par_want,",
122+
"try re-running Configure.pl with the '--gen-parrot' option.",
123+
"Or, use '--with-parrot=' to explicitly specify the Parrot",
124+
"executable to use to build NQP.";
125+
}
96126

97-
sorry(@errors) if @errors;
127+
sorry(@errors) if @errors;
98128

99-
print "Using $with_parrot (version $config{'parrot::git_describe'}).\n";
129+
print "Using $with_parrot (version $config{'parrot::git_describe'}).\n";
100130

101-
$config{'makefile-timing'} = $options{'makefile-timing'};
102-
$config{'stagestats'} = '--stagestats' if $options{'makefile-timing'};
103-
$config{'shell'} = $^O eq 'MSWin32' ? 'cmd' : 'sh';
104-
$config{'bat'} = $^O eq 'MSWin32' ? '.bat' : '';
105-
if ($^O eq 'MSWin32' or $^O eq 'cygwin') {
106-
$config{'dll'} = '$(PARROT_BIN_DIR)/$(PARROT_LIB_SHARED)';
107-
$config{'dllcopy'} = '$(PARROT_LIB_SHARED)';
108-
$config{'make_dllcopy'} =
109-
'$(PARROT_DLL_COPY) : $(PARROT_DLL)'."\n\t".'$(CP) $(PARROT_DLL) .';
110-
}
131+
if ($^O eq 'MSWin32' or $^O eq 'cygwin') {
132+
$config{'dll'} = '$(PARROT_BIN_DIR)/$(PARROT_LIB_SHARED)';
133+
$config{'dllcopy'} = '$(PARROT_LIB_SHARED)';
134+
$config{'make_dllcopy'} =
135+
'$(PARROT_DLL_COPY) : $(PARROT_DLL)'."\n\t".'$(CP) $(PARROT_DLL) .';
136+
}
111137

112-
my $make = fill_template_text('@make@', %config);
138+
my $make = fill_template_text('@make@', %config);
113139

114-
if ($make eq 'nmake') {
115-
system_or_die('cd 3rdparty\dyncall && Configure.bat' .
116-
($config{'parrot::archname'} =~ /x64/ ? ' /target-x64' : ''));
117-
$config{'dyncall_build'} = 'cd 3rdparty\dyncall && nmake Nmakefile';
118-
}
119-
else {
120-
if ($^O eq 'MSWin32') {
121-
my $configure_args =
122-
$config{'parrot::archname'} =~ /x86/ ? ' /target-x86' : ' /target-x64';
123-
124-
$configure_args .= $config{'parrot::cc'} eq 'gcc' ? ' /tool-gcc' : '';
125-
126-
system_or_die('cd 3rdparty\dyncall && Configure.bat' . $configure_args);
127-
$config{'dyncall_build'} = "cd 3rdparty/dyncall && $make BUILD_DIR=. -f Makefile.embedded mingw32";
128-
} else {
129-
my $target_args = '';
130-
# heuristic according to
131-
# https://github.com/perl6/nqp/issues/100#issuecomment-18523608
132-
if ($^O eq 'darwin' && qx/ld 2>&1/ =~ /inferred architecture x86_64/) {
133-
$target_args = " --target-x64";
134-
}
135-
system_or_die('cd 3rdparty/dyncall && sh configure' . $target_args);
140+
if ($make eq 'nmake') {
141+
system_or_die('cd 3rdparty\dyncall && Configure.bat' .
142+
($config{'parrot::archname'} =~ /x64/ ? ' /target-x64' : ''));
143+
$config{'dyncall_build'} = 'cd 3rdparty\dyncall && nmake Nmakefile';
144+
}
145+
else {
146+
if ($^O eq 'MSWin32') {
147+
my $configure_args =
148+
$config{'parrot::archname'} =~ /x86/ ? ' /target-x86' : ' /target-x64';
136149

137-
if ($^O eq 'netbsd') {
138-
$config{'dyncall_build'} = "cd 3rdparty/dyncall && BUILD_DIR=. $make -f BSDmakefile";
150+
$configure_args .= $config{'parrot::cc'} eq 'gcc' ? ' /tool-gcc' : '';
151+
152+
system_or_die('cd 3rdparty\dyncall && Configure.bat' . $configure_args);
153+
$config{'dyncall_build'} = "cd 3rdparty/dyncall && $make BUILD_DIR=. -f Makefile.embedded mingw32";
139154
} else {
140-
$config{'dyncall_build'} = "cd 3rdparty/dyncall && BUILD_DIR=. $make";
155+
my $target_args = '';
156+
# heuristic according to
157+
# https://github.com/perl6/nqp/issues/100#issuecomment-18523608
158+
if ($^O eq 'darwin' && qx/ld 2>&1/ =~ /inferred architecture x86_64/) {
159+
$target_args = " --target-x64";
160+
}
161+
system_or_die('cd 3rdparty/dyncall && sh configure' . $target_args);
162+
163+
if ($^O eq 'netbsd') {
164+
$config{'dyncall_build'} = "cd 3rdparty/dyncall && BUILD_DIR=. $make -f BSDmakefile";
165+
} else {
166+
$config{'dyncall_build'} = "cd 3rdparty/dyncall && BUILD_DIR=. $make";
167+
}
141168
}
142169
}
170+
171+
fill_template_file(
172+
['tools/build/Makefile-common.in', 'tools/build/Makefile-Parrot.in'], 'Makefile',
173+
%config,
174+
);
175+
fill_template_file('src/vm/parrot/nqp.sh', 'gen/parrot/nqp_launcher', %config);
176+
chmod 0755, 'gen/parrot/nqp_launcher';
143177
}
178+
if ($backends{moar}) {
179+
my @errors;
180+
my $moar_path = "$prefix${slash}bin${slash}moar" . ($^O =~ /MSWin32/ ? '.exe' : '');
181+
my @moar_info = `$moar_path --help`;
182+
my $moar_found = 0;
183+
for (@moar_info) {
184+
if (/USAGE: moar/) {
185+
$moar_found = 1;
186+
last;
187+
}
188+
}
189+
if (!$moar_found) {
190+
push @errors,
191+
"No MoarVM (moar executable) found using the --prefix";
192+
}
193+
sorry(@errors) if @errors;
194+
$config{'make'} = $^O eq 'MSWin32' ? 'nmake' : 'make';
195+
$config{'runner'} = $^O eq 'MSWin32' ? 'nqp.bat' : 'nqp';
196+
fill_template_file(
197+
['tools/build/Makefile-common.in', 'tools/build/Makefile-Moar.in'],
198+
'Makefile',
199+
%config,
200+
);
144201

145-
fill_template_file(
146-
['tools/build/Makefile-common.in', 'tools/build/Makefile-Parrot.in'], 'Makefile',
147-
%config,
148-
);
149-
fill_template_file('src/vm/parrot/nqp.sh', 'gen/parrot/nqp_launcher', %config);
150-
chmod 0755, 'gen/parrot/nqp_launcher';
202+
}
151203

152-
{
204+
my $make = fill_template_text('@make@', %config);
205+
unless ($options{'no-clean'}) {
153206
no warnings;
154207
print "Cleaning up ...\n";
155208
if (open my $CLEAN, '-|', "$make clean") {
@@ -181,6 +234,7 @@ sub print_help {
181234
General Options:
182235
--help Show this text
183236
--prefix=dir Install files in dir
237+
--backends=list Backends to use: parrot,jvm,moar
184238
--with-parrot=path/to/bin/parrot
185239
Parrot executable to use to build NQP
186240
--gen-parrot[=branch]

0 commit comments

Comments
 (0)