Improve VLA wording in NEWS
[autoconf.git] / tests / mktests.pl
blob573ae5aea1f0270ac1b29ef2bb68f8810c9fb7e4
1 #! /usr/bin/perl
3 # Build some of the Autoconf test files.
5 # Copyright (C) 2000-2017, 2020-2024 Free Software Foundation, Inc.
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.
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.
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/>.
20 use 5.006;
21 use strict;
22 use warnings FATAL => 'all';
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_/,
33 # Used in many places.
34 qr/^AC_.*_IFELSE$/,
35 qr/^AC_LANG/,
36 qr/^AC_RUN_LOG$/,
37 qr/^AC_TRY/,
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$/,
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$/,
53 # Fail when the source does not exist.
54 qr/^AC_CONFIG/,
56 # AU defined to nothing.
57 qr/^AC_(CYGWIN|CYGWIN32|EMXOS2|MING32|EXEEXT|OBJEXT)$/,
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?$/,
65 # Is a number.
66 qr/^AC_FD_CC$/,
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)$/,
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$/,
76 # Obsolete, checked in semantics.
77 qr/^AC_FUNC_WAIT3$/,
78 qr/^AC_FUNC_SETVBUF_REVERSED$/,
79 qr/^AC_SYS_RESTARTABLE_SYSCALLS$/,
81 # Not intended to be invoked at the top level.
82 qr/^AC_INCLUDES_DEFAULT$/,
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/,
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)?)$/,
93 # Use without an argument is obsolete.
94 # Checked in semantics.
95 qr/^AC_PROG_LEX$/,
97 # Requires a working C++ compiler, which is not a given.
98 qr/^AC_PROG_CXX_C_O$/,
100 # Already tested by AT_CHECK_MACRO.
101 qr/^AC_OUTPUT$/,
103 # Tested alongside m4_divert_text.
104 qr/^AC_PRESERVE_HELP_ORDER$/,
106 # Tested in erlang.at.
107 qr/^AC_ERLANG_SUBST_(INSTALL_LIB_SUBDIR|ROOT_DIR)$/,
108 qr/^AC_ERLANG_CHECK_LIB$/,
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))$/,
118 # Use AC_REQUIRE.
119 qr/^AC_(CYGWIN|MINGW32|EMXOS2)$/,
121 # Already in configure.ac.
122 qr/^AC_(INIT|OUTPUT)$/,
124 # AC_LANG_SAVE needs user interaction to be removed.
125 # AC_LANG_RESTORE cannot be used alone.
126 qr/^AC_LANG_(SAVE|RESTORE)$/,
128 # Need arguments. Tested in tools.at.
129 qr/^AC_(DIAGNOSE|FATAL|OBSOLETE|WARNING)$/,
130 qr/^AC_(FOREACH|LINK_FILES|PREREQ)$/,
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)$/,
137 # Not macros, just mapping from old variable name to a new one.
138 qr/^ac_cv_prog_(gcc|gxx|g77)$/,
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.)
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]' },
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]')
178 AC_C_TYPEOF => {
179 test_parameters => ('[cxx_define_varies:typeof' .
180 ' cxx_define_varies:HAVE_TYPEOF' .
181 ' cxx_cv_varies:cxx_typeof]')
183 AC_C__GENERIC => {
184 test_parameters => ('[cxx_define_varies:HAVE_C__GENERIC' .
185 ' cxx_cv_varies:cxx__Generic]')
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]')
193 # stdbool.h is supposed to be includable from C++, per C++2011
194 # [support.runtime], but the type _Bool was not added to the C++
195 # standard, so it may or may not be present depending on how much
196 # the C++ compiler cares about C source compatibility.
197 AC_CHECK_HEADER_STDBOOL => {
198 test_parameters => ('[cxx_define_varies:HAVE__BOOL' .
199 ' cxx_cv_varies:type__Bool]')
201 AC_HEADER_STDBOOL => {
202 test_parameters => ('[cxx_define_varies:HAVE__BOOL' .
203 ' cxx_cv_varies:type__Bool]')
206 # G++ forces -D_GNU_SOURCE which, with some versions of GNU libc,
207 # changes the declaration of strerror_r. Blech.
208 AC_FUNC_STRERROR_R => {
209 test_parameters => ('[cxx_define_varies:STRERROR_R_CHAR_P' .
210 ' cxx_cv_varies:func_strerror_r_char_p]')
214 # skip_macro MACRO, EXCLUDE-LIST
215 # ------------------------------
216 # Returns truthy if any of the regexes in EXCLUDE-LIST match MACRO.
217 sub skip_macro
219 my $macro = shift;
220 for my $pat (@_)
222 return 1 if $macro =~ $pat;
224 return 0;
228 # emit_test FH, TEST-MACRO, MACRO
229 # --------------------------------
230 # Emit code to FH to test MACRO using TEST-MACRO.
231 # TEST-MACRO is expected to be either AT_CHECK_MACRO or AT_CHECK_AU_MACRO;
232 # see local.at.
233 sub emit_test
235 my ($fh, $test_macro, $macro) = @_;
236 my $params = $test_parameters{$macro} || {};
237 my $macro_use = ${$params}{macro_use} || '';
238 my $additional_commands = ${$params}{additional_commands} || '';
239 my $autoconf_flags = ${$params}{autoconf_flags} || '';
240 my $test_parameters = ${$params}{test_parameters} || '';
242 $autoconf_flags = '[]'
243 if $autoconf_flags eq '' && $test_parameters ne '';
244 $additional_commands = '[]'
245 if $additional_commands eq '' && $autoconf_flags ne '';
246 $macro_use = '[]'
247 if $macro_use eq '' && $additional_commands ne '';
249 print $fh "$test_macro([$macro]";
250 print $fh ", $autoconf_flags" if $autoconf_flags ne '';
251 print $fh ", $additional_commands" if $additional_commands ne '';
252 print $fh ", $autoconf_flags" if $autoconf_flags ne '';
253 print $fh ", $test_parameters" if $test_parameters ne '';
254 print $fh ")\n";
257 # scan_m4_files
258 # -------------
259 # Scan all of the Autoconf source files and produce lists of macros
260 # to be tested
261 sub scan_m4_files
263 my @macros_to_test;
264 my %required_macros;
266 for my $file (@_)
268 open my $fh, "<", $file
269 or die "$file: $!\n";
271 my (@ac_macros, @au_macros);
272 while (<$fh>)
274 chomp;
275 s/\bdnl\b.*$//;
276 if (/\bAC_REQUIRE\(\[*([a-zA-Z0-9_]+)/)
278 $required_macros{$1} = 1;
280 elsif (/^AC_DEFUN(?:_ONCE)?\(\[*([a-zA-Z0-9_]+)/)
282 push @ac_macros, $1
283 unless skip_macro $1, @ac_exclude_list;
285 elsif (/^AU_DEFUN?\(\[*([a-zA-Z0-9_]+)/)
287 push @au_macros, $1
288 unless skip_macro $1, @au_exclude_list;
291 push @macros_to_test, [ $file, \@ac_macros, \@au_macros ];
294 # Do **NOT** filter out AC_FUNC_ALLOCA. Filtering it out
295 # ended up eliding a direct test of AC_FUNC_ALLOCA which
296 # would have exposed a bug, while no required use does so.
297 # Clearing this hash entirely would currently enable direct tests
298 # of 38 macros, but would require designating each that must be
299 # skipped when cross-compiling.
300 delete $required_macros{AC_FUNC_ALLOCA};
302 # Filter out macros that are AC_REQUIREd by some other macro;
303 # it's not necessary to test them directly.
304 my @pruned_macros_to_test;
305 for my $elt (@macros_to_test)
307 my ($file, $ac_macros, $au_macros) = @$elt;
308 my (@pruned_ac_macros, @pruned_au_macros);
310 for my $macro (@$ac_macros)
312 push @pruned_ac_macros, $macro
313 unless defined $required_macros{$macro};
315 for my $macro (@$au_macros)
317 push @pruned_au_macros, $macro
318 unless defined $required_macros{$macro};
321 push @pruned_macros_to_test, [
322 $file, \@pruned_ac_macros, \@pruned_au_macros
326 return @pruned_macros_to_test;
330 # make_read_only FILE
331 # -------------------
332 # Make FILE read-only on disk. Also clears the execute and special bits.
333 sub make_read_only
335 my $f = shift;
336 my $mode = (stat $f)[2];
337 die "stat($f): $!\n" unless defined $mode;
338 # clear all the bits in $mode except r--r--r--
339 $mode &= 00444;
340 chmod $mode, $f or die "making $f read-only: $!\n";
344 # create_test_files OUTDIR, M4-FILES...
345 # -----------------
346 # Main loop: for each file listed in M4-FILES, generate an .at file
347 # named "ac${file}.at" that does cursory tests on each of the macros
348 # defined in $file.
349 sub create_test_files
351 my $outdir = shift;
352 if (@_ == 0)
354 print STDERR "usage: $0 outdir m4-files...\n";
355 exit 1;
358 for my $elt (scan_m4_files @_)
360 my ($file, $ac_macros, $au_macros) = @$elt;
362 my $base = $file;
363 $base =~ s|^.*/([^/.]+)(?:.[^/]*)?$|$1|;
365 my $tmpout = "${outdir}/ac${base}.tat";
366 my $out = "${outdir}/ac${base}.at";
368 open my $fh, ">", $tmpout
369 or die "$tmpout: $!\n";
371 print $fh <<"EOF";
372 # -*- autotest -*-
373 # Generated by $0 from $file.
374 # Do not edit this file by hand.
378 if (@$ac_macros || @$au_macros)
380 print $fh "AT_BANNER([Testing autoconf/$base macros.])\n";
382 if (@$ac_macros)
384 print $fh "\n# Modern macros.\n";
385 emit_test ($fh, 'AT_CHECK_MACRO', $_)
386 for sort @$ac_macros;
388 if (@$au_macros)
390 print $fh "\n# Obsolete macros.\n";
391 emit_test ($fh, 'AT_CHECK_AU_MACRO', $_)
392 for sort @$au_macros;
395 else
397 print $fh "# Nothing to test.\n";
400 close $fh or die "writing to $tmpout: $!\n";
401 make_read_only $tmpout;
402 rename $tmpout, $out or die "updating $out: $!\n";
406 create_test_files @ARGV;
407 exit 0;
409 ### Setup "GNU" style for perl-mode and cperl-mode.
410 ## Local Variables:
411 ## perl-indent-level: 2
412 ## perl-continued-statement-offset: 2
413 ## perl-continued-brace-offset: 0
414 ## perl-brace-offset: 0
415 ## perl-brace-imaginary-offset: 0
416 ## perl-label-offset: -2
417 ## cperl-indent-level: 2
418 ## cperl-brace-offset: 0
419 ## cperl-continued-brace-offset: 0
420 ## cperl-label-offset: -2
421 ## cperl-extra-newline-before-brace: t
422 ## cperl-merge-trailing-else: nil
423 ## cperl-continued-statement-offset: 2
424 ## End: