Author: jhoblitt
Date: Fri Oct 21 03:40:53 2005
New Revision: 9527

Added:
   trunk/config/inter/lex.pl
   trunk/config/inter/yacc.pl
Modified:
   trunk/config/inter/progs.pl
   trunk/lib/Parrot/Configure/RunSteps.pm
Log:
improve lex & yacc probing logic
split lex & yacc probes out of config/inter/progs.pl into config/inter/lex.pl & 
config/inter/yacc.pl  


Added: trunk/config/inter/lex.pl
==============================================================================
--- (empty file)
+++ trunk/config/inter/lex.pl   Fri Oct 21 03:40:53 2005
@@ -0,0 +1,85 @@
+# Copyright: 2001-2005 The Perl Foundation.  All Rights Reserved.
+# $Id$
+
+=head1 NAME
+
+config/auto/lex.pl - lexical analyzer generator
+
+=head1 DESCRIPTION
+
+Determines whether C<lex> is installed and if it's actually C<flex>.
+
+=cut
+
+package Configure::Step;
+
+use strict;
+
+use vars qw( $description @args $prompt $util );
+use Parrot::Configure::Step qw( :inter capture_output check_progs );
+
+$util           = 'lex';
+$description    = "Determining whether $util is installed";
+$prompt         = "Do you have a lexical analyzer generator like flex or lex?";
[EMAIL PROTECTED]           = qw( lex ask maintainer );
+
+sub runstep {
+    my %args;
+    @[EMAIL PROTECTED]@_;
+
+    # undef means we don't have flex... default to not having flex
+    Configure::Data->set(flex_version => undef);
+
+    unless ($args{maintainer}) {
+        Configure::Data->set( $util => $^O eq 'Win32' ? 'REM' : 'echo' );
+        $Configure::Step::result = 'skipped';
+        return undef;
+    }
+
+    my $prog;
+    # precedence of sources for the program:
+    # default -> probe -> environment -> option -> ask
+    $prog ||= $args{$util};
+    $prog ||= $ENV{uc($util)};
+
+    # never override the user.  If a non-existent program is specified then
+    # the user is responsible for the consequences.
+    if (defined $prog) {
+        Configure::Data->set($util => $prog);
+        $Configure::Step::result = 'yes';
+        return undef;
+    }
+
+    $prog = check_progs(['flex', 'lex']);
+
+    unless ($prog) {
+        # fall back to default
+        $Configure::Step::result = 'no';
+        return undef;
+    }
+
+    if ($args{ask}) {
+        $prog = prompt($prompt, $prog ? $prog : Configure::Data->get($util));
+    }
+
+    my ($stdout, $stderr, $ret) = capture_output($prog, '--version');
+
+    # don't override the user even if the program they provided appears to be
+    # broken
+    if ($ret == -1 and ! $args{ask}) {
+        # fall back to default
+        $Configure::Step::result = 'no';
+        return undef;
+    }
+
+    # if '--version' returns a string assume that this is flex.
+    # flex calls it self by $0 so it will claim to be lex if invoked as `lex`
+    if ($stdout =~ /f?lex \s+ (\d+) \. (\d+) \. (\d+)/x) {
+        Configure::Data->set(flex_version => [$1, $2, $3]);
+    }
+
+    Configure::Data->set($util => $prog);
+    $Configure::Step::result = 'yes';
+}
+
+1;

Modified: trunk/config/inter/progs.pl
==============================================================================
--- trunk/config/inter/progs.pl (original)
+++ trunk/config/inter/progs.pl Fri Oct 21 03:40:53 2005
@@ -109,21 +109,6 @@ END
     $debug='y'  if $args{debugging};
     $debug = prompt("Do you want a debugging build of Parrot?", $debug) if 
$args{ask};
 
-    if ($args{'maintainer'}) {
-       $lex = integrate(Configure::Data->get('lex'), $args{lex});
-       $lex  = &$first_working($lex,  'flex', 'lex');
-       $yacc = integrate(Configure::Data->get('yacc'), $args{yacc});
-       $yacc = &$first_working($yacc, 'bison -v -y', 'yacc', 'byacc');
-    }
-    else {
-       $lex = $yacc = $null;
-    }
-    $lex = prompt("Do you have a lexical analyzer generator, like flex or 
lex?",$lex) if $args{ask};
-    Configure::Data->set(lex =>  $lex);
-
-    $yacc = prompt("Do you have a parser generator, like bison or 
yacc?",$yacc) if $args{ask};
-    Configure::Data->set(yacc =>  $yacc);
-
   if(!$debug || $debug =~ /n/i) {
     Configure::Data->set(
       cc_debug => '',

Added: trunk/config/inter/yacc.pl
==============================================================================
--- (empty file)
+++ trunk/config/inter/yacc.pl  Fri Oct 21 03:40:53 2005
@@ -0,0 +1,85 @@
+# Copyright: 2001-2005 The Perl Foundation.  All Rights Reserved.
+# $Id$
+
+=head1 NAME
+
+config/auto/yacc.pl - parser generator
+
+=head1 DESCRIPTION
+
+Determines whether C<yacc> is installed and if it's actually C<bison>.
+
+=cut
+
+package Configure::Step;
+
+use strict;
+
+use vars qw( $description @args $prompt $util );
+use Parrot::Configure::Step qw( :inter capture_output check_progs );
+
+$util           = 'yacc';
+$description    = "Determining whether $util is installed";
+$prompt         = "Do you have a parser generator, like bison or yacc?";
[EMAIL PROTECTED] =          qw( yacc ask maintainer );
+
+sub runstep {
+    my %args;
+    @[EMAIL PROTECTED]@_;
+
+    # undef means we don't have bison... default to not having bison
+    Configure::Data->set(bison_version => undef);
+
+    unless ($args{maintainer}) {
+        Configure::Data->set( $util => $^O eq 'Win32' ? 'REM' : 'echo' );
+        $Configure::Step::result = 'skipped';
+        return undef;
+    }
+
+    my $prog;
+    # precedence of sources for the program:
+    # default -> probe -> environment -> option -> ask
+    $prog ||= $args{$util};
+    $prog ||= $ENV{uc($util)};
+
+    # never override the user.  If a non-existent program is specified then
+    # the user is responsible for the consequences.
+    if (defined $prog) {
+        Configure::Data->set($util => $prog);
+        $Configure::Step::result = 'yes';
+        return undef;
+    }
+
+    $prog = check_progs(['bison -v -y', 'yacc', 'byacc']);
+
+    unless ($prog) {
+        # fall back to default
+        $Configure::Step::result = 'no';
+        return undef;
+    }
+
+    if ($args{ask}) {
+        $prog = prompt($prompt, $prog ? $prog : Configure::Data->get($util));
+    }
+
+    my ($stdout, $stderr, $ret) = capture_output($prog, '--version');
+
+    # don't override the user even if the program they provided appears to be
+    # broken
+    if ($ret == -1 and ! $args{ask}) {
+        # fall back to default
+        $Configure::Step::result = 'no';
+        return undef;
+    }
+
+    # if '--version' returns a string assume that this is bison.
+    # if this is bison pretending to be yacc '--version' doesn't work
+    if ($stdout =~ /Bison .*? (\d+) \. (\d+) (\w)? /x) {
+        Configure::Data->set(bison_version => [$1, $2, $3]);
+    }
+
+    Configure::Data->set($util => $prog);
+    $Configure::Step::result = 'yes';
+}
+
+1;

Modified: trunk/lib/Parrot/Configure/RunSteps.pm
==============================================================================
--- trunk/lib/Parrot/Configure/RunSteps.pm      (original)
+++ trunk/lib/Parrot/Configure/RunSteps.pm      Fri Oct 21 03:40:53 2005
@@ -31,6 +31,8 @@ use vars qw(@steps);
     init/hints.pl
     init/headers.pl
     inter/progs.pl
+    inter/lex.pl
+    inter/yacc.pl
     auto/gcc.pl
     init/optimize.pl
     inter/shlibs.pl

Reply via email to