summaryrefslogtreecommitdiff
path: root/scripts/perl.req
blob: d19afbcdb5f6f6f6bf61fde8ef3aaba065decece (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/perl

# a simple makedepends like script for perl.

# I plan to rewrite this in C so that perl is not required by RPM at
# build time.

# by Ken Estes Mail.com kestes@staff.mail.com

# it would be much better if perl could tell us the dependencies of a
# given script.

if ("@ARGV") {
  foreach (@ARGV) {
    process_file($_);
  }
} else {
  
  # notice we are passed a list of filenames NOT as common in unix the
  # contents of the file.
  
  foreach (<>) {
    process_file($_);
  }
}


foreach $module (sort keys %require) {
  if (length($require{$module}) == 0) {
    print "perl($module)\n";
  } else {

    print "perl($module)>=$require{$module}\n";

    # we need to print it without the version number until the
    # requires syntax accepts version numbers correctly.

    print "perl($module)\n";
  }
}

exit 0;



sub process_file {
  
  my ($file) = @_;
  chomp $file;
  
  open(FILE, "<$file")||
    die("Could not open file: '$file' : $!\n");
  
  while (<FILE>) {
    
    # skip the documentation
    if ( (m/^=(head1|head2|pod)/) .. (m/^=(cut)/) ) {
      next;
    }

    # skip the data section
    if (m/^__(DATA|END)__$/) {
      last;
    }

    if ( 

# ouch could be in a eval, perhaps we do not want these since we catch
# an exception they must not be required

#   eval { require Term::ReadLine } or die $@;
#   eval "require Term::Rendezvous;" or die $@;
#   eval { require Carp } if defined $^S; # If error/warning during compilation,


	(m/^\s*         # we hope the inclusion starts the line
	 (do|require|use)\s+(?!\{)     # do not want 'do {' loops
	 # quotes around name are always legal
	 [\'\"]?([^\;\ \'\"\t]*)[\'\"]?[\t\;\ ]
	 # the syntax for 'use' allows version requirements
	 \s*([.0-9]*)
	 /x)
       ) {
      my ($module, $version) = ($2,$3);

      # if there is some interpolation of variables just skip this
      # dependency, we do not want
      #        do "$ENV{LOGDIR}/$rcfile";
   
      ($module =~ m/\$/) && next;

      # if the module ends in a comma we probaly caught some
      # documentation of the form 'check stuff,\n do stuff, clean
      # stuff.' there are several of these in the perl distribution

      ($module  =~ m/[,>]$/) && next;

      # ph files do not use the package name inside the file.
      # perlmodlib  documentation says:
      
      #       the .ph files made by h2ph will probably end up as
      #       extension modules made by h2xs.
      
      # so do not expend much effort on these.


      # there is no easy way to find out if a file named systeminfo.ph
      # will be included with the name sys/systeminfo.ph so only use the
      # basename of *.ph files

      ($module  =~ m/\.ph$/) && ($module =~ s!.*/!!g );


      $require{$module}=$version;
      $line{$module}=$_;
    }
    
  }
 
}