File Coverage

blib/lib/auto/share/dist/Alien-autoconf/bin/autoupdate
Criterion Covered Total %
statement 65 141 46.1
branch 2 40 5.0
condition 11 30 36.6
subroutine 16 17 94.1
pod n/a
total 94 228 41.2


line stmt bran cond sub pod time code
1             #! /usr/local/bin/perl
2             BEGIN {
3 1     1   6964 use strict;
  1         2  
  1         45  
4 1     1   6 use warnings;
  1         1  
  1         62  
5 1     1   6 use File::Spec;
  1         3  
  1         265  
6 1     1   39 my($v,$d) = File::Spec->splitpath(File::Spec->rel2abs(__FILE__));
7 1         19 my @d = File::Spec->splitdir($d);
8 1         6 pop @d for 1..2;
9 1         28 my $dist_dir = File::Spec->catpath($v,File::Spec->catdir(@d), '');
10 1   33     33 $ENV{AUTOM4TE} ||= File::Spec->catfile($dist_dir, 'bin/autom4te');
11 1   33     14 $ENV{autom4te_perllibdir} ||= File::Spec->catdir($dist_dir, 'share/autoconf');
12 1   33     13 $ENV{AC_MACRODIR} ||= File::Spec->catdir($dist_dir, 'share/autoconf');
13 1   33     37 $ENV{AUTOCONF} ||= File::Spec->catfile($dist_dir, 'bin/autoconf');
14 1   33     25 $ENV{AUTOHEADER} ||= File::Spec->catfile($dist_dir, 'bin/autoheader');
15 1 50 33     25 $ENV{AUTOM4TE_CFG} ||= File::Spec->catfile($dist_dir, 'share/autoconf/autom4te.blib.cfg')
      33        
16             if $d[-5] eq 'lib' && $d[-6] eq 'blib';
17 1   33     91 $ENV{trailer_m4} ||= File::Spec->catdir($dist_dir, 'share/autoconf/autoconf/trailer.m4');
18             }
19             # -*- perl -*-
20             # Generated from bin/autoupdate.in; do not edit by hand.
21              
22             # autoupdate - modernize an Autoconf file.
23             # Copyright (C) 1994, 1999-2017, 2020-2023 Free Software Foundation,
24             # Inc.
25              
26             # This program is free software: you can redistribute it and/or modify
27             # it under the terms of the GNU General Public License as published by
28             # the Free Software Foundation, either version 3 of the License, or
29             # (at your option) any later version.
30              
31             # This program is distributed in the hope that it will be useful,
32             # but WITHOUT ANY WARRANTY; without even the implied warranty of
33             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34             # GNU General Public License for more details.
35              
36             # You should have received a copy of the GNU General Public License
37             # along with this program. If not, see .
38              
39             # Originally written by David MacKenzie .
40             # Rewritten by Akim Demaille .
41              
42 1         185591 eval 'case $# in 0) exec /usr/local/bin/perl -S "$0";; *) exec /usr/local/bin/perl -S "$0" "$@";; esac'
43             if 0;
44              
45 1     1   25 use 5.006;
  1         9  
46 1     1   6 use strict;
  1         2  
  1         36  
47 1     1   5 use warnings FATAL => 'all';
  1         2  
  1         130  
48              
49             BEGIN
50             {
51 1   50 1   5 my $pkgdatadir = $ENV{'autom4te_perllibdir'} || '/usr/local/lib/perl5/site_perl/5.42.0/x86_64-linux/auto/share/dist/Alien-autoconf/share/autoconf';
52 1         3 unshift @INC, $pkgdatadir;
53              
54             # Override SHELL. On DJGPP SHELL may not be set to a shell
55             # that can handle redirection and quote arguments correctly,
56             # e.g.: COMMAND.COM. For DJGPP always use the shell that configure
57             # has detected.
58 1 50       38 $ENV{'SHELL'} = '/bin/bash' if ($^O eq 'dos');
59             }
60              
61 1     1   7 use File::Basename;
  1         1  
  1         113  
62              
63 1     1   761 use Autom4te::ChannelDefs;
  1         4  
  1         147  
64 1     1   8 use Autom4te::Channels;
  1         2  
  1         173  
65 1     1   667 use Autom4te::Configure_ac;
  1         5  
  1         111  
66 1     1   627 use Autom4te::FileUtils;
  1         5  
  1         421  
67 1     1   1384 use Autom4te::General;
  1         5  
  1         221  
68 1     1   749 use Autom4te::XFile;
  1         4  
  1         118654  
69              
70             # Lib files.
71 1   50     8 my $autom4te = $ENV{'AUTOM4TE'} || '/usr/local/lib/perl5/site_perl/5.42.0/x86_64-linux/auto/share/dist/Alien-autoconf/bin/autom4te';
72 1         4 my $autoconf = "$autom4te --language=autoconf";
73             # We need to find m4sugar.
74 1         3 my @prepend_include;
75 1         4 my @include = ('/usr/local/lib/perl5/site_perl/5.42.0/x86_64-linux/auto/share/dist/Alien-autoconf/share/autoconf');
76 1         4 my $force = 0;
77             # m4.
78 1   50     9 my $m4 = $ENV{"M4"} || '/usr/local/lib/perl5/site_perl/5.42.0/x86_64-linux/auto/share/dist/Alien-m4/bin/m4';
79              
80              
81             # $HELP
82             # -----
83 1         9 $help = "Usage: $0 [OPTION]... [TEMPLATE-FILE]...
84              
85             Update each TEMPLATE-FILE if given, or 'configure.ac' if present,
86             or else 'configure.in', to the syntax of the current version of
87             Autoconf. The original files are backed up.
88              
89             Operation modes:
90             -h, --help print this help, then exit
91             -V, --version print version number, then exit
92             -v, --verbose verbosely report processing
93             -d, --debug don't remove temporary files
94             -f, --force consider all files obsolete
95              
96             Library directories:
97             -B, --prepend-include=DIR prepend directory DIR to search path
98             -I, --include=DIR append directory DIR to search path
99              
100             Report bugs to .
101              
102             The full documentation for Autoconf can be read via 'info autoconf',
103             or on the Web at .
104             ";
105              
106             # $VERSION
107             # --------
108 1         3 $version = "autoupdate (GNU Autoconf) 2.72
109             Copyright (C) 2023 Free Software Foundation, Inc.
110             License GPLv3+/Autoconf: GNU GPL version 3 or later
111             ,
112             This is free software: you are free to change and redistribute it.
113             There is NO WARRANTY, to the extent permitted by law.
114              
115             Written by David J. MacKenzie and Akim Demaille.
116             ";
117              
118             ## ---------- ##
119             ## Routines. ##
120             ## ---------- ##
121              
122              
123             # parse_args ()
124             # -------------
125             # Process any command line arguments.
126             sub parse_args ()
127             {
128 1     1   3 my $srcdir;
129              
130 1         8 getopt ('I|include=s' => \@include,
131             'B|prepend-include=s' => \@prepend_include,
132             'f|force' => \$force);
133              
134 0 0         if (! @ARGV)
135             {
136 0           my $configure_ac = require_configure_ac;
137 0           push @ARGV, $configure_ac;
138             }
139             }
140              
141              
142              
143             # ----------------- #
144             # Autoconf macros. #
145             # ----------------- #
146              
147 1         3 my (%ac_macros, %au_macros, %m4_builtins);
148              
149             # HANDLE_AUTOCONF_MACROS ()
150             # -------------------------
151             # @M4_BUILTINS -- M4 builtins and a useful comment.
152             sub handle_autoconf_macros ()
153             {
154             # Get the builtins.
155 0     0     xsystem ("echo dumpdef | $m4 2>" . shell_quote ("$tmp/m4.defs") . " >/dev/null");
156 0           my $m4_defs = new Autom4te::XFile ("$tmp/m4.defs", "<");
157 0           while ($_ = $m4_defs->getline)
158             {
159 0 0         $m4_builtins{$1} = 1
160             if /^(\w+):/;
161             }
162 0           $m4_defs->close;
163              
164 0           my $macros = new Autom4te::XFile ("$autoconf"
165             . " --trace AU_DEFINE:'AU:\$f:\$1'"
166             . " --trace define:'AC:\$f:\$1'"
167             . " --melt /dev/null |");
168 0           while ($_ = $macros->getline)
169             {
170 0           chomp;
171 0 0         my ($domain, $file, $macro) = /^(AC|AU):(.*):([^:]*)$/ or next;
172 0 0         if ($domain eq "AU")
    0          
173             {
174 0           $au_macros{$macro} = 1;
175             }
176             elsif ($file =~ /(^|\/)m4sugar\/(m4sugar|version)\.m4$/)
177             {
178             # Add the m4sugar macros to m4_builtins.
179 0           $m4_builtins{$macro} = 1;
180             }
181             else
182             {
183             # Autoconf, aclocal, and m4sh macros.
184 0           $ac_macros{$macro} = 1;
185             }
186             }
187 0           $macros->close;
188              
189              
190             # Don't keep AU macros in @AC_MACROS.
191             delete $ac_macros{$_}
192 0           foreach (keys %au_macros);
193             # Don't keep M4sugar macros which are redefined by Autoconf,
194             # such as 'builtin', 'changequote' etc. See autoconf/autoconf.m4.
195             delete $ac_macros{$_}
196 0           foreach (keys %m4_builtins);
197 0 0         error "no current Autoconf macros found"
198             unless keys %ac_macros;
199 0 0         error "no obsolete Autoconf macros found"
200             unless keys %au_macros;
201              
202 0 0         if ($debug)
203             {
204 0           print STDERR "Current Autoconf macros:\n";
205 0           print STDERR join (' ', sort keys %ac_macros) . "\n\n";
206 0           print STDERR "Obsolete Autoconf macros:\n";
207 0           print STDERR join (' ', sort keys %au_macros) . "\n\n";
208             }
209              
210             # ac.m4 -- autoquoting definitions of the AC macros (M4sugar excluded).
211             # unac.m4 -- undefine the AC macros.
212 0           my $ac_m4 = new Autom4te::XFile ("$tmp/ac.m4", ">");
213 0           print $ac_m4 "# ac.m4 -- autoquoting definitions of the AC macros.\n";
214 0           my $unac_m4 = new Autom4te::XFile ("$tmp/unac.m4", ">");
215 0           print $unac_m4 "# unac.m4 -- undefine the AC macros.\n";
216 0           foreach (sort keys %ac_macros)
217             {
218 0           print $ac_m4 "_au_m4_define([$_], [m4_if(\$#, 0, [[\$0]], [[\$0(\$\@)]])])\n";
219 0           print $unac_m4 "_au_m4_undefine([$_])\n";
220             }
221              
222             # m4save.m4 -- save the m4 builtins.
223             # unm4.m4 -- disable the m4 builtins.
224             # m4.m4 -- enable the m4 builtins.
225 0           my $m4save_m4 = new Autom4te::XFile ("$tmp/m4save.m4", ">");
226 0           print $m4save_m4 "# m4save.m4 -- save the m4 builtins.\n";
227 0           my $unm4_m4 = new Autom4te::XFile ("$tmp/unm4.m4", ">");
228 0           print $unm4_m4 "# unm4.m4 -- disable the m4 builtins.\n";
229 0           my $m4_m4 = new Autom4te::XFile ("$tmp/m4.m4", ">");
230 0           print $m4_m4 "# m4.m4 -- enable the m4 builtins.\n";
231 0           foreach (sort keys %m4_builtins)
232             {
233 0           print $m4save_m4 "_au__save([$_])\n";
234 0           print $unm4_m4 "_au__undefine([$_])\n";
235 0           print $m4_m4 "_au__restore([$_])\n";
236             }
237             }
238              
239              
240             ## -------------- ##
241             ## Main program. ##
242             ## -------------- ##
243              
244 1         4 parse_args;
245 0 0       0 $autoconf .= " --debug" if $debug;
246 0 0       0 $autoconf .= " --force" if $force;
247 0 0       0 $autoconf .= " --verbose" if $verbose;
248 0         0 $autoconf .= join (' --include=', '', map { shell_quote ($_) } @include);
  0         0  
249 0         0 $autoconf .= join (' --prepend-include=', '', map { shell_quote ($_) } @prepend_include);
  0         0  
250              
251             # Disable all warnings from autoconf invocations.
252             # In particular we do not want warnings about obsolete constructs,
253             # which are on by default as of autoconf 2.70.
254 0         0 $ENV{'WARNINGS'} = 'none';
255              
256 0         0 mktmpdir ('au');
257 0         0 handle_autoconf_macros;
258              
259             # $au_changequote -- enable the quote '[', ']' right before any AU macro.
260 0         0 my $au_changequote =
261             's/\b(' . join ('|', keys %au_macros) . ')\b/_au_m4_changequote([,])$1/g';
262              
263             # au.m4 -- definitions the AU macros.
264 0         0 xsystem ("$autoconf --trace AU_DEFINE:'_au_defun(\@<:\@\$1\@:>\@,
265             \@<:\@\$2\@:>\@)' --melt /dev/null "
266             . ">" . shell_quote ("$tmp/au.m4"));
267              
268              
269              
270             ## ------------------- ##
271             ## Process the files. ##
272             ## ------------------- ##
273              
274 0         0 foreach my $file (@ARGV)
275             {
276             # We need an actual file.
277 0 0       0 if ($file eq '-')
    0          
278             {
279 0         0 $file = "$tmp/stdin";
280 0         0 system "cat >" . shell_quote ($file);
281             }
282             elsif (! -r "$file")
283             {
284 0         0 die "$me: $file: No such file or directory";
285             }
286              
287             # input.m4 -- m4 program to produce the updated file.
288             # Load the values, the dispatcher, neutralize m4, and the prepared
289             # input file.
290 0         0 my $input_m4 = <<\EOF;
291             divert(-1) -*- Autoconf -*-
292             changequote([,])
293              
294             # Define our special macros:
295             define([_au__defn], defn([defn]))
296             define([_au__divert], defn([divert]))
297             define([_au__ifdef], defn([ifdef]))
298             define([_au__include], defn([include]))
299             define([_au___undefine], defn([undefine]))
300             define([_au__undefine], [_au__ifdef([$1], [_au___undefine([$1])])])
301             define([_au__save], [m4_ifdef([$1],
302             [m4_define([_au_$1], _m4_defn([$1]))])])
303             define([_au__restore],
304             [_au_m4_ifdef([_au_$1],
305             [_au_m4_define([$1], _au__defn([_au_$1]))])])
306              
307             # Set up m4sugar.
308             include(m4sugar/m4sugar.m4)
309              
310             # Redefine __file__ to make warnings nicer; $file is replaced below.
311             m4_define([__file__], [$file])
312              
313             # Redefine m4_location to fix the line number.
314             m4_define([m4_location], [__file__:m4_eval(__line__ - _au__first_line)])
315              
316             # Move all the builtins into the '_au_' pseudo namespace
317             m4_include([m4save.m4])
318              
319             # _au_defun(NAME, BODY)
320             # ---------------------
321             # Define NAME to BODY, plus AU activation/deactivation.
322             _au_m4_define([_au_defun],
323             [_au_m4_define([$1],
324             [_au_enable()dnl
325             $2[]dnl
326             _au_disable()])])
327              
328             # Import the definition of the obsolete macros.
329             _au__include([au.m4])
330              
331              
332             ## ------------------------ ##
333             ## _au_enable/_au_disable. ##
334             ## ------------------------ ##
335              
336             # They work by pair: each time an AU macro is activated, it runs
337             # _au_enable, and at its end its runs _au_disable (see _au_defun
338             # above). AU macros might use AU macros, which should
339             # enable/disable only for the outer AU macros.
340             #
341             # '_au_enabled' is used to this end, determining whether we really
342             # enable/disable.
343              
344              
345             # __au_enable
346             # -----------
347             # Reenable the builtins, m4sugar, and the autoquoting AC macros.
348             _au_m4_define([__au_enable],
349             [_au__divert(-1)
350             # Enable special characters.
351             _au_m4_changecom([#])
352              
353             _au__include([m4.m4])
354             _au__include([ac.m4])
355              
356             _au__divert(0)])
357              
358             # _au_enable
359             # ----------
360             # Called at the beginning of all the obsolete macros. If this is the
361             # outermost level, call __au_enable.
362             _au_m4_define([_au_enable],
363             [_au_m4_ifdef([_au_enabled],
364             [],
365             [__au_enable()])_au_dnl
366             _au_m4_pushdef([_au_enabled])])
367              
368              
369             # __au_disable
370             # ------------
371             # Disable the AC autoquoting macros, m4sugar, and m4.
372             _au_m4_define([__au_disable],
373             [_au__divert(-1)
374             _au__include([unac.m4])
375             _au__include([unm4.m4])
376              
377             # Disable special characters.
378             _au_m4_changequote()
379             _au_m4_changecom()
380              
381             _au__divert(0)])
382              
383             # _au_disable
384             # -----------
385             # Called at the end of all the obsolete macros. If we are at the
386             # outermost level, call __au_disable.
387             _au_m4_define([_au_disable],
388             [_au_m4_popdef([_au_enabled])_au_dnl
389             _au_m4_ifdef([_au_enabled],
390             [],
391             [__au_disable()])])
392              
393              
394             ## ------------------------------- ##
395             ## Disable, and process the file. ##
396             ## ------------------------------- ##
397             # The AC autoquoting macros are not loaded yet, hence invoking
398             # '_au_disable' would be wrong.
399             _au__include([unm4.m4])
400              
401             # Disable special characters, and set the first line number.
402             _au_m4_changequote()
403             _au_m4_changecom()
404              
405             _au_m4_define(_au__first_line, _au___line__)_au__divert(0)_au_dnl
406             EOF
407              
408 0         0 $input_m4 =~ s/^ //mg;
409 0         0 $input_m4 =~ s/\$file/$file/g;
410              
411             # prepared input -- input, but reenables the quote before each AU macro.
412 0 0       0 open INPUT_M4, ">", "$tmp/input.m4"
413             or error "cannot open: $!";
414 0 0       0 open FILE, "<", $file
415             or error "cannot open: $!";
416 0         0 print INPUT_M4 "$input_m4";
417 0         0 while ()
418             {
419 0         0 eval $au_changequote;
420 0         0 print INPUT_M4;
421             }
422 0 0       0 close FILE
423             or error "cannot close $file: $!";
424 0 0       0 close INPUT_M4
425             or error "cannot close $tmp/input.m4: $!";
426              
427             # Now ask m4 to perform the update.
428             xsystem ("$m4 --include=" . shell_quote ($tmp)
429 0         0 . join (' --include=', '', map { shell_quote ($_) } reverse (@prepend_include))
430 0         0 . join (' --include=', '', map { shell_quote ($_) } @include)
  0         0  
431             . " " . shell_quote ("$tmp/input.m4") . " > " . shell_quote ("$tmp/updated"));
432 0 0       0 update_file ("$tmp/updated",
433             "$file" eq "$tmp/stdin" ? '-' : "$file");
434             }
435 0         0 exit 0;
436              
437              
438             # ## ---------------------------- ##
439             # ## How 'autoupdate' functions. ##
440             # ## ---------------------------- ##
441             #
442             # The task of 'autoupdate' is not trivial: the biggest difficulty being
443             # that you must limit the changes to the parts that really need to be
444             # updated. Finding a satisfying implementation proved to be quite hard,
445             # as this is the fifth implementation of 'autoupdate'.
446             #
447             # Below, we will use a simple example of an obsolete macro:
448             #
449             # AU_DEFUN([OLD], [NEW([$1, $2], m4_eval([$1 + $2]))])
450             # AC_DEFUN([NEW], [echo "sum($1) = $2"])
451             #
452             # the input file contains
453             #
454             # dnl The Unbelievable Truth
455             # OLD(1, 2)
456             # NEW([0, 0], [0])
457             #
458             # Of course the expected output is
459             #
460             # dnl The Unbelievable Truth
461             # NEW([1, 2], [3])
462             # NEW([0, 0], [0])
463             #
464             #
465             # # First implementation: sed
466             # # =========================
467             #
468             # The first implementation was only able to change the name of obsolete
469             # macros.
470             #
471             # The file 'acoldnames.m4' defined the old names based on the new names.
472             # It was simple then to produce a sed script such as:
473             #
474             # s/OLD/NEW/g
475             #
476             # Updating merely consisted in running this script on the file to
477             # update.
478             #
479             # This scheme suffers from an obvious limitation: that 'autoupdate' was
480             # unable to cope with new macros that just swap some of its arguments
481             # compared to the old macro. Fortunately, that was enough to upgrade
482             # from Autoconf 1 to Autoconf 2. (But I have no idea whether the
483             # changes in Autoconf 2 were precisely limited by this constraint.)
484             #
485             #
486             # # Second implementation: hooks
487             # # ============================
488             #
489             # The version 2.15 of Autoconf brought a vast number of changes compared
490             # to 2.13, so a solution was needed. One could think of extending the
491             # 'sed' scripts with specialized code for complex macros. However, this
492             # approach is of course full of flaws:
493             #
494             # a. the Autoconf maintainers have to write these snippets, which we
495             # just don't want to,
496             #
497             # b. I really don't think you'll ever manage to handle the quoting of
498             # m4 with a sed script.
499             #
500             # To satisfy a., let's remark that the code which implements the old
501             # features in term of the new feature is exactly the code which should
502             # replace the old code.
503             #
504             # To answer point b, as usual in the history of Autoconf, the answer, at
505             # least on the paper, is simple: m4 is the best tool to parse m4, so
506             # let's use m4.
507             #
508             # Therefore the specification is:
509             #
510             # I want to be able to tell Autoconf, well, m4, that the macro I
511             # am currently defining is an obsolete macro (so that the user is
512             # warned), and its code is the code to use when running autoconf,
513             # but that the very same code has to be used when running
514             # autoupdate. To summarize, the interface I want is
515             # 'AU_DEFUN(OLD-NAME, NEW-CODE)'.
516             #
517             #
518             # Now for the technical details.
519             #
520             # When running autoconf, except for the warning, AU_DEFUN is basically
521             # AC_DEFUN.
522             #
523             # When running autoupdate, we want *only* OLD-NAMEs to be expanded.
524             # This obviously means that acgeneral.m4 and acspecific.m4 must not be
525             # loaded. Nonetheless, because we want to use a rich set of m4
526             # features, m4sugar.m4 is needed. Please note that the fact that
527             # Autoconf's macros are not loaded is positive on two points:
528             #
529             # - we do get an updated 'configure.ac', not a 'configure'!
530             #
531             # - the old macros are replaced by *calls* to the new-macros, not the
532             # body of the new macros, since their body is not defined!!!
533             # (Whoa, that's really beautiful!).
534             #
535             # Additionally we need to disable the quotes when reading the input for
536             # two reasons: first because otherwise 'm4' will swallow the quotes of
537             # other macros:
538             #
539             # NEW([1, 2], 3)
540             # => NEW(1, 2, 3)
541             #
542             # and second, because we want to update the macro calls which are
543             # quoted, i.e., we want
544             #
545             # FOO([OLD(1, 2)])
546             # => FOO([NEW([1, 2], [3])])
547             #
548             # If we don't disable the quotes, only the macros called at the top
549             # level would be updated.
550             #
551             # So, let's disable the quotes.
552             #
553             # Well, not quite: m4sugar.m4 still needs to use quotes for some macros.
554             # Well, in this case, when running in autoupdate code, each macro first
555             # reestablishes the quotes, expands itself, and disables the quotes.
556             #
557             # Thinking a bit more, you realize that in fact, people may use 'define',
558             # 'ifelse' etc. in their files, and you certainly don't want to process
559             # them. Another example is 'dnl': you don't want to remove the
560             # comments. You then realize you don't want exactly to import m4sugar:
561             # you want to specify when it is enabled (macros active), and disabled.
562             # m4sugar provides m4_disable/m4_enable to this end.
563             #
564             # You're getting close to it. Now remains one task: how to handle
565             # twofold definitions?
566             #
567             # Remember that the same AU_DEFUN must be understood in two different
568             # ways, the AC way, and the AU way.
569             #
570             # One first solution is to check whether acgeneral.m4 was loaded. But
571             # that's definitely not cute. Another is simply to install 'hooks',
572             # that is to say, to keep in some place m4 knows, late 'define' to be
573             # triggered *only* in AU mode.
574             #
575             # You first think of designing AU_DEFUN like this:
576             #
577             # 1. AC_DEFUN(OLD-NAME,
578             # [Warn the user OLD-NAME is obsolete.
579             # NEW-CODE])
580             #
581             # 2. Store for late AU binding([define(OLD_NAME,
582             # [Reestablish the quotes.
583             # NEW-CODE
584             # Disable the quotes.])])
585             #
586             # but this will not work: NEW-CODE probably uses $1, $2 etc. and these
587             # guys will be replaced with the argument of 'Store for late AU binding'
588             # when you call it.
589             #
590             # I don't think there is a means to avoid this using this technology
591             # (remember that $1 etc. are *always* expanded in m4). You may also try
592             # to replace them with $[1] to preserve them for a later evaluation, but
593             # if 'Store for late AU binding' is properly written, it will remain
594             # quoted till the end...
595             #
596             # You have to change technology. Since the problem is that '$1'
597             # etc. should be 'consumed' right away, one solution is to define now a
598             # second macro, 'AU_OLD-NAME', and to install a hook than binds OLD-NAME
599             # to AU_OLD-NAME. Then, autoupdate.m4 just need to run the hooks. By
600             # the way, the same method was used in autoheader.
601             #
602             #
603             # # Third implementation: m4 namespaces by m4sugar
604             # # ==============================================
605             #
606             # Actually, this implementation was just a clean up of the previous
607             # implementation: instead of defining hooks by hand, m4sugar was equipped
608             # with 'namespaces'. What are they?
609             #
610             # Sometimes we want to disable some *set* of macros, and restore them
611             # later. We provide support for this via namespaces.
612             #
613             # There are basically three characters playing this scene: defining a
614             # macro in a namespace, disabling a namespace, and restoring a namespace
615             # (i.e., all the definitions it holds).
616             #
617             # Technically, to define a MACRO in NAMESPACE means to define the macro
618             # named 'NAMESPACE::MACRO' to the VALUE. At the same time, we append
619             # 'undefine(NAME)' in the macro named 'm4_disable(NAMESPACE)', and
620             # similarly a binding of NAME to the value of 'NAMESPACE::MACRO' in
621             # 'm4_enable(NAMESPACE)'. These mechanisms allow to bind the macro of
622             # NAMESPACE and to unbind them at will.
623             #
624             # Of course this implementation is really inefficient: m4 has to grow
625             # strings which can become quickly huge, which slows it significantly.
626             #
627             # In particular one should avoid as much as possible to use 'define' for
628             # temporaries. Now that 'define' has quite a complex meaning, it is an
629             # expensive operations that should be limited to macros. Use
630             # 'm4_define' for temporaries.
631             #
632             # Private copies of the macros we used in entering / exiting the m4sugar
633             # namespace. It is much more convenient than fighting with the renamed
634             # version of define etc.
635             #
636             #
637             #
638             # Those two implementations suffered from serious problems:
639             #
640             # - namespaces were really expensive, and incurred a major performance
641             # loss on 'autoconf' itself, not only 'autoupdate'. One solution
642             # would have been the limit the use of namespaces to 'autoupdate', but
643             # that's again some complications on m4sugar, which really doesn't need
644             # this. So we wanted to get rid of the namespaces.
645             #
646             # - since the quotes were disabled, autoupdate was sometimes making
647             # wrong guesses, for instance on:
648             #
649             # foo([1, 2])
650             #
651             # m4 saw 2 arguments: '[1'and '2]'. A simple solution, somewhat
652             # fragile, is to reestablish the quotes right before all the obsolete
653             # macros, i.e., to use sed so that the previous text becomes
654             #
655             # changequote([, ])foo([1, 2])
656             #
657             # To this end, one wants to trace the definition of obsolete macros.
658             #
659             # It was there that the limitations of the namespace approach became
660             # painful: because it was a complex machinery playing a lot with the
661             # builtins of m4 (hence, quite fragile), tracing was almost impossible.
662             #
663             #
664             # So this approach was dropped.
665             #
666             #
667             # # The fourth implementation: two steps
668             # # ====================================
669             #
670             # If you drop the uses of namespaces, you no longer can compute the
671             # updated value, and replace the old call with it simultaneously.
672             #
673             # Obviously you will use m4 to compute the updated values, but you may
674             # use some other tool to achieve the replacement. Personally, I trust
675             # nobody but m4 to parse m4, so below, m4 will perform the two tasks.
676             #
677             # How can m4 be used to replace *some* macros calls with newer values.
678             # Well, that's dead simple: m4 should learn the definitions of obsolete
679             # macros, forget its builtins, disable the quotes, and then run on the
680             # input file, which amounts to doing this:
681             #
682             # divert(-1)dnl
683             # changequote([, ])
684             # define([OLD], [NEW([$1, $2], m4_eval([$1 + $2]))changequote()])
685             # undefine([dnl])
686             # undefine([m4_eval])
687             # # Some more undefines...
688             # changequote()
689             # divert(0)dnl
690             # dnl The Unbelievable Truth
691             # changequote([, ])OLD(1, 2)
692             # NEW([0, 0],
693             # 0)
694             #
695             # which will result in
696             #
697             # dnl The Unbelievable Truth
698             # NEW(1, 2, m4_eval(1 + 2))
699             # NEW([0, 0],
700             # 0)
701             #
702             # Grpmh. Two problems. A minor problem: it would have been much better
703             # to have the 'm4_eval' computed, and a major problem: you lost the
704             # quotation in the result.
705             #
706             # Let's address the big problem first. One solution is to define any
707             # modern macro to rewrite its calls with the proper quotation, thanks to
708             # '$@'. Again, tracing the 'define's makes it possible to know which
709             # are these macros, so you input is:
710             #
711             # divert(-1)dnl
712             # changequote([, ])
713             # define([OLD], [NEW([$1, $2], m4_eval([$1 + $2]))changequote()])
714             # define([NEW], [[NEW($@)]changequote()])
715             # undefine([dnl])
716             # undefine([m4_eval])
717             # # Some more undefines...
718             # changequote()
719             # divert(0)dnl
720             # dnl The Unbelievable Truth
721             # changequote([, ])OLD(1, 2)
722             # changequote([, ])NEW([0, 0],
723             # 0)
724             #
725             # which results in
726             #
727             # dnl The Unbelievable Truth
728             # NEW([1, 2],[m4_eval(1 + 2)])
729             # NEW([0, 0],[0])
730             #
731             # Our problem is solved, i.e., the first call to 'NEW' is properly
732             # quoted, but introduced another problem: we changed the layout of the
733             # second calls, which can be a drama in the case of huge macro calls
734             # (think of 'AC_TRY_RUN' for instance). This example didn't show it,
735             # but we also introduced parens to macros which did not have some:
736             #
737             # AC_INIT
738             # => AC_INIT()
739             #
740             # No big deal for the semantics (unless the macro depends upon $#, which
741             # is bad), but the users would not be happy.
742             #
743             # Additionally, we introduced quotes that were not there before, which is
744             # OK in most cases, but could change the semantics of the file.
745             #
746             # Cruel dilemma: we do want the auto-quoting definition of 'NEW' when
747             # evaluating 'OLD', but we don't when we evaluate the second 'NEW'.
748             # Back to namespaces?
749             #
750             # No.
751             #
752             #
753             # # Second step: replacement
754             # # ------------------------
755             #
756             # No, as announced above, we will work in two steps: in a first step we
757             # compute the updated values, and in a second step we replace them. Our
758             # goal is something like this:
759             #
760             # divert(-1)dnl
761             # changequote([, ])
762             # define([OLD], [NEW([1, 2], [3])changequote()])
763             # undefine([dnl])
764             # undefine([m4_eval])
765             # # Some more undefines...
766             # changequote()
767             # divert(0)dnl
768             # dnl The Unbelievable Truth
769             # changequote([, ])OLD(1, 2)
770             # NEW([0, 0],
771             # 0)
772             #
773             # i.e., the new value of 'OLD' is precomputed using the auto-quoting
774             # definition of 'NEW' and the m4 builtins. We'll see how afterwards,
775             # let's finish with the replacement.
776             #
777             # Of course the solution above is wrong: if there were other calls to
778             # 'OLD' with different values, we would smash them to the same value.
779             # But it is quite easy to generalize the scheme above:
780             #
781             # divert(-1)dnl
782             # changequote([, ])
783             # define([OLD([1],[2])], [NEW([1, 2], [3])])
784             # define([OLD], [defn([OLD($@)])changequote()])
785             # undefine([dnl])
786             # undefine([m4_eval])
787             # # Some more undefines...
788             # changequote()
789             # divert(0)dnl
790             # dnl The Unbelievable Truth
791             # changequote([, ])OLD(1, 2)
792             # NEW([0, 0],
793             # 0)
794             #
795             # i.e., for each call to obsolete macros, we build an array 'call =>
796             # value', and use a macro to dispatch these values. This results in:
797             #
798             # dnl The Unbelievable Truth
799             # NEW([1, 2], [3])
800             # NEW([0, 0],
801             # 0)
802             #
803             # In French, we say 'Youpi !', which you might roughly translate as
804             # 'Yippee!'.
805             #
806             #
807             # # First step: computation
808             # # -----------------------
809             #
810             # Let's study the anatomy of the file, and name its sections:
811             #
812             # prologue
813             # divert(-1)dnl
814             # changequote([, ])
815             # values
816             # define([OLD([1],[2])], [NEW([1, 2], [3])])
817             # dispatcher
818             # define([OLD], [defn([OLD($@)])changequote()])
819             # disabler
820             # undefine([dnl])
821             # undefine([m4_eval])
822             # # Some more undefines...
823             # changequote()
824             # divert(0)dnl
825             # input
826             # dnl The Unbelievable Truth
827             # changequote([, ])OLD(1, 2)
828             # NEW([0, 0],
829             # 0)
830             #
831             #
832             # # Computing the 'values' section
833             # # ..............................
834             #
835             # First we need to get the list of all the AU macro uses. To this end,
836             # first get the list of all the AU macros names by tracing 'AU_DEFUN' in
837             # the initialization of autoconf. This list is computed in the file
838             # 'au.txt' below.
839             #
840             # Then use this list to trace all the AU macro uses in the input. The
841             # goal is obtain in the case of our example:
842             #
843             # [define([OLD([1],[2])],]@<<@OLD([1],[2])@>>@[)]
844             #
845             # This is the file 'values.in' below.
846             #
847             # We want to evaluate this with only the builtins (in fact m4sugar), the
848             # auto-quoting definitions of the new macros ('new.m4'), and the
849             # definition of the old macros ('old.m4'). Computing these last two
850             # files is easy: it's just a matter of using the right '--trace' option.
851             #
852             # So the content of 'values.in' is:
853             #
854             # include($autoconf_dir/m4sugar.m4)
855             # m4_include(new.m4)
856             # m4_include(old.m4)
857             # divert(0)dnl
858             # [define([OLD([1],[2])],]@<<@OLD([1],[2])@>>@[)]
859             #
860             # We run m4 on it, which yields:
861             #
862             # define([OLD([1],[2])],@<<@NEW([1, 2], [3])@>>@)
863             #
864             # Transform '@<<@' and '@>>@' into quotes and we get
865             #
866             # define([OLD([1],[2])],[NEW([1, 2], [3])])
867             #
868             # This is 'values.m4'.
869             #
870             #
871             # # Computing the 'dispatcher' section
872             # # ..................................
873             #
874             # The 'prologue', and the 'disabler' are simple and need no commenting.
875             #
876             # To compute the 'dispatcher' ('dispatch.m4'), again, it is a simple
877             # matter of using the right '--trace'.
878             #
879             # Finally, the input is not exactly the input file, rather it is the
880             # input file with the added 'changequote'. To this end, we build
881             # 'quote.sed'.
882             #
883             #
884             # # Putting it all together
885             # # .......................
886             #
887             # We build the file 'input.m4' which contains:
888             #
889             # divert(-1)dnl
890             # changequote([, ])
891             # include(values.m4)
892             # include(dispatch.m4)
893             # undefine([dnl])
894             # undefine([eval])
895             # # Some more undefines...
896             # changequote()
897             # divert(0)dnl
898             # dnl The Unbelievable Truth
899             # changequote([, ])OLD(1, 2)
900             # NEW([0, 0],
901             # 0)
902             #
903             # And we just run m4 on it. Et voilĂ , Monsieur ! Mais oui, mais oui.
904             #
905             # Well, there are a few additional technicalities. For instance, we
906             # rely on 'changequote', 'ifelse' and 'defn', but we don't want to
907             # interpret the changequotes of the user, so we simply use another name:
908             # '_au_changequote' etc.
909             #
910             #
911             # # Failure of the fourth approach
912             # # ------------------------------
913             #
914             # This approach is heavily based on traces, but then there is an obvious
915             # problem: non expanded code will never be seen. In particular, the body
916             # of a 'define' definition is not seen, so on the input
917             #
918             # define([idem], [OLD(0, [$1])])
919             #
920             # autoupdate would never see the 'OLD', and wouldn't have updated it.
921             # Worse yet, if 'idem(0)' was used later, then autoupdate sees that
922             # 'OLD' is used, computes the result for 'OLD(0, 0)' and sets up a
923             # dispatcher for 'OLD'. Since there was no computed value for 'OLD(0,
924             # [$1])', the dispatcher would have replaced with... nothing, leading
925             # to
926             #
927             # define([idem], [])
928             #
929             # With some more thinking, you see that the two step approach is wrong,
930             # the namespace approach was much saner.
931             #
932             # But you learned a lot, in particular you realized that using traces
933             # can make it possible to simulate namespaces!
934             #
935             #
936             #
937             # # The fifth implementation: m4 namespaces by files
938             # # ================================================
939             #
940             # The fourth implementation demonstrated something unsurprising: you
941             # cannot precompute, i.e., the namespace approach was the right one.
942             # Still, we no longer want them, they're too expensive. Let's have a
943             # look at the way it worked.
944             #
945             # When updating
946             #
947             # dnl The Unbelievable Truth
948             # OLD(1, 2)
949             # NEW([0, 0], [0])
950             #
951             # you evaluate 'input.m4':
952             #
953             # divert(-1)
954             # changequote([, ])
955             # define([OLD],
956             # [m4_enable()NEW([$1, $2], m4_eval([$1 + $2]))m4_disable()])
957             # ...
958             # m4_disable()
959             # dnl The Unbelievable Truth
960             # OLD(1, 2)
961             # NEW([0, 0], [0])
962             #
963             # where 'm4_disable' undefines the m4 and m4sugar, and disables the quotes
964             # and comments:
965             #
966             # define([m4_disable],
967             # [undefine([__file__])
968             # ...
969             # changecom(#)
970             # changequote()])
971             #
972             # 'm4_enable' does the converse: reestablish quotes and comments
973             # --easy--, reestablish m4sugar --easy: just load 'm4sugar.m4' again-- and
974             # reenable the builtins. This later task requires that you first save
975             # the builtins. And BTW, the definition above of 'm4_disable' cannot
976             # work: you undefined 'changequote' before using it! So you need to use
977             # your privates copies of the builtins. Let's introduce three files for
978             # this:
979             #
980             # 'm4save.m4'
981             # moves the m4 builtins into the '_au_' pseudo namespace,
982             # 'unm4.m4'
983             # undefines the builtins,
984             # 'm4.m4'
985             # restores them.
986             #
987             # So 'input.m4' is:
988             #
989             # divert(-1)
990             # changequote([, ])
991             #
992             # include([m4save.m4])
993             #
994             # # Import AU.
995             # define([OLD],
996             # [m4_enable()NEW([$1, $2], m4_eval([$1 + $2]))m4_disable()])
997             #
998             # define([_au_enable],
999             # [_au_changecom([#])
1000             # _au_include([m4.m4])
1001             # _au_include(m4sugar.m4)])
1002             #
1003             # define([_au_disable],
1004             # [# Disable m4sugar.
1005             # # Disable the m4 builtins.
1006             # _au_include([unm4.m4])
1007             # # 1. Disable special characters.
1008             # _au_changequote()
1009             # _au_changecom()])
1010             #
1011             # m4_disable()
1012             # dnl The Unbelievable Truth
1013             # OLD(1, 2)
1014             # NEW([0, 0], [0])
1015             #
1016             # Based on what we learned in the fourth implementation we know that we
1017             # have to enable the quotes *before* any AU macro, and we know we need
1018             # to build autoquoting versions of the AC macros. But the autoquoting
1019             # AC definitions must be disabled in the rest of the file, and enabled
1020             # inside AU macros.
1021             #
1022             # Using 'autoconf --trace' it is easy to build the files
1023             #
1024             # 'ac.m4'
1025             # define the autoquoting AC fake macros
1026             # 'disable.m4'
1027             # undefine the m4sugar and AC autoquoting macros.
1028             # 'au.m4'
1029             # definitions of the AU macros (such as 'OLD' above).
1030             #
1031             # Now, 'input.m4' is:
1032             #
1033             # divert(-1)
1034             # changequote([, ])
1035             #
1036             # include([m4save.m4])
1037             # # Import AU.
1038             # include([au.m4])
1039             #
1040             # define([_au_enable],
1041             # [_au_changecom([#])
1042             # _au_include([m4.m4])
1043             # _au_include(m4sugar.m4)
1044             # _au_include(ac.m4)])
1045             #
1046             # define([_au_disable],
1047             # [_au_include([disable.m4])
1048             # _au_include([unm4.m4])
1049             # # 1. Disable special characters.
1050             # _au_changequote()
1051             # _au_changecom()])
1052             #
1053             # m4_disable()
1054             # dnl The Unbelievable Truth
1055             # _au_changequote([, ])OLD(1, 2)
1056             # NEW([0, 0], [0])
1057             #
1058             # Finally, version V is ready.
1059             #
1060             # Well... almost.
1061             #
1062             # There is a slight problem that remains: if an AU macro OUTER includes
1063             # an AU macro INNER, then _au_enable will be run when entering OUTER
1064             # and when entering INNER (not good, but not too bad yet). But when
1065             # getting out of INNER, _au_disable will disable everything while we
1066             # were still in OUTER. Badaboom.
1067             #
1068             # Therefore _au_enable and _au_disable have to be written to work by
1069             # pairs: each _au_enable pushdef's _au_enabled, and each _au_disable
1070             # popdef's _au_enabled. And of course _au_enable and _au_disable are
1071             # effective when _au_enabled is *not* defined.
1072             #
1073             # Finally, version V' is ready. And there is much rejoicing. (And I
1074             # have free time again. I think. Yeah, right.)
1075              
1076             ### Setup "GNU" style for perl-mode and cperl-mode.
1077             ## Local Variables:
1078             ## perl-indent-level: 2
1079             ## perl-continued-statement-offset: 2
1080             ## perl-continued-brace-offset: 0
1081             ## perl-brace-offset: 0
1082             ## perl-brace-imaginary-offset: 0
1083             ## perl-label-offset: -2
1084             ## cperl-indent-level: 2
1085             ## cperl-brace-offset: 0
1086             ## cperl-continued-brace-offset: 0
1087             ## cperl-label-offset: -2
1088             ## cperl-extra-newline-before-brace: t
1089             ## cperl-merge-trailing-else: nil
1090             ## cperl-continued-statement-offset: 2
1091             ## End: