3
# Given a list of filenames on the command line or on stdin this
4
# script returns the interpreter that is required to run the
5
# filenames. Usually this is extracted from the #! line of the file
6
# but we also handle the various 'exec' tricks that people use to
7
# start the interpreter via an intermediate shell.
9
# Also we want to convert:
10
# /usr/local/bin/perl5.00404
11
# /usr/local/bin/tclsh8.0
12
# into dependencies with RPM version numbers.
18
# These have all been seen on our system or are "recommended" in
24
# # the next line restarts using wish \
28
# #!/bin/sh -- # -*- perl -*- -p
29
# eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
30
# if $running_under_some_shell;
33
# #!/bin/sh -- # -*- perl -*- -p
34
# eval '(exit $?0)' && eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
37
# #!/bin/sh -- # -*- perl -*- -p
38
# & eval 'exec /usr/bin/perl -wS $0 $argv:q'
39
# if $running_under_some_shell;
42
# #! /usr/bin/env python
53
# notice we are passed a list of filenames NOT as common in unix the
54
# contents of the file.
62
foreach $prog (sort keys %require) {
65
# ignore variable interpolation and any program whose name is made
66
# up only of non word characters ('<', '&&', etc).
68
( ( $prog != /\$/ ) || ( $prog =~ /^\W+$/ ) ) &&
71
# filenames of the form './miniperl' will be reported in canonical
76
if ( $prog !~ /\$/ ) {
77
print "exectuable($prog)\n";
80
$prog=basename($prog);
82
if ( $prog !~ /\$/ ) {
83
print "exectuable($prog)\n";
85
# get the correct version dependencies for magic numbers like:
86
# /usr/local/bin/perl5.00404
87
# /usr/local/bin/tclsh8.0
88
# these are always PACKAGE versions since typical executables do not
92
if ($module =~ s/([.0-9]+)$//) {
94
print "$prog>=$version\n";
109
my ($version, $magic) = ();
111
(-f $file) || return ;
113
open(FILE, "<$file")||
114
die("$0: Could not open file: '$file' : $!\n");
116
my $rc = sysread(FILE,$line,1000);
120
# Ignore all parameter substitution.
121
# I have no hope of parsing something like:
122
# exec ${SHELL:-/bin/sh}
123
$rc =~ s/\$\{.*\}//g;
124
$rc =~ s/echo\s+.*[\n;]//g;
126
if ( ($rc > 1) && ($line =~ m/^\#\!\s*/) ) {
128
if ($line =~ m/\b(exec|env)\s+([\'\"\`\\]+)?([^ \t\n\r]+)/) {
132
# strip off extra lines and any arguments
133
if ($line =~ m/^\#\!\s*([^ \t\n\r]+)/) {
140
die("$0: Could not close file: '$file' : $!\n");