Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: 2009-02
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 158 lines (124 sloc) 3.763 kb
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
#! perl
# Copyright (C) 2009 The Perl Foundation

use strict;
use warnings;
use 5.008;


my %valid_options = (
    'help' => 'Display configuration help',
    'parrot-config' => 'Use configuration given by parrot_config binary',
    'gen-parrot' => 'Automatically retrieve and build Parrot',
);


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


# Update/generate parrot build if needed
if ($options{'gen-parrot'}) {
    system("$^X build/gen_parrot.pl");
}

# Get a list of parrot-configs to invoke.
my @parrot_config_exe = qw(
parrot/parrot_config
../../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 <<'END';
Unable to locate parrot_config.
To automatically checkout (svn) and build a copy of parrot,
try re-running Configure.pl with the '--gen-parrot' option.
Or, use the '--parrot-config' option to explicitly specify
the location of parrot_config.
END
}

# 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/;
    }
    return %options;
}


sub read_parrot_config {
    my @parrot_config_exe = @_;
    my %config = ();
    for my $exe (@parrot_config_exe) {
        no warnings;
        if (open my $PARROT_CONFIG, '-|', "$exe --dump") {
            print "Reading configuration information from $exe\n";
            while (<$PARROT_CONFIG>) {
                if (/(\w+) => '(.*)'/) { $config{$1} = $2 }
            }
            close $PARROT_CONFIG or die $!;
            last if %config;
        }
    }
    return %config;
}


# Generate a Makefile from a configuration
sub create_makefile {
    my %config = @_;
    my $infile = 'build/Makefile.in';
    open my $ROOTIN, '<', $infile or
        die "Unable to read $infile\n";
    my $maketext = join('', <$ROOTIN>);
    close $ROOTIN or die $!;

    $config{'win32_libparrot_copy'} = $^O eq 'MSWin32' ? 'copy $(BUILD_DIR)\libparrot.dll .' : '';
    $maketext =~ s/@(\w+)@/$config{$1}/g;
    if ($^O eq 'MSWin32') {
        $maketext =~ s{/}{\\}g;
    }

    my $outfile = 'Makefile';
    print "Creating $outfile\n";
    open(my $MAKEOUT, '>', $outfile) ||
        die "Unable to write $outfile\n";
    print {$MAKEOUT} $maketext;
    close $MAKEOUT or die $!;

    return;
}


sub done {
    my $make = $config{'make'};
    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 check out (via svn) a copy of the Perl 6
official test suite and run its tests.

END
    exit 0;
}


# Print some help text.
sub print_help {
    print <<'END';
Configure.pl - Rakudo Configure

General Options:
--help Show this text
--gen-parrot Download and build a copy of Parrot to use
--parrot-config=(config)
Use configuration information from config

END

    return;
}

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4:
Something went wrong with that request. Please try again.