Permalink
Browse files

Refactor build/gen_how_pm.pl and build/gen_setting.pl into tools/buil…

…d/gen-cat.pl. Update to shiny new Configure.pl.
  • Loading branch information...
1 parent f412826 commit 290d603e9c5b079e7117abcc47311843d38545aa @pmichaud pmichaud committed May 31, 2011
View
@@ -6,74 +6,80 @@
use warnings;
use Getopt::Long;
use Cwd;
-use lib "build/lib";
-use Rakudo::CompareRevisions qw(compare_parrot_revs);
+use lib "tools/lib";
+use NQP::Config qw(cmp_rev read_parrot_config slurp system_or_die);
MAIN: {
+ my %config;
+ $config{'nqp_config_status'} = join(' ', map { "\"$_\""} @ARGV);
+
my %options;
- GetOptions(\%options, 'help!', 'parrot-config=s',
- 'gen-parrot!', 'gen-parrot-prefix=s', 'gen-parrot-option=s@');
+ GetOptions(\%options, 'help!', 'parrot-config=s', 'prefix=s',
+ 'gen-parrot!', 'gen-parrot-option=s@', 'min-parrot-revision=s');
# Print help if it's requested
if ($options{'help'}) {
print_help();
exit(0);
}
- # Determine the revision of Parrot we require
- open my $REQ, "build/PARROT_REVISION"
- || die "cannot open build/PARROT_REVISION\n";
- my ($reqsvn, $reqpar) = split(' ', <$REQ>);
- close $REQ;
+ # Save options in config.status
+ if (open(my $CONFIG_STATUS, '>', 'config.status')) {
+ print $CONFIG_STATUS
+ "$^X Configure.pl $config{'nqp_config_status'} \$*\n";
+ close($CONFIG_STATUS);
+ }
- # Update/generate parrot build if needed
- if ($options{'gen-parrot'}) {
- my @opts = @{ $options{'gen-parrot-option'} || [] };
- my $prefix = $options{'gen-parrot-prefix'} || cwd()."/parrot_install";
- # parrot's Configure.pl mishandles win32 backslashes in --prefix
- $prefix =~ s{\\}{/}g;
- my @command = ($^X, "build/gen_parrot.pl", "--prefix=$prefix", "--gc=gms", "--optimize", @opts);
+ my $parrot_config_exe = $options{'parrot-config'};
+ if ($options{'gen-parrot'}) {
+ my @opts = @{ $options{'gen-parrot-option'} || [] };
+ push @opts, "--min-parrot-revision=$options{'min-parrot-revision'}"
+ if $options{'min-parrot-revision'};
+ my $prefix = $options{'prefix'} || cwd()."/install";
+ my @cmd = ($^X, "tools/build/gen-parrot.pl", "--prefix=$prefix",
+ "--optimize", @opts);
print "Generating Parrot ...\n";
- print "@command\n\n";
- system @command;
+ print "@cmd\n\n";
+ system_or_die(@cmd);
+ # use the newly-built parrot config
+ $parrot_config_exe = "$prefix/bin/parrot_config";
}
- # Get a list of parrot-configs to invoke.
- my @parrot_config_exe = qw(
- parrot_install/bin/parrot_config
- ../../parrot_config
- parrot_config
- );
- if (exists $options{'gen-parrot-prefix'}) {
- unshift @parrot_config_exe,
- $options{'gen-parrot-prefix'} . '/bin/parrot_config';
+ my %parrot_config;
+ if ($parrot_config_exe) {
+ %parrot_config = read_parrot_config($parrot_config_exe);
}
-
- if ($options{'parrot-config'} && $options{'parrot-config'} ne '1') {
- @parrot_config_exe = ($options{'parrot-config'});
+ else {
+ # look in some standard locations
+ %parrot_config = read_parrot_config(qw(
+ install/bin/parrot_config
+ parrot_config
+ ));
}
- # Get configuration information from parrot_config
- my %config = read_parrot_config(@parrot_config_exe);
-
- my $parrot_errors = '';
- if (!%config) {
- $parrot_errors .= "Unable to locate parrot_config\n";
+ my $errors;
+ if (!%parrot_config) {
+ $errors .= "Unable to locate parrot_config\n";
}
- elsif (compare_parrot_revs($reqsvn, $config{'git_describe'}) > 0 &&
+ %config = (%config, %parrot_config);
+
+ my ($revision_want) = $options{'min_parrot-revision'}
+ || split(' ', slurp("tools/build/PARROT_REVISION"));
+ my $revision_have = $config{'parrot::git_describe'};
- ($reqpar eq '' || version_int($reqpar) > version_int($config{'VERSION'}))) {
- $parrot_errors .= "Parrot revision $reqsvn required (currently $config{'git_describe'})\n";
+ if (cmp_rev($revision_have, $revision_want) < 0) {
+ $errors .= "Parrot revision $revision_want required"
+ . " (currently $revision_have)\n";
}
- if ($parrot_errors) {
+ if ($errors) {
die <<"END";
===SORRY!===
-$parrot_errors
-To automatically checkout (git) and build a copy of parrot $reqsvn,
+$errors
+To automatically checkout (git) and build a copy of parrot $revision_want,
try re-running Configure.pl with the '--gen-parrot' option.
-Or, use the '--parrot-config' option to explicitly specify
+Or, use the the '--parrot-config' option to explicitly specify
the location of parrot_config to be used to build NQP.
END
@@ -84,122 +90,54 @@ END
# Create the Makefile using the information we just got
create_makefile(%config);
- my $make = $config{'make'};
+
+ my $make = $config{'parrot::make'};
{
no warnings;
print "Cleaning up ...\n";
if (open my $CLEAN, '-|', "$make clean") {
my @slurp = <$CLEAN>;
- close $CLEAN;
+ close($CLEAN);
}
}
print <<"END";
You can now use '$make' to build NQP.
-After that, you can use '$make test' to run some local tests.
+After that, you can use '$make test' to run some tests, and
+'$make install' to install NQP.
END
exit 0;
-
-}
-
-
-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 "\nReading configuration information from $exe ...\n";
- while (<$PARROT_CONFIG>) {
- if (/(\w+) => '(.*)'/) { $config{$1} = $2 }
- }
- close $PARROT_CONFIG or die $!;
- last if %config;
- }
- }
- return %config;
}
sub verify_parrot {
- print "Verifying Parrot installation...\n";
- my %config = @_;
- my $PARROT_VERSION = $config{'versiondir'};
- my $PARROT_LIB_DIR = $config{'libdir'}.$PARROT_VERSION;
- my $PARROT_SRC_DIR = $config{'srcdir'}.$PARROT_VERSION;
- my $PARROT_INCLUDE_DIR = $config{'includedir'}.$PARROT_VERSION;
- my $PARROT_TOOLS_DIR = "$PARROT_LIB_DIR/tools";
- my @required_files = (
- "$PARROT_LIB_DIR/library/PGE/Perl6Grammar.pbc",
- "$PARROT_LIB_DIR/library/PCT/HLLCompiler.pbc",
- "$PARROT_TOOLS_DIR/build/ops2c.pl",
- "$PARROT_TOOLS_DIR/build/pmc2c.pl",
- "$PARROT_SRC_DIR",
- "$PARROT_SRC_DIR/pmc",
- "$PARROT_INCLUDE_DIR",
- "$PARROT_INCLUDE_DIR/pmc",
- );
- my @missing;
- for my $reqfile (@required_files) {
- push @missing, " $reqfile" unless -e $reqfile;
- }
- if (@missing) {
- my $missing = join("\n", @missing);
- die <<"END";
-
-===SORRY!===
-I'm missing some needed files from the Parrot installation:
-$missing
-(Perhaps you need to use Parrot's "make install-dev" or
-install the "parrot-devel" package for your system?)
-
-END
- }
+ 1;
}
-# Generate a Makefile from a configuration
+
sub create_makefile {
my %config = @_;
-
- my $maketext = slurp( 'build/Makefile.in' );
-
- $config{'win32_libparrot_copy'} = $^O eq 'MSWin32' ? 'copy $(PARROT_BIN_DIR)\libparrot.dll .' : '';
- $maketext =~ s/@(\w+)@/$config{$1}/g;
- if ($^O eq 'MSWin32') {
- $maketext =~ s{/}{\\}g;
- $maketext =~ s{\\\*}{\\\\*}g;
- $maketext =~ s{http:\S+}{ do {my $t = $&; $t =~ s'\\'/'g; $t} }eg;
- }
-
- my $outfile = 'Makefile';
- print "\nCreating $outfile ...\n";
- open(my $MAKEOUT, '>', $outfile) ||
- die "Unable to write $outfile\n";
- print {$MAKEOUT} $maketext;
- close $MAKEOUT or die $!;
-
+ my $maketext = slurp( 'tools/build/Makefile.in' );
+
+ $config{'win32_libparrot_copy'} =
+ $^O eq 'MSWin32'
+ ? 'copy $(PARROT_BIN_DIR)\libparrot.dll .'
+ : '';
+
+ my $makefile = 'Makefile';
+ $maketext =~ s/@([:\w]+)@/$config{$1} || $config{"parrot::$1"}/ge;
+ print "\nCreating $makefile ...\n";
+ open(my $MAKE, '>', $makefile)
+ or die "Unable to write $makefile\n";
+ print $MAKE $maketext;
+ close($MAKE) or die $!;
return;
}
-sub slurp {
- my $filename = shift;
-
- open my $fh, '<', $filename or die "Unable to read $filename\n";
- local $/ = undef;
- my $maketext = <$fh>;
- close $fh or die $!;
-
- return $maketext;
-}
-
-sub version_int {
- sprintf('%d%03d%03d', split(/\./, $_[0]))
-}
-
-
+
# Print some help text.
sub print_help {
print <<'END';
@@ -208,10 +146,11 @@ sub print_help {
General Options:
--help Show this text
--gen-parrot Download and build a copy of Parrot to use
+ --prefix=dir Install files in dir
+ --parrot-config=path/to/parrot_config
+ Use information from existing parrot_config
--gen-parrot-option='--option=value'
- Set parrot config option when using --gen-parrot
- --parrot-config=(config)
- Use configuration information from config
+ Pass option(s) to --gen-parrot configuration
END
return;
View
@@ -0,0 +1,3 @@
+
+1;
+{YOU_ARE_HERE}
Oops, something went wrong.

0 comments on commit 290d603

Please sign in to comment.