Perl's chop / chomp considered bad, use a regexp instead
[openssl.git] / util / files.pl
1 #!/usr/local/bin/perl
2 #
3 # used to generate the file MINFO for use by util/mk1mf.pl
4 # It is basically a list of all variables from the passed makefile
5 #
6
7 while ($ARGV[0] =~ /^([^\s=]+)\s*=\s*(.*)$/)
8         {
9         $sym{$1} = $2;
10         shift;
11         }
12
13 $s="";
14 while (<>)
15         {
16         s|\R$||;
17         s/#.*//;
18         if (/^([^\s=]+)\s*=\s*(.*)$/)
19                 {
20                 $o="";
21                 ($s,$b)=($1,$2);
22                 for (;;)
23                         {
24                         if ($b =~ /\\$/)
25                                 {
26                                 $b=$`; # Keep what is before the backslash
27                                 $o.=$b." ";
28                                 $b=<>;
29                                 $b =~ s|\R$||; # Better chomp
30                                 }
31                         else
32                                 {
33                                 $o.=$b." ";
34                                 last;
35                                 }
36                         }
37                 $o =~ s/^\s+//;
38                 $o =~ s/\s+$//;
39                 $o =~ s/\s+/ /g;
40
41                 $o =~ s/\$[({]([^)}]+)[)}]/$sym{$1}/g;
42                 $sym{$s}=$o if !exists $sym{$s};
43                 }
44         }
45
46 $pwd=`pwd`; $pwd =~ s|\R$||;
47
48 if ($sym{'TOP'} eq ".")
49         {
50         $n=0;
51         $dir=".";
52         }
53 else    {
54         $n=split(/\//,$sym{'TOP'});
55         @_=split(/\//,$pwd);
56         $z=$#_-$n+1;
57         foreach $i ($z .. $#_) { $dir.=$_[$i]."/"; }
58         chop($dir);             # Remove the last slash
59         }
60
61 print "RELATIVE_DIRECTORY=$dir\n";
62
63 foreach (sort keys %sym)
64         {
65         print "$_=$sym{$_}\n";
66         }
67 print "RELATIVE_DIRECTORY=\n";