38 |
use vars qw(@cfiles @makefiles @shfiles %printed); |
use vars qw(@cfiles @makefiles @shfiles %printed); |
39 |
|
|
40 |
# The kind of the words we are looking for. |
# The kind of the words we are looking for. |
41 |
my @kinds = qw (functions headers identifiers programs |
my @kinds = qw (function header identifier program |
42 |
makevars libraries); |
makevar librarie); |
43 |
|
|
44 |
# For each kind, the default macro. |
# For each kind, the default macro. |
45 |
my %generic_macro = |
my %generic_macro = |
46 |
( |
( |
47 |
'functions' => 'AC_CHECK_FUNCS', |
'function' => 'AC_CHECK_FUNCS', |
48 |
'headers' => 'AC_CHECK_HEADERS', |
'header' => 'AC_CHECK_HEADERS', |
49 |
'identifiers' => 'AC_CHECK_TYPES', |
'identifier' => 'AC_CHECK_TYPES', |
50 |
'programs' => 'AC_CHECK_PROGS', |
'program' => 'AC_CHECK_PROGS', |
51 |
'libraries' => 'AC_CHECK_LIB' |
'library' => 'AC_CHECK_LIB' |
52 |
); |
); |
53 |
|
|
54 |
my %kind_comment = |
my %kind_comment = |
55 |
( |
( |
56 |
'functions' => 'Checks for library functions.', |
'function' => 'Checks for library functions.', |
57 |
'headers' => 'Checks for header files.', |
'header' => 'Checks for header files.', |
58 |
'identifiers' => 'Checks for typedefs, structures, and compiler characteristics.', |
'identifier' => 'Checks for typedefs, structures, and compiler characteristics.', |
59 |
'programs' => 'Checks for programs.', |
'program' => 'Checks for programs.', |
60 |
); |
); |
61 |
|
|
62 |
# $USED{KIND}{ITEM} is the list of locations where the ITEM (of KIND) was used |
# $USED{KIND}{ITEM} is the list of locations where the ITEM (of KIND) was used |
162 |
# '<kind>: <word> warn: <message>'. |
# '<kind>: <word> warn: <message>'. |
163 |
if (/^(\S+):\s+(\S+)\s+(\S.*)$/) |
if (/^(\S+):\s+(\S+)\s+(\S.*)$/) |
164 |
{ |
{ |
165 |
my ($kind, $word, $macro) = ("$1s", $2, $3); |
my ($kind, $word, $macro) = ($1, $2, $3); |
166 |
error "$file:$.: invalid kind: $_" |
error "$file:$.: invalid kind: $_" |
167 |
unless grep { $_ eq $kind } @kinds; |
unless grep { $_ eq $kind } @kinds; |
168 |
push @{$macro{$kind}{$word}}, $macro; |
push @{$macro{$kind}{$word}}, $macro; |
173 |
} |
} |
174 |
} |
} |
175 |
|
|
176 |
|
if ($debug) |
177 |
|
{ |
178 |
|
foreach my $kind (@kinds) |
179 |
|
{ |
180 |
|
foreach my $word (sort keys %{$macro{$kind}}) |
181 |
|
{ |
182 |
|
print "$kind: $word: @{$macro{$kind}{$word}}\n"; |
183 |
|
} |
184 |
|
} |
185 |
|
|
186 |
|
} |
187 |
} |
} |
188 |
|
|
189 |
|
|
197 |
if ( |
if ( |
198 |
# Check for all the libraries. But `-links' is certainly a |
# Check for all the libraries. But `-links' is certainly a |
199 |
# `find' argument, and `-le', a `test' argument. |
# `find' argument, and `-le', a `test' argument. |
200 |
($kind eq 'libraries' && $word !~ /^(e|inks)$/) |
($kind eq 'library' && $word !~ /^(e|inks)$/) |
201 |
# Other than libraries are to be checked only if listed in |
# Other than libraries are to be checked only if listed in |
202 |
# the Autoscan library files. |
# the Autoscan library files. |
203 |
|| defined $macro{$kind}{$word} |
|| defined $macro{$kind}{$word} |
249 |
{ |
{ |
250 |
if (/^include\s*<([^>]*)>/) |
if (/^include\s*<([^>]*)>/) |
251 |
{ |
{ |
252 |
used ('headers', $1); |
used ('header', $1); |
253 |
} |
} |
254 |
if (s/^(if|ifdef|ifndef|elif)\s+//) |
if (s/^(if|ifdef|ifndef|elif)\s+//) |
255 |
{ |
{ |
256 |
foreach my $word (split (/\W+/)) |
foreach my $word (split (/\W+/)) |
257 |
{ |
{ |
258 |
used ('identifiers', $word) |
used ('identifier', $word) |
259 |
unless $word eq 'defined' || $word !~ /^[a-zA-Z_]/; |
unless $word eq 'defined' || $word !~ /^[a-zA-Z_]/; |
260 |
} |
} |
261 |
} |
} |
271 |
# Maybe we should ignore function definitions (in column 0)? |
# Maybe we should ignore function definitions (in column 0)? |
272 |
while (s/\b([a-zA-Z_]\w*)\s*\(/ /) |
while (s/\b([a-zA-Z_]\w*)\s*\(/ /) |
273 |
{ |
{ |
274 |
used ('functions', $1); |
used ('function', $1); |
275 |
} |
} |
276 |
while (s/\b([a-zA-Z_]\w*)\b/ /) |
while (s/\b([a-zA-Z_]\w*)\b/ /) |
277 |
{ |
{ |
278 |
used ('identifiers', $1); |
used ('identifier', $1); |
279 |
} |
} |
280 |
} |
} |
281 |
|
|
300 |
# Variable assignments. |
# Variable assignments. |
301 |
while (s/\b([a-zA-Z_]\w*)\s*=/ /) |
while (s/\b([a-zA-Z_]\w*)\s*=/ /) |
302 |
{ |
{ |
303 |
used ('makevars', $1); |
used ('makevar', $1); |
304 |
} |
} |
305 |
# Be sure to catch a whole word. For instance `lex$U.$(OBJEXT)' |
# Be sure to catch a whole word. For instance `lex$U.$(OBJEXT)' |
306 |
# is a single token. Otherwise we might believe `lex' is needed. |
# is a single token. Otherwise we might believe `lex' is needed. |
309 |
# Libraries. |
# Libraries. |
310 |
if ($word =~ /^-l([a-zA-Z_]\w*)$/) |
if ($word =~ /^-l([a-zA-Z_]\w*)$/) |
311 |
{ |
{ |
312 |
used ('libraries', $1); |
used ('library', $1); |
313 |
} |
} |
314 |
# Tokens in the code. |
# Tokens in the code. |
315 |
# We allow some additional characters, e.g., `+', since |
# We allow some additional characters, e.g., `+', since |
316 |
# autoscan/programs includes `c++'. |
# autoscan/programs includes `c++'. |
317 |
if ($word =~ /^[a-zA-Z_][\w+]*$/) |
if ($word =~ /^[a-zA-Z_][\w+]*$/) |
318 |
{ |
{ |
319 |
used ('programs', $word); |
used ('program', $word); |
320 |
} |
} |
321 |
} |
} |
322 |
} |
} |
344 |
# Tokens in the code. |
# Tokens in the code. |
345 |
while (s/\b([a-zA-Z_]\w*)\b/ /) |
while (s/\b([a-zA-Z_]\w*)\b/ /) |
346 |
{ |
{ |
347 |
used ('programs', $1); |
used ('program', $1); |
348 |
} |
} |
349 |
} |
} |
350 |
|
|
370 |
|
|
371 |
if (/\.[chlym](\.in)?$/) |
if (/\.[chlym](\.in)?$/) |
372 |
{ |
{ |
373 |
used 'programs', 'cc', $File::Find::name; |
used 'program', 'cc', $File::Find::name; |
374 |
scan_c_file ($_); |
scan_c_file ($_); |
375 |
} |
} |
376 |
elsif (/\.(cc|cpp|cxx|CC|C|hh|hpp|hxx|HH|H|yy|ypp|ll|lpp)(\.in)?$/) |
elsif (/\.(cc|cpp|cxx|CC|C|hh|hpp|hxx|HH|H|yy|ypp|ll|lpp)(\.in)?$/) |
377 |
{ |
{ |
378 |
used 'programs', 'c++', $File::Find::name; |
used 'program', 'c++', $File::Find::name; |
379 |
scan_c_file ($_); |
scan_c_file ($_); |
380 |
} |
} |
381 |
elsif (/^[Mm]akefile(\.in)?$/ || /^GNUmakefile(\.in)?$/) |
elsif (/^[Mm]akefile(\.in)?$/ || /^GNUmakefile(\.in)?$/) |
477 |
my ($file) = @_; |
my ($file) = @_; |
478 |
|
|
479 |
print $file "\n# Checks for libraries.\n"; |
print $file "\n# Checks for libraries.\n"; |
480 |
foreach my $word (sort keys %{$used{'libraries'}}) |
foreach my $word (sort keys %{$used{'library'}}) |
481 |
{ |
{ |
482 |
print $file "# FIXME: Replace `main' with a function in `-l$word':\n"; |
print $file "# FIXME: Replace `main' with a function in `-l$word':\n"; |
483 |
print $file "AC_CHECK_LIB([$word], [main])\n"; |
print $file "AC_CHECK_LIB([$word], [main])\n"; |
504 |
print $file "AC_CONFIG_HEADER([config.h])\n"; |
print $file "AC_CONFIG_HEADER([config.h])\n"; |
505 |
} |
} |
506 |
|
|
507 |
output_kind ($file, 'programs'); |
output_kind ($file, 'program'); |
508 |
output_kind ($file, 'makevars'); |
output_kind ($file, 'makevar'); |
509 |
output_libraries ($file); |
output_libraries ($file); |
510 |
output_kind ($file, 'headers'); |
output_kind ($file, 'header'); |
511 |
output_kind ($file, 'identifiers'); |
output_kind ($file, 'identifier'); |
512 |
output_kind ($file, 'functions'); |
output_kind ($file, 'function'); |
513 |
|
|
514 |
# Change DIR/Makefile.in to DIR/Makefile. |
# Change DIR/Makefile.in to DIR/Makefile. |
515 |
foreach my $m (@makefiles) |
foreach my $m (@makefiles) |