Code

remove g++ 4.1.1 compiler errors
[inkscape.git] / src / mkfiles.pl
1 #!/usr/bin/perl
2 ############################################################################
3 #
4 # Creates make.files - a list of all source files
5 #
6 ############################################################################
8 #
9 # main - top level code
10 #
12 if ( @ARGV ) {                # parse command line args
13     print "usage: perl mkfiles.pl\n\n";
14     exit 1;
15 }
17 $tolower = 0;  #Do we want to convert items in make.files to lower case?
18 $verbose = 1;  #Do we want to list the files?
22 print "###########################\n";
23 print "## Generating make.files ##\n";
24 print "###########################\n";
26 &doMakeFiles();  #Do your magic!
28 print "###########################\n";
29 print "## make.files   done     ##\n";
30 print "###########################\n";
32 exit 0;
36 ############################################################################
37 #
38 # Main routine.  Read make.exclude,  then search the current directory
39 # recursively for source code items, rejecting those listed in make.exclude
40 #
41 ############################################################################
42 sub doMakeFiles
43 {
44     my $excludes;   #list of files to exclude
45     my @excluded;   #list of files that were actually excluded
46     my @irrelevant; #list of files in make.exclude that were not found
47     my $line;       #current line from make.exclude
48     my $patterns;   #The extensions for which to search
49     my @files;      #Result of find_files()
50     my @codefiles;  #Sorted list of @files
51     my $datestr;    #Current date
52     local(*MAKE_DOT_EXCLUDE);
53     local(*MAKE_DOT_FILES);
55     if ( -r "make.exclude" )
56         {
57         open MAKE_DOT_EXCLUDE, "make.exclude" or
58             die "make.exclude: $!";
59         while (<MAKE_DOT_EXCLUDE>)
60             {
61             $line = $_;
62             #Trim whitespace from ends
63             # $line =~ s/^\s|\t|\n//;
64 +           $line =~ s/^\s+//;
65 +           $line =~ s/\s+$//;
66             #Ignore if no text in line
67             next if ( length($line) < 1 );
68             #Ignore if starts with '#'
69             next if ( $line =~ /^#/ );
70             # print $line, "\n";
71             $excludes->{$line} = 1;
72             }
73         close MAKE_DOT_EXCLUDE;
74         }
75     
76     #while ( my ($key, $value) = each(%{$excludes}) )
77     #    {
78     #    print "$key => $value\n";
79     #    }
80     
81     $patterns = '.c$|.cpp$|.h$|.hpp$|.xpm$';
82     
83     @files = &find_files(".", $patterns, $excludes, \@excluded);
84     
85     # Print the list of files excluded
86     print "###EXCLUDED: ", scalar(@excluded), " files/directories rejected by request\n";
87     @excluded = sort(@excluded);
88     foreach (@excluded)
89         {
90         if ($verbose)
91           {
92           print "    $_\n";
93           }
94         #mark the item in the hash table , so we know it occurred
95         $excludes->{$_} = 0;
96         }
98     # Count how many files in make.exclude were not used
99     foreach (keys(%{$excludes}))
100         {
101         #if still a 1, then it was not used
102         if ($excludes->{$_} !=0)
103             {
104             push @irrelevant, $_;
105             }
106         }
107  
108     # Print the list of file in make.exclude, but not used.
109     if (scalar(@irrelevant)>0)
110         {
111         @irrelevant = sort(@irrelevant);
112         print "###IRRELEVANT: ", scalar(@irrelevant), " entries in make.exclude that were not found\n";
113         foreach (@irrelevant)
114             {
115             if ($verbose)
116               {
117               print "    $_\n";
118               }
119             }
120         }
122     @codefiles = sort(@files);
123     
124     $datestr = gmtime();
125     open MAKE_DOT_FILES, ">make.files" or
126         die("make.files: $!");
127     print MAKE_DOT_FILES "########################################################\n";
128     print MAKE_DOT_FILES "## File: make.files\n";
129     print MAKE_DOT_FILES "## Purpose: Used by mkdep.pl\n";
130     print MAKE_DOT_FILES "## Generated by mkfiles.pl at :$datestr\n";
131     print MAKE_DOT_FILES "########################################################\n\n";
132     foreach (@codefiles)
133         {
134         next if (length($_)<1);
135         print MAKE_DOT_FILES "$_\n";
136         }
137     close MAKE_DOT_FILES;
138     
139 } # doMakeFiles
140     
144 ############################################################################
146 # Search the current directory recursively,  checking rejecting items from
147 # make.exclude, or adding those that match the extensions in $patterns.
148 # @param $dir      the current directory being searched
149 # @param $patterns the file extensions for which we are searching
150 # @param $excludes a hash of the files which should be rejected
151 # @param $excluded an array in which to store a record of all files rejected
153 ############################################################################
154 sub find_files
156     my($dir, $patterns, $excludes, $excluded) = @_;
157     my $file;
158     my $p;
159     my @files = ();
160     my @file_result;
161     local(*DIR);
162     
163     
164     $dir =~ s=\\=/=g;
165     
166     # Check for 0-length
167     if (length($dir)<1)
168         {
169         $dir = '.';
170         }
171     
172     # Process a directory of files
173     if ( opendir(DIR,$dir) )
174         {
175         # Remove leading .
176         if ( $dir eq '.' )
177             {
178             $dir = '';
179             }
181         foreach $file ( readdir(DIR) )
182             {
183             # Don't allow '..'
184             next if ( $file  =~ /^\.\.?$/ );
185             next if ( length($file)<1 );
187             if (length($dir)>0)
188                 {
189                 $p = $dir . '/' . $file;
190                 }
191             else
192                 {
193                 $p = $file;
194                 }
195                 
196             if ($tolower != 0)
197                 {
198                 $p = lc($p);
199                 }
201             #print "File:$p\n";
202             
203             # Check if it is an excluded file
204             if (defined($excludes->{$p}))
205                 {
206                 #print "EXCLUDED:$p\n";
207                 push @{$excluded}, $p;
208                 next;
209                 }
210             # Check for a desired extension
211             if ($p =~ /$patterns/i)
212                 {
213                 #print "match:$p\n";
214                 push @files, $p;
215                 next;
216                 }
217              #We have seen '0' inserted from a null result.  This
218              #should avoid this problem
219              @file_result = &find_files($p, $patterns, $excludes, $excluded);
220              if (scalar(@file_result)>0)
221                  {
222                  push @files, @file_result;
223                  }
224              }
225         closedir(DIR);
226         }
227     return @files;