Skip to content

Commit

Permalink
start to fold ConfigureJVM.pl into Configure.pl
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Oct 22, 2013
1 parent a135bc6 commit 499325e
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 90 deletions.
203 changes: 146 additions & 57 deletions Configure.pl
Expand Up @@ -15,21 +15,24 @@
my $lang = 'Rakudo';
my $lclang = lc $lang;
my $uclang = uc $lang;
my $slash = $^O eq 'MSWin32' ? '\\' : '/';


MAIN: {
if (-r 'config.default') {
unshift @ARGV, shellwords(slurp('config.default'));
}

my %config;
my %config = (perl => $^X);
my $config_status = "${lclang}_config_status";
$config{$config_status} = join ' ', map { qq("$_") } @ARGV;

my $exe = $NQP::Configure::exe;

my %options;
GetOptions(\%options, 'help!', 'prefix=s',
'with-nqp=s', 'gen-nqp:s',
'backends=s',
'with-nqp-p=s', 'gen-nqp-p:s',
'with-parrot=s', 'gen-parrot:s', 'parrot-option=s@',
'parrot-make-option=s@',
'make-install!', 'makefile-timing!',
Expand All @@ -44,11 +47,39 @@
exit(0);
}

my $prefix = $options{'prefix'} || cwd().'/install';
my $with_nqp = $options{'with-nqp'};
my $gen_nqp = $options{'gen-nqp'};
my $with_parrot = $options{'with-parrot'};
my $gen_parrot = $options{'gen-parrot'};
my $prefix = $options{'prefix'} || cwd().'/install';
my %known_backends = (parrot => 1, jvm => 1);
my %letter_to_backend;
for (keys %known_backends) {
$letter_to_backend{ substr($_, 0, 1) } = $_;
}
my %backends;
if (defined $options{backends}) {
for my $b (split /,\s*/, $options{backends}) {
$b = lc $b;
unless ($known_backends{$b}) {
die "Uknown backend '$b'; Supported backends are: ",
join(", ", sort keys %backends),
"\n";
}
}
unless (%backends) {
die "--prefix given, but no valid backend?!\n";
}
}
else {
for my $l (keys %letter_to_backend) {
# TODO: needs .exe/.bat magic on windows?
if (-x "$prefix/bin/nqp-$l") {
my $b = $letter_to_backend{$l};
print "Found $prefix/bin/nqp-$l (backend $b)\n";
$backends{$b} = 1;
}
}
unless (%backends) {
die "No suitable nqp executables found! Please specify some --backends, or a --prefix that contains nqp-{p,j} executables\n";
}
}

# Save options in config.status
unlink('config.status');
Expand All @@ -58,71 +89,129 @@
close($CONFIG_STATUS);
}

# --with-parrot and --gen-parrot imply --gen-nqp
if (!defined $gen_nqp && !defined $with_nqp && (defined $with_parrot || defined $gen_parrot)) {
$gen_nqp = '';
}
$config{prefix} = $prefix;
$config{slash} = $slash;
$config{'makefile-timing'} = $options{'makefile-timing'};
$config{'stagestats'} = '--stagestats' if $options{'makefile-timing'};
$config{'cpsep'} = $^O eq 'MSWin32' ? ';' : ':';
my $make = $config{'make'} = $^O eq 'MSWin32' ? 'nmake' : 'make';

open my $MAKEFILE, '>', 'Makefile'
or die "Cannot open 'Makefile' for writing: $!";

fill_template_file('tools/build/Makefile-common.in', $MAKEFILE, %config);

my $gen_nqp = $options{'gen-nqp'};

# determine the version of NQP we want
my ($nqp_want) = split(' ', slurp('tools/build/NQP_REVISION'));

if (defined $gen_nqp) {
$with_nqp = gen_nqp($nqp_want, %options);
}
if ($backends{parrot}) {
my $with_parrot = $options{'with-parrot'};
my $gen_parrot = $options{'gen-parrot'};
my $nqp_p = "$prefix/bin/nqp-p";
$nqp_p = undef unless -x $nqp_p;

my @errors;
# --with-parrot and --gen-parrot imply --gen-nqp
if (!defined $gen_nqp && !defined $nqp_p && (defined $with_parrot || defined $gen_parrot)) {
$gen_nqp = '';
}

my %nqp_config;
if ($with_nqp) {
%nqp_config = read_config($with_nqp)
or push @errors, "Unable to read configuration from $with_nqp.";
}
else {
%nqp_config = read_config("$prefix/bin/nqp-p$exe", "nqp-p$exe")
or push @errors, "Unable to find an NQP executable.";
$with_nqp = fill_template_text('@bindir@/nqp@exe@', %nqp_config)
}
if (defined $gen_nqp) {
$nqp_p = gen_nqp($nqp_want, %options);
}

%config = (%config, %nqp_config);
my $nqp_have = $config{'nqp::version'} || '';
if ($nqp_have && cmp_rev($nqp_have, $nqp_want) < 0) {
push @errors, "NQP revision $nqp_want required (currently $nqp_have).";
}
my @errors;

if (!@errors) {
push @errors, verify_install([ @NQP::Configure::required_parrot_files,
@NQP::Configure::required_nqp_files ],
%config);
push @errors,
"(Perhaps you need to 'make install', 'make install-dev',",
"or install the 'devel' package for NQP or Parrot?)"
if @errors;
}
my %nqp_config;
if ($nqp_p) {
%nqp_config = read_config($nqp_p)
or push @errors, "Unable to read configuration from $nqp_p.";
}
else {
%nqp_config = read_config("$prefix/bin/nqp-p$exe", "nqp-p$exe")
or push @errors, "Unable to find an NQP executable.";
$nqp_p = fill_template_text('@bindir@/nqp@exe@', %nqp_config)
}

%config = (%config, %nqp_config);
my $nqp_have = $config{'nqp::version'} || '';
if ($nqp_have && cmp_rev($nqp_have, $nqp_want) < 0) {
push @errors, "NQP revision $nqp_want required (currently $nqp_have).";
}

if (!@errors) {
push @errors, verify_install([ @NQP::Configure::required_parrot_files,
@NQP::Configure::required_nqp_files ],
%config);
push @errors,
"(Perhaps you need to 'make install', 'make install-dev',",
"or install the 'devel' package for NQP or Parrot?)"
if @errors;
}

if (@errors && !defined $gen_nqp) {
push @errors,
"\nTo automatically clone (git) and build a copy of NQP $nqp_want,",
"try re-running Configure.pl with the '--gen-nqp' or '--gen-parrot'",
"options. Or, use '--with-nqp=' or '--with-parrot=' to explicitly",
"specify the NQP or Parrot executable to use to build $lang.";
}

sorry(@errors) if @errors;

print "Using $nqp_p (version $config{'nqp::version'}).\n";

$config{'makefile-timing'} = $options{'makefile-timing'};
$config{'stagestats'} = '--stagestats' if $options{'makefile-timing'};
$config{'shell'} = $^O eq 'MSWin32' ? 'cmd' : 'sh';
if ($^O eq 'MSWin32' or $^O eq 'cygwin') {
$config{'dll'} = '$(PARROT_BIN_DIR)/$(PARROT_LIB_SHARED)';
$config{'dllcopy'} = '$(PARROT_LIB_SHARED)';
$config{'make_dllcopy'} =
'$(PARROT_DLL_COPY): $(PARROT_DLL)'."\n\t".'$(CP) $(PARROT_DLL) .';
}

if (@errors && !defined $gen_nqp) {
push @errors,
"\nTo automatically clone (git) and build a copy of NQP $nqp_want,",
"try re-running Configure.pl with the '--gen-nqp' or '--gen-parrot'",
"options. Or, use '--with-nqp=' or '--with-parrot=' to explicitly",
"specify the NQP or Parrot executable to use to build $lang.";
my $make = fill_template_text('@make@', %config);
fill_template_file('tools/build/Makefile-Parrot.in', $MAKEFILE, %config);
}
if ($backends{jvm}) {
my $nqp_j = "$prefix/bin/nqp-j";
$nqp_j = undef unless -x $nqp_j;
if (!defined $gen_nqp && !defined $nqp_j) {
die "$prefix/bin/nqp-j does not exists or is not executable (maybe use --gen-nqp?\n";
}

sorry(@errors) if @errors;
if (defined $gen_nqp) {
$options{'with-jvm'} = 1;
$options{'prefix'} = $prefix;
$nqp_j = gen_nqp($nqp_want, %options);
}
my @errors;

print "Using $with_nqp (version $config{'nqp::version'}).\n";
unless (`$nqp_j --version` =~ /This is nqp .+ JVM/) {
push @errors, "No NQP on JVM found; use --with-nqp to specify or --gen-nqp";
}

$config{'makefile-timing'} = $options{'makefile-timing'};
$config{'stagestats'} = '--stagestats' if $options{'makefile-timing'};
$config{'shell'} = $^O eq 'MSWin32' ? 'cmd' : 'sh';
if ($^O eq 'MSWin32' or $^O eq 'cygwin') {
$config{'dll'} = '$(PARROT_BIN_DIR)/$(PARROT_LIB_SHARED)';
$config{'dllcopy'} = '$(PARROT_LIB_SHARED)';
$config{'make_dllcopy'} =
'$(PARROT_DLL_COPY): $(PARROT_DLL)'."\n\t".'$(CP) $(PARROT_DLL) .';
my %nqp_config = read_config($nqp_j)
or push @errors, "Unable to read configuration from $nqp_j.";
unless (defined $nqp_config{'jvm::runtime.jars'}) {
push @errors, "jvm::runtime.jars value not available from $nqp_j --show-config.";
}

sorry(@errors) if @errors;

print "Using $nqp_j.\n";

$config{'nqp_prefix'} = $nqp_config{'jvm::runtime.prefix'};
$config{'nqp_jars'} = $nqp_config{'jvm::runtime.jars'};
$config{'nqp_classpath'} = $nqp_config{'jvm::runtime.classpath'};


fill_template_file('tools/build/Makefile-JVM.in', $MAKEFILE, %config);
}

my $make = fill_template_text('@make@', %config);
fill_template_file('tools/build/Makefile-Parrot.in', 'Makefile', %config);
close $MAKEFILE or die "Cannot write 'Makefile': $!";

{
no warnings;
Expand Down
18 changes: 3 additions & 15 deletions tools/build/Makefile-JVM.in
@@ -1,11 +1,3 @@
PERL = @perl@
PROVE = prove
MKPATH = $(PERL) -MExtUtils::Command -e mkpath
CHMOD = $(PERL) -MExtUtils::Command -e chmod
CP = $(PERL) -MExtUtils::Command -e cp
RM_F = $(PERL) -MExtUtils::Command -e rm_f
RM_RF = $(PERL) -MExtUtils::Command -e rm_rf

JAVA = java
JAVAC = javac
JAR = jar
Expand Down Expand Up @@ -44,7 +36,7 @@ SETTING_JAR = CORE.setting.jar
PERL6_LANG_JARS = $(PERL6_ML_JAR) $(PERL6_W_JAR) $(PERL6_G_JAR) $(PERL6_OPS_JAR) $(PERL6_A_JAR) \
$(PERL6_O_JAR) $(PERL6_P_JAR) $(PERL6_C_JAR) $(PERL6_M_JAR) $(PERL6_B_JAR)

METAMODEL_SOURCES = \
J_METAMODEL_SOURCES = \
src/Perl6/Metamodel/Archetypes.nqp \
src/Perl6/Metamodel/Naming.nqp \
src/Perl6/Metamodel/Documenting.nqp \
Expand Down Expand Up @@ -89,10 +81,6 @@ METAMODEL_SOURCES = \
src/Perl6/Metamodel/Dispatchers.nqp \
src/vm/jvm/Perl6/Metamodel/JavaHOW.nqp \

BOOTSTRAP_SOURCES = \
src/Perl6/Metamodel/BOOTSTRAP.nqp \
src/Perl6/Metamodel/EXPORTHOW.nqp \

# The ordering here is important for bootstrapping reasons. In general:
# * traits almost certainly have to come first
# * stubs have to come after traits since they use them
Expand Down Expand Up @@ -277,8 +265,8 @@ $(PERL6_JAR): src/main.nqp $(RUNTIME_JAR) $(PERL6_G_JAR) $(PERL6_A_JAR) $(PERL6_
$(J_NQP) --target=jar --javaclass=perl6 --output=$(PERL6_JAR) \
src/gen/main.nqp

$(PERL6_M_JAR): $(METAMODEL_SOURCES) $(PERL6_OPS_JAR)
$(PERL) $(J_GEN_CAT) $(METAMODEL_SOURCES) > src/gen/Metamodel.nqp
$(PERL6_M_JAR): $(J_METAMODEL_SOURCES) $(PERL6_OPS_JAR)
$(PERL) $(J_GEN_CAT) $(J_METAMODEL_SOURCES) > src/gen/Metamodel.nqp
$(J_NQP) --target=jar --output=$(PERL6_M_JAR) --encoding=utf8 \
src/gen/Metamodel.nqp

Expand Down
20 changes: 3 additions & 17 deletions tools/build/Makefile-Parrot.in
@@ -1,13 +1,3 @@
PERL = @perl@
PROVE = prove
MKPATH = $(PERL) -MExtUtils::Command -e mkpath
CHMOD = $(PERL) -MExtUtils::Command -e chmod
CP = $(PERL) -MExtUtils::Command -e cp
RM_F = $(PERL) -MExtUtils::Command -e rm_f
RM_RF = $(PERL) -MExtUtils::Command -e rm_rf

# Copyright (C) 2006-2013, The Perl Foundation.

SHELL = @shell@
PARROT_ARGS =

Expand Down Expand Up @@ -88,7 +78,7 @@ DYNOPS = $(OPS_DIR)/$(OPS)$(LOAD_EXT)

OPS_SOURCE = perl6.ops

METAMODEL_SOURCES = \
P_METAMODEL_SOURCES = \
src/Perl6/Metamodel/Archetypes.nqp \
src/Perl6/Metamodel/Naming.nqp \
src/Perl6/Metamodel/Documenting.nqp \
Expand Down Expand Up @@ -133,10 +123,6 @@ METAMODEL_SOURCES = \
src/Perl6/Metamodel/ContainerDescriptor.nqp \
src/Perl6/Metamodel/Dispatchers.nqp \

BOOTSTRAP_SOURCES = \
src/Perl6/Metamodel/BOOTSTRAP.nqp \
src/Perl6/Metamodel/EXPORTHOW.nqp \

# The ordering here is important for bootstrapping reasons. In general:
# * traits almost certainly have to come first
# * stubs have to come after traits since they use them
Expand Down Expand Up @@ -384,8 +370,8 @@ $(PERL6_C_PBC): $(NQP_EXE) $(DYNEXT_DYNOPS) $(PERL6_O_PBC) src/Perl6/Compiler.nq
src/Perl6/Compiler.nqp
$(PARROT) $(PARROT_ARGS) -o $(PERL6_C_PBC) $(PERL6_C)

$(PERL6_M_PBC): $(NQP_EXE) $(DYNEXT_DYNOPS) $(METAMODEL_SOURCES) $(PERL6_OPS_PBC)
$(PERL) $(P_GEN_CAT) $(METAMODEL_SOURCES) > src/gen/Metamodel.nqp
$(PERL6_M_PBC): $(NQP_EXE) $(DYNEXT_DYNOPS) $(P_METAMODEL_SOURCES) $(PERL6_OPS_PBC)
$(PERL) $(P_GEN_CAT) $(P_METAMODEL_SOURCES) > src/gen/Metamodel.nqp
$(NQP_EXE) --target=pir --output=$(PERL6_M) --encoding=utf8 \
--vmlibs=perl6_ops src/gen/Metamodel.nqp
$(PARROT) $(PARROT_ARGS) -o $(PERL6_M_PBC) $(PERL6_M)
Expand Down
13 changes: 13 additions & 0 deletions tools/build/Makefile-common.in
@@ -0,0 +1,13 @@
# Copyright (C) 2006-2013, The Perl Foundation.

PERL = @perl@
PROVE = prove
MKPATH = $(PERL) -MExtUtils::Command -e mkpath
CHMOD = $(PERL) -MExtUtils::Command -e chmod
CP = $(PERL) -MExtUtils::Command -e cp
RM_F = $(PERL) -MExtUtils::Command -e rm_f
RM_RF = $(PERL) -MExtUtils::Command -e rm_rf

BOOTSTRAP_SOURCES = \
src/Perl6/Metamodel/BOOTSTRAP.nqp \
src/Perl6/Metamodel/EXPORTHOW.nqp \
2 changes: 1 addition & 1 deletion tools/lib/NQP/Configure.pm
Expand Up @@ -25,7 +25,7 @@ our @required_parrot_files = qw(
);

our @required_nqp_files = qw(
@bindir@/nqp@exe@
@bindir@/nqp-p@exe@
);

our $nqp_git = 'http://github.com/perl6/nqp.git';
Expand Down

0 comments on commit 499325e

Please sign in to comment.