| 1 |
#! /usr/bin/perl |
| 2 |
|
| 3 |
# Build some of the Autoconf test files. |
| 4 |
|
| 5 |
# Copyright (C) 2000-2017, 2020-2026 Free Software Foundation, Inc. |
| 6 |
|
| 7 |
# This program is free software: you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation, either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
|
| 12 |
# This program is distributed in the hope that it will be useful, |
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
|
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
use 5.006; |
| 21 |
use strict; |
| 22 |
use warnings FATAL => 'all'; |
| 23 |
|
| 24 |
# ac_exclude_list |
| 25 |
# --------------- |
| 26 |
# Check all AC_DEFUN'ed macros with AT_CHECK_MACRO, except these. |
| 27 |
# Not every macro can be run without arguments, and some are already |
| 28 |
# tested elsewhere. |
| 29 |
my @ac_exclude_list = ( |
| 30 |
# Internal macros should not be invoked directly from a configure.ac. |
| 31 |
qr/^_?_AC_/, |
| 32 |
|
| 33 |
# Used in many places. |
| 34 |
qr/^AC_.*_IFELSE$/, |
| 35 |
qr/^AC_LANG/, |
| 36 |
qr/^AC_RUN_LOG$/, |
| 37 |
qr/^AC_TRY/, |
| 38 |
|
| 39 |
# Need an argument. |
| 40 |
qr/^AC_(CANONICALIZE|PREFIX_PROGRAM|PREREQ)$/, |
| 41 |
qr/^AC_(SEARCH_LIBS|REPLACE_FUNCS)$/, |
| 42 |
qr/^AC_(CACHE_CHECK|COMPUTE)_INT$/, |
| 43 |
qr/^AC_ARG_VAR$/, |
| 44 |
qr/^AC_REQUIRE_SHELL_FN$/, |
| 45 |
|
| 46 |
# Performed in the semantics tests. |
| 47 |
qr/^AC_CHECK_( |
| 48 |
ALIGNOF|DECL|FILE|FUNC|HEADER|LIB|MEMBER |
| 49 |
|PROG|SIZEOF|(TARGET_)?TOOL|TYPE |
| 50 |
)S?$/x, |
| 51 |
qr/^AC_PATH_PROGS_FEATURE_CHECK$/, |
| 52 |
|
| 53 |
# Fail when the source does not exist. |
| 54 |
qr/^AC_CONFIG/, |
| 55 |
|
| 56 |
# AU defined to nothing. |
| 57 |
qr/^AC_(CYGWIN|CYGWIN32|EMXOS2|MING32|EXEEXT|OBJEXT)$/, |
| 58 |
|
| 59 |
# Produce "= val" because $1, the variable used to store the result, |
| 60 |
# is empty. |
| 61 |
qr/^AC_(F77|FC)_FUNC$/, |
| 62 |
qr/^AC_FC_(PP_)?SRCEXT$/, |
| 63 |
qr/^AC_PATH_((TARGET_)?TOOL|PROG)S?$/, |
| 64 |
|
| 65 |
# Is a number. |
| 66 |
qr/^AC_FD_CC$/, |
| 67 |
|
| 68 |
# Obsolete, but needs to be AC_DEFUNed and cannot safely be called |
| 69 |
# without arguments. Tested in tools.at. |
| 70 |
qr/^AC_(DIAGNOSE|FATAL|FOREACH|OBSOLETE|WARNING)$/, |
| 71 |
|
| 72 |
# Require a file that is not shipped with Autoconf. But it should. |
| 73 |
qr/^AC_FUNC_(GETLOADAVG|FNMATCH_GNU)$/, |
| 74 |
qr/^AC_REPLACE_FNMATCH$/, |
| 75 |
|
| 76 |
# Obsolete, checked in semantics. |
| 77 |
qr/^AC_FUNC_WAIT3$/, |
| 78 |
qr/^AC_FUNC_SETVBUF_REVERSED$/, |
| 79 |
qr/^AC_SYS_RESTARTABLE_SYSCALLS$/, |
| 80 |
|
| 81 |
# Not intended to be invoked at the top level. |
| 82 |
qr/^AC_INCLUDES_DEFAULT$/, |
| 83 |
|
| 84 |
# AC_INIT includes all the AC_INIT macros. |
| 85 |
# There is an infinite m4 recursion if AC_INIT is used twice. |
| 86 |
qr/^AC_INIT/, |
| 87 |
|
| 88 |
# Checked in semantics. |
| 89 |
qr/^AC_(PROG_CC|C_CONST|C_VOLATILE)$/, |
| 90 |
qr/^AC_PATH_XTRA$/, |
| 91 |
qr/^AC_SYS_(LARGEFILE|YEAR2038(_RECOMMENDED)?)$/, |
| 92 |
|
| 93 |
# Use without an argument is obsolete. |
| 94 |
# Checked in semantics. |
| 95 |
qr/^AC_PROG_LEX$/, |
| 96 |
|
| 97 |
# Requires a working C++ compiler, which is not a given. |
| 98 |
qr/^AC_PROG_CXX_C_O$/, |
| 99 |
|
| 100 |
# Already tested by AT_CHECK_MACRO. |
| 101 |
qr/^AC_OUTPUT$/, |
| 102 |
|
| 103 |
# Tested alongside m4_divert_text. |
| 104 |
qr/^AC_PRESERVE_HELP_ORDER$/, |
| 105 |
|
| 106 |
# Tested in erlang.at. |
| 107 |
qr/^AC_ERLANG_SUBST_(INSTALL_LIB_SUBDIR|ROOT_DIR)$/, |
| 108 |
qr/^AC_ERLANG_CHECK_LIB$/, |
| 109 |
); |
| 110 |
|
| 111 |
# au_exclude_list |
| 112 |
# --------------- |
| 113 |
# Check all AU_DEFUN'ed macros with AT_CHECK_AU_MACRO, except these. |
| 114 |
my @au_exclude_list = ( |
| 115 |
# Empty. |
| 116 |
qr/^AC_(C_CROSS|PROG_(CC_(C[89]9|STDC)|GCC_TRADITIONAL))$/, |
| 117 |
|
| 118 |
# Use AC_REQUIRE. |
| 119 |
qr/^AC_(CYGWIN|MINGW32|EMXOS2)$/, |
| 120 |
|
| 121 |
# Already in configure.ac. |
| 122 |
qr/^AC_(INIT|OUTPUT)$/, |
| 123 |
|
| 124 |
# AC_LANG_SAVE needs user interaction to be removed. |
| 125 |
# AC_LANG_RESTORE cannot be used alone. |
| 126 |
qr/^AC_LANG_(SAVE|RESTORE)$/, |
| 127 |
|
| 128 |
# Need arguments. Tested in tools.at. |
| 129 |
qr/^AC_(DIAGNOSE|FATAL|OBSOLETE|WARNING)$/, |
| 130 |
qr/^AC_(FOREACH|LINK_FILES|PREREQ)$/, |
| 131 |
|
| 132 |
# Need arguments. Tested in semantics.at. |
| 133 |
qr/^AC_HAVE_LIBRARY$/, |
| 134 |
qr/^AC_COMPILE_CHECK$/, |
| 135 |
qr/^AC_TRY_(COMPILE|CPP|LINK|RUN)$/, |
| 136 |
|
| 137 |
# Not macros, just mapping from old variable name to a new one. |
| 138 |
qr/^ac_cv_prog_(gcc|gxx|g77)$/, |
| 139 |
); |
| 140 |
|
| 141 |
|
| 142 |
# test_parameters |
| 143 |
# --------------- |
| 144 |
# Extra arguments to pass to the test macro for particular macros. |
| 145 |
# Keys are macro names, values are records containing one or more |
| 146 |
# of the possible optional arguments to AT_CHECK_(AU_)MACRO: |
| 147 |
# macro_use, additional_commands, autoconf_flags, test_parameters => '...'. |
| 148 |
# Entries in this hash are grouped by common situations, and sorted |
| 149 |
# alphabetically within each group. |
| 150 |
# Note that you must provide M4 quotation; emit_test will not quote |
| 151 |
# the arguments for you. (This is so you can _not_ quote the arguments |
| 152 |
# when that's useful.) |
| 153 |
|
| 154 |
my %test_parameters = ( |
| 155 |
# Uses AC_RUN_IFELSE, cross-compilation test fails. |
| 156 |
AC_FC_CHECK_BOUNDS => { test_parameters => '[no-cross]' }, |
| 157 |
AC_FUNC_CHOWN => { test_parameters => '[no-cross]' }, |
| 158 |
AC_FUNC_FNMATCH => { test_parameters => '[no-cross]' }, |
| 159 |
AC_FUNC_FORK => { test_parameters => '[no-cross]' }, |
| 160 |
AC_FUNC_GETGROUPS => { test_parameters => '[no-cross]' }, |
| 161 |
AC_FUNC_LSTAT => { test_parameters => '[no-cross]' }, |
| 162 |
AC_FUNC_MALLOC => { test_parameters => '[no-cross]' }, |
| 163 |
AC_FUNC_MEMCMP => { test_parameters => '[no-cross]' }, |
| 164 |
AC_FUNC_MKTIME => { test_parameters => '[no-cross]' }, |
| 165 |
AC_FUNC_MMAP => { test_parameters => '[no-cross]' }, |
| 166 |
AC_FUNC_REALLOC => { test_parameters => '[no-cross]' }, |
| 167 |
AC_FUNC_STAT => { test_parameters => '[no-cross]' }, |
| 168 |
AC_FUNC_STRCOLL => { test_parameters => '[no-cross]' }, |
| 169 |
AC_FUNC_STRNLEN => { test_parameters => '[no-cross]' }, |
| 170 |
AC_FUNC_STRTOD => { test_parameters => '[no-cross]' }, |
| 171 |
|
| 172 |
# Different result with a C++ compiler than a C compiler: |
| 173 |
# C++ compilers may or may not support these features from C1999 and later. |
| 174 |
AC_C_RESTRICT => { |
| 175 |
test_parameters => ('[cxx_define_varies:restrict' . |
| 176 |
' cxx_cv_varies:cxx_restrict]') |
| 177 |
}, |
| 178 |
AC_C_TYPEOF => { |
| 179 |
test_parameters => ('[cxx_define_varies:typeof' . |
| 180 |
' cxx_define_varies:HAVE_TYPEOF' . |
| 181 |
' cxx_cv_varies:cxx_typeof]') |
| 182 |
}, |
| 183 |
AC_C__GENERIC => { |
| 184 |
test_parameters => ('[cxx_define_varies:HAVE_C__GENERIC' . |
| 185 |
' cxx_cv_varies:cxx__Generic]') |
| 186 |
}, |
| 187 |
AC_C_VARARRAYS => { |
| 188 |
test_parameters => ('[cxx_define_varies:HAVE_C_VARARRAYS' . |
| 189 |
' cxx_define_varies:__STDC_NO_VLA__' . |
| 190 |
' cxx_cv_varies:cxx_vararrays]') |
| 191 |
}, |
| 192 |
AC_C_FLEXIBLE_ARRAY_MEMBER => { |
| 193 |
test_parameters => ('[cxx_define_varies:FLEXIBLE_ARRAY_MEMBER' . |
| 194 |
' cxx_cv_varies:cxx_flexmember]') |
| 195 |
}, |
| 196 |
|
| 197 |
# stdbool.h is supposed to be includable from C++, per C++2011 |
| 198 |
# [support.runtime], but the type _Bool was not added to the C++ |
| 199 |
# standard, so it may or may not be present depending on how much |
| 200 |
# the C++ compiler cares about C source compatibility. |
| 201 |
AC_CHECK_HEADER_STDBOOL => { |
| 202 |
test_parameters => ('[cxx_define_varies:HAVE__BOOL' . |
| 203 |
' cxx_cv_varies:type__Bool]') |
| 204 |
}, |
| 205 |
AC_HEADER_STDBOOL => { |
| 206 |
test_parameters => ('[cxx_define_varies:HAVE__BOOL' . |
| 207 |
' cxx_cv_varies:type__Bool]') |
| 208 |
}, |
| 209 |
|
| 210 |
# G++ forces -D_GNU_SOURCE which, with some versions of GNU libc, |
| 211 |
# changes the declaration of strerror_r. Blech. |
| 212 |
AC_FUNC_STRERROR_R => { |
| 213 |
test_parameters => ('[cxx_define_varies:STRERROR_R_CHAR_P' . |
| 214 |
' cxx_cv_varies:func_strerror_r_char_p]') |
| 215 |
}, |
| 216 |
); |
| 217 |
|
| 218 |
# skip_macro MACRO, EXCLUDE-LIST |
| 219 |
# ------------------------------ |
| 220 |
# Returns truthy if any of the regexes in EXCLUDE-LIST match MACRO. |
| 221 |
sub skip_macro |
| 222 |
{ |
| 223 |
my $macro = shift; |
| 224 |
for my $pat (@_) |
| 225 |
{ |
| 226 |
return 1 if $macro =~ $pat; |
| 227 |
} |
| 228 |
return 0; |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
# emit_test FH, TEST-MACRO, MACRO |
| 233 |
# -------------------------------- |
| 234 |
# Emit code to FH to test MACRO using TEST-MACRO. |
| 235 |
# TEST-MACRO is expected to be either AT_CHECK_MACRO or AT_CHECK_AU_MACRO; |
| 236 |
# see local.at. |
| 237 |
sub emit_test |
| 238 |
{ |
| 239 |
my ($fh, $test_macro, $macro) = @_; |
| 240 |
my $params = $test_parameters{$macro} || {}; |
| 241 |
my $macro_use = ${$params}{macro_use} || ''; |
| 242 |
my $additional_commands = ${$params}{additional_commands} || ''; |
| 243 |
my $autoconf_flags = ${$params}{autoconf_flags} || ''; |
| 244 |
my $test_parameters = ${$params}{test_parameters} || ''; |
| 245 |
|
| 246 |
$autoconf_flags = '[]' |
| 247 |
if $autoconf_flags eq '' && $test_parameters ne ''; |
| 248 |
$additional_commands = '[]' |
| 249 |
if $additional_commands eq '' && $autoconf_flags ne ''; |
| 250 |
$macro_use = '[]' |
| 251 |
if $macro_use eq '' && $additional_commands ne ''; |
| 252 |
|
| 253 |
print $fh "$test_macro([$macro]"; |
| 254 |
print $fh ", $autoconf_flags" if $autoconf_flags ne ''; |
| 255 |
print $fh ", $additional_commands" if $additional_commands ne ''; |
| 256 |
print $fh ", $autoconf_flags" if $autoconf_flags ne ''; |
| 257 |
print $fh ", $test_parameters" if $test_parameters ne ''; |
| 258 |
print $fh ")\n"; |
| 259 |
} |
| 260 |
|
| 261 |
# scan_m4_files |
| 262 |
# ------------- |
| 263 |
# Scan all of the Autoconf source files and produce lists of macros |
| 264 |
# to be tested |
| 265 |
sub scan_m4_files |
| 266 |
{ |
| 267 |
my @macros_to_test; |
| 268 |
my %required_macros; |
| 269 |
|
| 270 |
for my $file (@_) |
| 271 |
{ |
| 272 |
open my $fh, "<", $file |
| 273 |
or die "$file: $!\n"; |
| 274 |
|
| 275 |
my (@ac_macros, @au_macros); |
| 276 |
while (<$fh>) |
| 277 |
{ |
| 278 |
chomp; |
| 279 |
s/\bdnl\b.*$//; |
| 280 |
if (/\bAC_REQUIRE\(\[*([a-zA-Z0-9_]+)/) |
| 281 |
{ |
| 282 |
$required_macros{$1} = 1; |
| 283 |
} |
| 284 |
elsif (/^AC_DEFUN(?:_ONCE)?\(\[*([a-zA-Z0-9_]+)/) |
| 285 |
{ |
| 286 |
push @ac_macros, $1 |
| 287 |
unless skip_macro $1, @ac_exclude_list; |
| 288 |
} |
| 289 |
elsif (/^AU_DEFUN?\(\[*([a-zA-Z0-9_]+)/) |
| 290 |
{ |
| 291 |
push @au_macros, $1 |
| 292 |
unless skip_macro $1, @au_exclude_list; |
| 293 |
} |
| 294 |
} |
| 295 |
push @macros_to_test, [ $file, \@ac_macros, \@au_macros ]; |
| 296 |
} |
| 297 |
|
| 298 |
# Do **NOT** filter out AC_FUNC_ALLOCA. Filtering it out |
| 299 |
# ended up eliding a direct test of AC_FUNC_ALLOCA which |
| 300 |
# would have exposed a bug, while no required use does so. |
| 301 |
# Clearing this hash entirely would currently enable direct tests |
| 302 |
# of 38 macros, but would require designating each that must be |
| 303 |
# skipped when cross-compiling. |
| 304 |
delete $required_macros{AC_FUNC_ALLOCA}; |
| 305 |
|
| 306 |
# Filter out macros that are AC_REQUIREd by some other macro; |
| 307 |
# it's not necessary to test them directly. |
| 308 |
my @pruned_macros_to_test; |
| 309 |
for my $elt (@macros_to_test) |
| 310 |
{ |
| 311 |
my ($file, $ac_macros, $au_macros) = @$elt; |
| 312 |
my (@pruned_ac_macros, @pruned_au_macros); |
| 313 |
|
| 314 |
for my $macro (@$ac_macros) |
| 315 |
{ |
| 316 |
push @pruned_ac_macros, $macro |
| 317 |
unless defined $required_macros{$macro}; |
| 318 |
} |
| 319 |
for my $macro (@$au_macros) |
| 320 |
{ |
| 321 |
push @pruned_au_macros, $macro |
| 322 |
unless defined $required_macros{$macro}; |
| 323 |
} |
| 324 |
|
| 325 |
push @pruned_macros_to_test, [ |
| 326 |
$file, \@pruned_ac_macros, \@pruned_au_macros |
| 327 |
]; |
| 328 |
} |
| 329 |
|
| 330 |
return @pruned_macros_to_test; |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
# make_read_only FILE |
| 335 |
# ------------------- |
| 336 |
# Make FILE read-only on disk. Also clears the execute and special bits. |
| 337 |
sub make_read_only |
| 338 |
{ |
| 339 |
my $f = shift; |
| 340 |
my $mode = (stat $f)[2]; |
| 341 |
die "stat($f): $!\n" unless defined $mode; |
| 342 |
# clear all the bits in $mode except r--r--r-- |
| 343 |
$mode &= 00444; |
| 344 |
chmod $mode, $f or die "making $f read-only: $!\n"; |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
# create_test_files OUTDIR, M4-FILES... |
| 349 |
# ----------------- |
| 350 |
# Main loop: for each file listed in M4-FILES, generate an .at file |
| 351 |
# named "ac${file}.at" that does cursory tests on each of the macros |
| 352 |
# defined in $file. |
| 353 |
sub create_test_files |
| 354 |
{ |
| 355 |
my $outdir = shift; |
| 356 |
if (@_ == 0) |
| 357 |
{ |
| 358 |
print STDERR "usage: $0 outdir m4-files...\n"; |
| 359 |
exit 1; |
| 360 |
} |
| 361 |
|
| 362 |
for my $elt (scan_m4_files @_) |
| 363 |
{ |
| 364 |
my ($file, $ac_macros, $au_macros) = @$elt; |
| 365 |
|
| 366 |
my $base = $file; |
| 367 |
$base =~ s|^.*/([^/.]+)(?:.[^/]*)?$|$1|; |
| 368 |
|
| 369 |
my $tmpout = "${outdir}/ac${base}.tat"; |
| 370 |
my $out = "${outdir}/ac${base}.at"; |
| 371 |
|
| 372 |
open my $fh, ">", $tmpout |
| 373 |
or die "$tmpout: $!\n"; |
| 374 |
|
| 375 |
print $fh <<"EOF"; |
| 376 |
# -*- autotest -*- |
| 377 |
# Generated by $0 from $file. |
| 378 |
# Do not edit this file by hand. |
| 379 |
|
| 380 |
EOF |
| 381 |
|
| 382 |
if (@$ac_macros || @$au_macros) |
| 383 |
{ |
| 384 |
print $fh "AT_BANNER([Testing autoconf/$base macros.])\n"; |
| 385 |
|
| 386 |
if (@$ac_macros) |
| 387 |
{ |
| 388 |
print $fh "\n# Modern macros.\n"; |
| 389 |
emit_test ($fh, 'AT_CHECK_MACRO', $_) |
| 390 |
for sort @$ac_macros; |
| 391 |
} |
| 392 |
if (@$au_macros) |
| 393 |
{ |
| 394 |
print $fh "\n# Obsolete macros.\n"; |
| 395 |
emit_test ($fh, 'AT_CHECK_AU_MACRO', $_) |
| 396 |
for sort @$au_macros; |
| 397 |
} |
| 398 |
} |
| 399 |
else |
| 400 |
{ |
| 401 |
print $fh "# Nothing to test.\n"; |
| 402 |
} |
| 403 |
|
| 404 |
close $fh or die "writing to $tmpout: $!\n"; |
| 405 |
make_read_only $tmpout; |
| 406 |
rename $tmpout, $out or die "updating $out: $!\n"; |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
create_test_files @ARGV; |
| 411 |
exit 0; |
| 412 |
|
| 413 |
### Setup "GNU" style for perl-mode and cperl-mode. |
| 414 |
## Local Variables: |
| 415 |
## perl-indent-level: 2 |
| 416 |
## perl-continued-statement-offset: 2 |
| 417 |
## perl-continued-brace-offset: 0 |
| 418 |
## perl-brace-offset: 0 |
| 419 |
## perl-brace-imaginary-offset: 0 |
| 420 |
## perl-label-offset: -2 |
| 421 |
## cperl-indent-level: 2 |
| 422 |
## cperl-brace-offset: 0 |
| 423 |
## cperl-continued-brace-offset: 0 |
| 424 |
## cperl-label-offset: -2 |
| 425 |
## cperl-extra-newline-before-brace: t |
| 426 |
## cperl-merge-trailing-else: nil |
| 427 |
## cperl-continued-statement-offset: 2 |
| 428 |
## End: |