+
+ while ($line =~ /$m4_include_rx/go)
+ {
+ my $ifile = $2 || $3;
+ # Skip missing `sinclude'd files.
+ next if $1 ne 'm4_' && ! -f $ifile;
+ push (@inc_files, $ifile);
+ $inc_lines{$ifile} = $.;
+ }
+ }
+
+ # Ignore any file that has an old serial (or no serial if we know
+ # another one with a serial).
+ return ()
+ if ($serial_older ||
+ ($type != FT_AUTOMAKE && !$serial_seen && exists $serial{$basename}));
+
+ $file_contents{$file} = $contents;
+
+ # For some reason I don't understand, it does not work
+ # to do `map { scan_file ($_, ...) } @inc_files' below.
+ # With Perl 5.8.2 it undefines @inc_files.
+ my @copy = @inc_files;
+ my @all_inc_files = (@inc_files,
+ map { scan_file ($type, $_,
+ "$file:$inc_lines{$_}") } @copy);
+ $file_includes{$file} = \@all_inc_files;
+ return @all_inc_files;
+}
+
+# strip_redundant_includes (%FILES)
+# ---------------------------------
+# Each key in %FILES is a file that must be present in the output.
+# However some of these files might already include other files in %FILES,
+# so there is no point in including them another time.
+# This removes items of %FILES which are already included by another file.
+sub strip_redundant_includes (%)
+{
+ my %files = @_;
+
+ # Always include acinclude.m4, even if it does not appear to be used.
+ $files{'acinclude.m4'} = 1 if -f 'acinclude.m4';
+ # File included by $configure_ac are redundant.
+ $files{$configure_ac} = 1;
+
+ # Files at the end of @file_order should override those at the beginning,
+ # so it is important to preserve these trailing files. We can remove
+ # a file A if it is going to be output before a file B that includes
+ # file A, not the converse.
+ foreach my $file (reverse @file_order)
+ {
+ next unless exists $files{$file};
+ foreach my $ifile (@{$file_includes{$file}})
+ {
+ next unless exists $files{$ifile};
+ delete $files{$ifile};
+ verb "$ifile is already included by $file";
+ }