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.
|
2002-04-20 02:59:59 +08:00
|
|
|
# Copyright (C) 1994, 1999, 2000, 2001, 2002 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>.
|
|
|
|
|
2002-04-20 02:59:59 +08:00
|
|
|
eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
|
2001-09-20 22:55:49 +08:00
|
|
|
if 0;
|
|
|
|
|
2001-08-01 23:01:16 +08:00
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
my $perllibdir = $ENV{'autom4te_perllibdir'} || "@datadir@";
|
|
|
|
unshift @INC, "$perllibdir";
|
|
|
|
}
|
|
|
|
|
2001-09-05 15:06:40 +08:00
|
|
|
use Autom4te::General;
|
|
|
|
use Autom4te::XFile;
|
2001-06-25 14:15:07 +08:00
|
|
|
use File::Basename;
|
2001-07-03 22:10:41 +08:00
|
|
|
use File::Find;
|
2001-01-23 04:21:33 +08:00
|
|
|
use strict;
|
|
|
|
|
2001-11-26 18:53:00 +08:00
|
|
|
use vars qw(@cfiles @makefiles @shfiles %printed);
|
|
|
|
|
|
|
|
# The list of C keywords.
|
|
|
|
my %c_keywords = map { $_ => 1}
|
|
|
|
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);
|
1994-04-30 09:42:39 +08:00
|
|
|
|
2001-11-26 18:51:29 +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 =
|
|
|
|
(
|
2002-09-27 15:35:39 +08:00
|
|
|
'functions' => 'Checks for library functions.',
|
|
|
|
'headers' => 'Checks for header files.',
|
2001-06-12 18:05:27 +08:00
|
|
|
'identifiers' => 'Checks for typedefs, structures, and compiler characteristics.',
|
2002-09-27 15:35:39 +08:00
|
|
|
'programs' => 'Checks for programs.',
|
2001-06-12 18:05:27 +08:00
|
|
|
);
|
2001-01-24 15:58:46 +08:00
|
|
|
|
2002-09-27 15:35:39 +08:00
|
|
|
# $USED{KIND}{ITEM} is the list of locations where the ITEM (of KIND) was used
|
|
|
|
# in the user package.
|
|
|
|
# For instance $USED{function}{alloca} is the list of `file:line' where
|
|
|
|
# `alloca (...)' appears.
|
|
|
|
my %used = ();
|
|
|
|
|
|
|
|
# $MACRO{KIND}{ITEM} is the list of macros to use to test ITEM.
|
|
|
|
# Initialized from lib/autoscan/*. E.g., $MACRO{function}{alloca} contains
|
|
|
|
# the singleton AC_FUNC_ALLOCA. Some require several checks.
|
|
|
|
my %macro = ();
|
|
|
|
|
|
|
|
# $NEEDED_MACROS{MACRO} is an array of locations requiring MACRO.
|
|
|
|
# E.g., $NEEDED_MACROS{AC_FUNC_ALLOC} the list of `file:line' containing
|
|
|
|
# `alloca (...)'.
|
|
|
|
my %needed_macros = ();
|
|
|
|
|
2001-01-29 17:50:01 +08:00
|
|
|
my $configure_scan = 'configure.scan';
|
2001-09-05 15:06:40 +08:00
|
|
|
my $log = new Autom4te::XFile ">$me.log";
|
2001-01-24 15:58:46 +08:00
|
|
|
|
2001-07-03 22:10:41 +08:00
|
|
|
# Autoconf and lib files.
|
2002-06-13 01:26:19 +08:00
|
|
|
my $autom4te = $ENV{'AUTOM4TE'} || '@bindir@/@autom4te-name@';
|
2001-09-05 15:06:02 +08:00
|
|
|
my $autoconf = "$autom4te --language=autoconf";
|
2002-07-17 16:30:42 +08:00
|
|
|
my @prepend_include;
|
2001-09-05 15:06:02 +08:00
|
|
|
my @include = ('@datadir@');
|
2001-02-12 00:38:44 +08:00
|
|
|
|
2001-09-05 15:06:02 +08:00
|
|
|
# $help
|
|
|
|
# -----
|
|
|
|
$help = "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-07-14 22:19:19 +08:00
|
|
|
common portability problems, check for incompleteness of
|
|
|
|
`configure.ac', and create a file `$configure_scan' which is a
|
|
|
|
preliminary `configure.ac' for that package.
|
1999-01-08 11:38:59 +08:00
|
|
|
|
2001-09-05 15:06:02 +08:00
|
|
|
-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
|
2002-07-17 16:30:42 +08:00
|
|
|
-B, --prepend-include=DIR prepend directory DIR to search path
|
|
|
|
-I, --include=DIR append directory DIR to search path
|
1999-01-08 11:38:59 +08:00
|
|
|
|
2000-08-01 18:05:11 +08:00
|
|
|
Report bugs to <bug-autoconf\@gnu.org>.\n";
|
2001-01-29 17:24:13 +08:00
|
|
|
|
2001-09-05 15:06:02 +08:00
|
|
|
# $version
|
|
|
|
# --------
|
|
|
|
$version = "autoscan (@PACKAGE_NAME@) @VERSION@
|
2002-01-25 02:41:16 +08:00
|
|
|
Written by David J. MacKenzie and Akim Demaille.
|
2000-01-10 18:11:57 +08:00
|
|
|
|
2002-03-08 19:46:31 +08:00
|
|
|
Copyright 2002 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";
|
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
|
2001-09-05 15:06:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
## ------------------------ ##
|
|
|
|
## Command line interface. ##
|
|
|
|
## ------------------------ ##
|
|
|
|
|
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
|
|
|
{
|
2002-09-27 15:35:39 +08:00
|
|
|
getopt ('I|include=s' => \@include,
|
2002-09-12 23:04:18 +08:00
|
|
|
'B|prepend-include=s' => \@prepend_include);
|
2000-08-01 18:05:11 +08:00
|
|
|
|
|
|
|
die "$me: too many arguments
|
2000-08-01 19:12:12 +08:00
|
|
|
Try `$me --help' for more information.\n"
|
2001-09-05 15:06:02 +08:00
|
|
|
if @ARGV > 1;
|
|
|
|
|
|
|
|
my $srcdir = $ARGV[0] || ".";
|
1994-04-30 09:42:39 +08:00
|
|
|
|
2001-09-05 15:06:02 +08:00
|
|
|
verbose "srcdir = $srcdir";
|
2002-09-02 15:41:56 +08:00
|
|
|
chdir $srcdir || error "cannot cd to $srcdir: $!";
|
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
|
|
|
|
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
|
|
|
{
|
2002-07-17 16:30:42 +08:00
|
|
|
my $file = find_file ("autoscan/$kind",
|
|
|
|
reverse(@prepend_include), @include);
|
2001-09-05 15:06:40 +08:00
|
|
|
my $table = new Autom4te::XFile $file;
|
2001-07-14 22:19:19 +08:00
|
|
|
while ($_ = $table->getline)
|
2001-01-23 03:04:00 +08:00
|
|
|
{
|
|
|
|
# Ignore blank lines and comments.
|
|
|
|
next
|
|
|
|
if /^\s*$/ || /^\s*\#/;
|
2002-09-27 15:35:39 +08:00
|
|
|
|
|
|
|
# '<word> <macro invocation>' or...
|
|
|
|
# '<word> warn: <message>' or...
|
|
|
|
# '<word>'.
|
|
|
|
if (/^(\S+)\s+(\S.*)$/ || /^(\S+)\s*$/)
|
2001-06-25 14:15:07 +08:00
|
|
|
{
|
2002-09-27 15:35:39 +08:00
|
|
|
my $word = $1;
|
|
|
|
my $macro = $2 || $generic_macro{$kind};
|
|
|
|
# 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 ("$file:$.: "
|
|
|
|
. "ignoring implicit call to the generic macro for $word\n");
|
|
|
|
$tables_are_consistent = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
push @{$macro{$kind}{$word}}, $macro;
|
|
|
|
}
|
|
|
|
next;
|
2001-06-25 14:15:07 +08:00
|
|
|
}
|
2002-09-27 15:35:39 +08:00
|
|
|
|
|
|
|
error "cannot parse definition in $file:\n$_";
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
2001-09-05 15:06:40 +08:00
|
|
|
$table->close;
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
2001-06-25 14:15:07 +08:00
|
|
|
|
2002-09-02 15:41:56 +08:00
|
|
|
error "some tables are inconsistent"
|
2001-06-25 14:15:07 +08:00
|
|
|
if !$tables_are_consistent;
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
|
2001-11-26 18:51:44 +08:00
|
|
|
# used($KIND, $WORD, [$WHERE])
|
|
|
|
# ----------------------------
|
2002-01-07 04:47:57 +08:00
|
|
|
# $WORD is used as a $KIND.
|
2001-11-26 18:51:44 +08:00
|
|
|
sub used ($$;$)
|
|
|
|
{
|
|
|
|
my ($kind, $word, $where) = @_;
|
|
|
|
$where ||= "$File::Find::name:$.";
|
|
|
|
push (@{$used{$kind}{$word}}, $where);
|
|
|
|
}
|
2000-04-11 20:06:12 +08:00
|
|
|
|
2002-09-27 15:35:39 +08:00
|
|
|
|
2001-07-03 22:11:06 +08:00
|
|
|
## ----------------------- ##
|
|
|
|
## Scanning source files. ##
|
|
|
|
## ----------------------- ##
|
1994-04-30 09:42:39 +08:00
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
|
2001-09-05 15:06:02 +08:00
|
|
|
# scan_c_file($FILENAME)
|
|
|
|
# ----------------------
|
2001-01-29 17:24:13 +08:00
|
|
|
sub scan_c_file ($)
|
2000-04-11 20:06:12 +08:00
|
|
|
{
|
2001-07-14 22:19:19 +08:00
|
|
|
my ($filename) = @_;
|
2001-11-26 18:52:46 +08:00
|
|
|
push @cfiles, $File::Find::name;
|
2001-07-03 22:11:06 +08:00
|
|
|
|
|
|
|
# Nonzero if in a multiline comment.
|
|
|
|
my $in_comment = 0;
|
2000-04-11 20:06:12 +08:00
|
|
|
|
2001-09-05 15:06:40 +08:00
|
|
|
my $file = new Autom4te::XFile "<$filename";
|
2001-07-14 22:19:19 +08:00
|
|
|
|
|
|
|
while ($_ = $file->getline)
|
2001-01-23 03:04:00 +08:00
|
|
|
{
|
2001-11-26 18:51:14 +08:00
|
|
|
# Strip out comments.
|
|
|
|
if ($in_comment && s,^.*?\*/,,)
|
2001-01-23 03:04:00 +08:00
|
|
|
{
|
|
|
|
$in_comment = 0;
|
|
|
|
}
|
2001-11-26 18:51:14 +08:00
|
|
|
# The whole line is inside a commment.
|
|
|
|
next if $in_comment;
|
2001-01-23 03:04:00 +08:00
|
|
|
# All on one line.
|
2001-11-26 18:51:14 +08:00
|
|
|
s,/\*.*?\*/,,g;
|
|
|
|
|
2001-01-23 03:04:00 +08:00
|
|
|
# Starting on this line.
|
2001-11-26 18:51:14 +08:00
|
|
|
if (s,/\*.*$,,)
|
2001-01-23 03:04:00 +08:00
|
|
|
{
|
|
|
|
$in_comment = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Preprocessor directives.
|
2001-11-26 18:51:29 +08:00
|
|
|
if (s/^\s*\#\s*//)
|
2001-01-23 03:04:00 +08:00
|
|
|
{
|
2001-11-26 18:51:29 +08:00
|
|
|
if (/^include\s*<([^>]*)>/)
|
|
|
|
{
|
2001-11-26 18:51:44 +08:00
|
|
|
used ('headers', $1);
|
2001-11-26 18:51:29 +08:00
|
|
|
}
|
|
|
|
if (s/^(if|ifdef|ifndef|elif)\s+//)
|
|
|
|
{
|
|
|
|
foreach my $word (split (/\W+/))
|
|
|
|
{
|
2001-11-26 18:51:44 +08:00
|
|
|
used ('identifiers', $word)
|
2001-11-26 18:51:29 +08:00
|
|
|
unless $word eq 'defined' || $word !~ /^[a-zA-Z_]/;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# Ignore other preprocessor directives.
|
|
|
|
next;
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# 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-11-26 18:51:44 +08:00
|
|
|
used ('functions', $1)
|
2001-11-26 18:53:00 +08:00
|
|
|
if !$c_keywords{$1};
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
|
|
|
while (s/\b([a-zA-Z_]\w*)\b/ /)
|
|
|
|
{
|
2001-11-26 18:51:44 +08:00
|
|
|
used ('identifiers', $1)
|
2001-11-26 18:53:00 +08:00
|
|
|
if !$c_keywords{$1};
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
2001-07-14 22:19:19 +08:00
|
|
|
|
2001-09-05 15:06:40 +08:00
|
|
|
$file->close;
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
|
2001-09-05 15:06:02 +08:00
|
|
|
# scan_makefile($MAKEFILE-NAME)
|
|
|
|
# -----------------------------
|
2001-01-29 17:24:13 +08:00
|
|
|
sub scan_makefile ($)
|
1994-04-30 09:42:39 +08:00
|
|
|
{
|
2001-07-14 22:19:19 +08:00
|
|
|
my ($filename) = @_;
|
2001-11-26 18:52:46 +08:00
|
|
|
push @makefiles, $File::Find::name;
|
2000-04-11 20:06:12 +08:00
|
|
|
|
2001-09-05 15:06:40 +08:00
|
|
|
my $file = new Autom4te::XFile "<$filename";
|
2001-07-14 22:19:19 +08:00
|
|
|
|
|
|
|
while ($_ = $file->getline)
|
2001-01-23 03:04:00 +08:00
|
|
|
{
|
2001-11-26 18:52:46 +08:00
|
|
|
# Strip out comments.
|
2001-01-23 03:04:00 +08:00
|
|
|
s/#.*//;
|
|
|
|
|
|
|
|
# Variable assignments.
|
|
|
|
while (s/\b([a-zA-Z_]\w*)\s*=/ /)
|
|
|
|
{
|
2001-11-26 18:51:44 +08:00
|
|
|
used ('makevars', $1);
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
2001-11-26 18:52:46 +08:00
|
|
|
# Be sure to catch a whole word. For instance `lex$U.$(OBJEXT)'
|
|
|
|
# is a single token. Otherwise we might believe `lex' is needed.
|
|
|
|
foreach my $word (split (/\s+/))
|
2001-01-23 03:04:00 +08:00
|
|
|
{
|
2001-11-26 18:52:46 +08:00
|
|
|
# Libraries.
|
|
|
|
if ($word =~ /^-l([a-zA-Z_]\w*)$/)
|
|
|
|
{
|
|
|
|
used ('libraries', $1);
|
|
|
|
}
|
|
|
|
# Tokens in the code.
|
|
|
|
# We allow some additional characters, e.g., `+', since
|
|
|
|
# autoscan/programs includes `c++'.
|
|
|
|
if ($word =~ /^[a-zA-Z_][\w+]*$/)
|
|
|
|
{
|
|
|
|
used ('programs', $word);
|
|
|
|
}
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
|
|
|
}
|
2001-07-14 22:19:19 +08:00
|
|
|
|
2001-09-05 15:06:40 +08:00
|
|
|
$file->close;
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
|
2001-09-05 15:06:02 +08:00
|
|
|
# scan_sh_file($SHELL-SCRIPT-NAME)
|
|
|
|
# --------------------------------
|
2001-01-29 17:24:13 +08:00
|
|
|
sub scan_sh_file ($)
|
1994-04-30 09:42:39 +08:00
|
|
|
{
|
2001-07-14 22:19:19 +08:00
|
|
|
my ($filename) = @_;
|
2001-11-26 18:52:46 +08:00
|
|
|
push @shfiles, $File::Find::name;
|
2000-04-11 20:06:12 +08:00
|
|
|
|
2001-09-05 15:06:40 +08:00
|
|
|
my $file = new Autom4te::XFile "<$filename";
|
2001-07-14 22:19:19 +08:00
|
|
|
|
|
|
|
while ($_ = $file->getline)
|
2001-01-23 03:04:00 +08:00
|
|
|
{
|
|
|
|
# Strip out comments and variable references.
|
|
|
|
s/#.*//;
|
|
|
|
s/\${[^\}]*}//g;
|
|
|
|
s/@[^@]*@//g;
|
|
|
|
|
|
|
|
# Tokens in the code.
|
|
|
|
while (s/\b([a-zA-Z_]\w*)\b/ /)
|
|
|
|
{
|
2001-11-26 18:51:44 +08:00
|
|
|
used ('programs', $1);
|
2001-01-23 03:04:00 +08:00
|
|
|
}
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
2001-07-14 22:19:19 +08:00
|
|
|
|
2001-09-05 15:06:40 +08:00
|
|
|
$file->close;
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-03 22:11:06 +08:00
|
|
|
# scan_file ()
|
|
|
|
# ------------
|
|
|
|
# Called by &find on each file. $_ contains the current filename with
|
|
|
|
# the current directory of the walk through.
|
|
|
|
sub scan_file ()
|
|
|
|
{
|
2001-07-04 15:45:12 +08:00
|
|
|
# Wanted only if there is no corresponding FILE.in.
|
|
|
|
return
|
|
|
|
if -f "$_.in";
|
|
|
|
|
2001-07-03 22:11:06 +08:00
|
|
|
# Save $_ as Find::File requires it to be preserved.
|
|
|
|
my $underscore = $_;
|
|
|
|
|
|
|
|
# Strip a useless leading `./'.
|
|
|
|
$File::Find::name =~ s,^\./,,;
|
|
|
|
|
2001-07-10 17:16:33 +08:00
|
|
|
if (/\.[chlym](\.in)?$/)
|
|
|
|
{
|
2002-03-19 23:25:26 +08:00
|
|
|
used 'programs', 'cc', $File::Find::name;
|
2001-07-10 17:16:33 +08:00
|
|
|
scan_c_file ($_);
|
|
|
|
}
|
|
|
|
elsif (/\.(cc|cpp|cxx|CC|C|hh|hpp|hxx|HH|H|yy|ypp|ll|lpp)(\.in)?$/)
|
2001-07-03 22:11:06 +08:00
|
|
|
{
|
2002-03-19 23:25:26 +08:00
|
|
|
used 'programs', 'c++', $File::Find::name;
|
2001-07-03 22:11:06 +08:00
|
|
|
scan_c_file ($_);
|
|
|
|
}
|
2001-07-04 15:45:12 +08:00
|
|
|
elsif (/^[Mm]akefile(\.in)?$/ || /^GNUmakefile(\.in)?$/)
|
2001-07-03 22:11:06 +08:00
|
|
|
{
|
|
|
|
scan_makefile ($_);
|
|
|
|
}
|
2001-07-04 15:45:12 +08:00
|
|
|
elsif (/\.sh(\.in)?$/)
|
2001-07-03 22:11:06 +08:00
|
|
|
{
|
|
|
|
scan_sh_file ($_);
|
|
|
|
}
|
|
|
|
|
|
|
|
$_ = $underscore;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# scan_files ()
|
|
|
|
# -------------
|
|
|
|
# Read through the files and collect lists of tokens in them
|
|
|
|
# that might create nonportabilities.
|
|
|
|
sub scan_files ()
|
|
|
|
{
|
|
|
|
find (\&scan_file, '.');
|
|
|
|
|
|
|
|
if ($verbose)
|
|
|
|
{
|
2001-11-26 18:52:46 +08:00
|
|
|
print "cfiles: @cfiles\n";
|
|
|
|
print "makefiles: @makefiles\n";
|
|
|
|
print "shfiles: @shfiles\n";
|
2001-07-03 22:11:06 +08:00
|
|
|
|
|
|
|
foreach my $kind (@kinds)
|
|
|
|
{
|
|
|
|
print "\n$kind:\n";
|
|
|
|
foreach my $word (sort keys %{$used{$kind}})
|
|
|
|
{
|
|
|
|
print "$word: @{$used{$kind}{$word}}\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
## ----------------------- ##
|
|
|
|
## Output configure.scan. ##
|
|
|
|
## ----------------------- ##
|
|
|
|
|
|
|
|
|
2001-07-14 22:19:19 +08:00
|
|
|
# output_kind ($FILE, $KIND)
|
|
|
|
# --------------------------
|
|
|
|
sub output_kind ($$)
|
2001-06-12 18:05:27 +08:00
|
|
|
{
|
2001-07-14 22:19:19 +08:00
|
|
|
my ($file, $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-07-14 22:19:19 +08:00
|
|
|
print $file "\n# $kind_comment{$kind}\n"
|
2001-06-12 18:16:49 +08:00
|
|
|
if exists $kind_comment{$kind};
|
2001-06-12 18:05:27 +08:00
|
|
|
foreach my $word (sort keys %{$used{$kind}})
|
|
|
|
{
|
2001-11-26 18:51:29 +08:00
|
|
|
# Words that were caught, but not to be checked according to the
|
|
|
|
# autoscan library files.
|
2001-06-25 14:15:07 +08:00
|
|
|
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
|
|
|
{
|
2002-09-27 15:35:39 +08:00
|
|
|
if ($macro =~ /^warn:\s+(.*)/)
|
|
|
|
{
|
|
|
|
my $message = $1;
|
|
|
|
foreach my $location (@{$used{$kind}{$word}})
|
|
|
|
{
|
|
|
|
warn "$location: warning: $message\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (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})
|
|
|
|
{
|
2001-07-14 22:19:19 +08:00
|
|
|
print $file "$macro\n";
|
2001-06-25 14:15:07 +08:00
|
|
|
$printed{$macro} = 1;
|
|
|
|
}
|
|
|
|
push (@{$needed_macros{$macro}},
|
|
|
|
@{$used{$kind}{$word}});
|
2001-06-12 18:05:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-07-14 22:19:19 +08:00
|
|
|
print $file "$generic_macro{$kind}([" . join(' ', sort(@have)) . "])\n"
|
2001-06-12 18:05:27 +08:00
|
|
|
if @have;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-14 22:19:19 +08:00
|
|
|
# output_libraries ($FILE)
|
|
|
|
# ------------------------
|
|
|
|
sub output_libraries ($)
|
2001-01-23 03:01:23 +08:00
|
|
|
{
|
2001-07-14 22:19:19 +08:00
|
|
|
my ($file) = @_;
|
|
|
|
|
|
|
|
print $file "\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
|
|
|
{
|
2001-07-14 22:19:19 +08:00
|
|
|
print $file "# FIXME: Replace `main' with a function in `-l$word':\n";
|
|
|
|
print $file "AC_CHECK_LIB([$word], [main])\n";
|
2001-01-23 03:04:47 +08:00
|
|
|
}
|
1994-04-30 09:42:39 +08:00
|
|
|
}
|
|
|
|
|
2001-01-29 17:24:13 +08:00
|
|
|
|
2001-09-05 15:06:02 +08:00
|
|
|
# output ($CONFIGURE_SCAN)
|
|
|
|
# ------------------------
|
2001-01-29 17:24:13 +08:00
|
|
|
# Print a proto configure.ac.
|
|
|
|
sub output ($)
|
|
|
|
{
|
|
|
|
my $configure_scan = shift;
|
|
|
|
my %unique_makefiles;
|
|
|
|
|
2001-09-05 15:06:40 +08:00
|
|
|
my $file = new Autom4te::XFile ">$configure_scan";
|
2001-01-29 17:24:13 +08:00
|
|
|
|
2001-11-26 18:51:29 +08:00
|
|
|
print $file
|
|
|
|
("# Process this file with autoconf to produce a configure script.\n"
|
|
|
|
. "AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)\n");
|
2001-01-29 17:24:13 +08:00
|
|
|
if (defined $cfiles[0])
|
|
|
|
{
|
2001-07-14 22:19:19 +08:00
|
|
|
print $file "AC_CONFIG_SRCDIR([$cfiles[0]])\n";
|
|
|
|
print $file "AC_CONFIG_HEADER([config.h])\n";
|
2001-01-29 17:24:13 +08:00
|
|
|
}
|
|
|
|
|
2001-07-14 22:19:19 +08:00
|
|
|
output_kind ($file, 'programs');
|
|
|
|
output_kind ($file, 'makevars');
|
|
|
|
output_libraries ($file);
|
|
|
|
output_kind ($file, 'headers');
|
|
|
|
output_kind ($file, 'identifiers');
|
|
|
|
output_kind ($file, '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
|
|
|
}
|
2001-07-14 22:19:19 +08:00
|
|
|
print $file "\nAC_CONFIG_FILES([",
|
2001-06-25 14:15:07 +08:00
|
|
|
join ("\n ", sort keys %unique_makefiles), "])\n";
|
2001-07-14 22:19:19 +08:00
|
|
|
print $file "AC_OUTPUT\n";
|
2001-01-29 17:24:13 +08:00
|
|
|
|
2001-09-05 15:06:40 +08:00
|
|
|
$file->close;
|
2001-01-29 17:24:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-03 22:11:06 +08:00
|
|
|
|
|
|
|
## --------------------------------------- ##
|
|
|
|
## Checking the accuracy of configure.ac. ##
|
|
|
|
## --------------------------------------- ##
|
|
|
|
|
|
|
|
|
2001-09-05 15:06:40 +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-07-14 22:19:19 +08:00
|
|
|
my ($configure_ac) = @_;
|
2001-01-23 03:01:23 +08:00
|
|
|
|
2001-07-14 22:19:19 +08:00
|
|
|
# Find what needed macros are invoked in CONFIGURE_AC.
|
2001-08-01 23:02:36 +08:00
|
|
|
# I'd be very happy if someone could explain to me why sort (uniq ...)
|
|
|
|
# doesn't work properly: I need `uniq (sort ...)'. --akim
|
|
|
|
my $trace_option =
|
2001-11-26 18:51:29 +08:00
|
|
|
join (' --trace=', '',
|
2001-08-01 23:02:36 +08:00
|
|
|
uniq (sort (map { s/\(.*//; $_ } keys %needed_macros)));
|
2001-01-23 03:01:23 +08:00
|
|
|
|
2001-09-05 15:06:02 +08:00
|
|
|
verbose "running: $autoconf $trace_option $configure_ac";
|
2001-07-14 22:19:19 +08:00
|
|
|
my $traces =
|
2001-09-05 15:06:40 +08:00
|
|
|
new Autom4te::XFile "$autoconf $trace_option $configure_ac|";
|
2001-01-23 03:01:23 +08:00
|
|
|
|
2001-07-14 22:19:19 +08:00
|
|
|
while ($_ = $traces->getline)
|
2001-01-23 03:01:23 +08:00
|
|
|
{
|
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;
|
|
|
|
}
|
2001-09-05 15:06:40 +08:00
|
|
|
delete $needed_macros{"$macro([$word])"};
|
2001-01-24 15:58:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-09-05 15:06:40 +08:00
|
|
|
delete $needed_macros{$macro};
|
2001-01-24 15:58:16 +08:00
|
|
|
}
|
2001-01-23 03:01:23 +08:00
|
|
|
}
|
|
|
|
|
2001-09-05 15:06:40 +08:00
|
|
|
$traces->close;
|
2001-01-23 03:04:47 +08:00
|
|
|
|
2001-07-14 22:19:19 +08:00
|
|
|
# Report the missing macros.
|
2001-02-12 01:15:03 +08:00
|
|
|
foreach my $macro (sort keys %needed_macros)
|
2001-01-23 03:01:23 +08:00
|
|
|
{
|
2001-07-14 22:19:19 +08:00
|
|
|
warn ("$configure_ac: warning: missing $macro wanted by: "
|
|
|
|
. (${$needed_macros{$macro}}[0])
|
|
|
|
. "\n");
|
|
|
|
print $log "$me: warning: missing $macro wanted by: \n";
|
2001-02-20 17:24:40 +08:00
|
|
|
foreach my $need (@{$needed_macros{$macro}})
|
|
|
|
{
|
2001-07-14 22:19:19 +08:00
|
|
|
print $log "\t$need\n";
|
2001-02-20 17:24:40 +08:00
|
|
|
}
|
2001-01-23 03:01:23 +08:00
|
|
|
}
|
|
|
|
}
|
2001-01-29 17:24:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
## -------------- ##
|
|
|
|
## Main program. ##
|
|
|
|
## -------------- ##
|
|
|
|
|
2001-07-03 22:10:41 +08:00
|
|
|
parse_args;
|
2001-09-05 15:06:02 +08:00
|
|
|
$autoconf .= " --debug" if $debug;
|
|
|
|
$autoconf .= " --verbose" if $verbose;
|
|
|
|
$autoconf .= join (' --include=', '', @include);
|
2002-07-17 16:30:42 +08:00
|
|
|
$autoconf .= join (' --prepend-include=', '', @prepend_include);
|
2001-09-05 15:06:02 +08:00
|
|
|
|
2001-02-21 16:47:16 +08:00
|
|
|
my $configure_ac = find_configure_ac;
|
2001-01-29 17:24:13 +08:00
|
|
|
init_tables;
|
|
|
|
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
|
|
|
}
|
2001-11-26 18:52:46 +08:00
|
|
|
# This close is really needed. For some reason, probably best named
|
|
|
|
# a bug, it seems that the dtor of $LOG is not called automatically
|
|
|
|
# at END. It results in a truncated file.
|
2001-09-05 15:06:40 +08:00
|
|
|
$log->close;
|
2001-01-29 17:24:13 +08:00
|
|
|
exit 0;
|