eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
if 0;
BEGIN
{
my $perllibdir = $ENV{'autom4te_perllibdir'} || "@datadir@";
unshift @INC, "$perllibdir";
}
use Autom4te::General;
use Autom4te::XFile;
use File::Basename;
use File::Find;
use strict;
use vars qw(@cfiles @makefiles @shfiles %printed);
my @kinds = qw (function header identifier program
makevar librarie);
my %generic_macro =
(
'function' => 'AC_CHECK_FUNCS',
'header' => 'AC_CHECK_HEADERS',
'identifier' => 'AC_CHECK_TYPES',
'program' => 'AC_CHECK_PROGS',
'library' => 'AC_CHECK_LIB'
);
my %kind_comment =
(
'function' => 'Checks for library functions.',
'header' => 'Checks for header files.',
'identifier' => 'Checks for typedefs, structures, and compiler characteristics.',
'program' => 'Checks for programs.',
);
my %used = ();
my %macro = ();
my %needed_macros =
(
'AC_PREREQ' => [$me],
);
my $configure_scan = 'configure.scan';
my $log = new Autom4te::XFile ">$me.log";
my $autom4te = $ENV{'AUTOM4TE'} || '@bindir@/@autom4te-name@';
my $autoconf = "$autom4te --language=autoconf";
my @prepend_include;
my @include = ('@datadir@');
$help = "Usage: $0 [OPTION] ... [SRCDIR]
Examine source files in the directory tree rooted at SRCDIR, or the
current directory if none is given. Search the source files for
common portability problems, check for incompleteness of
`configure.ac', and create a file `$configure_scan' which is a
preliminary `configure.ac' for that package.
-h, --help print this help, then exit
-V, --version print version number, then exit
-v, --verbose verbosely report processing
-d, --debug don't remove temporary files
Library directories:
-B, --prepend-include=DIR prepend directory DIR to search path
-I, --include=DIR append directory DIR to search path
Report bugs to <bug-autoconf\@gnu.org>.\n";
$version = "autoscan (@PACKAGE_NAME@) @VERSION@
Written by David J. MacKenzie and Akim Demaille.
Copyright 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
sub parse_args ()
{
getopt ('I|include=s' => \@include,
'B|prepend-include=s' => \@prepend_include);
die "$me: too many arguments
Try `$me --help' for more information.\n"
if @ARGV > 1;
my $srcdir = $ARGV[0] || ".";
verbose "srcdir = $srcdir";
chdir $srcdir || error "cannot cd to $srcdir: $!";
}
sub init_tables ()
{
my $file = find_file ("autoscan/autoscan.list",
reverse (@prepend_include), @include);
my $table = new Autom4te::XFile $file;
my $tables_are_consistent = 1;
while ($_ = $table->getline)
{
next
if /^\s*$/ || /^\s*\
if (/^(\S+):\s+(\S+)\s+(\S.*)$/)
{
my ($kind, $word, $macro) = ($1, $2, $3);
error "$file:$.: invalid kind: $_"
unless grep { $_ eq $kind } @kinds;
push @{$macro{$kind}{$word}}, $macro;
}
else
{
error "$file:$.: invalid definition: $_";
}
}
if ($debug)
{
foreach my $kind (@kinds)
{
foreach my $word (sort keys %{$macro{$kind}})
{
print "$kind: $word: @{$macro{$kind}{$word}}\n";
}
}
}
}
sub used ($$;$)
{
my ($kind, $word, $where) = @_;
$where ||= "$File::Find::name:$.";
if (
($kind eq 'library' && $word !~ /^(e|inks)$/)
|| defined $macro{$kind}{$word}
)
{
push (@{$used{$kind}{$word}}, $where);
}
}
sub scan_c_file ($)
{
my ($filename) = @_;
push @cfiles, $File::Find::name;
my $in_comment = 0;
my $file = new Autom4te::XFile "<$filename";
while ($_ = $file->getline)
{
if ($in_comment && s,^.*?\*/,,)
{
$in_comment = 0;
}
next if $in_comment;
s,/\*.*?\*/,,g;
if (s,/\*.*$,,)
{
$in_comment = 1;
}
if (s/^\s*\ {
if (/^include\s*<([^>]*)>/)
{
used ('header', $1);
}
if (s/^(if|ifdef|ifndef|elif)\s+//)
{
foreach my $word (split (/\W+/))
{
used ('identifier', $word)
unless $word eq 'defined' || $word !~ /^[a-zA-Z_]/;
}
}
next;
}
s,\"[^\"]*\",,g;
s,\'[^\']*\',,g;
while (s/\b([a-zA-Z_]\w*)\s*\(/ /)
{
used ('function', $1);
}
while (s/\b([a-zA-Z_]\w*)\b/ /)
{
used ('identifier', $1);
}
}
$file->close;
}
sub scan_makefile ($)
{
my ($filename) = @_;
push @makefiles, $File::Find::name;
my $file = new Autom4te::XFile "<$filename";
while ($_ = $file->getline)
{
s/
while (s/\b([a-zA-Z_]\w*)\s*=/ /)
{
used ('makevar', $1);
}
foreach my $word (split (/\s+/))
{
if ($word =~ /^-l([a-zA-Z_]\w*)$/)
{
used ('library', $1);
}
if ($word =~ /^[a-zA-Z_][\w+]*$/)
{
used ('program', $word);
}
}
}
$file->close;
}
sub scan_sh_file ($)
{
my ($filename) = @_;
push @shfiles, $File::Find::name;
my $file = new Autom4te::XFile "<$filename";
while ($_ = $file->getline)
{
s/ s/\${[^\}]*}//g;
s/@[^@]*@//g;
while (s/\b([a-zA-Z_]\w*)\b/ /)
{
used ('program', $1);
}
}
$file->close;
}
sub scan_file ()
{
return
if -f "$_.in";
local $_ = $_;
$File::Find::name =~ s,^\./,,;
if (/\.[chlym](\.in)?$/)
{
used 'program', 'cc', $File::Find::name;
scan_c_file ($_);
}
elsif (/\.(cc|cpp|cxx|CC|C|hh|hpp|hxx|HH|H|yy|ypp|ll|lpp)(\.in)?$/)
{
used 'program', 'c++', $File::Find::name;
scan_c_file ($_);
}
elsif ((/^((?:GNUm|M|m)akefile)(\.in)?$/ && ! -f "$1.am")
|| /^(?:GNUm|M|m)akefile(\.am)?$/)
{
scan_makefile ($_);
}
elsif (/\.sh(\.in)?$/)
{
scan_sh_file ($_);
}
}
sub scan_files ()
{
find (\&scan_file, '.');
if ($verbose)
{
print "cfiles: @cfiles\n";
print "makefiles: @makefiles\n";
print "shfiles: @shfiles\n";
foreach my $kind (@kinds)
{
print "\n$kind:\n";
foreach my $word (sort keys %{$used{$kind}})
{
print "$word: @{$used{$kind}{$word}}\n";
}
}
}
}
sub output_kind ($$)
{
my ($file, $kind) = @_;
my @have;
print $file "\n# $kind_comment{$kind}\n"
if exists $kind_comment{$kind};
foreach my $word (sort keys %{$used{$kind}})
{
foreach my $macro (@{$macro{$kind}{$word}})
{
if ($macro =~ /^warn:\s+(.*)/)
{
my $message = $1;
foreach my $location (@{$used{$kind}{$word}})
{
warn "$location: warning: $message\n";
}
}
elsif (exists $generic_macro{$kind}
&& $macro eq $generic_macro{$kind})
{
push (@have, $word);
push (@{$needed_macros{"$generic_macro{$kind}([$word])"}},
@{$used{$kind}{$word}});
}
else
{
if (! $printed{$macro})
{
print $file "$macro\n";
$printed{$macro} = 1;
}
push (@{$needed_macros{$macro}},
@{$used{$kind}{$word}});
}
}
}
print $file "$generic_macro{$kind}([" . join(' ', sort(@have)) . "])\n"
if @have;
}
sub output_libraries ($)
{
my ($file) = @_;
print $file "\n# Checks for libraries.\n";
foreach my $word (sort keys %{$used{'library'}})
{
print $file "# FIXME: Replace `main' with a function in `-l$word':\n";
print $file "AC_CHECK_LIB([$word], [main])\n";
}
}
sub output ($)
{
my $configure_scan = shift;
my %unique_makefiles;
my $file = new Autom4te::XFile ">$configure_scan";
print $file
("# -*- Autoconf -*-\n" .
"# Process this file with autoconf to produce a configure script.\n" .
"\n" .
"AC_PREREQ(@VERSION@)\n" .
"AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)\n");
if (defined $cfiles[0])
{
print $file "AC_CONFIG_SRCDIR([$cfiles[0]])\n";
print $file "AC_CONFIG_HEADER([config.h])\n";
}
output_kind ($file, 'program');
output_kind ($file, 'makevar');
output_libraries ($file);
output_kind ($file, 'header');
output_kind ($file, 'identifier');
output_kind ($file, 'function');
if (@makefiles)
{
foreach my $m (@makefiles)
{
$m =~ s/\.(?:in|am)$//;
$unique_makefiles{$m}++;
}
print $file ("\nAC_CONFIG_FILES([",
join ("\n ",
sort keys %unique_makefiles), "])\n");
}
print $file "AC_OUTPUT\n";
$file->close;
}
sub check_configure_ac ($)
{
my ($configure_ac) = @_;
my $trace_option =
join (' --trace=', '',
uniq (sort (map { s/\(.*//; $_ } keys %needed_macros)));
verbose "running: $autoconf $trace_option $configure_ac";
my $traces =
new Autom4te::XFile "$autoconf $trace_option $configure_ac|";
while ($_ = $traces->getline)
{
chomp;
my ($file, $line, $macro, @args) = split (/:/, $_);
if ($macro =~ /^AC_CHECK_(HEADER|FUNC|TYPE|MEMBER)S$/)
{
foreach my $word (split (/\s|,/, $args[0]))
{
if ($macro eq "AC_CHECK_MEMBERS"
&& $word =~ /^stat.st_/)
{
$word = "struct " . $word;
}
delete $needed_macros{"$macro([$word])"};
}
}
else
{
delete $needed_macros{$macro};
}
}
$traces->close;
foreach my $macro (sort keys %needed_macros)
{
warn ("$configure_ac: warning: missing $macro wanted by: "
. (${$needed_macros{$macro}}[0])
. "\n");
print $log "$me: warning: missing $macro wanted by: \n";
foreach my $need (@{$needed_macros{$macro}})
{
print $log "\t$need\n";
}
}
}
parse_args;
$autoconf .= " --debug" if $debug;
$autoconf .= " --verbose" if $verbose;
$autoconf .= join (' --include=', '', @include);
$autoconf .= join (' --prepend-include=', '', @prepend_include);
my $configure_ac = find_configure_ac;
init_tables;
scan_files;
output ('configure.scan');
if ($configure_ac)
{
check_configure_ac ($configure_ac);
}
$log->close;
exit 0;