2000-08-01 18:05:11 +08:00
|
|
|
#! @PERL@ -w
|
2001-05-22 22:04:22 +08:00
|
|
|
# -*- perl -*-
|
2001-01-12 17:19:59 +08:00
|
|
|
# autoscan - Create configure.scan (a preliminary configure.ac) for a package.
|
2001-01-29 17:24:13 +08:00
|
|
|
# Copyright 1994, 1999, 2000, 2001 Free Software Foundation, Inc.
|
1994-04-30 09:42:39 +08:00
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
# any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
1996-06-13 01:55:25 +08:00
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
# 02111-1307, USA.
|
1994-04-30 09:42:39 +08:00
|
|
|
|
|
|
|
# Written by David MacKenzie <djm@gnu.ai.mit.edu>.
|
|
|
|
|
2001-03-14 02:15:58 +08:00
|
|
|
use 5.005;
|
1994-04-30 09:42:39 +08:00
|
|
|
require "find.pl";
|
2001-06-25 14:15:07 +08:00
|
|
|
use File::Basename;
|
2000-08-01 18:05:11 +08:00
|
|
|
use Getopt::Long;
|
2001-01-23 04:21:33 +08:00
|
|
|
use strict;
|
|
|
|
|
2001-06-25 14:15:07 +08:00
|
|
|
use vars qw($autoconf $datadir $initfile $name
|
2001-06-12 17:33:58 +08:00
|
|
|
@cfiles @makefiles @shfiles %c_keywords %printed);
|
1994-04-30 09:42:39 +08:00
|
|
|
|
2001-06-25 14:15:07 +08:00
|
|
|
my $me = basename ($0);
|
|
|
|
my $verbose = 0;
|
2000-04-11 20:06:12 +08:00
|
|
|
|
2001-06-12 17:33:58 +08:00
|
|
|
# $USED{KIND}{ITEM} is set if ITEM is used in the program.
|
|
|
|
# It is set to its list of locations.
|
|
|
|
my %used = ();
|
|
|
|
|
2001-06-25 14:15:07 +08:00
|
|
|
# $MACRO{KIND}{ITEM} is the list of macros to use to test ITEM.
|
2001-06-12 16:40:02 +08:00
|
|
|
my %macro = ();
|
|
|
|
|
|
|
|
# $NEEDED_MACROS{MACRO} is an array of locations requiring MACRO.
|
|
|
|
my %needed_macros = ();
|
1994-04-30 09:42:39 +08:00
|
|
|
|
2001-06-12 17:33:58 +08:00
|
|
|
my @kinds = qw (functions headers identifiers programs makevars libraries);
|
2001-01-24 15:58:46 +08:00
|
|
|
|
|
|
|
# For each kind, the default macro.
|
|
|
|
my %generic_macro =
|
|
|
|
(
|
2001-01-29 17:50:01 +08:00
|
|
|
'functions' => 'AC_CHECK_FUNCS',
|
|
|
|
'headers' => 'AC_CHECK_HEADERS',
|
|
|
|
'identifiers' => 'AC_CHECK_TYPES',
|
2001-06-12 17:45:01 +08:00
|
|
|
'programs' => 'AC_CHECK_PROGS',
|
2001-06-12 17:33:58 +08:00
|
|
|
'libraries' => 'AC_CHECK_LIB'
|
2001-01-24 15:58:46 +08:00
|
|
|
);
|
|
|
|
|
2001-06-12 18:05:27 +08:00
|
|
|
my %kind_comment =
|
|
|
|
(
|
|
|
|
'functions' => 'Checks for library functions.',
|
|
|
|
'headers' => 'Checks for header files.',
|
|
|
|
'identifiers' => 'Checks for typedefs, structures, and compiler characteristics.',
|
2001-06-12 18:16:49 +08:00
|
|
|
'programs' => 'Checks for programs.',
|
2001-06-12 18:05:27 +08:00
|
|
|
);
|
2001-01-24 15:58:46 +08:00
|
|
|
|
2001-01-29 17:50:01 +08:00
|
|
|
my $configure_scan = 'configure.scan';
|
2001-01-24 15:58:46 +08:00
|
|
|
|
2001-02-12 00:38:44 +08:00
|
|
|
|
|
|
|
# Exit nonzero whenever closing STDOUT fails.
|
|
|
|
sub END
|
|
|
|
{
|
|
|
|
use POSIX qw (_exit);
|
|
|
|
# This is required if the code might send any output to stdout
|
|
|
|
# E.g., even --version or --help. So it's best to do it unconditionally.
|
|
|
|
close STDOUT
|
|
|
|
or (warn "$me: closing standard output: $!\n"), _exit (1);
|
|
|
|
}
|
|
|
|
|
2001-01-23 04:21:33 +08:00
|
|
|
# find_autoconf
|
|
|
|
# -------------
|
|
|
|
# Find the lib files and autoconf.
|
|
|
|
sub find_autoconf
|
|
|
|
{
|
|
|
|
$datadir = $ENV{"AC_MACRODIR"} || "@datadir@";
|
2001-06-25 14:15:07 +08:00
|
|
|
my $dir = dirname ($0);
|
2001-01-23 04:21:33 +08:00
|
|
|
$autoconf = '';
|
|
|
|
# We test "$dir/autoconf" in case we are in the build tree, in which case
|
|
|
|
# the names are not transformed yet.
|
2001-02-12 01:15:03 +08:00
|
|
|
foreach my $file ($ENV{"AUTOCONF"} || '',
|
2001-02-21 16:47:16 +08:00
|
|
|
"$dir/@autoconf-name@",
|
|
|
|
"$dir/autoconf",
|
|
|
|
"@bindir@/@autoconf-name@")
|
2001-01-23 04:21:33 +08:00
|
|
|
{
|
2001-02-21 16:47:16 +08:00
|
|
|
if (-x $file)
|
2001-01-23 04:21:33 +08:00
|
|
|
{
|
|
|
|
$autoconf = $file;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
|
2001-02-21 16:47:16 +08:00
|
|
|
# $CONFIGURE_AC
|
|
|
|
# &find_configure_ac ()
|
|
|
|
# ---------------------
|
|
|
|
sub find_configure_ac ()
|
|
|
|
{
|
|
|
|
if (-f 'configure.ac')
|
|
|
|
{
|
|
|
|
if (-f 'configure.in')
|
|
|
|
{
|
|
|
|
warn "warning: `configure.ac' and `configure.in' both present.\n";
|
|
|
|
warn "warning: proceeding with `configure.ac'.\n";
|
|
|
|
}
|
|
|
|
return 'configure.ac';
|
|
|
|
}
|
|
|
|
elsif (-f 'configure.in')
|
|
|
|
{
|
|
|
|
return 'configure.in';
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
# print_usage ()
|
|
|
|
# --------------
|
2000-08-01 18:05:11 +08:00
|
|
|
# Display usage (--help).
|
2001-01-29 17:24:13 +08:00
|
|
|
sub print_usage ()
|
1994-04-30 09:42:39 +08:00
|
|
|
{
|
2000-08-01 18:05:11 +08:00
|
|
|
print "Usage: $0 [OPTION] ... [SRCDIR]
|
1999-01-08 11:38:59 +08:00
|
|
|
|
|
|
|
Examine source files in the directory tree rooted at SRCDIR, or the
|
|
|
|
current directory if none is given. Search the source files for
|
2001-01-29 17:50:01 +08:00
|
|
|
common portability problems and create a file `$configure_scan' which
|
2001-01-12 17:19:59 +08:00
|
|
|
is a preliminary `configure.ac' for that package.
|
1999-01-08 11:38:59 +08:00
|
|
|
|
2000-03-03 02:17:26 +08:00
|
|
|
-h, --help print this help, then exit
|
|
|
|
-V, --version print version number, then exit
|
1999-01-08 11:38:59 +08:00
|
|
|
-v, --verbose verbosely report processing
|
2000-07-19 17:03:53 +08:00
|
|
|
|
|
|
|
Library directories:
|
|
|
|
-A, --autoconf-dir=ACDIR Autoconf's files location (rarely needed)
|
2000-08-01 19:12:12 +08:00
|
|
|
-l, --localdir=DIR location of `aclocal.m4' and `acconfig.h'
|
1999-01-08 11:38:59 +08:00
|
|
|
|
2000-08-01 18:05:11 +08:00
|
|
|
Report bugs to <bug-autoconf\@gnu.org>.\n";
|
|
|
|
exit 0;
|
|
|
|
}
|
2000-01-10 18:11:57 +08:00
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
|
|
|
|
# print_version ()
|
|
|
|
# ----------------
|
2000-08-01 18:05:11 +08:00
|
|
|
# Display version (--version).
|
|
|
|
sub print_version
|
|
|
|
{
|
2001-01-16 18:25:57 +08:00
|
|
|
print "autoscan (@PACKAGE_NAME@) @VERSION@
|
2000-01-10 18:11:57 +08:00
|
|
|
Written by David J. MacKenzie.
|
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
Copyright 1994, 1999, 2000, 2001 Free Software Foundation, Inc.
|
2000-01-10 18:11:57 +08:00
|
|
|
This is free software; see the source for copying conditions. There is NO
|
2000-08-01 18:05:11 +08:00
|
|
|
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
|
|
|
|
# parse_args ()
|
|
|
|
# -------------
|
2000-08-01 18:05:11 +08:00
|
|
|
# Process any command line arguments.
|
2001-01-29 17:24:13 +08:00
|
|
|
sub parse_args ()
|
2000-08-01 18:05:11 +08:00
|
|
|
{
|
2001-01-23 04:21:33 +08:00
|
|
|
my $srcdir;
|
2000-09-04 22:50:50 +08:00
|
|
|
Getopt::Long::config ("bundling");
|
2000-08-01 18:05:11 +08:00
|
|
|
Getopt::Long::GetOptions ("A|autoconf-dir|m|macrodir=s" => \$datadir,
|
|
|
|
"h|help" => \&print_usage,
|
|
|
|
"V|version" => \&print_version,
|
2000-09-04 22:50:50 +08:00
|
|
|
"v|verbose" => \$verbose)
|
2000-08-01 18:05:11 +08:00
|
|
|
or exit 1;
|
|
|
|
|
|
|
|
die "$me: too many arguments
|
2000-08-01 19:12:12 +08:00
|
|
|
Try `$me --help' for more information.\n"
|
2000-08-01 18:05:11 +08:00
|
|
|
if (@ARGV > 1);
|
|
|
|
($srcdir) = @ARGV;
|
|
|
|
$srcdir = "."
|
2001-01-23 18:28:29 +08:00
|
|
|
if !defined $srcdir;
|
1994-04-30 09:42:39 +08:00
|
|
|
|
2000-04-11 20:06:12 +08:00
|
|
|
print "srcdir=$srcdir\n" if $verbose;
|
|
|
|
chdir $srcdir || die "$me: cannot cd to $srcdir: $!\n";
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
|
|
|
|
# init_tables ()
|
|
|
|
# --------------
|
1994-04-30 09:42:39 +08:00
|
|
|
# Put values in the tables of what to do with each token.
|
2001-01-29 17:24:13 +08:00
|
|
|
sub init_tables ()
|
1994-04-30 09:42:39 +08:00
|
|
|
{
|
2000-04-11 20:06:12 +08:00
|
|
|
# Initialize a table of C keywords (to ignore).
|
|
|
|
# Taken from K&R 1st edition p. 180.
|
|
|
|
# ANSI C, GNU C, and C++ keywords can introduce portability problems,
|
|
|
|
# so don't ignore them.
|
2001-06-12 17:33:58 +08:00
|
|
|
|
|
|
|
foreach (qw (int char float double struct union long short unsigned
|
|
|
|
auto extern register typedef static goto return sizeof break
|
|
|
|
continue if else for do while switch case default))
|
2001-01-23 03:01:40 +08:00
|
|
|
{
|
2001-06-12 17:33:58 +08:00
|
|
|
$c_keywords{$_} = 0;
|
2001-01-23 03:01:40 +08:00
|
|
|
}
|
2000-04-11 20:06:12 +08:00
|
|
|
|
|
|
|
# The data file format supports only one line of macros per function.
|
|
|
|
# If more than that is required for a common portability problem,
|
|
|
|
# a new Autoconf macro should probably be written for that case,
|
2001-01-12 17:19:59 +08:00
|
|
|
# instead of duplicating the code in lots of configure.ac files.
|
2001-06-25 14:15:07 +08:00
|
|
|
my $tables_are_consistent = 1;
|
2001-02-12 01:15:03 +08:00
|
|
|
foreach my $kind (@kinds)
|
2001-01-23 03:04:00 +08:00
|
|
|
{
|
2001-02-12 01:15:03 +08:00
|
|
|
my $file = "$datadir/ac$kind";
|
|
|
|
open TABLE, $file or
|
|
|
|
die "$me: cannot open $file: $!\n";
|
2001-01-23 03:04:00 +08:00
|
|
|
while (<TABLE>)
|
|
|
|
{
|
|
|
|
# Ignore blank lines and comments.
|
|
|
|
next
|
|
|
|
if /^\s*$/ || /^\s*\#/;
|
2001-01-24 15:58:46 +08:00
|
|
|
unless (/^(\S+)\s+(\S.*)$/ || /^(\S+)\s*$/)
|
2001-01-23 03:04:00 +08:00
|
|
|
{
|
2001-02-12 01:15:03 +08:00
|
|
|
die "$me: cannot parse definition in $file:\n$_\n";
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
2001-02-12 01:15:03 +08:00
|
|
|
my $word = $1;
|
|
|
|
my $macro = $2 || $generic_macro{$kind};
|
2001-06-25 14:15:07 +08:00
|
|
|
# The default macro must be explicitly listed for words
|
|
|
|
# which have a specific macros. This allows to enforce
|
|
|
|
# consistency checks.
|
|
|
|
if (!defined $2 && exists $macro{$kind}{$word})
|
|
|
|
{
|
|
|
|
warn ("$datadir/ac$kind:$.: "
|
|
|
|
. "ignoring implicit call to the generic macro for $word\n");
|
|
|
|
$tables_are_consistent = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
push @{$macro{$kind}{$word}}, $macro;
|
|
|
|
}
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
|
|
|
close(TABLE);
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
2001-06-25 14:15:07 +08:00
|
|
|
|
|
|
|
die "$me: some tables are inconsistent\n"
|
|
|
|
if !$tables_are_consistent;
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
|
|
|
|
# wanted ()
|
|
|
|
# ---------
|
1994-04-30 09:42:39 +08:00
|
|
|
# Collect names of various kinds of files in the package.
|
|
|
|
# Called by &find on each file.
|
2001-01-29 17:24:13 +08:00
|
|
|
sub wanted ()
|
1994-04-30 09:42:39 +08:00
|
|
|
{
|
2001-01-23 03:01:40 +08:00
|
|
|
# Strip a useless leading `./'.
|
|
|
|
$name =~ s,^\./,,;
|
|
|
|
|
|
|
|
if (/^.*\.[chlymC]$/ || /^.*\.cc$/)
|
|
|
|
{
|
2001-01-29 17:24:13 +08:00
|
|
|
push (@cfiles, $name);
|
2001-01-23 03:01:40 +08:00
|
|
|
}
|
|
|
|
elsif (/^[Mm]akefile$/ || /^GNUmakefile$/)
|
|
|
|
{
|
|
|
|
# Wanted only if there is no corresponding Makefile.in.
|
|
|
|
# Using Find, $_ contains the current filename with the current
|
|
|
|
# directory of the walk through.
|
2001-01-29 17:24:13 +08:00
|
|
|
push (@makefiles, $name)
|
2001-01-23 03:01:40 +08:00
|
|
|
if ! -f "$_.in";
|
|
|
|
}
|
|
|
|
elsif (/^[Mm]akefile\.in$/)
|
|
|
|
{
|
2001-01-29 17:24:13 +08:00
|
|
|
push (@makefiles, $name);
|
2001-01-23 03:01:40 +08:00
|
|
|
}
|
|
|
|
elsif (/^.*\.sh$/)
|
|
|
|
{
|
2001-01-29 17:24:13 +08:00
|
|
|
push (@shfiles, $name);
|
2001-01-23 03:01:40 +08:00
|
|
|
}
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
|
|
|
|
# scan_files ()
|
|
|
|
# -------------
|
1994-04-30 09:42:39 +08:00
|
|
|
# Read through the files and collect lists of tokens in them
|
|
|
|
# that might create nonportabilities.
|
2001-01-29 17:24:13 +08:00
|
|
|
sub scan_files ()
|
1994-04-30 09:42:39 +08:00
|
|
|
{
|
2001-01-23 04:21:33 +08:00
|
|
|
my $file;
|
2001-01-23 03:04:00 +08:00
|
|
|
if (defined $cfiles[0])
|
|
|
|
{
|
|
|
|
$initfile = $cfiles[0]; # Pick one at random.
|
|
|
|
}
|
2000-04-11 20:06:12 +08:00
|
|
|
|
2001-01-23 03:04:00 +08:00
|
|
|
foreach $file (@cfiles)
|
|
|
|
{
|
2001-06-12 17:33:58 +08:00
|
|
|
push (@{$used{'programs'}{"cc"}}, $file);
|
2001-01-29 17:24:13 +08:00
|
|
|
scan_c_file ($file);
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
2000-04-11 20:06:12 +08:00
|
|
|
|
2001-01-23 03:04:00 +08:00
|
|
|
foreach $file (@makefiles)
|
|
|
|
{
|
2001-01-29 17:24:13 +08:00
|
|
|
scan_makefile ($file);
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
2000-04-11 20:06:12 +08:00
|
|
|
|
2001-01-23 03:04:00 +08:00
|
|
|
foreach $file (@shfiles)
|
|
|
|
{
|
2001-01-29 17:24:13 +08:00
|
|
|
scan_sh_file ($file);
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
2001-02-03 02:15:36 +08:00
|
|
|
|
|
|
|
if ($verbose)
|
|
|
|
{
|
|
|
|
print "cfiles:", join(" ", @cfiles), "\n";
|
|
|
|
print "makefiles:", join(" ", @makefiles), "\n";
|
|
|
|
print "shfiles:", join(" ", @shfiles), "\n";
|
|
|
|
|
2001-06-12 17:33:58 +08:00
|
|
|
foreach my $kind (@kinds)
|
2001-02-03 02:15:36 +08:00
|
|
|
{
|
2001-06-12 17:33:58 +08:00
|
|
|
print "\n$kind:\n";
|
|
|
|
foreach my $word (sort keys %{$used{$kind}})
|
2001-02-03 02:15:36 +08:00
|
|
|
{
|
2001-06-12 17:33:58 +08:00
|
|
|
print "$word: @{$used{$kind}{$word}}\n";
|
2001-02-03 02:15:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-04-11 20:06:12 +08:00
|
|
|
}
|
1994-04-30 09:42:39 +08:00
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
|
2001-01-23 03:04:00 +08:00
|
|
|
# scan_c_file(FILE)
|
|
|
|
# -----------------
|
2001-01-29 17:24:13 +08:00
|
|
|
sub scan_c_file ($)
|
2000-04-11 20:06:12 +08:00
|
|
|
{
|
2001-01-23 04:21:33 +08:00
|
|
|
my ($file) = @_;
|
|
|
|
my ($in_comment) = 0; # Nonzero if in a multiline comment.
|
2000-04-11 20:06:12 +08:00
|
|
|
|
|
|
|
open(CFILE, "<$file") || die "$me: cannot open $file: $!\n";
|
2001-01-23 03:04:00 +08:00
|
|
|
while (<CFILE>)
|
|
|
|
{
|
|
|
|
# Strip out comments, approximately.
|
|
|
|
# Ending on this line.
|
|
|
|
if ($in_comment && m,\*/,)
|
|
|
|
{
|
|
|
|
s,.*\*/,,;
|
|
|
|
$in_comment = 0;
|
|
|
|
}
|
|
|
|
# All on one line.
|
|
|
|
s,/\*.*\*/,,g;
|
|
|
|
# Starting on this line.
|
|
|
|
if (m,/\*,)
|
|
|
|
{
|
|
|
|
$in_comment = 1;
|
|
|
|
}
|
|
|
|
# Continuing on this line.
|
|
|
|
next if $in_comment;
|
|
|
|
|
|
|
|
# Preprocessor directives.
|
|
|
|
if (/^\s*\#\s*include\s*<([^>]*)>/)
|
|
|
|
{
|
2001-06-12 17:33:58 +08:00
|
|
|
push (@{$used{'headers'}{$1}}, "$file:$.");
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
|
|
|
# Ignore other preprocessor directives.
|
|
|
|
next if /^\s*\#/;
|
|
|
|
|
|
|
|
# Remove string and character constants.
|
|
|
|
s,\"[^\"]*\",,g;
|
|
|
|
s,\'[^\']*\',,g;
|
|
|
|
|
|
|
|
# Tokens in the code.
|
|
|
|
# Maybe we should ignore function definitions (in column 0)?
|
|
|
|
while (s/\b([a-zA-Z_]\w*)\s*\(/ /)
|
|
|
|
{
|
2001-06-12 17:33:58 +08:00
|
|
|
push (@{$used{'functions'}{$1}}, "$file:$.")
|
2001-01-23 18:28:29 +08:00
|
|
|
if !defined $c_keywords{$1};
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
|
|
|
while (s/\b([a-zA-Z_]\w*)\b/ /)
|
|
|
|
{
|
2001-06-12 17:33:58 +08:00
|
|
|
push (@{$used{'identifiers'}{$1}}, "$file:$.")
|
2001-01-23 18:28:29 +08:00
|
|
|
if !defined $c_keywords{$1};
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
2000-04-11 20:06:12 +08:00
|
|
|
close(CFILE);
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
|
|
|
|
# scan_makefile(MAKEFILE)
|
|
|
|
# -----------------------
|
|
|
|
sub scan_makefile ($)
|
1994-04-30 09:42:39 +08:00
|
|
|
{
|
2001-01-23 04:21:33 +08:00
|
|
|
my ($file) = @_;
|
2000-04-11 20:06:12 +08:00
|
|
|
|
|
|
|
open(MFILE, "<$file") || die "$me: cannot open $file: $!\n";
|
2001-01-23 03:04:00 +08:00
|
|
|
while (<MFILE>)
|
|
|
|
{
|
|
|
|
# Strip out comments and variable references.
|
|
|
|
s/#.*//;
|
|
|
|
s/\$\([^\)]*\)//g;
|
|
|
|
s/\${[^\}]*}//g;
|
|
|
|
s/@[^@]*@//g;
|
|
|
|
|
|
|
|
# Variable assignments.
|
|
|
|
while (s/\b([a-zA-Z_]\w*)\s*=/ /)
|
|
|
|
{
|
2001-06-12 17:33:58 +08:00
|
|
|
push (@{$used{'makevars'}{$1}}, "$file:$.");
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
|
|
|
# Libraries.
|
|
|
|
while (s/\B-l([a-zA-Z_]\w*)\b/ /)
|
|
|
|
{
|
2001-06-12 17:33:58 +08:00
|
|
|
push (@{$used{'libraries'}{$1}}, "$file:$.");
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
|
|
|
# Tokens in the code.
|
|
|
|
while (s/\b([a-zA-Z_]\w*)\b/ /)
|
|
|
|
{
|
2001-06-12 17:33:58 +08:00
|
|
|
push (@{$used{'programs'}{$1}}, "$file:$.");
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
|
|
|
}
|
2000-04-11 20:06:12 +08:00
|
|
|
close(MFILE);
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
|
|
|
|
# scan_sh_file(SHELL-SCRIPT)
|
|
|
|
# --------------------------
|
|
|
|
sub scan_sh_file ($)
|
1994-04-30 09:42:39 +08:00
|
|
|
{
|
2001-01-23 04:21:33 +08:00
|
|
|
my ($file) = @_;
|
2000-04-11 20:06:12 +08:00
|
|
|
|
|
|
|
open(MFILE, "<$file") || die "$me: cannot open $file: $!\n";
|
2001-01-23 03:04:00 +08:00
|
|
|
while (<MFILE>)
|
|
|
|
{
|
|
|
|
# Strip out comments and variable references.
|
|
|
|
s/#.*//;
|
|
|
|
s/\${[^\}]*}//g;
|
|
|
|
s/@[^@]*@//g;
|
|
|
|
|
|
|
|
# Tokens in the code.
|
|
|
|
while (s/\b([a-zA-Z_]\w*)\b/ /)
|
|
|
|
{
|
2001-06-12 17:33:58 +08:00
|
|
|
push (@{$used{'programs'}{$1}}, "$file:$.");
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
2000-04-11 20:06:12 +08:00
|
|
|
close(MFILE);
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-12 18:05:27 +08:00
|
|
|
# output_kind ($KIND)
|
|
|
|
# -------------------
|
|
|
|
sub output_kind ($)
|
|
|
|
{
|
|
|
|
my ($kind) = @_;
|
2001-06-25 14:15:07 +08:00
|
|
|
# Lists of words to be checked with the generic macro.
|
2001-06-12 18:05:27 +08:00
|
|
|
my @have;
|
|
|
|
|
2001-06-12 18:16:49 +08:00
|
|
|
print CONF "\n# $kind_comment{$kind}\n"
|
|
|
|
if exists $kind_comment{$kind};
|
2001-06-12 18:05:27 +08:00
|
|
|
foreach my $word (sort keys %{$used{$kind}})
|
|
|
|
{
|
2001-06-25 14:15:07 +08:00
|
|
|
# Words that were caught, but not to be checked according to
|
|
|
|
# the autoscan library files.
|
|
|
|
next
|
|
|
|
if ! exists $macro{$kind}{$word};
|
|
|
|
|
|
|
|
# Output the needed macro invocations in $configure_scan if not
|
|
|
|
# already printed, and remember these macros are needed.
|
|
|
|
foreach my $macro (@{$macro{$kind}{$word}})
|
2001-06-12 18:05:27 +08:00
|
|
|
{
|
2001-06-12 18:16:49 +08:00
|
|
|
if (exists $generic_macro{$kind}
|
2001-06-25 14:15:07 +08:00
|
|
|
&& $macro eq $generic_macro{$kind})
|
2001-06-12 18:05:27 +08:00
|
|
|
{
|
|
|
|
push (@have, $word);
|
|
|
|
push (@{$needed_macros{"$generic_macro{$kind}([$word])"}},
|
|
|
|
@{$used{$kind}{$word}});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-06-25 14:15:07 +08:00
|
|
|
if (! $printed{$macro})
|
|
|
|
{
|
|
|
|
print CONF "$macro\n";
|
|
|
|
$printed{$macro} = 1;
|
|
|
|
}
|
|
|
|
push (@{$needed_macros{$macro}},
|
|
|
|
@{$used{$kind}{$word}});
|
2001-06-12 18:05:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print CONF "$generic_macro{$kind}([" . join(' ', sort(@have)) . "])\n"
|
|
|
|
if @have;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
# output_libraries ()
|
|
|
|
# -------------------
|
|
|
|
sub output_libraries ()
|
2001-01-23 03:01:23 +08:00
|
|
|
{
|
2000-04-11 20:06:12 +08:00
|
|
|
print CONF "\n# Checks for libraries.\n";
|
2001-06-12 17:33:58 +08:00
|
|
|
foreach my $word (sort keys %{$used{'libraries'}})
|
2001-01-23 03:04:47 +08:00
|
|
|
{
|
|
|
|
print CONF "# FIXME: Replace `main' with a function in `-l$word':\n";
|
|
|
|
print CONF "AC_CHECK_LIB([$word], [main])\n";
|
|
|
|
}
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
|
|
|
|
# output (CONFIGURE_SCAN)
|
|
|
|
# -----------------------
|
|
|
|
# Print a proto configure.ac.
|
|
|
|
sub output ($)
|
|
|
|
{
|
|
|
|
my $configure_scan = shift;
|
|
|
|
my %unique_makefiles;
|
|
|
|
|
|
|
|
open (CONF, ">$configure_scan") ||
|
|
|
|
die "$me: cannot create $configure_scan: $!\n";
|
|
|
|
|
|
|
|
print CONF "# Process this file with autoconf to produce a configure script.\n";
|
|
|
|
print CONF "AC_INIT\n";
|
|
|
|
if (defined $initfile)
|
|
|
|
{
|
|
|
|
print CONF "AC_CONFIG_SRCDIR([$initfile])\n";
|
|
|
|
}
|
|
|
|
if (defined $cfiles[0])
|
|
|
|
{
|
|
|
|
print CONF "AC_CONFIG_HEADER([config.h])\n";
|
|
|
|
}
|
|
|
|
|
2001-06-12 18:16:49 +08:00
|
|
|
output_kind ('programs');
|
|
|
|
output_kind ('makevars');
|
2001-01-29 17:24:13 +08:00
|
|
|
output_libraries;
|
2001-06-12 18:16:49 +08:00
|
|
|
output_kind ('headers');
|
|
|
|
output_kind ('identifiers');
|
|
|
|
output_kind ('functions');
|
2001-01-29 17:24:13 +08:00
|
|
|
|
|
|
|
# Change DIR/Makefile.in to DIR/Makefile.
|
2001-02-12 01:15:03 +08:00
|
|
|
foreach my $m (@makefiles)
|
2001-01-29 17:24:13 +08:00
|
|
|
{
|
2001-02-12 01:15:03 +08:00
|
|
|
$m =~ s/\.in$//;
|
|
|
|
$unique_makefiles{$m}++;
|
2001-01-29 17:24:13 +08:00
|
|
|
}
|
|
|
|
print CONF "\nAC_CONFIG_FILES([",
|
2001-06-25 14:15:07 +08:00
|
|
|
join ("\n ", sort keys %unique_makefiles), "])\n";
|
2001-01-29 17:24:13 +08:00
|
|
|
print CONF "AC_OUTPUT\n";
|
|
|
|
|
|
|
|
close CONF ||
|
2001-01-29 17:50:01 +08:00
|
|
|
die "$me: closing $configure_scan: $!\n";
|
2001-01-29 17:24:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# check_configure_ac (CONFIGURE_AC)
|
|
|
|
# ---------------------------------
|
2001-01-23 03:01:23 +08:00
|
|
|
# Use autoconf to check if all the suggested macros are included
|
2001-01-29 17:24:13 +08:00
|
|
|
# in CONFIGURE_AC.
|
|
|
|
sub check_configure_ac ($)
|
2001-01-23 03:01:23 +08:00
|
|
|
{
|
2001-01-23 04:21:33 +08:00
|
|
|
my ($configure_ac) = $@;
|
|
|
|
my ($trace_option) = '';
|
2001-01-23 03:01:23 +08:00
|
|
|
|
2001-02-12 01:15:03 +08:00
|
|
|
foreach my $macro (sort keys %needed_macros)
|
2001-01-23 03:01:23 +08:00
|
|
|
{
|
2001-01-24 15:58:16 +08:00
|
|
|
$macro =~ s/\(.*//;
|
2001-01-23 03:01:23 +08:00
|
|
|
$trace_option .= " -t $macro";
|
|
|
|
}
|
|
|
|
|
2001-01-23 03:05:16 +08:00
|
|
|
open (TRACES, "$autoconf -A $datadir $trace_option $configure_ac|") ||
|
2001-01-23 03:01:23 +08:00
|
|
|
die "$me: cannot create read traces: $!\n";
|
|
|
|
|
|
|
|
while (<TRACES>)
|
|
|
|
{
|
2001-01-24 15:58:16 +08:00
|
|
|
chomp;
|
|
|
|
my ($file, $line, $macro, @args) = split (/:/, $_);
|
2001-01-24 15:58:31 +08:00
|
|
|
if ($macro =~ /^AC_CHECK_(HEADER|FUNC|TYPE|MEMBER)S$/)
|
2001-01-24 15:58:16 +08:00
|
|
|
{
|
2001-01-24 15:58:31 +08:00
|
|
|
# To be rigorous, we should distinguish between space and comma
|
|
|
|
# separated macros. But there is no point.
|
2001-02-12 01:15:03 +08:00
|
|
|
foreach my $word (split (/\s|,/, $args[0]))
|
2001-01-24 15:58:16 +08:00
|
|
|
{
|
2001-01-24 15:58:46 +08:00
|
|
|
# AC_CHECK_MEMBERS wants `struct' or `union'.
|
2001-01-24 15:58:31 +08:00
|
|
|
if ($macro eq "AC_CHECK_MEMBERS"
|
|
|
|
&& $word =~ /^stat.st_/)
|
|
|
|
{
|
|
|
|
$word = "struct " . $word;
|
|
|
|
}
|
|
|
|
delete ($needed_macros{"$macro([$word])"});
|
2001-01-24 15:58:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete ($needed_macros{$macro});
|
|
|
|
}
|
2001-01-23 03:01:23 +08:00
|
|
|
}
|
|
|
|
|
2001-01-23 03:04:47 +08:00
|
|
|
close (TRACES) ||
|
|
|
|
die "$me: cannot close traces: $!\n";
|
|
|
|
|
2001-02-12 01:15:03 +08:00
|
|
|
foreach my $macro (sort keys %needed_macros)
|
2001-01-23 03:01:23 +08:00
|
|
|
{
|
2001-02-20 17:24:40 +08:00
|
|
|
warn "$me: warning: missing $macro wanted by: \n";
|
|
|
|
foreach my $need (@{$needed_macros{$macro}})
|
|
|
|
{
|
|
|
|
warn "\t$need\n";
|
|
|
|
}
|
2001-01-23 03:01:23 +08:00
|
|
|
}
|
|
|
|
}
|
2001-01-29 17:24:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
## -------------- ##
|
|
|
|
## Main program. ##
|
|
|
|
## -------------- ##
|
|
|
|
|
|
|
|
# Find the lib files and autoconf.
|
|
|
|
find_autoconf;
|
2001-02-21 16:47:16 +08:00
|
|
|
my $configure_ac = find_configure_ac;
|
2001-01-29 17:24:13 +08:00
|
|
|
parse_args;
|
|
|
|
init_tables;
|
|
|
|
find ('.');
|
|
|
|
scan_files;
|
|
|
|
output ('configure.scan');
|
2001-02-21 16:47:16 +08:00
|
|
|
if ($configure_ac)
|
2001-01-29 17:24:13 +08:00
|
|
|
{
|
2001-02-21 16:47:16 +08:00
|
|
|
check_configure_ac ($configure_ac);
|
2001-01-29 17:24:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
exit 0;
|