On Mon, Oct 17, 2005 at 04:16:01AM -0700, Joshua Hoblitt wrote: > # 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.
Attached is an enhanced version of this patch that handles programs being specified with options. Any objections to this? -J --
Index: lib/Parrot/Configure/Step.pm =================================================================== --- lib/Parrot/Configure/Step.pm (revision 9511) +++ 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,46 @@ 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; + + my $util = basename($prog); + # use the first word in the string to ignore any options + ($util) = $util =~ /(\w+)/; + foreach my $dir (File::Spec->path) { + my $path = File::Spec->catfile($dir, $util); + + 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
pgpnrekhVHqNQ.pgp
Description: PGP signature