Skip to content

Commit

Permalink
modernize some code, and add error checking
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Weeks <tene@allalone.org>
  • Loading branch information
petdance authored and tene committed Feb 25, 2009
1 parent 9f3d289 commit f9cb35e
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions Configure.pl
Expand Up @@ -28,19 +28,22 @@
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");
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";
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.
Expand Down Expand Up @@ -68,7 +71,7 @@ sub get_command_options {
}
die qq/Invalid option "$arg". See "perl Configure.pl --help" for valid options.\n/;
}
%options;
return %options;
}


Expand All @@ -82,33 +85,37 @@ sub read_parrot_config {
while (<$PARROT_CONFIG>) {
if (/(\w+) => '(.*)'/) { $config{$1} = $2 }
}
close $PARROT_CONFIG;
close $PARROT_CONFIG or die $!;
last if %config;
}
}
%config;
return %config;
}


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

print "Creating Makefile\n";
open(MAKEFILE, ">Makefile") ||
die "Unable to write Makefile\n";
print MAKEFILE $maketext;
close(MAKEFILE);
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;
}


Expand Down Expand Up @@ -138,6 +145,8 @@ sub print_help {
Use configuration information from config
END

return;
}

# Local Variables:
Expand Down

0 comments on commit f9cb35e

Please sign in to comment.