3 # RPM (and its source code) is covered under two separate licenses.
5 # The entire code base may be distributed under the terms of the GNU
6 # General Public License (GPL), which appears immediately below.
7 # Alternatively, all of the source code in the lib subdirectory of the
8 # RPM source code distribution as well as any code derived from that
9 # code may instead be distributed under the GNU Library General Public
10 # License (LGPL), at the choice of the distributor. The complete text
11 # of the LGPL appears at the bottom of this file.
13 # This alternatively is allowed to enable applications to be linked
14 # against the RPM library (commonly called librpm) without forcing
15 # such applications to be distributed under the GPL.
17 # Any questions regarding the licensing of RPM should be addressed to
18 # Erik Troan <ewt@redhat.com>.
20 # a simple makedepend like script for perl.
22 # To save development time I do not parse the perl grammar but
23 # instead just lex it looking for what I want. I take special care to
24 # ignore comments and pod's.
26 # It would be much better if perl could tell us the dependencies of a
29 # The filenames to scan are either passed on the command line or if
30 # that is empty they are passed via stdin.
32 # If there are strings in the file which match the pattern
33 # m/^\s*\$RPM_Requires\s*=\s*["'](.*)['"]/i
34 # then these are treated as additional names which are required by the
35 # file and are printed as well.
37 # I plan to rewrite this in C so that perl is not required by RPM at
40 # by Ken Estes Mail.com kestes@staff.mail.com
43 eval { require version; $HAVE_VERSION = 1; };
52 # notice we are passed a list of filenames NOT as common in unix the
53 # contents of the file.
61 foreach $perlver (sort keys %perlreq) {
62 print "perl >= $perlver\n";
64 foreach $module (sort keys %require) {
65 if (length($require{$module}) == 0) {
66 print "perl($module)\n";
69 # I am not using rpm3.0 so I do not want spaces around my
70 # operators. Also I will need to change the processing of the
71 # $RPM_* variable when I upgrade.
73 print "perl($module) >= $require{$module}\n";
82 my ($module, $newver) = @_;
83 my $oldver = $require{$module};
85 $require{$module} = $newver
86 if ($HAVE_VERSION && $newver && version->new($oldver) < $newver);
89 $require{$module} = $newver;
98 if (!open(FILE, $file)) {
99 warn("$0: Warning: Could not open file '$file' for reading: $!\n");
105 # skip the "= <<" block
107 if (m/^\s*(?:my\s*)?\$(?:.*)\s*=\s*<<\s*(["'`])(.+?)\1/ ||
108 m/^\s*(?:my\s*)?\$(.*)\s*=\s*<<(\w+)\s*;/) {
112 ( $_ eq $tag ) && last;
117 # skip q{} quoted sections - just hope we don't have curly brackets
118 # within the quote, nor an escaped hash mark that isn't a comment
119 # marker, such as occurs right here. Draw the line somewhere.
120 if ( m/^.*\Wq[qxwr]?\s*([{([#|\/])[^})\]#|\/]*$/ && ! m/^\s*(require|use)\s/ ) {
122 $tag =~ tr/{\(\[\#|\//})]#|\//;
123 $tag = quotemeta($tag);
125 ( $_ =~ m/$tag/ ) && last;
129 # skip the documentation
131 # we should not need to have item in this if statement (it
132 # properly belongs in the over/back section) but people do not
135 if (/^=(head[1-4]|pod|for|item)/) {
136 /^=cut/ && next while <FILE>;
140 /^=back/ && next while <FILE>;
143 # skip the data section
144 if (m/^__(DATA|END)__$/) {
148 # Each keyword can appear multiple times. Don't
149 # bother with datastructures to store these strings,
150 # if we need to print it print it now.
152 # Again allow for "our".
153 if (m/^\s*(our\s+)?\$RPM_Requires\s*=\s*["'](.*)['"]/i) {
154 foreach $_ (split(/\s+/, $2)) {
159 my $modver_re = qr/[.0-9]+/;
162 # The (require|use) match further down in this subroutine will match lines
163 # within a multi-line print or return statements. So, let's skip over such
164 # statements whose content should not be loading modules anyway. -BEF-
166 if (m/print(?:\s+|\s+\S+\s+)\<\<\s*(["'`])(.+?)\1/ ||
167 m/print(\s+|\s+\S+\s+)\<\<(\w+)/ ||
168 m/return(\s+)\<\<(\w+)/ ) {
173 ( $_ eq $tag ) && last;
178 # Skip multiline print and assign statements
179 if ( m/\$\S+\s*=\s*(")([^"\\]|(\\.))*$/ ||
180 m/\$\S+\s*=\s*(')([^'\\]|(\\.))*$/ ||
181 m/print\s+(")([^"\\]|(\\.))*$/ ||
182 m/print\s+(')([^'\\]|(\\.))*$/ ) {
186 m/^([^\\$quote]|(\\.))*$quote/ && last;
193 # ouch could be in a eval, perhaps we do not want these since we catch
194 # an exception they must not be required
196 # eval { require Term::ReadLine } or die $@;
197 # eval "require Term::Rendezvous;" or die $@;
198 # eval { require Carp } if defined $^S; # If error/warning during compilation,
201 (m/^(\s*) # we hope the inclusion starts the line
202 (require|use)\s+(?!\{) # do not want 'do {' loops
203 # quotes around name are always legal
204 ['"]?([^; '"\t#]+)['"]?[\t; ]
205 # the syntax for 'use' allows version requirements
206 # the latter part is for "use base qw(Foo)" and friends special case
207 \s*($modver_re|(qw\s*[(\/'"]\s*|['"])[^)\/"'\$]*?\s*[)\/"'])?
210 my ($whitespace, $statement, $module, $version) = ($1, $2, $3, $4);
212 # we only consider require statements that are flushed against
213 # the left edge. any other require statements give too many
214 # false positives, as they are usually inside of an if statement
215 # as a fallback module or a rarely used option
217 ($whitespace ne "" && $statement eq "require") && next;
219 # if there is some interpolation of variables just skip this
220 # dependency, we do not want
221 # do "$ENV{LOGDIR}/$rcfile";
223 ($module =~ m/\$/) && next;
225 # skip if the phrase was "use of" -- shows up in gimp-perl, et al.
226 next if $module eq 'of';
228 # if the module ends in a comma we probably caught some
229 # documentation of the form 'check stuff,\n do stuff, clean
230 # stuff.' there are several of these in the perl distribution
232 ($module =~ m/[,>]$/) && next;
234 # if the module name starts in a dot it is not a module name.
235 # Is this necessary? Please give me an example if you turn this
238 # ($module =~ m/^\./) && next;
240 # if the module starts with /, it is an absolute path to a file
241 if ($module =~ m(^/)) {
246 # sometimes people do use POSIX qw(foo), or use POSIX(qw(foo)) etc.
247 # we can strip qw.*$, as well as (.*$:
248 $module =~ s/qw.*$//;
249 $module =~ s/\(.*$//;
251 # if the module ends with .pm, strip it to leave only basename.
252 $module =~ s/\.pm$//;
254 # some perl programmers write 'require URI/URL;' when
255 # they mean 'require URI::URL;'
259 # trim off trailing parentheses if any. Sometimes people pass
260 # the module an empty list.
262 $module =~ s/\(\s*\)$//;
264 if ( $module =~ m/^v?([0-9._]+)$/ ) {
265 # if module is a number then both require and use interpret that
266 # to mean that a particular version of perl is specified
269 if ($ver =~ /5.00/) {
270 $perlreq{"0:$ver"} = 1;
274 $perlreq{"1:$ver"} = 1;
280 # ph files do not use the package name inside the file.
281 # perlmodlib documentation says:
283 # the .ph files made by h2ph will probably end up as
284 # extension modules made by h2xs.
286 # so do not expend much effort on these.
289 # there is no easy way to find out if a file named systeminfo.ph
290 # will be included with the name sys/systeminfo.ph so only use the
291 # basename of *.ph files
293 ($module =~ m/\.ph$/) && next;
295 # use base|parent qw(Foo) dependencies
296 if ($statement eq "use" && ($module eq "base" || $module eq "parent")) {
297 add_require($module, undef);
298 if ($version =~ /^qw\s*[(\/'"]\s*([^)\/"']+?)\s*[)\/"']/) {
299 add_require($_, undef) for split(' ', $1);
301 elsif ($version =~ /(["'])([^"']+)\1/) {
302 add_require($2, undef);
306 $version = undef unless $version =~ /^$modver_re$/o;
308 add_require($module, $version);
314 die("$0: Could not close file: '$file' : $!\n");