# New Ticket Created by  Joshua Hoblitt 
# Please include the string:  [perl #37458]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=37458 >


This transaction appears to have no content
This patch adds a new function named check_progs(), rather similar to
Autoconf's AC_CHECK_PROGS macro, to Parrot::Configure::Step.  Nothing
will be using it immediately but I've have some patches coming RSN that
will depend on this.  Those patches may require some discussion (while
this small hopefully won't) so I've split this function out.

Cheers,

-J

--
 Step.pm |   47 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 2 deletions(-)

Index: lib/Parrot/Configure/Step.pm
===================================================================
--- lib/Parrot/Configure/Step.pm        (revision 9496)
+++ lib/Parrot/Configure/Step.pm        (working copy)
@@ -26,7 +26,10 @@
 use strict;
 use Exporter;
 use Carp;
+use File::Basename qw( basename );
 use File::Copy ();
+use File::Spec;
+
 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 @ISA = qw(Exporter);
@@ -34,11 +37,13 @@
 @EXPORT = ();
 
 @EXPORT_OK = qw(prompt genfile copy_if_diff move_if_diff integrate
-                cc_gen cc_build cc_run cc_clean cc_run_capture capture_output);
+                cc_gen cc_build cc_run cc_clean cc_run_capture capture_output
+                check_progs);
 
 %EXPORT_TAGS = (
         inter => [qw(prompt integrate)],
-        auto  => [qw(cc_gen cc_build cc_run cc_clean cc_run_capture)],
+        auto  => [qw(cc_gen cc_build cc_run cc_clean cc_run_capture
+                  capture_output check_progs)],
         gen   => [qw(genfile copy_if_diff move_if_diff)]
                );
 
@@ -463,6 +468,44 @@
     return $output;
 }
 
+=item C<check_progs($programs)>
+
+Where C<$programs> may be either a scalar with the name of a single program or
+an array ref of programs to search the current C<PATH> for.  The first matching
+program name is returned or C<undef> on failure.  Note: this function only
+returns the name of the program and not it's complete path.
+
+This function is similar to C<autoconf>'s C<AC_CHECK_PROGS> macro.
+
+=cut
+
+sub check_progs {
+    my $progs = shift;
+
+    $progs = [$progs] unless ref $progs eq 'ARRAY';
+    my $verbose = Configure::Data->get('verbose');
+
+    print "checking for program: ", join(" or ", @$progs), "\n" if $verbose;
+    foreach my $prog (@$progs) {
+        # try relative path first in case it's not in the path
+        return $prog if -x $prog;
+
+        $prog = basename($prog);
+        foreach my $dir (File::Spec->path) {
+            my $path = File::Spec->catfile($dir, $prog);
+
+            if ($verbose) {
+                print "trying: $path\n";
+                print "$path is executable\n" if -x $path;
+            }
+
+            return $prog if -x $path;
+        }
+    }
+
+    return undef;
+}
+
 =back
 
 =head1 SEE ALSO

Attachment: pgpHDZzmSRkaS.pgp
Description: PGP signature

Reply via email to