Skip to content

Commit

Permalink
Update Configure.pl with some help messages and options.
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick R. Michaud committed Feb 4, 2009
1 parent 0c50158 commit 7d7f1af
Showing 1 changed file with 123 additions and 3 deletions.
126 changes: 123 additions & 3 deletions Configure.pl
@@ -1,8 +1,128 @@
#! perl
# Copyright (C) 2008 The Perl Foundation
# Copyright (C) 2009 The Perl Foundation

use strict;
use warnings;

chdir '../..';
`$^X -Ilib tools/dev/reconfigure.pl --step=gen::languages --languages=rakudo`;

my %valid_options = (
'help' => 'Display configuration help',
'parrot-config' => 'Use configuration given by parrot_config binary',
);


# 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);
}

# If we're in a Parrot build tree and --parrot-config isn't
# specified, use the build tree's reconfigure.pl and exit.
if (!$options{'parrot-config'} && -e "../../tools/dev/reconfigure.pl") {
print "Building Makefile with ../../tools/dev/reconfigure.pl\n";
chdir '../..';
`$^X -Ilib tools/dev/reconfigure.pl --step=gen::languages --languages=rakudo`;
done();
}


# Get a list of parrot-configs to invoke.
my @parrot_config_exe = qw(parrot/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 "Unable to obtain configuration from "
. join(', ', @parrot_config_exe) . "\n";
}

# Create the Makefile using the information we just got
create_makefile(%config);

# Done.
done();


# 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(PARROT_CONFIG, "$exe --dump |")) {
print "Reading configuration information from $exe\n";
while (<PARROT_CONFIG>) {
if (/(\w+) => '(.*)'/) { $config{$1} = $2 }
}
close(PARROT_CONFIG);
last;
}
}
%config;
}


# Generate a Makefile from a configuration
sub create_makefile {
my %config = @_;
open(ROOTIN, "<config/makefiles/root.in") ||
die "Unable to read config/makefiles/root.in \n";
my $maketext = join('', <ROOTIN>);
close(ROOTIN);
$maketext =~ s/@(\w+)@/$config{$1}/g;

print "Creating Makefile\n";
open(MAKEFILE, ">Makefile") ||
die "Unable to read config/makefiles/root.in \n";
print MAKEFILE $maketext;
close(MAKEFILE);
}


sub done {
print <<END;
You can now use 'make' to build Rakudo Perl.
After that, you can use 'make test' to run some local tests,
or 'make spectest' to obtain a copy of the spectest suite
and test that.
END
exit 0;
}


# Print some help text.
sub print_help {
print <<END;
Configure.pl - Rakudo Configure
General Options:
--help Show this text
--parrot-config=(config)
Use configuration information from config
END
}

0 comments on commit 7d7f1af

Please sign in to comment.