Skip to content

Commit

Permalink
Commit adapted Configure.pl from Rakudo.
Browse files Browse the repository at this point in the history
Clean up src/pmc in src/pmc/Makefile
  • Loading branch information
bschmalhofer committed Mar 1, 2009
1 parent 9e8dab6 commit 06fe934
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,6 +12,7 @@

/src/pct/gen_*.pir

/src/pmc/Makefile
/src/pmc/php*.c
/src/pmc/php*.h
/src/pmc/pmc_php*.h
Expand Down
158 changes: 151 additions & 7 deletions Configure.pl
@@ -1,16 +1,160 @@
# Copyright (C) 2009, The Perl Foundation.
#! perl
# Copyright (C) 2009 The Perl Foundation

use strict;
use warnings;
use 5.008;

my $build_dir = '../..';
my $hll = 'pipp';
my $cmd = qq{$^X -Ilib tools/dev/reconfigure.pl --step=gen::languages --languages=$hll};

print "Running '$cmd' in $build_dir\n";
chdir $build_dir;
`$cmd`
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 = (
"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_makefiles(
\%config,
{ 'build/templates/Makefile.in' => 'Makefile',
'build/templates/src/pmc/Makefile.in' => 'src/pmc/Makefile',
}
);

# Done.
done($config{'make'});


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

return %config;
}


# Generate a Makefile from a configuration
sub create_makefiles {
my ($config, $makefiles) = @_;

while (my ($template_fn, $target_fn) = each %{$makefiles}) {
my $content;
{
open my $template_fh, '<', $template_fn or
die "Unable to read $template_fn.";
$content = join('', <$template_fh>);
close $template_fn;
}

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

print "Creating $target_fn from $template_fn.\n";
{
open(my $target_fh, '>', $target_fn)
or die "Unable to write $target_fn\n";
print $target_fh $content;
close($target_fh);
}
}
}


sub done {
my ($make) = @_;
print <<"END";
You can now use '$make' to build Pipp.
After that, you can use '$make test' to run some local tests.
See 'docs/testing.pod' for how to run the PHP 5.3 testsuite.
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
}

# Local Variables:
# mode: cperl
Expand Down
14 changes: 4 additions & 10 deletions build/templates/Makefile.in
Expand Up @@ -14,6 +14,7 @@ PMC_DIR = src/pmc
PARROT_DYNEXT = $(BUILD_DIR)/runtime/parrot/dynext

# Set up commands
MAKE = @make_c@
PARROT = $(BUILD_DIR)/parrot@exe@
PERL = @perl@
RM_F = @rm_f@
Expand Down Expand Up @@ -116,7 +117,7 @@ PHP_EXT = \
library/php_pcre.pbc

# default
build
all: build

# This is a listing of all targets, that are meant to be called by users
help:
Expand Down Expand Up @@ -149,7 +150,7 @@ help:
@echo ""

# regenerate the Makefile
Makefile: build/Makefile.in
Makefile: build/templates/Makefile.in
$(PERL) Configure.pl

build: build-common
Expand Down Expand Up @@ -337,14 +338,7 @@ clean: clean-pmc clean-test clean-hash
pipp$(EXE)

clean-pmc:
$(RM_F) \
"$(PMC_DIR)/*dump" \
"$(PMC_DIR)/php*.c" \
"$(PMC_DIR)/pmc_*h" \
"$(PMC_DIR)/php_group.h" \
"$(PMC_DIR)/*$(O)" \
"$(PMC_DIR)/*$(LOAD_EXT)"

$(MAKE) $(PMC_DIR) clean

clean-test:
$(RM_F) \
Expand Down
24 changes: 23 additions & 1 deletion build/templates/src/pmc/Makefile.in
@@ -1,7 +1,20 @@
# Build the PMCs for Pipp.

# Set up commands
PERL = @perl@
RM_F = @rm_f@

# Set up directories
PMC_DIR = src/pmc

# Set up extensions
LOAD_EXT = @load_ext@
O = @o@

# default
build
build:
@echo "Not yet implemented"


# This is a listing of all targets, that are meant to be called by users
help:
Expand All @@ -11,3 +24,12 @@ help:
@echo "Building:"
@echo " build: Build the PMCs."
@echo " This is the default."
@echo ""
@echo "Cleaning:"
@echo " clean: Clean up."
@echo ""

# cleaning up
clean:
$(RM_F) "*dump" "php*.c" "pmc_*h" "php_group.h" "*$(O)" "*$(LOAD_EXT)"

0 comments on commit 06fe934

Please sign in to comment.