7 (my $VERSION = '$Revision: 1.1 $ ') =~ tr/[0-9].//cd;
8 (my $ME = $0) =~ s|.*/||;
10 use constant ST_INIT => 1;
11 use constant ST_FILES => 2;
12 use constant ST_DEPENDENTS => 3;
14 # Read a module description file and derive the set of files
15 # included directly by any .c or .h file listed in the `Files:' section.
16 # Take the union of all such sets for any dependent modules.
17 # Then, compare that set with the set derived from the names
18 # listed in the various Files: sections.
20 # Parse a module file (returning list of Files: names and
21 # list of dependent-modules.
22 # my ($file, $dep) = parse_module_file $module_file;
23 sub parse_module_file ($)
25 my ($module_file) = @_;
27 open FH, '<', $module_file
28 or die "$ME: can't open `$module_file' for reading: $!\n";
34 while (defined (my $line = <FH>))
36 if ($state eq ST_INIT)
38 if ($line =~ /^Files:$/)
42 elsif ($line =~ /^Depends-on:$/)
44 $state = ST_DEPENDENTS;
58 if ($state eq ST_FILES)
62 elsif ($state eq ST_DEPENDENTS)
70 # my @t = sort keys %file_set;
71 # print "files: @t\n";
72 # my @u = sort keys %dep_set;
73 # print "dependents: @u\n";
75 return (\%file_set, \%dep_set);
78 # Extract the set of files required for this module, including
79 # those required via dependent modules.
93 my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR);
96 print $STREAM "Try `$ME --help' for more information.\n";
100 # FIXME: add new option descriptions here
102 Usage: $ME [OPTIONS] FIXME: FILE ?
106 --help display this help and exit
107 --version output version information and exit
108 --verbose generate verbose output
115 sub find_included_lib_files ($)
120 my %special_non_dup = ( 'fnmatch_loop.c' => 1, 'regex.c' => 1 );
124 or die "$ME: can't open `$file' for reading: $!\n";
126 while (defined (my $line = <FH>))
128 # Ignore test-driver code at end of file.
129 $line =~ m!^\#if(def)? TEST_!
132 $line =~ m!^\s*\#\s*include\s+"!
137 exists $inc{$line} && ! exists $special_non_dup{$line}
138 and warn "$ME: $file: duplicate inclusion of $line\n";
140 # Some known exceptions.
141 $file =~ /\bfull-write\.c$/ && $line eq 'full-read.h'
143 $file =~ /\bsafe-read.c$/ && $line eq 'safe-write.h'
145 $file =~ /\bhash\.c$/ && $line eq 'obstack.h'
158 # FIXME: add new options here
159 help => sub { usage 0 },
160 version => sub { print "$ME version $VERSION\n"; exit },
163 # Make sure we have the right number of non-option arguments.
164 # Always tell the user why we fail.
165 # FIXME: this assumes there is exactly 1 required argument.
167 and (warn "$ME: missing FILE argument\n"), usage 1;
170 my %module_all_files;
180 exists $seen_module{$m}
182 $seen_module{$m} = 1;
183 my ($file, $dep) = parse_module_file $m;
184 my @t = sort keys %$file;
187 foreach my $f (keys %$file)
189 $module_all_files{$f} = 1;
195 # Exempt headers like unlocked-io.h that are `#include'd
196 # but not necessarily used.
197 'unlocked-io.h' => 1,
199 # Give gettext.h a free pass only when included from lib/error.c,
200 # since that we've made that exception solely to make the error
201 # module easier to use -- at RMS's request.
202 'lib/error.c:gettext.h' => 1,
205 my @t = sort keys %module_all_files;
206 # warn "ALL files: @t\n";
208 # Derive from %module_all_files (by parsing the .c and .h files therein),
209 # the list of all #include'd files that reside in lib/.
210 foreach my $f (keys %module_all_files)
214 # FIXME: this is too naive
215 my $inc = find_included_lib_files "../$f";
216 foreach my $i (sort keys %$inc)
218 my $lib_file = "lib/$i";
219 exists $exempt_header{"$f:$i"}
220 || exists $exempt_header{$i}
222 !exists $module_all_files{$lib_file} && -f "../lib/$i"
223 and warn "$f: $i is `#include'd, but not "
224 . "listed in module's Files: section\n";
226 #my @t = sort keys %$inc;
227 #print "** $f: @t\n";