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